2 Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
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.
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.
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.
20 /** @file src/ffmpeg_decoder.h
21 * @brief A decoder using FFmpeg to decode content.
27 #include <boost/shared_ptr.hpp>
28 #include <boost/optional.hpp>
29 #include <boost/thread/mutex.hpp>
31 #include <libavcodec/avcodec.h>
35 #include "video_decoder.h"
36 #include "audio_decoder.h"
37 #include "subtitle_decoder.h"
42 class ffmpeg_pts_offset_test;
44 /** @class FFmpegDecoder
45 * @brief A decoder using FFmpeg to decode content.
47 class FFmpegDecoder : public VideoDecoder, public AudioDecoder, public SubtitleDecoder, public FFmpeg
50 FFmpegDecoder (boost::shared_ptr<const FFmpegContent>, boost::shared_ptr<Log>);
54 friend class ::ffmpeg_pts_offset_test;
56 void seek (ContentTime time, bool);
60 void setup_subtitle ();
62 AVSampleFormat audio_sample_format () const;
63 int bytes_per_audio_sample () const;
65 bool decode_video_packet ();
66 void decode_audio_packet ();
67 void decode_subtitle_packet ();
69 void maybe_add_subtitle ();
70 boost::shared_ptr<AudioBuffers> deinterleave_audio (uint8_t** data, int size);
72 bool seek_overrun_finished (ContentTime, boost::optional<ContentTime>, boost::optional<ContentTime>) const;
73 bool seek_final_finished (int, int) const;
74 int minimal_run (boost::function<bool (boost::optional<ContentTime>, boost::optional<ContentTime>, int)>);
75 void seek_and_flush (ContentTime);
77 boost::shared_ptr<Log> _log;
78 AVCodecContext* _subtitle_codec_context; ///< may be 0 if there is no subtitle
79 AVCodec* _subtitle_codec; ///< may be 0 if there is no subtitle
81 std::list<boost::shared_ptr<FilterGraph> > _filter_graphs;
82 boost::mutex _filter_graphs_mutex;
84 ContentTime _pts_offset;