2 Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /** @file src/ffmpeg_decoder.h
21 * @brief A decoder using FFmpeg to decode content.
27 #include <boost/shared_ptr.hpp>
28 #include <boost/optional.hpp>
29 #include <boost/thread/mutex.hpp>
31 #include <libavcodec/avcodec.h>
32 #include <libpostproc/postprocess.h>
36 #include "video_decoder.h"
37 #include "audio_decoder.h"
41 struct AVCodecContext;
42 struct AVFilterContext;
43 struct AVFormatContext;
45 struct AVBufferContext;
53 class FFmpegAudioStream : public AudioStream
56 FFmpegAudioStream (std::string n, int i, int s, int64_t c)
62 std::string to_string () const;
64 std::string name () const {
72 static boost::shared_ptr<FFmpegAudioStream> create (std::string t, boost::optional<int> v);
75 friend class stream_test;
77 FFmpegAudioStream (std::string t, boost::optional<int> v);
83 /** @class FFmpegDecoder
84 * @brief A decoder using FFmpeg to decode content.
86 class FFmpegDecoder : public VideoDecoder, public AudioDecoder
89 FFmpegDecoder (boost::shared_ptr<Film>, DecodeOptions);
92 float frames_per_second () const;
93 libdcp::Size native_size () const;
94 SourceFrame length () const;
95 int time_base_numerator () const;
96 int time_base_denominator () const;
97 int sample_aspect_ratio_numerator () const;
98 int sample_aspect_ratio_denominator () const;
100 void set_audio_stream (boost::shared_ptr<AudioStream>);
101 void set_subtitle_stream (boost::shared_ptr<SubtitleStream>);
104 bool seek_to_last ();
105 void seek_forward ();
110 /* No copy construction */
111 FFmpegDecoder (FFmpegDecoder const &);
114 bool do_seek (double p, bool, bool);
115 PixelFormat pixel_format () const;
116 AVSampleFormat audio_sample_format () const;
117 int bytes_per_audio_sample () const;
119 void filter_and_emit_video ();
121 void setup_general ();
124 void setup_subtitle ();
126 void decode_audio_packet ();
128 void maybe_add_subtitle ();
129 boost::shared_ptr<AudioBuffers> deinterleave_audio (uint8_t** data, int size);
131 void film_changed (Film::Property);
133 std::string stream_name (AVStream* s) const;
135 AVFormatContext* _format_context;
140 AVCodecContext* _video_codec_context;
141 AVCodec* _video_codec;
142 AVCodecContext* _audio_codec_context; ///< may be 0 if there is no audio
143 AVCodec* _audio_codec; ///< may be 0 if there is no audio
144 AVCodecContext* _subtitle_codec_context; ///< may be 0 if there is no subtitle
145 AVCodec* _subtitle_codec; ///< may be 0 if there is no subtitle
149 std::list<boost::shared_ptr<FilterGraph> > _filter_graphs;
150 boost::mutex _filter_graphs_mutex;
152 static boost::mutex _mutex;