gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash ChangeLog libmedia/ffmpeg/VideoDecoderFfm...


From: Bastiaan Jacques
Subject: [Gnash-commit] gnash ChangeLog libmedia/ffmpeg/VideoDecoderFfm...
Date: Mon, 25 Feb 2008 00:06:07 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Bastiaan Jacques <bjacques>     08/02/25 00:06:07

Modified files:
        .              : ChangeLog 
        libmedia/ffmpeg: VideoDecoderFfmpeg.cpp VideoDecoderFfmpeg.h 
        server/asobj   : NetStreamFfmpeg.cpp 

Log message:
                * libmedia/ffmpeg/VideoDecoderFfmpeg.{cpp,h}: Fix up 
convertRGB24 so
                that it no longer touches the source frame and enforce that with
                constness.
                * server/asobj/NetStreamFfmpeg.cpp: Update to match the changes 
to
                convertRGB24.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.5737&r2=1.5738
http://cvs.savannah.gnu.org/viewcvs/gnash/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp?cvsroot=gnash&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/gnash/libmedia/ffmpeg/VideoDecoderFfmpeg.h?cvsroot=gnash&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/NetStreamFfmpeg.cpp?cvsroot=gnash&r1=1.106&r2=1.107

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.5737
retrieving revision 1.5738
diff -u -b -r1.5737 -r1.5738
--- ChangeLog   24 Feb 2008 19:21:11 -0000      1.5737
+++ ChangeLog   25 Feb 2008 00:06:06 -0000      1.5738
@@ -1,5 +1,13 @@
 2008-02-24 Bastiaan Jacques <address@hidden>
 
+       * libmedia/ffmpeg/VideoDecoderFfmpeg.{cpp,h}: Fix up convertRGB24 so
+       that it no longer touches the source frame and enforce that with
+       constness.
+       * server/asobj/NetStreamFfmpeg.cpp: Update to match the changes to
+       convertRGB24.
+
+2008-02-24 Bastiaan Jacques <address@hidden>
+
        * libmedia/ffmpeg/VideoDecoderFfmpeg.{cpp,h}: Cleanup; remove unused
        methods and code. Avoid unnecessary memcpy calls. Tabs to spaces.
        * server/parser/video_stream_def.{cpp,h}: Mutex-protect the video

Index: libmedia/ffmpeg/VideoDecoderFfmpeg.cpp
===================================================================
RCS file: /sources/gnash/gnash/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- libmedia/ffmpeg/VideoDecoderFfmpeg.cpp      24 Feb 2008 19:21:12 -0000      
1.4
+++ libmedia/ffmpeg/VideoDecoderFfmpeg.cpp      25 Feb 2008 00:06:07 -0000      
1.5
@@ -17,7 +17,7 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 //
 
-// $Id: VideoDecoderFfmpeg.cpp,v 1.4 2008/02/24 19:21:12 bjacques Exp $
+// $Id: VideoDecoderFfmpeg.cpp,v 1.5 2008/02/25 00:06:07 bjacques Exp $
 
 #include "VideoDecoderFfmpeg.h"
 
@@ -97,35 +97,32 @@
   }
 }
 
