Build with git.
[dcpomatic.git] / src / lib / ffmpeg_compatibility.cc
1 /*
2     Copyright (C) 2012 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 extern "C" {
21 #include <libavfilter/avfiltergraph.h>
22 }
23 #include "exceptions.h"
24
25 #ifdef DVDOMATIC_FFMPEG_0_8_3   
26
27 typedef struct {
28         enum PixelFormat pix_fmt;
29 } AVSinkContext;
30
31 static int
32 avsink_init (AVFilterContext* ctx, const char* args, void* opaque)
33 {
34         AVSinkContext* priv = (AVSinkContext *) ctx->priv;
35         if (!opaque) {
36                 return AVERROR (EINVAL);
37         }
38
39         *priv = *(AVSinkContext *) opaque;
40         return 0;
41 }
42
43 static void
44 null_end_frame (AVFilterLink *)
45 {
46
47 }
48
49 static int
50 avsink_query_formats (AVFilterContext* ctx)
51 {
52         AVSinkContext* priv = (AVSinkContext *) ctx->priv;
53         enum PixelFormat pix_fmts[] = {
54                 priv->pix_fmt,
55                 PIX_FMT_NONE
56         };
57
58         avfilter_set_common_formats (ctx, avfilter_make_format_list ((int *) pix_fmts));
59         return 0;
60 }
61
62 #endif
63
64 AVFilter*
65 get_sink ()
66 {
67 #ifdef DVDOMATIC_FFMPEG_0_8_3   
68         /* XXX does this leak stuff? */
69         AVFilter* buffer_sink = new AVFilter;
70         buffer_sink->name = av_strdup ("avsink");
71         buffer_sink->priv_size = sizeof (AVSinkContext);
72         buffer_sink->init = avsink_init;
73         buffer_sink->query_formats = avsink_query_formats;
74         buffer_sink->inputs = new AVFilterPad[2];
75         AVFilterPad* i0 = const_cast<AVFilterPad*> (&buffer_sink->inputs[0]);
76         i0->name = "default";
77         i0->type = AVMEDIA_TYPE_VIDEO;
78         i0->min_perms = AV_PERM_READ;
79         i0->rej_perms = 0;
80         i0->start_frame = 0;
81         i0->get_video_buffer = 0;
82         i0->get_audio_buffer = 0;
83         i0->end_frame = null_end_frame;
84         i0->draw_slice = 0;
85         i0->filter_samples = 0;
86         i0->poll_frame = 0;
87         i0->request_frame = 0;
88         i0->config_props = 0;
89         const_cast<AVFilterPad*> (&buffer_sink->inputs[1])->name = 0;
90         buffer_sink->outputs = new AVFilterPad[1];
91         const_cast<AVFilterPad*> (&buffer_sink->outputs[0])->name = 0;
92         return buffer_sink;
93 #else
94         AVFilter* buffer_sink = avfilter_get_by_name("buffersink");
95         if (buffer_sink == 0) {
96                 throw DecodeError ("Could not create buffer sink filter");
97         }
98
99         return buffer_sink;
100 #endif
101 }
102
103 #ifdef DVDOMATIC_FFMPEG_0_8_3
104 AVFilterInOut *
105 avfilter_inout_alloc ()
106 {
107         return (AVFilterInOut *) av_malloc (sizeof (AVFilterInOut));
108 }
109 #endif