Use SRC_LINEAR for speed when analysing audio (#685).
[dcpomatic.git] / src / lib / ffmpeg_decoder.h
1 /*
2     Copyright (C) 2012-2014 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 "video_decoder.h"
26 #include "audio_decoder.h"
27 #include "subtitle_decoder.h"
28 #include "ffmpeg.h"
29 extern "C" {
30 #include <libavcodec/avcodec.h>
31 }
32 #include <boost/shared_ptr.hpp>
33 #include <boost/thread/mutex.hpp>
34 #include <stdint.h>
35
36 class Log;
37 class FilterGraph;
38 class FFmpegAudioStream;
39 struct ffmpeg_pts_offset_test;
40
41 /** @class FFmpegDecoder
42  *  @brief A decoder using FFmpeg to decode content.
43  */
44 class FFmpegDecoder : public VideoDecoder, public AudioDecoder, public SubtitleDecoder, public FFmpeg
45 {
46 public:
47         FFmpegDecoder (boost::shared_ptr<const FFmpegContent>, boost::shared_ptr<Log>, bool fast);
48
49 private:
50         friend struct ::ffmpeg_pts_offset_test;
51
52         bool pass ();
53         void seek (ContentTime time, bool);
54         void flush ();
55
56         AVSampleFormat audio_sample_format (boost::shared_ptr<FFmpegAudioStream> stream) const;
57         int bytes_per_audio_sample (boost::shared_ptr<FFmpegAudioStream> stream) const;
58
59         bool decode_video_packet ();
60         void decode_audio_packet ();
61         void decode_subtitle_packet ();
62
63         void decode_bitmap_subtitle (AVSubtitleRect const * rect, ContentTimePeriod period);
64
65         void maybe_add_subtitle ();
66         boost::shared_ptr<AudioBuffers> deinterleave_audio (boost::shared_ptr<FFmpegAudioStream> stream, uint8_t** data, int size);
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<FilterGraph> > _filter_graphs;
74         boost::mutex _filter_graphs_mutex;
75
76         ContentTime _pts_offset;
77 };