Cleanup: white space.
[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
22 /** @file  src/ffmpeg_decoder.h
23  *  @brief A decoder using FFmpeg to decode content.
24  */
25
26
27 #include "bitmap_text.h"
28 #include "decoder.h"
29 #include "ffmpeg.h"
30 #include "video_filter_graph_set.h"
31 #include "util.h"
32 extern "C" {
33 #include <libavcodec/avcodec.h>
34 }
35 #include <boost/thread/mutex.hpp>
36 #include <stdint.h>
37
38
39 class AudioBuffers;
40 class FFmpegAudioStream;
41 class Image;
42 class Log;
43 class VideoFilterGraph;
44 struct ffmpeg_pts_offset_test;
45
46
47 /** @class FFmpegDecoder
48  *  @brief A decoder using FFmpeg to decode content.
49  */
50 class FFmpegDecoder : public FFmpeg, public Decoder
51 {
52 public:
53         FFmpegDecoder (std::shared_ptr<const Film> film, std::shared_ptr<const FFmpegContent>, bool fast);
54
55         bool pass () override;
56         void seek (dcpomatic::ContentTime time, bool) override;
57
58 private:
59         friend struct ::ffmpeg_pts_offset_test;
60
61         enum class FlushResult {
62                 DONE,
63                 AGAIN
64         };
65
66         FlushResult flush();
67
68         AVSampleFormat audio_sample_format (std::shared_ptr<FFmpegAudioStream> stream) const;
69         int bytes_per_audio_sample (std::shared_ptr<FFmpegAudioStream> stream) const;
70
71         std::shared_ptr<FFmpegAudioStream> audio_stream_from_index (int index) const;
72         void process_audio_frame (std::shared_ptr<FFmpegAudioStream> stream);
73
74         void process_video_frame ();
75
76         bool decode_and_process_video_packet (AVPacket* packet);
77         void decode_and_process_audio_packet (AVPacket* packet);
78         void decode_and_process_subtitle_packet (AVPacket* packet);
79
80         BitmapText process_bitmap_subtitle (AVSubtitleRect const * rect);
81         void process_ass_subtitle (std::string ass, dcpomatic::ContentTime from);
82
83         void maybe_add_subtitle ();
84
85         FlushResult flush_codecs();
86         FlushResult flush_fill();
87
88         VideoFilterGraphSet _filter_graphs;
89
90         dcpomatic::ContentTime _pts_offset;
91         boost::optional<dcpomatic::ContentTime> _current_subtitle_to;
92         /** true if we have a subtitle which has not had emit_stop called for it yet */
93         bool _have_current_subtitle = false;
94
95         std::shared_ptr<Image> _black_image;
96
97         std::map<std::shared_ptr<FFmpegAudioStream>, boost::optional<dcpomatic::ContentTime>> _next_time;
98
99         enum class FlushState {
100                 CODECS,
101                 AUDIO_DECODER,
102                 FILL,
103         };
104
105         FlushState _flush_state = FlushState::CODECS;
106 };