1 /*
2 * Copyright (c) 2012 Derek Buitenhuis
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation;
9 * version 2 of the License.
10 *
11 * FFmpeg 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 GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 /**
22 * @file
23 * Known FOURCCs:
24 * 'ULY0' (YCbCr 4:2:0), 'ULY2' (YCbCr 4:2:2), 'ULRG' (RGB), 'ULRA' (RGBA),
25 * 'ULH0' (YCbCr 4:2:0 BT.709), 'ULH2' (YCbCr 4:2:2 BT.709)
26 */
27
28 extern "C" {
32 }
33
36
38 {
41 uint32_t
flags, in_format;
42
45 in_format = UTVF_YV12;
49 else
51 break;
53 in_format = UTVF_YUYV;
57 else
59 break;
64 break;
69 break;
70 default:
72 }
73
74 /* Check before we alloc anything */
78 }
79
81
84
85 /* Alloc extradata buffer */
87
88 if (!info) {
91 }
92
93 /*
94 * We use this buffer to hold the data that Ut Video returns,
95 * since we cannot decode planes separately with it.
96 */
100
101 if (utv->
buffer == NULL) {
104 }
105
106 /*
107 * Create a Ut Video instance. Since the function wants
108 * an "interface name" string, pass it the name of the lib.
109 */
110 utv->
codec = CCodec::CreateInstance(UNFCC(avctx->
codec_tag),
"libavcodec");
111
112 /* Initialize encoder */
114 CBGROSSWIDTH_WINDOWS);
115
116 /* Get extradata from encoder */
120 CBGROSSWIDTH_WINDOWS);
122
123 /* Set flags */
124 utv->
codec->SetState(&flags,
sizeof(flags));
125
126 return 0;
127 }
128
130 const AVFrame *pic,
int *got_packet)
131 {
134 int ret, rgb_size, i;
135 bool keyframe;
138
139 /* Alloc buffer */
141 return ret;
142
144
145 /* Move input if needed data into Ut Video friendly buffer */
151 for (i = 0; i < h; i++) {
153 y += w;
154 }
155 for (i = 0; i < h / 2; i++) {
160 }
161 break;
163 for (i = 0; i < h; i++)
164 memcpy(utv->
buffer + i * (w << 1),
166 break;
169 /* Ut Video takes bottom-up BGR */
171 for (i = 0; i < h; i++)
172 memcpy(utv->
buffer + (h - i - 1) * w * rgb_size,
174 w * rgb_size);
175 break;
176 default:
178 }
179
180 /* Encode frame */
182
186 }
187
188 /*
189 * Ut Video is intra-only and every frame is a keyframe,
190 * and the API always returns true. In case something
191 * durastic changes in the future, such as inter support,
192 * assert that this is true.
193 */
197
199 *got_packet = 1;
200 return 0;
201 }
202
204 {
206
210
211 utv->
codec->EncodeEnd();
212 CCodec::DeleteInstance(utv->
codec);
213
214 return 0;
215 }
216
218 "libutvideo",
223 NULL, /* supported_framerates */
227 },
228 NULL, /* supported_samplerates */
229 NULL, /* sample_fmts */
230 NULL, /* channel_layouts */
231 0, /* max_lowres */
232 NULL, /* priv_class */
233 NULL, /* profiles */
235 NULL, /* next */
236 NULL, /* init_thread_copy */
237 NULL, /* update_thread_context */
238 NULL, /* defaults */
239 NULL, /* init_static_data */
241 NULL, /* encode */
243 NULL, /* decode */
245 NULL, /* flush */
246 };