Set up all FFmpeg decoders in one method.
authorCarl Hetherington <cth@carlh.net>
Thu, 22 May 2014 14:05:57 +0000 (15:05 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 22 May 2014 14:05:57 +0000 (15:05 +0100)
src/lib/ffmpeg.cc
src/lib/ffmpeg.h
src/lib/ffmpeg_decoder.cc
src/lib/ffmpeg_decoder.h

index 6f66ebbc069793d6a13250e0cf8f7c2d966bd08f..017960f2a26ef46de980c1622a912efa7bfa87af 100644 (file)
@@ -49,8 +49,7 @@ FFmpeg::FFmpeg (boost::shared_ptr<const FFmpegContent> c)
        , _video_stream (-1)
 {
        setup_general ();
-       setup_video ();
-       setup_audio ();
+       setup_decoders ();
 }
 
 FFmpeg::~FFmpeg ()
@@ -145,46 +144,24 @@ FFmpeg::setup_general ()
 }
 
 void
-FFmpeg::setup_video ()
-{
-       boost::mutex::scoped_lock lm (_mutex);
-
-       assert (_video_stream >= 0);
-       AVCodecContext* context = _format_context->streams[_video_stream]->codec;
-       AVCodec* codec = avcodec_find_decoder (context->codec_id);
-
-       if (codec == 0) {
-               throw DecodeError (_("could not find video decoder"));
-       }
-
-       if (avcodec_open2 (context, codec, 0) < 0) {
-               throw DecodeError (N_("could not open video decoder"));
-       }
-}
-
-void
-FFmpeg::setup_audio ()
+FFmpeg::setup_decoders ()
 {
        boost::mutex::scoped_lock lm (_mutex);
 
        for (uint32_t i = 0; i < _format_context->nb_streams; ++i) {
                AVCodecContext* context = _format_context->streams[i]->codec;
-               if (context->codec_type != AVMEDIA_TYPE_AUDIO) {
-                       continue;
-               }
                
                AVCodec* codec = avcodec_find_decoder (context->codec_id);
                if (codec == 0) {
-                       throw DecodeError (_("could not find audio decoder"));
+                       throw DecodeError (N_("could not find decoder"));
                }
                
                if (avcodec_open2 (context, codec, 0) < 0) {
-                       throw DecodeError (N_("could not open audio decoder"));
+                       throw DecodeError (N_("could not open decoder"));
                }
        }
 }
 
-
 AVCodecContext *
 FFmpeg::video_codec_context () const
 {
index 760918437d403dd0624984e31a07fb0bdddff583..1d2c312e6d528c181ec8e5ee3d9ef6c1566bf95f 100644 (file)
@@ -79,8 +79,7 @@ protected:
 
 private:
        void setup_general ();
-       void setup_video ();
-       void setup_audio ();
+       void setup_decoders ();
 };
 
 #endif
index eec70501a11b70ca52e83685cd2d6d1bcf209df5..7d152e4904a32682a8c64f0e84ee4d9470efd280 100644 (file)
@@ -67,8 +67,6 @@ FFmpegDecoder::FFmpegDecoder (shared_ptr<const FFmpegContent> c, shared_ptr<Log>
        , _subtitle_codec_context (0)
        , _subtitle_codec (0)
 {
-       setup_subtitle ();
-
        /* Audio and video frame PTS values may not start with 0.  We want
           to fiddle them so that:
 
@@ -495,33 +493,7 @@ FFmpegDecoder::decode_video_packet ()
 
        return true;
 }
-
        
-void
-FFmpegDecoder::setup_subtitle ()
-{
-       boost::mutex::scoped_lock lm (_mutex);
-       
-       if (!_ffmpeg_content->subtitle_stream()) {
-               return;
-       }
-
-       _subtitle_codec_context = _ffmpeg_content->subtitle_stream()->stream(_format_context)->codec;
-       if (_subtitle_codec_context == 0) {
-               throw DecodeError (N_("could not find subtitle stream"));
-       }
-
-       _subtitle_codec = avcodec_find_decoder (_subtitle_codec_context->codec_id);
-
-       if (_subtitle_codec == 0) {
-               throw DecodeError (N_("could not find subtitle decoder"));
-       }
-       
-       if (avcodec_open2 (_subtitle_codec_context, _subtitle_codec, 0) < 0) {
-               throw DecodeError (N_("could not open subtitle decoder"));
-       }
-}
-
 void
 FFmpegDecoder::decode_subtitle_packet ()
 {
index 2cda8f89d5b6263db0600454369d7732cd893c1f..6006fc08d521b2595d418fbb24138e03e6485ebc 100644 (file)
@@ -57,8 +57,6 @@ private:
        bool pass ();
        void flush ();
 
-       void setup_subtitle ();
-
        AVSampleFormat audio_sample_format () const;
        int bytes_per_audio_sample () const;