2 Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
21 /** @file src/ffmpeg_decoder.h
22 * @brief A decoder using FFmpeg to decode content.
29 #include <libavcodec/avcodec.h>
31 #include <boost/thread/mutex.hpp>
35 class VideoFilterGraph;
36 class FFmpegAudioStream;
39 struct ffmpeg_pts_offset_test;
41 /** @class FFmpegDecoder
42 * @brief A decoder using FFmpeg to decode content.
44 class FFmpegDecoder : public FFmpeg, public Decoder
47 FFmpegDecoder (std::shared_ptr<const Film> film, std::shared_ptr<const FFmpegContent>, bool fast);
50 void seek (dcpomatic::ContentTime time, bool);
53 friend struct ::ffmpeg_pts_offset_test;
57 AVSampleFormat audio_sample_format (std::shared_ptr<FFmpegAudioStream> stream) const;
58 int bytes_per_audio_sample (std::shared_ptr<FFmpegAudioStream> stream) const;
60 std::shared_ptr<FFmpegAudioStream> audio_stream_from_index (int index) const;
61 void process_audio_frame (std::shared_ptr<FFmpegAudioStream> stream, int stream_index, int64_t packet_pts);
63 bool decode_video_packet (AVPacket* packet);
64 void decode_audio_packet (AVPacket* packet);
65 void decode_subtitle_packet (AVPacket* packet);
67 void decode_bitmap_subtitle (AVSubtitleRect const * rect, dcpomatic::ContentTime from);
68 void decode_ass_subtitle (std::string ass, dcpomatic::ContentTime from);
70 void maybe_add_subtitle ();
71 std::shared_ptr<AudioBuffers> deinterleave_audio (std::shared_ptr<FFmpegAudioStream> stream) const;
73 std::list<std::shared_ptr<VideoFilterGraph> > _filter_graphs;
74 boost::mutex _filter_graphs_mutex;
76 dcpomatic::ContentTime _pts_offset;
77 boost::optional<dcpomatic::ContentTime> _current_subtitle_to;
78 /** true if we have a subtitle which has not had emit_stop called for it yet */
79 bool _have_current_subtitle;
81 std::shared_ptr<Image> _black_image;
83 std::vector<boost::optional<dcpomatic::ContentTime> > _next_time;