-}
-
-FFmpegDecoder::~FFmpegDecoder ()
-{
- boost::mutex::scoped_lock lm (_mutex);
-
- if (_audio_codec_context) {
- avcodec_close (_audio_codec_context);
- }
-
- if (_video_codec_context) {
- avcodec_close (_video_codec_context);
- }
-
- if (_subtitle_codec_context) {
- avcodec_close (_subtitle_codec_context);
- }
-
- av_free (_frame);
-
- avformat_close_input (&_format_context);
-}
-
-void
-FFmpegDecoder::setup_general ()
-{
- av_register_all ();
-
- if (avformat_open_input (&_format_context, _film->content_path().c_str(), 0, 0) < 0) {
- throw OpenFileError (_film->content_path ());
- }
-
- if (avformat_find_stream_info (_format_context, 0) < 0) {
- throw DecodeError (_("could not find stream information"));
- }
-
- /* Find video, audio and subtitle streams and choose the first of each */
-
- for (uint32_t i = 0; i < _format_context->nb_streams; ++i) {
- AVStream* s = _format_context->streams[i];
- if (s->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
- _video_stream = i;
- } else if (s->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
-
- /* This is a hack; sometimes it seems that _audio_codec_context->channel_layout isn't set up,
- so bodge it here. No idea why we should have to do this.
- */
-
- if (s->codec->channel_layout == 0) {
- s->codec->channel_layout = av_get_default_channel_layout (s->codec->channels);
- }
-
- _audio_streams.push_back (
- shared_ptr<AudioStream> (
- new FFmpegAudioStream (stream_name (s), i, s->codec->sample_rate, s->codec->channel_layout)
- )
- );
-
- } else if (s->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
- _subtitle_streams.push_back (
- shared_ptr<SubtitleStream> (
- new SubtitleStream (stream_name (s), i)
- )
- );
- }
- }
-
- if (_video_stream < 0) {
- throw DecodeError (N_("could not find video stream"));
- }