Tidying.
[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 "decoder.h"
28 #include "ffmpeg.h"
29 #include "util.h"
30 extern "C" {
31 #include <libavcodec/avcodec.h>
32 }
33 #include <boost/thread/mutex.hpp>
34 #include <stdint.h>
35
36
37 class AudioBuffers;
38 class FFmpegAudioStream;
39 class Image;
40 class Log;
41 class VideoFilterGraph;
42 struct ffmpeg_pts_offset_test;
43
44
45 /** @class FFmpegDecoder
46  *  @brief A decoder using FFmpeg to decode content.
47  */
48 class FFmpegDecoder : public FFmpeg, public Decoder
49 {
50 public:
51         FFmpegDecoder (std::shared_ptr<const Film> film, std::shared_ptr<const FFmpegContent>, bool fast);
52
53         bool pass () override;
54         void seek (dcpomatic::ContentTime time, bool) override;
55
56 private:
57         friend struct ::ffmpeg_pts_offset_test;
58
59         bool flush ();
60
61         static std::shared_ptr<AudioBuffers> deinterleave_audio (AVFrame* frame);
62
63         AVSampleFormat audio_sample_format (std::shared_ptr<FFmpegAudioStream> stream) const;
64         int bytes_per_audio_sample (std::shared_ptr<FFmpegAudioStream> stream) const;
65
66         std::shared_ptr<FFmpegAudioStream> audio_stream_from_index (int index) const;
67         void process_audio_frame (std::shared_ptr<FFmpegAudioStream> stream);
68
69         void process_video_frame ();
70
71         bool decode_and_process_video_packet (AVPacket* packet);
72         void decode_and_process_audio_packet (AVPacket* packet);
73         void decode_and_process_subtitle_packet (AVPacket* packet);
74
75         void process_bitmap_subtitle (AVSubtitleRect const * rect, dcpomatic::ContentTime from);
76         void process_ass_subtitle (std::string ass, dcpomatic::ContentTime from);
77
78         void maybe_add_subtitle ();
79
80         std::list<std::shared_ptr<VideoFilterGraph>> _filter_graphs;
81         boost::mutex _filter_graphs_mutex;
82
83         dcpomatic::ContentTime _pts_offset;
84         boost::optional<dcpomatic::ContentTime> _current_subtitle_to;
85         /** true if we have a subtitle which has not had emit_stop called for it yet */
86         bool _have_current_subtitle = false;
87
88         std::shared_ptr<Image> _black_image;
89
90         std::map<std::shared_ptr<FFmpegAudioStream>, boost::optional<dcpomatic::ContentTime>> _next_time;
91 };