, _video_stream (-1)
{
setup_general ();
- setup_video ();
- setup_audio ();
+ setup_decoders ();
}
FFmpeg::~FFmpeg ()
}
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
{
, _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:
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 ()
{