No-op; fix GPL address and use the explicit-program-name version.
[dcpomatic.git] / src / lib / ffmpeg.h
1 /*
2     Copyright (C) 2013-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 #ifndef DCPOMATIC_FFMPEG_H
22 #define DCPOMATIC_FFMPEG_H
23
24 #include "file_group.h"
25 #include "ffmpeg_subtitle_period.h"
26 extern "C" {
27 #include <libavcodec/avcodec.h>
28 }
29 #include <boost/shared_ptr.hpp>
30 #include <boost/thread/mutex.hpp>
31
32 struct AVFormatContext;
33 struct AVFrame;
34 struct AVIOContext;
35
36 class FFmpegContent;
37 class FFmpegAudioStream;
38 class Log;
39
40 class FFmpeg
41 {
42 public:
43         FFmpeg (boost::shared_ptr<const FFmpegContent>);
44         virtual ~FFmpeg ();
45
46         boost::shared_ptr<const FFmpegContent> ffmpeg_content () const {
47                 return _ffmpeg_content;
48         }
49
50         int avio_read (uint8_t *, int);
51         int64_t avio_seek (int64_t, int);
52
53 protected:
54         AVCodecContext* video_codec_context () const;
55         AVCodecContext* subtitle_codec_context () const;
56         ContentTime pts_offset (
57                 std::vector<boost::shared_ptr<FFmpegAudioStream> > audio_streams, boost::optional<ContentTime> first_video, double video_frame_rate
58                 ) const;
59
60         static FFmpegSubtitlePeriod subtitle_period (AVSubtitle const & sub);
61         static std::string subtitle_id (AVSubtitle const & sub);
62         static bool subtitle_starts_image (AVSubtitle const & sub);
63
64         boost::shared_ptr<const FFmpegContent> _ffmpeg_content;
65
66         uint8_t* _avio_buffer;
67         int _avio_buffer_size;
68         AVIOContext* _avio_context;
69         FileGroup _file_group;
70
71         AVFormatContext* _format_context;
72         AVPacket _packet;
73         AVFrame* _frame;
74
75         /** Index of video stream within AVFormatContext */
76         boost::optional<int> _video_stream;
77
78         /* It would appear (though not completely verified) that one must have
79            a mutex around calls to avcodec_open* and avcodec_close... and here
80            it is.
81         */
82         static boost::mutex _mutex;
83
84 private:
85         void setup_general ();
86         void setup_decoders ();
87
88         static void ffmpeg_log_callback (void* ptr, int level, const char* fmt, va_list vl);
89         static boost::weak_ptr<Log> _ffmpeg_log;
90 };
91
92 #endif