Mercurial > libavcodec.hg
annotate libdiracenc.c @ 11888:f4100e794063 libavcodec
Remove libfaad wrapper
author | mru |
---|---|
date | Sun, 20 Jun 2010 10:24:05 +0000 |
parents | 7dd2a45249a9 |
children |
rev | line source |
---|---|
6734 | 1 /* |
2 * Dirac encoding support via libdirac library | |
3 * Copyright (c) 2005 BBC, Andrew Kennedy <dirac at rd dot bbc dot co dot uk> | |
4 * Copyright (c) 2006-2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com > | |
5 * | |
6 * This file is part of FFmpeg. | |
7 * | |
8 * FFmpeg is free software; you can redistribute it and/or | |
9 * modify it under the terms of the GNU Lesser General Public | |
10 * License as published by the Free Software Foundation; either | |
11 * version 2.1 of the License, or (at your option) any later version. | |
12 * | |
13 * FFmpeg is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * Lesser General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU Lesser General Public | |
19 * License along with FFmpeg; if not, write to the Free Software | |
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
21 */ | |
22 | |
23 /** | |
11644
7dd2a45249a9
Remove explicit filename from Doxygen @file commands.
diego
parents:
11560
diff
changeset
|
24 * @file |
6734 | 25 * Dirac encoding support via libdirac library; more details about the |
26 * Dirac project can be found at http://dirac.sourceforge.net/. | |
27 * The libdirac_encoder library implements Dirac specification version 2.2 | |
28 * (http://dirac.sourceforge.net/specification.html). | |
29 */ | |
30 | |
31 #include "libdirac_libschro.h" | |
32 #include "libdirac.h" | |
33 | |
34 #undef NDEBUG | |
35 #include <assert.h> | |
36 | |
37 | |
38 #include <libdirac_encoder/dirac_encoder.h> | |
39 | |
40 /** Dirac encoder private data */ | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
41 typedef struct FfmpegDiracEncoderParams { |
6734 | 42 /** Dirac encoder context */ |
43 dirac_encoder_context_t enc_ctx; | |
44 | |
45 /** frame being encoded */ | |
46 AVFrame picture; | |
47 | |
48 /** frame size */ | |
49 int frame_size; | |
50 | |
51 /** Dirac encoder handle */ | |
52 dirac_encoder_t* p_encoder; | |
53 | |
54 /** input frame buffer */ | |
55 unsigned char *p_in_frame_buf; | |
56 | |
7252 | 57 /** buffer to store encoder output before writing it to the frame queue */ |
58 unsigned char *enc_buf; | |
59 | |
60 /** size of encoder buffer */ | |
61 int enc_buf_size; | |
62 | |
6734 | 63 /** queue storing encoded frames */ |
64 FfmpegDiracSchroQueue enc_frame_queue; | |
65 | |
66 /** end of sequence signalled by user, 0 - false, 1 - true */ | |
67 int eos_signalled; | |
68 | |
69 /** end of sequence returned by encoder, 0 - false, 1 - true */ | |
70 int eos_pulled; | |
71 } FfmpegDiracEncoderParams; | |
72 | |
73 /** | |
74 * Works out Dirac-compatible chroma format. | |
75 */ | |
76 static dirac_chroma_t GetDiracChromaFormat(enum PixelFormat ff_pix_fmt) | |
77 { | |
78 int num_formats = sizeof(ffmpeg_dirac_pixel_format_map) / | |
79 sizeof(ffmpeg_dirac_pixel_format_map[0]); | |
80 int idx; | |
81 | |
10059
c6ace59701ce
Drop some more useless braces around if/for constructs.
diego
parents:
10056
diff
changeset
|
82 for (idx = 0; idx < num_formats; ++idx) |
c6ace59701ce
Drop some more useless braces around if/for constructs.
diego
parents:
10056
diff
changeset
|
83 if (ffmpeg_dirac_pixel_format_map[idx].ff_pix_fmt == ff_pix_fmt) |
6734 | 84 return ffmpeg_dirac_pixel_format_map[idx].dirac_pix_fmt; |
85 return formatNK; | |
86 } | |
87 | |
88 /** | |
89 * Dirac video preset table. Ensure that this tables matches up correctly | |
90 * with the ff_dirac_schro_video_format_info table in libdirac_libschro.c. | |
91 */ | |
92 static const VideoFormat ff_dirac_video_formats[]={ | |
93 VIDEO_FORMAT_CUSTOM , | |
94 VIDEO_FORMAT_QSIF525 , | |
95 VIDEO_FORMAT_QCIF , | |
96 VIDEO_FORMAT_SIF525 , | |
97 VIDEO_FORMAT_CIF , | |
98 VIDEO_FORMAT_4SIF525 , | |
99 VIDEO_FORMAT_4CIF , | |
100 VIDEO_FORMAT_SD_480I60 , | |
101 VIDEO_FORMAT_SD_576I50 , | |
102 VIDEO_FORMAT_HD_720P60 , | |
103 VIDEO_FORMAT_HD_720P50 , | |
104 VIDEO_FORMAT_HD_1080I60 , | |
105 VIDEO_FORMAT_HD_1080I50 , | |
106 VIDEO_FORMAT_HD_1080P60 , | |
107 VIDEO_FORMAT_HD_1080P50 , | |
108 VIDEO_FORMAT_DIGI_CINEMA_2K24 , | |
109 VIDEO_FORMAT_DIGI_CINEMA_4K24 , | |
110 }; | |
111 | |
112 /** | |
113 * Returns the video format preset matching the input video dimensions and | |
114 * time base. | |
115 */ | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
116 static VideoFormat GetDiracVideoFormatPreset(AVCodecContext *avccontext) |
6734 | 117 { |
118 unsigned int num_formats = sizeof(ff_dirac_video_formats) / | |
119 sizeof(ff_dirac_video_formats[0]); | |
120 | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
121 unsigned int idx = ff_dirac_schro_get_video_format_idx(avccontext); |
6734 | 122 |
123 return (idx < num_formats) ? | |
124 ff_dirac_video_formats[idx] : VIDEO_FORMAT_CUSTOM; | |
125 } | |
126 | |
9007
043574c5c153
Add missing av_cold in static init/close functions.
stefano
parents:
8718
diff
changeset
|
127 static av_cold int libdirac_encode_init(AVCodecContext *avccontext) |
6734 | 128 { |
129 | |
130 FfmpegDiracEncoderParams* p_dirac_params = avccontext->priv_data; | |
131 int no_local = 1; | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
132 int verbose = avccontext->debug; |
6734 | 133 VideoFormat preset; |
134 | |
135 /* get Dirac preset */ | |
136 preset = GetDiracVideoFormatPreset(avccontext); | |
137 | |
138 /* initialize the encoder context */ | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
139 dirac_encoder_context_init(&(p_dirac_params->enc_ctx), preset); |
6734 | 140 |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
141 p_dirac_params->enc_ctx.src_params.chroma = GetDiracChromaFormat(avccontext->pix_fmt); |
6734 | 142 |
143 if (p_dirac_params->enc_ctx.src_params.chroma == formatNK) { | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
144 av_log(avccontext, AV_LOG_ERROR, |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
145 "Unsupported pixel format %d. This codec supports only " |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
146 "Planar YUV formats (yuv420p, yuv422p, yuv444p\n", |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
147 avccontext->pix_fmt); |
6734 | 148 return -1; |
149 } | |
150 | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
151 p_dirac_params->enc_ctx.src_params.frame_rate.numerator = avccontext->time_base.den; |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
152 p_dirac_params->enc_ctx.src_params.frame_rate.denominator = avccontext->time_base.num; |
6734 | 153 |
154 p_dirac_params->enc_ctx.src_params.width = avccontext->width; | |
155 p_dirac_params->enc_ctx.src_params.height = avccontext->height; | |
156 | |
157 p_dirac_params->frame_size = avpicture_get_size(avccontext->pix_fmt, | |
158 avccontext->width, | |
159 avccontext->height); | |
160 | |
161 avccontext->coded_frame = &p_dirac_params->picture; | |
162 | |
163 if (no_local) { | |
164 p_dirac_params->enc_ctx.decode_flag = 0; | |
165 p_dirac_params->enc_ctx.instr_flag = 0; | |
166 } else { | |
167 p_dirac_params->enc_ctx.decode_flag = 1; | |
168 p_dirac_params->enc_ctx.instr_flag = 1; | |
169 } | |
170 | |
171 /* Intra-only sequence */ | |
10055 | 172 if (!avccontext->gop_size) { |
6734 | 173 p_dirac_params->enc_ctx.enc_params.num_L1 = 0; |
7839
e6348a5656e0
Add support for creating Simple Profile (I-frame only, no arithmetic coding)
diego
parents:
7252
diff
changeset
|
174 if (avccontext->coder_type == FF_CODER_TYPE_VLC) |
e6348a5656e0
Add support for creating Simple Profile (I-frame only, no arithmetic coding)
diego
parents:
7252
diff
changeset
|
175 p_dirac_params->enc_ctx.enc_params.using_ac = 0; |
e6348a5656e0
Add support for creating Simple Profile (I-frame only, no arithmetic coding)
diego
parents:
7252
diff
changeset
|
176 } else |
6734 | 177 avccontext->has_b_frames = 1; |
178 | |
179 if (avccontext->flags & CODEC_FLAG_QSCALE) { | |
10055 | 180 if (avccontext->global_quality) { |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
181 p_dirac_params->enc_ctx.enc_params.qf = avccontext->global_quality |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
182 / (FF_QP2LAMBDA * 10.0); |
6734 | 183 /* if it is not default bitrate then send target rate. */ |
184 if (avccontext->bit_rate >= 1000 && | |
10056
646065f63290
Remove useless braces around if/for/while expressions.
diego
parents:
10055
diff
changeset
|
185 avccontext->bit_rate != 200000) |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
186 p_dirac_params->enc_ctx.enc_params.trate = avccontext->bit_rate |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
187 / 1000; |
6734 | 188 } else |
189 p_dirac_params->enc_ctx.enc_params.lossless = 1; | |
190 } else if (avccontext->bit_rate >= 1000) | |
191 p_dirac_params->enc_ctx.enc_params.trate = avccontext->bit_rate / 1000; | |
192 | |
193 if ((preset > VIDEO_FORMAT_QCIF || preset < VIDEO_FORMAT_QSIF525) && | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
194 avccontext->bit_rate == 200000) |
6734 | 195 p_dirac_params->enc_ctx.enc_params.trate = 0; |
196 | |
10056
646065f63290
Remove useless braces around if/for/while expressions.
diego
parents:
10055
diff
changeset
|
197 if (avccontext->flags & CODEC_FLAG_INTERLACED_ME) |
6734 | 198 /* all material can be coded as interlaced or progressive |
199 * irrespective of the type of source material */ | |
200 p_dirac_params->enc_ctx.enc_params.picture_coding_mode = 1; | |
201 | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
202 p_dirac_params->p_encoder = dirac_encoder_init(&(p_dirac_params->enc_ctx), |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
203 verbose); |
6734 | 204 |
205 if (!p_dirac_params->p_encoder) { | |
206 av_log(avccontext, AV_LOG_ERROR, | |
207 "Unrecoverable Error: dirac_encoder_init failed. "); | |
208 return EXIT_FAILURE; | |
209 } | |
210 | |
211 /* allocate enough memory for the incoming data */ | |
212 p_dirac_params->p_in_frame_buf = av_malloc(p_dirac_params->frame_size); | |
213 | |
214 /* initialize the encoded frame queue */ | |
215 ff_dirac_schro_queue_init(&p_dirac_params->enc_frame_queue); | |
216 | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
217 return 0; |
6734 | 218 } |
219 | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
220 static void DiracFreeFrame(void *data) |
6734 | 221 { |
222 FfmpegDiracSchroEncodedFrame *enc_frame = data; | |
223 | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
224 av_freep(&(enc_frame->p_encbuf)); |
6734 | 225 av_free(enc_frame); |
226 } | |
227 | |
228 static int libdirac_encode_frame(AVCodecContext *avccontext, | |
229 unsigned char *frame, | |
230 int buf_size, void *data) | |
231 { | |
232 int enc_size = 0; | |
233 dirac_encoder_state_t state; | |
234 FfmpegDiracEncoderParams* p_dirac_params = avccontext->priv_data; | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
235 FfmpegDiracSchroEncodedFrame* p_frame_output = NULL; |
6734 | 236 FfmpegDiracSchroEncodedFrame* p_next_output_frame = NULL; |
237 int go = 1; | |
7252 | 238 int last_frame_in_sequence = 0; |
6734 | 239 |
10055 | 240 if (!data) { |
6734 | 241 /* push end of sequence if not already signalled */ |
242 if (!p_dirac_params->eos_signalled) { | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
243 dirac_encoder_end_sequence(p_dirac_params->p_encoder); |
6734 | 244 p_dirac_params->eos_signalled = 1; |
245 } | |
246 } else { | |
247 | |
248 /* Allocate frame data to Dirac input buffer. | |
249 * Input line size may differ from what the codec supports, | |
250 * especially when transcoding from one format to another. | |
251 * So use avpicture_layout to copy the frame. */ | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
252 avpicture_layout((AVPicture *)data, avccontext->pix_fmt, |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
253 avccontext->width, avccontext->height, |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
254 p_dirac_params->p_in_frame_buf, |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
255 p_dirac_params->frame_size); |
6734 | 256 |
257 /* load next frame */ | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
258 if (dirac_encoder_load(p_dirac_params->p_encoder, |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
259 p_dirac_params->p_in_frame_buf, |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
260 p_dirac_params->frame_size) < 0) { |
6734 | 261 av_log(avccontext, AV_LOG_ERROR, "Unrecoverable Encoder Error." |
262 " dirac_encoder_load failed...\n"); | |
263 return -1; | |
264 } | |
265 } | |
266 | |
267 if (p_dirac_params->eos_pulled) | |
268 go = 0; | |
269 | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
270 while (go) { |
6734 | 271 p_dirac_params->p_encoder->enc_buf.buffer = frame; |
272 p_dirac_params->p_encoder->enc_buf.size = buf_size; | |
273 /* process frame */ | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
274 state = dirac_encoder_output(p_dirac_params->p_encoder); |
6734 | 275 |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
276 switch (state) { |
6734 | 277 case ENC_STATE_AVAIL: |
278 case ENC_STATE_EOS: | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
279 assert(p_dirac_params->p_encoder->enc_buf.size > 0); |
7252 | 280 |
281 /* All non-frame data is prepended to actual frame data to | |
282 * be able to set the pts correctly. So we don't write data | |
283 * to the frame output queue until we actually have a frame | |
284 */ | |
285 | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
286 p_dirac_params->enc_buf = av_realloc(p_dirac_params->enc_buf, |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
287 p_dirac_params->enc_buf_size + |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
288 p_dirac_params->p_encoder->enc_buf.size); |
7252 | 289 memcpy(p_dirac_params->enc_buf + p_dirac_params->enc_buf_size, |
290 p_dirac_params->p_encoder->enc_buf.buffer, | |
291 p_dirac_params->p_encoder->enc_buf.size); | |
292 | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
293 p_dirac_params->enc_buf_size += p_dirac_params->p_encoder->enc_buf.size; |
7252 | 294 |
295 if (state == ENC_STATE_EOS) { | |
296 p_dirac_params->eos_pulled = 1; | |
297 go = 0; | |
298 } | |
299 | |
300 /* If non-frame data, don't output it until it we get an | |
301 * encoded frame back from the encoder. */ | |
302 if (p_dirac_params->p_encoder->enc_pparams.pnum == -1) | |
303 break; | |
304 | |
6734 | 305 /* create output frame */ |
306 p_frame_output = av_mallocz(sizeof(FfmpegDiracSchroEncodedFrame)); | |
307 /* set output data */ | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
308 p_frame_output->size = p_dirac_params->enc_buf_size; |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
309 p_frame_output->p_encbuf = p_dirac_params->enc_buf; |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
310 p_frame_output->frame_num = p_dirac_params->p_encoder->enc_pparams.pnum; |
6734 | 311 |
312 if (p_dirac_params->p_encoder->enc_pparams.ptype == INTRA_PICTURE && | |
313 p_dirac_params->p_encoder->enc_pparams.rtype == REFERENCE_PICTURE) | |
314 p_frame_output->key_frame = 1; | |
315 | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
316 ff_dirac_schro_queue_push_back(&p_dirac_params->enc_frame_queue, |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
317 p_frame_output); |
6734 | 318 |
7252 | 319 p_dirac_params->enc_buf_size = 0; |
320 p_dirac_params->enc_buf = NULL; | |
6734 | 321 break; |
322 | |
323 case ENC_STATE_BUFFER: | |
324 go = 0; | |
325 break; | |
326 | |
327 case ENC_STATE_INVALID: | |
328 av_log(avccontext, AV_LOG_ERROR, | |
329 "Unrecoverable Dirac Encoder Error. Quitting...\n"); | |
330 return -1; | |
331 | |
332 default: | |
333 av_log(avccontext, AV_LOG_ERROR, "Unknown Dirac Encoder state\n"); | |
334 return -1; | |
335 } | |
336 } | |
337 | |
338 /* copy 'next' frame in queue */ | |
7252 | 339 |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
340 if (p_dirac_params->enc_frame_queue.size == 1 && p_dirac_params->eos_pulled) |
7252 | 341 last_frame_in_sequence = 1; |
342 | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
343 p_next_output_frame = ff_dirac_schro_queue_pop(&p_dirac_params->enc_frame_queue); |
6734 | 344 |
10055 | 345 if (!p_next_output_frame) |
6734 | 346 return 0; |
347 | |
348 memcpy(frame, p_next_output_frame->p_encbuf, p_next_output_frame->size); | |
349 avccontext->coded_frame->key_frame = p_next_output_frame->key_frame; | |
350 /* Use the frame number of the encoded frame as the pts. It is OK to do | |
351 * so since Dirac is a constant framerate codec. It expects input to be | |
352 * of constant framerate. */ | |
353 avccontext->coded_frame->pts = p_next_output_frame->frame_num; | |
354 enc_size = p_next_output_frame->size; | |
355 | |
7252 | 356 /* Append the end of sequence information to the last frame in the |
357 * sequence. */ | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
358 if (last_frame_in_sequence && p_dirac_params->enc_buf_size > 0) { |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
359 memcpy(frame + enc_size, p_dirac_params->enc_buf, |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
360 p_dirac_params->enc_buf_size); |
7252 | 361 enc_size += p_dirac_params->enc_buf_size; |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
362 av_freep(&p_dirac_params->enc_buf); |
7252 | 363 p_dirac_params->enc_buf_size = 0; |
364 } | |
365 | |
6734 | 366 /* free frame */ |
367 DiracFreeFrame(p_next_output_frame); | |
368 | |
369 return enc_size; | |
370 } | |
371 | |
9007
043574c5c153
Add missing av_cold in static init/close functions.
stefano
parents:
8718
diff
changeset
|
372 static av_cold int libdirac_encode_close(AVCodecContext *avccontext) |
6734 | 373 { |
374 FfmpegDiracEncoderParams* p_dirac_params = avccontext->priv_data; | |
375 | |
376 /* close the encoder */ | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
377 dirac_encoder_close(p_dirac_params->p_encoder); |
6734 | 378 |
379 /* free data in the output frame queue */ | |
380 ff_dirac_schro_queue_free(&p_dirac_params->enc_frame_queue, | |
381 DiracFreeFrame); | |
382 | |
7252 | 383 /* free the encoder buffer */ |
384 if (p_dirac_params->enc_buf_size) | |
385 av_freep(&p_dirac_params->enc_buf); | |
386 | |
6734 | 387 /* free the input frame buffer */ |
388 av_freep(&p_dirac_params->p_in_frame_buf); | |
389 | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
390 return 0; |
6734 | 391 } |
392 | |
393 | |
394 AVCodec libdirac_encoder = { | |
395 "libdirac", | |
11560
8a4984c5cacc
Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents:
10146
diff
changeset
|
396 AVMEDIA_TYPE_VIDEO, |
6734 | 397 CODEC_ID_DIRAC, |
398 sizeof(FfmpegDiracEncoderParams), | |
399 libdirac_encode_init, | |
400 libdirac_encode_frame, | |
401 libdirac_encode_close, | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
402 .capabilities = CODEC_CAP_DELAY, |
10146
38cfe222e1a4
Mark all pix_fmts and supported_framerates compound literals as const.
reimar
parents:
10060
diff
changeset
|
403 .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_YUV444P, PIX_FMT_NONE}, |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
404 .long_name = NULL_IF_CONFIG_SMALL("libdirac Dirac 2.2"), |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10059
diff
changeset
|
405 }; |