Untested; extend CompactImage to return a AVPicture.
[dcpomatic.git] / src / lib / decoder.h
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 /** @file  src/decoder.h
21  *  @brief Parent class for decoders of content.
22  */
23
24 #ifndef DVDOMATIC_DECODER_H
25 #define DVDOMATIC_DECODER_H
26
27 #include <vector>
28 #include <string>
29 #include <stdint.h>
30 #include <boost/shared_ptr.hpp>
31 #include <boost/signals2.hpp>
32 #include "util.h"
33 #include "stream.h"
34 #include "video_source.h"
35 #include "audio_source.h"
36
37 class Job;
38 class Options;
39 class Image;
40 class Log;
41 class DelayLine;
42 class TimedSubtitle;
43 class Subtitle;
44 class Film;
45 class FilterGraph;
46
47 /** @class Decoder.
48  *  @brief Parent class for decoders of content.
49  *
50  *  These classes can be instructed run through their content
51  *  (by calling ::go), and they emit signals when video or audio data is ready for something else
52  *  to process.
53  */
54 class Decoder : public VideoSource, public AudioSource
55 {
56 public:
57         Decoder (boost::shared_ptr<Film>, boost::shared_ptr<const Options>, Job *);
58         virtual ~Decoder () {}
59
60         /* Methods to query our input video */
61
62         /** @return video frames per second, or 0 if unknown */
63         virtual float frames_per_second () const = 0;
64         /** @return native size in pixels */
65         virtual Size native_size () const = 0;
66
67         virtual int time_base_numerator () const = 0;
68         virtual int time_base_denominator () const = 0;
69         virtual int sample_aspect_ratio_numerator () const = 0;
70         virtual int sample_aspect_ratio_denominator () const = 0;
71         
72         virtual bool pass () = 0;
73         void go ();
74
75         SourceFrame video_frame () const {
76                 return _video_frame;
77         }
78
79         virtual void set_audio_stream (boost::optional<AudioStream>);
80         virtual void set_subtitle_stream (boost::optional<SubtitleStream>);
81
82         boost::optional<AudioStream> audio_stream () const {
83                 return _audio_stream;
84         }
85
86         boost::optional<SubtitleStream> subtitle_stream () const {
87                 return _subtitle_stream;
88         }
89
90         std::vector<AudioStream> audio_streams () const {
91                 return _audio_streams;
92         }
93         
94         std::vector<SubtitleStream> subtitle_streams () const {
95                 return _subtitle_streams;
96         }
97
98 protected:
99         
100         virtual PixelFormat pixel_format () const = 0;
101         
102         void process_video (AVFrame const *);
103         void process_audio (boost::shared_ptr<AudioBuffers>);
104         void process_subtitle (boost::shared_ptr<TimedSubtitle>);
105         void repeat_last_video ();
106
107         /** our Film */
108         boost::shared_ptr<Film> _film;
109         /** our options */
110         boost::shared_ptr<const Options> _opt;
111         /** associated Job, or 0 */
112         Job* _job;
113
114         boost::optional<AudioStream> _audio_stream;
115         boost::optional<SubtitleStream> _subtitle_stream;
116
117         std::vector<AudioStream> _audio_streams;
118         std::vector<SubtitleStream> _subtitle_streams;
119         
120 private:
121         void emit_video (boost::shared_ptr<Image>, boost::shared_ptr<Subtitle>);
122
123         SourceFrame _video_frame;
124
125         std::list<boost::shared_ptr<FilterGraph> > _filter_graphs;
126
127         boost::shared_ptr<TimedSubtitle> _timed_subtitle;
128
129         boost::shared_ptr<Image> _last_image;
130         boost::shared_ptr<Subtitle> _last_subtitle;
131 };
132
133 #endif