-
-// FIXME: this method modifies srcFrame, which is a big nono for a method
-//        that's supposed to return a new buffer. the second argument should
-//        be const and this method should return AVPicture.
-boost::uint8_t*
-VideoDecoderFfmpeg::convertRGB24(AVCodecContext* srcCtx, AVFrame* srcFrame)
+AVPicture /*static*/
+VideoDecoderFfmpeg::convertRGB24(AVCodecContext* srcCtx,
+                                 const AVFrame& srcFrame)
 {
+  AVPicture picture;
   int width = srcCtx->width, height = srcCtx->height;
 
+  picture.data[0] = NULL;
+  
   int bufsize = avpicture_get_size(PIX_FMT_RGB24, width, height);
   if (bufsize == -1) {
-    return NULL;
+    return picture;
   }
 
   boost::uint8_t* buffer = new boost::uint8_t[bufsize];
 
-  AVPicture picture;
-
   avpicture_fill(&picture, buffer, PIX_FMT_RGB24, width, height);
 
 #ifndef HAVE_SWSCALE_H
-  img_convert(&picture, PIX_FMT_RGB24, (AVPicture*) srcFrame,
+  img_convert(&picture, PIX_FMT_RGB24, (AVPicture*) &srcFrame,
       srcCtx->pix_fmt, width, height);
 #else
   // FIXME: this will live forever ...
   static struct SwsContext* context = NULL;
 
-  if (!context)
-  {
+  if (!context) {
     // FIXME: this leads to wrong results (read: segfaults) if this method
     //        is called from two unrelated video contexts, for example from
     //        a NetStreamFfmpeg and an embedded video context. Or two
@@ -134,30 +131,22 @@
            width, height, PIX_FMT_RGB24,
            SWS_FAST_BILINEAR, NULL, NULL, NULL);
     
-    if (!context)
-    {
+    if (!context) {
       delete [] buffer;
-      return NULL;
+      return picture;
     }
   }
 
-  int rv = sws_scale( 
-    context, srcFrame->data, srcFrame->linesize, 0, height, 
-    picture.data, picture.linesize 
-  );
+  int rv = sws_scale(context, const_cast<uint8_t**>(srcFrame.data),
+    const_cast<int*>(srcFrame.linesize), 0, height, picture.data,
+    picture.linesize);
 
-  if (rv == -1)
-  {
+  if (rv == -1) {
     delete [] buffer;
-    return NULL;
   }
 
 #endif // HAVE_SWSCALE_H
-
-  srcFrame->linesize[0] = picture.linesize[0];
-  srcFrame->data[0] = picture.data[0];
-
-  return buffer;
+  return picture;
 }
 
 std::auto_ptr<image::rgb>
@@ -180,12 +169,10 @@
     return ret;
   }
 
-  boost::uint8_t* decodedData = convertRGB24(_videoCodecCtx, frame);
-  
-  ret.reset(new image::rgb(decodedData, _videoCodecCtx->width,
-                           _videoCodecCtx->height, frame->linesize[0]));
+  AVPicture rgbpicture = convertRGB24(_videoCodecCtx, *frame);
 
-  frame->data[0] = NULL;
+  ret.reset(new image::rgb(rgbpicture.data[0], _videoCodecCtx->width,
+                           _videoCodecCtx->height, rgbpicture.linesize[0]));
 
   // FIXME: av_free doesn't free frame->data!
   av_free(frame);

Index: libmedia/ffmpeg/VideoDecoderFfmpeg.h
===================================================================
RCS file: /sources/gnash/gnash/libmedia/ffmpeg/VideoDecoderFfmpeg.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- libmedia/ffmpeg/VideoDecoderFfmpeg.h        24 Feb 2008 19:21:12 -0000      
1.4
+++ libmedia/ffmpeg/VideoDecoderFfmpeg.h        25 Feb 2008 00:06:07 -0000      
1.5
@@ -16,7 +16,7 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
-// $Id: VideoDecoderFfmpeg.h,v 1.4 2008/02/24 19:21:12 bjacques Exp $
+// $Id: VideoDecoderFfmpeg.h,v 1.5 2008/02/25 00:06:07 bjacques Exp $
 
 #ifndef __VIDEODECODERFFMPEG_H__
 #define __VIDEODECODERFFMPEG_H__
@@ -49,7 +49,17 @@
   
   bool peek();
   
-  static boost::uint8_t* convertRGB24(AVCodecContext* srcCtx, AVFrame* 
srcFrame);
+  
+  /// \brief converts an video frame from (almost) any type to RGB24.
+  ///
+  /// @param srcCtx The source context that was used to decode srcFrame.
+  /// @param srcFrame the source frame to be converted.
+  /// @return an AVPicture containing the converted image. Please be advised
+  ///         that the RGB data pointer is stored in AVPicture::data[0]. The
+  ///         caller owns that pointer, which must be freed with delete [].
+  ///         It is advised to wrap the pointer in a boost::scoped_array.
+  ///         If conversion fails, AVPicture::data[0] will be NULL.
+  static AVPicture convertRGB24(AVCodecContext* srcCtx, const AVFrame& 
srcFrame);
 
 private:
 

Index: server/asobj/NetStreamFfmpeg.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/NetStreamFfmpeg.cpp,v
retrieving revision 1.106
retrieving revision 1.107
diff -u -b -r1.106 -r1.107
--- server/asobj/NetStreamFfmpeg.cpp    22 Feb 2008 14:20:48 -0000      1.106
+++ server/asobj/NetStreamFfmpeg.cpp    25 Feb 2008 00:06:07 -0000      1.107
@@ -17,7 +17,7 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 //
 
-/* $Id: NetStreamFfmpeg.cpp,v 1.106 2008/02/22 14:20:48 strk Exp $ */
+/* $Id: NetStreamFfmpeg.cpp,v 1.107 2008/02/25 00:06:07 bjacques Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "gnashconfig.h"
@@ -892,8 +892,6 @@
        avcodec_decode_video(m_VCodecCtx, m_Frame, &got, packet->data, 
packet->size);
        if (got)
        {
-               boost::scoped_array<boost::uint8_t> buffer;
-
                if (m_imageframe == NULL)
                {
                        if (m_videoFrameFormat == render::YUV)
@@ -906,6 +904,8 @@
                        }
                }
 
+               AVPicture rgbpicture;
+
                if (m_videoFrameFormat == render::NONE)
                {
                        // NullGui?
@@ -921,7 +921,10 @@
                }
                else if (m_videoFrameFormat == render::RGB && 
m_VCodecCtx->pix_fmt != PIX_FMT_RGB24)
                {
-                       
buffer.reset(media::VideoDecoderFfmpeg::convertRGB24(m_VCodecCtx, m_Frame));
+                       rgbpicture = 
media::VideoDecoderFfmpeg::convertRGB24(m_VCodecCtx, *m_Frame);
+                       if (!rgbpicture.data[0]) {
+                               return false;
+                       }
                }
 
                media::raw_mediadata_t* video = new media::raw_mediadata_t();
@@ -991,9 +994,17 @@
                }
                else if (m_videoFrameFormat == render::RGB)
                {
+                       AVPicture* src;
+                       if (m_VCodecCtx->pix_fmt != PIX_FMT_RGB24)
+                       {
+                               src = &rgbpicture;
+                       } else
+                       {
+                               src = (AVPicture*) m_Frame;
+                       }
 
-                       boost::uint8_t* srcptr = m_Frame->data[0];
-                       boost::uint8_t* srcend = m_Frame->data[0] + 
m_Frame->linesize[0] * m_VCodecCtx->height;
+                       boost::uint8_t* srcptr = src->data[0];            
+                       boost::uint8_t* srcend = srcptr + 
rgbpicture.linesize[0] * m_VCodecCtx->height;
                        boost::uint8_t* dstptr = video->m_data;
                        unsigned int srcwidth = m_VCodecCtx->width * 3;
 
@@ -1001,11 +1012,15 @@
 
                        while (srcptr < srcend) {
                                memcpy(dstptr, srcptr, srcwidth);
-                               srcptr += m_Frame->linesize[0];
+                               srcptr += src->linesize[0];
                                dstptr += srcwidth;
                                video->m_size += srcwidth;
                        }
 
+                       if (m_VCodecCtx->pix_fmt != PIX_FMT_RGB24) {
+                               delete [] rgbpicture.data[0];
+                       }
+
                }
 
                if (m_isFLV) m_qvideo.push(video);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]