Basic grunt-work, untested and unfinished, but it compiles.
[dcpomatic.git] / src / lib / ffmpeg_decoder.h
1 /*
2     Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 /** @file  src/ffmpeg_decoder.h
22  *  @brief A decoder using FFmpeg to decode content.
23  */
24
25 #include "util.h"
26 #include "decoder.h"
27 #include "ffmpeg.h"
28 extern "C" {
29 #include <libavcodec/avcodec.h>
30 }
31 #include <boost/shared_ptr.hpp>
32 #include <boost/thread/mutex.hpp>
33 #include <stdint.h>
34
35 class Log;
36 class VideoFilterGraph;
37 class FFmpegAudioStream;
38 class AudioBuffers;
39 struct ffmpeg_pts_offset_test;
40
41 /** @class FFmpegDecoder
42  *  @brief A decoder using FFmpeg to decode content.
43  */
44 class FFmpegDecoder : public FFmpeg, public Decoder
45 {
46 public:
47         FFmpegDecoder (boost::shared_ptr<const FFmpegContent>, boost::shared_ptr<Log>);
48
49         void pass ();
50         void seek (ContentTime time, bool);
51
52 private:
53         friend struct ::ffmpeg_pts_offset_test;
54
55         void flush ();
56
57         AVSampleFormat audio_sample_format (boost::shared_ptr<FFmpegAudioStream> stream) const;
58         int bytes_per_audio_sample (boost::shared_ptr<FFmpegAudioStream> stream) const;
59
60         bool decode_video_packet ();
61         void decode_audio_packet ();
62         void decode_subtitle_packet ();
63
64         void decode_bitmap_subtitle (AVSubtitleRect const * rect, ContentTimePeriod period);
65         void decode_ass_subtitle (std::string ass, ContentTimePeriod period);
66
67         void maybe_add_subtitle ();
68         boost::shared_ptr<AudioBuffers> deinterleave_audio (boost::shared_ptr<FFmpegAudioStream> stream) const;
69
70         boost::shared_ptr<Log> _log;
71
72         std::list<boost::shared_ptr<VideoFilterGraph> > _filter_graphs;
73         boost::mutex _filter_graphs_mutex;
74
75         ContentTime _pts_offset;
76 };