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: Sun, 24 Feb 2008 19:21:13 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Bastiaan Jacques <bjacques>     08/02/24 19:21:12

Modified files:
        .              : ChangeLog 
        libmedia/ffmpeg: VideoDecoderFfmpeg.cpp VideoDecoderFfmpeg.h 
        server/parser  : video_stream_def.cpp video_stream_def.h 

Log message:
                * 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 
                frames vector, because video_stream_def's methods are called 
from 
                both the "loading thread" (parser) and the main execution 
thread 
                (rendering).

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.5736&r2=1.5737
http://cvs.savannah.gnu.org/viewcvs/gnash/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp?cvsroot=gnash&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/gnash/libmedia/ffmpeg/VideoDecoderFfmpeg.h?cvsroot=gnash&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/gnash/server/parser/video_stream_def.cpp?cvsroot=gnash&r1=1.41&r2=1.42
http://cvs.savannah.gnu.org/viewcvs/gnash/server/parser/video_stream_def.h?cvsroot=gnash&r1=1.24&r2=1.25

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.5736
retrieving revision 1.5737
diff -u -b -r1.5736 -r1.5737
--- ChangeLog   24 Feb 2008 11:03:07 -0000      1.5736
+++ ChangeLog   24 Feb 2008 19:21:11 -0000      1.5737
@@ -1,3 +1,12 @@
+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
+       frames vector, because video_stream_def's methods are called from
+       both the "loading thread" (parser) and the main execution thread
+       (rendering).
+
 2008-02-24 Benjamin Wolsey <address@hidden>
 
        * server/character.{h,cpp}: define all static const data members outside

Index: libmedia/ffmpeg/VideoDecoderFfmpeg.cpp
===================================================================
RCS file: /sources/gnash/gnash/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- libmedia/ffmpeg/VideoDecoderFfmpeg.cpp      23 Feb 2008 18:12:51 -0000      
1.3
+++ libmedia/ffmpeg/VideoDecoderFfmpeg.cpp      24 Feb 2008 19:21:12 -0000      
1.4
@@ -17,7 +17,7 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 //
 
-// $Id: VideoDecoderFfmpeg.cpp,v 1.3 2008/02/23 18:12:51 bjacques Exp $
+// $Id: VideoDecoderFfmpeg.cpp,v 1.4 2008/02/24 19:21:12 bjacques Exp $
 
 #include "VideoDecoderFfmpeg.h"
 
@@ -98,69 +98,9 @@
 }
 
 
