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/decoder.h
21 * @brief Parent class for decoders of content.
24 #ifndef DVDOMATIC_DECODER_H
25 #define DVDOMATIC_DECODER_H
30 #include <boost/shared_ptr.hpp>
31 #include <sigc++/sigc++.h>
43 * @brief Parent class for decoders of content.
45 * These classes can be instructed run through their content
46 * (by calling ::go), and they emit signals when video or audio data is ready for something else
52 Decoder (boost::shared_ptr<const FilmState>, boost::shared_ptr<const Options>, Job *, Log *, bool, bool);
55 /* Methods to query our input video */
57 /** @return length in video frames */
58 virtual int length_in_frames () const = 0;
59 /** @return video frames per second, or 0 if unknown */
60 virtual float frames_per_second () const = 0;
61 /** @return native size in pixels */
62 virtual Size native_size () const = 0;
63 /** @return number of audio channels */
64 virtual int audio_channels () const = 0;
65 /** @return audio sampling rate in Hz */
66 virtual int audio_sample_rate () const = 0;
67 /** @return format of audio samples */
68 virtual AVSampleFormat audio_sample_format () const = 0;
69 virtual int64_t audio_channel_layout () const = 0;
70 virtual bool has_subtitles () const = 0;
72 void process_begin ();
77 /** @return the index of the last video frame to be processed */
78 int last_video_frame () const {
82 /** Emitted when a video frame is ready.
83 * First parameter is the frame.
84 * Second parameter is its index within the content.
85 * Third parameter is either 0 or a subtitle that should be on this frame.
87 sigc::signal<void, boost::shared_ptr<Image>, int, boost::shared_ptr<Subtitle> > Video;
89 /** Emitted when some audio data is ready.
90 * First parameter is the interleaved sample data, format is given in the FilmState.
91 * Second parameter is the size of the data.
93 sigc::signal<void, uint8_t *, int> Audio;
96 /** perform a single pass at our content */
97 virtual bool do_pass () = 0;
98 virtual PixelFormat pixel_format () const = 0;
99 virtual int time_base_numerator () const = 0;
100 virtual int time_base_denominator () const = 0;
101 virtual int sample_aspect_ratio_numerator () const = 0;
102 virtual int sample_aspect_ratio_denominator () const = 0;
104 void process_video (AVFrame *);
105 void process_audio (uint8_t *, int);
106 void process_subtitle (boost::shared_ptr<Subtitle>);
109 boost::shared_ptr<const FilmState> _fs;
111 boost::shared_ptr<const Options> _opt;
112 /** associated Job, or 0 */
114 /** log that we can write to */
117 /** true to do the bare minimum of work; just run through the content. Useful for acquiring
118 * accurate frame counts as quickly as possible. This generates no video or audio output.
122 /** ignore_length Ignore the content's claimed length when computing progress */
126 void setup_video_filters ();
128 /** last video frame to be processed */
131 AVFilterContext* _buffer_src_context;
132 AVFilterContext* _buffer_sink_context;
134 bool _have_setup_video_filters;
135 DelayLine* _delay_line;
138 /* Number of audio frames that we have pushed to the encoder
139 (at the DCP sample rate).
141 int64_t _audio_frames_processed;
143 boost::shared_ptr<Subtitle> _subtitle;