40ccb9793e57290d971253ec38c6164255fc2f6b
[dcpomatic.git] / src / lib / ffmpeg_decoder.h
1 /*
2     Copyright (C) 2012-2016 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/ffmpeg_decoder.h
21  *  @brief A decoder using FFmpeg to decode content.
22  */
23
24 #include "util.h"
25 #include "decoder.h"
26 #include "ffmpeg.h"
27 extern "C" {
28 #include <libavcodec/avcodec.h>
29 }
30 #include <boost/shared_ptr.hpp>
31 #include <boost/thread/mutex.hpp>
32 #include <stdint.h>
33
34 class Log;
35 class VideoFilterGraph;
36 class FFmpegAudioStream;
37 class AudioBuffers;
38 struct ffmpeg_pts_offset_test;
39
40 /** @class FFmpegDecoder
41  *  @brief A decoder using FFmpeg to decode content.
42  */
43 class FFmpegDecoder : public FFmpeg, public Decoder
44 {
45 public:
46         FFmpegDecoder (boost::shared_ptr<const FFmpegContent>, boost::shared_ptr<Log>, bool fast);
47
48 private:
49         friend struct ::ffmpeg_pts_offset_test;
50
51         bool pass (PassReason, bool accurate);
52         void seek (ContentTime time, bool);
53         void flush ();
54
55         AVSampleFormat audio_sample_format (boost::shared_ptr<FFmpegAudioStream> stream) const;
56         int bytes_per_audio_sample (boost::shared_ptr<FFmpegAudioStream> stream) const;
57
58         bool decode_video_packet ();
59         void decode_audio_packet ();
60         void decode_subtitle_packet ();
61
62         void decode_bitmap_subtitle (AVSubtitleRect const * rect, ContentTimePeriod period);
63         void decode_ass_subtitle (std::string ass, ContentTimePeriod period);
64
65         void maybe_add_subtitle ();
66         boost::shared_ptr<AudioBuffers> deinterleave_audio (boost::shared_ptr<FFmpegAudioStream> stream) const;
67
68         std::list<ContentTimePeriod> image_subtitles_during (ContentTimePeriod, bool starting) const;
69         std::list<ContentTimePeriod> text_subtitles_during (ContentTimePeriod, bool starting) const;
70
71         boost::shared_ptr<Log> _log;
72
73         std::list<boost::shared_ptr<VideoFilterGraph> > _filter_graphs;
74         boost::mutex _filter_graphs_mutex;
75
76         ContentTime _pts_offset;
77 };