-bool VideoDecoderFfmpeg::setup(VideoInfo* info)
-{
-       // Init the avdecoder-decoder
-       avcodec_init();
-       avcodec_register_all();// change this to only register need codec?
-
-       if (info->type == FLASH) {
-               enum CodecID codec_id;
-
-               // Find the decoder and init the parser
-               switch(info->codec) {
-                       case VIDEO_CODEC_H263:
-                               codec_id = CODEC_ID_FLV1;
-                               break;
-#ifdef FFMPEG_VP6
-                       case VIDEO_CODEC_VP6:
-                               codec_id = CODEC_ID_VP6F;
-                               break;
-#endif
-                       case VIDEO_CODEC_SCREENVIDEO:
-                               codec_id = CODEC_ID_FLASHSV;
-                               break;
-                       default:
-                               log_error(_("Unsupported video codec %d"),
-                                               static_cast<int>(info->codec));
-                               return false;
-               }
-               _videoCodec = 
avcodec_find_decoder(static_cast<CodecID>(codec_id));
-       } else if (info->type == FFMPEG) {
-               _videoCodec = 
avcodec_find_decoder(static_cast<CodecID>(info->codec));
-       } else {
-               //log_error("Video codecType unknown: %d, %d, %d",
-               //                              info->type, FLASH, FFMPEG);
-               return false;
-       }
-
-       if (!_videoCodec) {
-               log_error(_("libavcodec can't decode the current video 
format"));
-               return false;
-       }
-
-       // Reuse the videoCodecCtx from the ffmpeg parser if exists/possible
-       if (info->videoCodecCtx) {
-               log_debug("re-using the parsers videoCodecCtx");
-               _videoCodecCtx = info->videoCodecCtx;
-       } else {
-               _videoCodecCtx = avcodec_alloc_context();
-       }
-
-       if (!_videoCodecCtx) {
-               log_error(_("libavcodec couldn't allocate context"));
-               return false;
-       }
-
-       int ret = avcodec_open(_videoCodecCtx, _videoCodec);
-       if (ret < 0) {
-               log_error(_("libavcodec failed to initialize codec"));
-               return false;
-       }
-
-       return true;
-}
-
+// 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)
 {
@@ -172,9 +112,6 @@
        }
 
        boost::uint8_t* buffer = new boost::uint8_t[bufsize];
-       if (!buffer) {
-               return NULL;
-       }
 
        AVPicture picture;
 
@@ -184,10 +121,15 @@
        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)
        {
+    // 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
+    //        separate instances of one of the former two.    
                context = sws_getContext(width, height, srcCtx->pix_fmt,
                                         width, height, PIX_FMT_RGB24,
                                         SWS_FAST_BILINEAR, NULL, NULL, NULL);
@@ -218,149 +160,36 @@
        return buffer;
 }
 
-boost::uint8_t* VideoDecoderFfmpeg::decode(boost::uint8_t* input,
-                               boost::uint32_t inputSize,
-                               boost::uint32_t& outputSize)
+std::auto_ptr<image::rgb>
+VideoDecoderFfmpeg::decode(boost::uint8_t* input, boost::uint32_t input_size)
 {
-       // Allocate a frame to store the decoded frame in
+  std::auto_ptr<image::rgb> ret;
+
        AVFrame* frame = avcodec_alloc_frame();
-       if ( ! frame )
-       {
+  if ( ! frame ) {
                log_error(_("Out of memory while allocating avcodec frame"));
-               throw std::bad_alloc();
+    return ret;
        }
 
-       int got = 0;
-       
-       avcodec_decode_video(_videoCodecCtx, frame, &got, input, inputSize);
-       
-       if (got)
-       {
-               boost::scoped_array<boost::uint8_t> buffer;
-               
-               // Set to the next multiple of four. Some videos have
-               // padding bytes, so that the source width is more than three 
times
-               // the video width. A likely explanation (supported by
-               // tests) is that it is always padded out to a multiple of 4.
-               // Have found no documenation on this.
-               unsigned int srcwidth = (_videoCodecCtx->width * 3 + 3) &~ 3; 
-
-               boost::uint8_t* decodedData = new boost::uint8_t[srcwidth * 
_videoCodecCtx->height];
-
-               buffer.reset(convertRGB24(_videoCodecCtx, frame));
-
-               // Copy the data to the buffer in the correct RGB format
-               boost::uint8_t* srcptr = frame->data[0];
-               boost::uint8_t* srcend = frame->data[0]
-                                       + frame->linesize[0]
-                                       * _videoCodecCtx->height;
-               boost::uint8_t* dstptr = decodedData;
-
-               outputSize = 0;
-
-               while (srcptr < srcend)
-               {
-                       memcpy(dstptr, srcptr, srcwidth);
-                       srcptr += frame->linesize[0];
-                       dstptr += srcwidth;
-                       outputSize += srcwidth;
-               }
+  int bytes = 0;  
+  avcodec_decode_video(_videoCodecCtx, frame, &bytes, input, input_size);
 
+  if (!bytes) {
+    log_error("Decoding of a video frame failed");
                av_free(frame);
-               return decodedData;
-
-/*             if (_videoFrameFormat == NONE) { // NullGui?
-                       return;
-
-               } else if (_videoFrameFormat == YUV && _videoCodecCtx->pix_fmt 
!= PIX_FMT_YUV420P) {
-                       abort();        // TODO
-                       //img_convert((AVPicture*) pFrameYUV, PIX_FMT_YUV420P, 
(AVPicture*) pFrame, pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height);
-                       // Don't use depreceted img_convert, use sws_scale
-
-               } else if (_videoFrameFormat == RGB && _videoCodecCtx->pix_fmt 
!= PIX_FMT_RGB24) {
-                       buffer.reset(convertRGB24(_videoCodecCtx, frame));
-               }
-
-               raw_mediadata_t* video = new raw_mediadata_t;
-               if (_videoFrameFormat == YUV) {
-                       abort(); // See image.cpp to see what yuv size is
-                       //video->m_data = new 
boost::uint8_t[static_cast<image::yuv*>(m_imageframe)->size()];
-               } else if (_videoFrameFormat == RGB) {
-                       video->m_data = new 
boost::uint8_t[_videoCodecCtx->width * _videoCodecCtx->height * 3];
-               //}
-
-               video->m_ptr = video->m_data;
-               video->m_stream_index = _videoIndex;
-               video->m_pts = 0;
-
-               video->m_pts = 
static_cast<boost::uint32_t>((as_double(_videoStream->time_base) * packet->dts) 
* 1000.0);
-
-
-               if (_videoFrameFormat == YUV) {
-                       //image::yuv* yuvframe = 
static_cast<image::yuv*>(_imageframe);
-                       int copied = 0;
-                       boost::uint8_t* ptr = video->m_data;
-                       for (int i = 0; i < 3 ; i++)
-                       {
-                               int shift = (i == 0 ? 0 : 1);
-                               boost::uint8_t* yuv_factor = _frame->data[i];
-                               int h = _videoCodecCtx->height >> shift;
-                               int w = _videoCodecCtx->width >> shift;
-                               for (int j = 0; j < h; j++)
-                               {
-                                       copied += w;
-                                       //assert(copied <= yuvframe->size());
-                                       memcpy(ptr, yuv_factor, w);
-                                       yuv_factor += _frame->linesize[i];
-                                       ptr += w;
-                               }
+    return ret;
                        }
-                       video->m_size = copied;
-               } else if (_videoFrameFormat == RGB) {
 
-                       boost::uint8_t* srcptr = _frame->data[0];
-                       boost::uint8_t* srcend = _frame->data[0] + 
_frame->linesize[0] * _videoCodecCtx->height;
-                       boost::uint8_t* dstptr = video->m_data;
-                       unsigned int srcwidth = _videoCodecCtx->width * 3;
+  boost::uint8_t* decodedData = convertRGB24(_videoCodecCtx, frame);
 
-                       video->m_size = 0;
+  ret.reset(new image::rgb(decodedData, _videoCodecCtx->width,
+                           _videoCodecCtx->height, frame->linesize[0]));
 
-                       while (srcptr < srcend) {
-                               memcpy(dstptr, srcptr, srcwidth);
-                               srcptr += _frame->linesize[0];
-                               dstptr += srcwidth;
-                               video->m_size += srcwidth;
-                       }
+  frame->data[0] = NULL;
 
-               }*/
-       }
-       else
-       {
-               log_error("Decoding of a video frame failed");
+  // FIXME: av_free doesn't free frame->data!
                av_free(frame);
-               return NULL;
-       }
-}
-
-std::auto_ptr<image::image_base>
-VideoDecoderFfmpeg::decodeToImage(boost::uint8_t* input, boost::uint32_t 
inputSize)
-{
-       boost::uint32_t outputSize = 0;
-       boost::uint8_t* decodedData = decode(input, inputSize, outputSize);
-
-       if (!decodedData || outputSize == 0)
-       {
-               return std::auto_ptr<image::image_base>(NULL);
-       }
-
-       std::auto_ptr<image::image_base> ret(new image::rgb(
-                                               _videoCodecCtx->width,
-                                               _videoCodecCtx->height
-                                               ));
-       ret->update(decodedData);
-       delete [] decodedData;
        return ret;
-       
 }
 
 
@@ -377,18 +206,7 @@
   std::auto_ptr<image::rgb> ret;
   
   BOOST_FOREACH(const EncodedVideoFrame* frame, _video_frames) {    
-    size_t output_size = 0;
-    boost::uint8_t* decoded_data = decode(frame->data(), frame->dataSize(),
-                                          output_size);
-    if (!decoded_data || !output_size) {
-      assert(!output_size && !decoded_data);
-      continue; 
-    }
-    
-    image::rgb* newimg = new image::rgb(decoded_data, _videoCodecCtx->width,
-      _videoCodecCtx->height, (_videoCodecCtx->width * 3 + 3) & ~3);
-
-    ret.reset(newimg);
+    ret = decode(frame->data(), frame->dataSize());
   }
   
   _video_frames.clear();

Index: libmedia/ffmpeg/VideoDecoderFfmpeg.h
===================================================================
RCS file: /sources/gnash/gnash/libmedia/ffmpeg/VideoDecoderFfmpeg.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- libmedia/ffmpeg/VideoDecoderFfmpeg.h        23 Feb 2008 18:12:51 -0000      
1.3
+++ libmedia/ffmpeg/VideoDecoderFfmpeg.h        24 Feb 2008 19:21:12 -0000      
1.4
@@ -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.3 2008/02/23 18:12:51 bjacques Exp $
+// $Id: VideoDecoderFfmpeg.h,v 1.4 2008/02/24 19:21:12 bjacques Exp $
 
 #ifndef __VIDEODECODERFFMPEG_H__
 #define __VIDEODECODERFFMPEG_H__
@@ -43,30 +43,22 @@
        VideoDecoderFfmpeg(videoCodecType format, int width, int height);
        ~VideoDecoderFfmpeg();
 
-       virtual unsigned getPaddingBytes() const { return 
FF_INPUT_BUFFER_PADDING_SIZE; }
-
-       bool setup(VideoInfo* info);
-
-
-       boost::uint8_t* decode(boost::uint8_t* input, boost::uint32_t 
inputSize, boost::uint32_t& outputSize);
-
-       std::auto_ptr<image::image_base> decodeToImage(boost::uint8_t* 
/*input*/, boost::uint32_t /*inputSize*/);
-
-       static boost::uint8_t* convertRGB24(AVCodecContext* srcCtx, AVFrame* 
srcFrame);
-       
-       
   void push(const EncodedVideoFrame& buffer);
 
   std::auto_ptr<image::rgb> pop();
   
   bool peek();
 
+  static boost::uint8_t* convertRGB24(AVCodecContext* srcCtx, AVFrame* 
srcFrame);
+
+private:
+
+  std::auto_ptr<image::rgb> decode(boost::uint8_t* input, boost::uint32_t 
input_size);
 private:
 
        AVCodec* _videoCodec;
        AVCodecContext* _videoCodecCtx;
        std::vector<const EncodedVideoFrame*> _video_frames;
-
 };
        
 } // gnash.media namespace 

Index: server/parser/video_stream_def.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/parser/video_stream_def.cpp,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -b -r1.41 -r1.42
--- server/parser/video_stream_def.cpp  23 Feb 2008 18:12:52 -0000      1.41
+++ server/parser/video_stream_def.cpp  24 Feb 2008 19:21:12 -0000      1.42
@@ -16,7 +16,7 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 // 
-// $Id: video_stream_def.cpp,v 1.41 2008/02/23 18:12:52 bjacques Exp $
+// $Id: video_stream_def.cpp,v 1.42 2008/02/24 19:21:12 bjacques Exp $
 
 #include "video_stream_def.h"
 #include "video_stream_instance.h"
@@ -125,6 +125,8 @@
   
   EncodedVideoFrame* frame = new EncodedVideoFrame(buffer, dataSize, frameNum);
 
+       boost::mutex::scoped_lock lock(_video_mutex);
+
        _video_frames.push_back(frame);
 }
 
@@ -145,6 +147,8 @@
 std::auto_ptr<image::image_base>
 video_stream_definition::get_frame_data(boost::uint32_t frameNum)
 {
+       boost::mutex::scoped_lock lock(_video_mutex);
+
        if (_video_frames.empty()) {
                return std::auto_ptr<image::image_base>();
        }

Index: server/parser/video_stream_def.h
===================================================================
RCS file: /sources/gnash/gnash/server/parser/video_stream_def.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -b -r1.24 -r1.25
--- server/parser/video_stream_def.h    23 Feb 2008 18:12:52 -0000      1.24
+++ server/parser/video_stream_def.h    24 Feb 2008 19:21:12 -0000      1.25
@@ -16,7 +16,7 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 // 
-// $Id: video_stream_def.h,v 1.24 2008/02/23 18:12:52 bjacques Exp $
+// $Id: video_stream_def.h,v 1.25 2008/02/24 19:21:12 bjacques Exp $
 
 #ifndef GNASH_VIDEO_STREAM_DEF_H
 #define GNASH_VIDEO_STREAM_DEF_H
@@ -41,11 +41,12 @@
 
 #include "image.h"
 
-#include <map>
 #include <boost/shared_array.hpp>
 #include <boost/shared_ptr.hpp>
 #include <boost/scoped_ptr.hpp> 
 
+#include <boost/thread/mutex.hpp>
+
 namespace gnash {
 
 
@@ -166,6 +167,9 @@
        ///
        typedef std::vector<media::EncodedVideoFrame*> EmbedFrameVec;
 
+       boost::mutex _video_mutex;
+       
+
        EmbedFrameVec _video_frames;
 
        /// Last decoded frame number




reply via email to

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