Mercurial > libavcodec.hg
annotate libschroedingerenc.c @ 12197:fbf4d5b1b664 libavcodec
Remove FF_MM_SSE2/3 flags for CPUs where this is generally not faster than
regular MMX code. Examples of this are the Core1 CPU. Instead, set a new flag,
FF_MM_SSE2/3SLOW, which can be checked for particular SSE2/3 functions that
have been checked specifically on such CPUs and are actually faster than
their MMX counterparts.
In addition, use this flag to enable particular VP8 and LPC SSE2 functions
that are faster than their MMX counterparts.
Based on a patch by Loren Merritt <lorenm AT u washington edu>.
author | rbultje |
---|---|
date | Mon, 19 Jul 2010 22:38:23 +0000 |
parents | d3098fb8ec05 |
children |
rev | line source |
---|---|
6738 | 1 /* |
2 * Dirac encoder support via Schroedinger libraries | |
3 * Copyright (c) 2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com > | |
4 * | |
5 * This file is part of FFmpeg. | |
6 * | |
7 * FFmpeg is free software; you can redistribute it and/or | |
8 * modify it under the terms of the GNU Lesser General Public | |
9 * License as published by the Free Software Foundation; either | |
10 * version 2.1 of the License, or (at your option) any later version. | |
11 * | |
12 * FFmpeg is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Lesser General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Lesser General Public | |
18 * License along with FFmpeg; if not, write to the Free Software | |
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
20 */ | |
21 | |
22 /** | |
11644
7dd2a45249a9
Remove explicit filename from Doxygen @file commands.
diego
parents:
11560
diff
changeset
|
23 * @file |
6738 | 24 * Dirac encoder support via libschroedinger-1.0 libraries. More details about |
25 * the Schroedinger project can be found at http://www.diracvideo.org/. | |
26 * The library implements Dirac Specification Version 2.2 | |
27 * (http://dirac.sourceforge.net/specification.html). | |
28 */ | |
29 | |
30 #undef NDEBUG | |
31 #include <assert.h> | |
32 | |
33 #include <schroedinger/schro.h> | |
34 #include <schroedinger/schrodebug.h> | |
35 #include <schroedinger/schrovideoformat.h> | |
36 | |
37 #include "avcodec.h" | |
38 #include "libdirac_libschro.h" | |
39 #include "libschroedinger.h" | |
11684 | 40 #include "bytestream.h" |
6738 | 41 |
42 | |
43 /** libschroedinger encoder private data */ | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
44 typedef struct FfmpegSchroEncoderParams { |
6738 | 45 /** Schroedinger video format */ |
46 SchroVideoFormat *format; | |
47 | |
48 /** Schroedinger frame format */ | |
49 SchroFrameFormat frame_format; | |
50 | |
51 /** frame being encoded */ | |
52 AVFrame picture; | |
53 | |
54 /** frame size */ | |
55 int frame_size; | |
56 | |
57 /** Schroedinger encoder handle*/ | |
58 SchroEncoder* encoder; | |
59 | |
7253
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
60 /** buffer to store encoder output before writing it to the frame queue*/ |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
61 unsigned char *enc_buf; |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
62 |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
63 /** Size of encoder buffer*/ |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
64 int enc_buf_size; |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
65 |
6738 | 66 /** queue storing encoded frames */ |
67 FfmpegDiracSchroQueue enc_frame_queue; | |
68 | |
69 /** end of sequence signalled */ | |
70 int eos_signalled; | |
71 | |
72 /** end of sequence pulled */ | |
73 int eos_pulled; | |
74 } FfmpegSchroEncoderParams; | |
75 | |
76 /** | |
77 * Works out Schro-compatible chroma format. | |
78 */ | |
79 static int SetSchroChromaFormat(AVCodecContext *avccontext) | |
80 { | |
81 int num_formats = sizeof(ffmpeg_schro_pixel_format_map) / | |
82 sizeof(ffmpeg_schro_pixel_format_map[0]); | |
83 int idx; | |
84 | |
85 FfmpegSchroEncoderParams* p_schro_params = avccontext->priv_data; | |
86 | |
87 for (idx = 0; idx < num_formats; ++idx) { | |
88 if (ffmpeg_schro_pixel_format_map[idx].ff_pix_fmt == | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
89 avccontext->pix_fmt) { |
6738 | 90 p_schro_params->format->chroma_format = |
91 ffmpeg_schro_pixel_format_map[idx].schro_pix_fmt; | |
92 return 0; | |
93 } | |
94 } | |
95 | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
96 av_log(avccontext, AV_LOG_ERROR, |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
97 "This codec currently only supports planar YUV 4:2:0, 4:2:2" |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
98 " and 4:4:4 formats.\n"); |
6738 | 99 |
100 return -1; | |
101 } | |
102 | |
103 static int libschroedinger_encode_init(AVCodecContext *avccontext) | |
104 { | |
105 FfmpegSchroEncoderParams* p_schro_params = avccontext->priv_data; | |
106 SchroVideoFormatEnum preset; | |
107 | |
108 /* Initialize the libraries that libschroedinger depends on. */ | |
109 schro_init(); | |
110 | |
111 /* Create an encoder object. */ | |
112 p_schro_params->encoder = schro_encoder_new(); | |
113 | |
114 if (!p_schro_params->encoder) { | |
115 av_log(avccontext, AV_LOG_ERROR, | |
116 "Unrecoverable Error: schro_encoder_new failed. "); | |
117 return -1; | |
118 } | |
119 | |
120 /* Initialize the format. */ | |
121 preset = ff_get_schro_video_format_preset(avccontext); | |
122 p_schro_params->format = | |
123 schro_encoder_get_video_format(p_schro_params->encoder); | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
124 schro_video_format_set_std_video_format(p_schro_params->format, preset); |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
125 p_schro_params->format->width = avccontext->width; |
6738 | 126 p_schro_params->format->height = avccontext->height; |
127 | |
128 if (SetSchroChromaFormat(avccontext) == -1) | |
129 return -1; | |
130 | |
11685 | 131 if (avccontext->color_primaries == AVCOL_PRI_BT709) { |
132 p_schro_params->format->colour_primaries = SCHRO_COLOUR_PRIMARY_HDTV; | |
133 } else if (avccontext->color_primaries == AVCOL_PRI_BT470BG) { | |
134 p_schro_params->format->colour_primaries = SCHRO_COLOUR_PRIMARY_SDTV_625; | |
135 } else if (avccontext->color_primaries == AVCOL_PRI_SMPTE170M) { | |
136 p_schro_params->format->colour_primaries = SCHRO_COLOUR_PRIMARY_SDTV_525; | |
137 } | |
138 | |
139 if (avccontext->colorspace == AVCOL_SPC_BT709) { | |
140 p_schro_params->format->colour_matrix = SCHRO_COLOUR_MATRIX_HDTV; | |
141 } else if (avccontext->colorspace == AVCOL_SPC_BT470BG) { | |
142 p_schro_params->format->colour_matrix = SCHRO_COLOUR_MATRIX_SDTV; | |
143 } | |
144 | |
145 if (avccontext->color_trc == AVCOL_TRC_BT709) { | |
146 p_schro_params->format->transfer_function = SCHRO_TRANSFER_CHAR_TV_GAMMA; | |
147 } | |
148 | |
6738 | 149 if (ff_get_schro_frame_format(p_schro_params->format->chroma_format, |
150 &p_schro_params->frame_format) == -1) { | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
151 av_log(avccontext, AV_LOG_ERROR, |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
152 "This codec currently supports only planar YUV 4:2:0, 4:2:2" |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
153 " and 4:4:4 formats.\n"); |
6738 | 154 return -1; |
155 } | |
156 | |
157 p_schro_params->format->frame_rate_numerator = avccontext->time_base.den; | |
158 p_schro_params->format->frame_rate_denominator = avccontext->time_base.num; | |
159 | |
160 p_schro_params->frame_size = avpicture_get_size(avccontext->pix_fmt, | |
161 avccontext->width, | |
162 avccontext->height); | |
163 | |
164 avccontext->coded_frame = &p_schro_params->picture; | |
165 | |
10055 | 166 if (!avccontext->gop_size) { |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
167 schro_encoder_setting_set_double(p_schro_params->encoder, |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
168 "gop_structure", |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
169 SCHRO_ENCODER_GOP_INTRA_ONLY); |
7839
e6348a5656e0
Add support for creating Simple Profile (I-frame only, no arithmetic coding)
diego
parents:
7253
diff
changeset
|
170 |
10056
646065f63290
Remove useless braces around if/for/while expressions.
diego
parents:
10055
diff
changeset
|
171 if (avccontext->coder_type == FF_CODER_TYPE_VLC) |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
172 schro_encoder_setting_set_double(p_schro_params->encoder, |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
173 "enable_noarith", 1); |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
174 } else { |
11682 | 175 schro_encoder_setting_set_double(p_schro_params->encoder, |
176 "au_distance", avccontext->gop_size); | |
6738 | 177 avccontext->has_b_frames = 1; |
178 } | |
179 | |
180 /* FIXME - Need to handle SCHRO_ENCODER_RATE_CONTROL_LOW_DELAY. */ | |
181 if (avccontext->flags & CODEC_FLAG_QSCALE) { | |
10055 | 182 if (!avccontext->global_quality) { |
6738 | 183 /* lossless coding */ |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
184 schro_encoder_setting_set_double(p_schro_params->encoder, |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
185 "rate_control", |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
186 SCHRO_ENCODER_RATE_CONTROL_LOSSLESS); |
6738 | 187 } else { |
11681
04c086666e50
schroenc: Use constant quality for constant quality, not noise threshold
conrad
parents:
11680
diff
changeset
|
188 int quality; |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
189 schro_encoder_setting_set_double(p_schro_params->encoder, |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
190 "rate_control", |
11681
04c086666e50
schroenc: Use constant quality for constant quality, not noise threshold
conrad
parents:
11680
diff
changeset
|
191 SCHRO_ENCODER_RATE_CONTROL_CONSTANT_QUALITY); |
6738 | 192 |
11681
04c086666e50
schroenc: Use constant quality for constant quality, not noise threshold
conrad
parents:
11680
diff
changeset
|
193 quality = avccontext->global_quality / FF_QP2LAMBDA; |
04c086666e50
schroenc: Use constant quality for constant quality, not noise threshold
conrad
parents:
11680
diff
changeset
|
194 if (quality > 10) |
04c086666e50
schroenc: Use constant quality for constant quality, not noise threshold
conrad
parents:
11680
diff
changeset
|
195 quality = 10; |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
196 schro_encoder_setting_set_double(p_schro_params->encoder, |
11681
04c086666e50
schroenc: Use constant quality for constant quality, not noise threshold
conrad
parents:
11680
diff
changeset
|
197 "quality", quality); |
6738 | 198 } |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
199 } else { |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
200 schro_encoder_setting_set_double(p_schro_params->encoder, |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
201 "rate_control", |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
202 SCHRO_ENCODER_RATE_CONTROL_CONSTANT_BITRATE); |
6738 | 203 |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
204 schro_encoder_setting_set_double(p_schro_params->encoder, |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
205 "bitrate", |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
206 avccontext->bit_rate); |
6738 | 207 |
208 } | |
209 | |
10056
646065f63290
Remove useless braces around if/for/while expressions.
diego
parents:
10055
diff
changeset
|
210 if (avccontext->flags & CODEC_FLAG_INTERLACED_ME) |
6738 | 211 /* All material can be coded as interlaced or progressive |
212 irrespective of the type of source material. */ | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
213 schro_encoder_setting_set_double(p_schro_params->encoder, |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
214 "interlaced_coding", 1); |
6738 | 215 |
11683 | 216 schro_encoder_setting_set_double(p_schro_params->encoder, "open_gop", |
217 !(avccontext->flags & CODEC_FLAG_CLOSED_GOP)); | |
218 | |
6738 | 219 /* FIXME: Signal range hardcoded to 8-bit data until both libschroedinger |
220 * and libdirac support other bit-depth data. */ | |
221 schro_video_format_set_std_signal_range(p_schro_params->format, | |
222 SCHRO_SIGNAL_RANGE_8BIT_VIDEO); | |
223 | |
224 /* Set the encoder format. */ | |
225 schro_encoder_set_video_format(p_schro_params->encoder, | |
226 p_schro_params->format); | |
227 | |
228 /* Set the debug level. */ | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
229 schro_debug_set_level(avccontext->debug); |
6738 | 230 |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
231 schro_encoder_start(p_schro_params->encoder); |
6738 | 232 |
233 /* Initialize the encoded frame queue. */ | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
234 ff_dirac_schro_queue_init(&p_schro_params->enc_frame_queue); |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
235 return 0; |
6738 | 236 } |
237 | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
238 static SchroFrame *libschroedinger_frame_from_data(AVCodecContext *avccontext, |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
239 void *in_data) |
6738 | 240 { |
241 FfmpegSchroEncoderParams* p_schro_params = avccontext->priv_data; | |
242 SchroFrame *in_frame; | |
243 /* Input line size may differ from what the codec supports. Especially | |
244 * when transcoding from one format to another. So use avpicture_layout | |
245 * to copy the frame. */ | |
10061
09f2db2d7c90
Fix bug caused by difference in stride and picture width.
diego
parents:
10060
diff
changeset
|
246 in_frame = ff_create_schro_frame(avccontext, p_schro_params->frame_format); |
6738 | 247 |
10061
09f2db2d7c90
Fix bug caused by difference in stride and picture width.
diego
parents:
10060
diff
changeset
|
248 if (in_frame) |
09f2db2d7c90
Fix bug caused by difference in stride and picture width.
diego
parents:
10060
diff
changeset
|
249 avpicture_layout((AVPicture *)in_data, avccontext->pix_fmt, |
09f2db2d7c90
Fix bug caused by difference in stride and picture width.
diego
parents:
10060
diff
changeset
|
250 avccontext->width, avccontext->height, |
09f2db2d7c90
Fix bug caused by difference in stride and picture width.
diego
parents:
10060
diff
changeset
|
251 in_frame->components[0].data, |
09f2db2d7c90
Fix bug caused by difference in stride and picture width.
diego
parents:
10060
diff
changeset
|
252 p_schro_params->frame_size); |
6738 | 253 |
254 return in_frame; | |
255 } | |
256 | |
257 static void SchroedingerFreeFrame(void *data) | |
258 { | |
259 FfmpegDiracSchroEncodedFrame *enc_frame = data; | |
260 | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
261 av_freep(&(enc_frame->p_encbuf)); |
6738 | 262 av_free(enc_frame); |
263 } | |
264 | |
265 static int libschroedinger_encode_frame(AVCodecContext *avccontext, | |
266 unsigned char *frame, | |
267 int buf_size, void *data) | |
268 { | |
269 int enc_size = 0; | |
270 FfmpegSchroEncoderParams* p_schro_params = avccontext->priv_data; | |
271 SchroEncoder *encoder = p_schro_params->encoder; | |
272 struct FfmpegDiracSchroEncodedFrame* p_frame_output = NULL; | |
273 int go = 1; | |
274 SchroBuffer *enc_buf; | |
275 int presentation_frame; | |
276 int parse_code; | |
7253
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
277 int last_frame_in_sequence = 0; |
6738 | 278 |
10058
d18468c5fee0
Simplify another 'if' condition: Replace 'exp == 0' by '!exp'.
diego
parents:
10056
diff
changeset
|
279 if (!data) { |
6738 | 280 /* Push end of sequence if not already signalled. */ |
281 if (!p_schro_params->eos_signalled) { | |
282 schro_encoder_end_of_stream(encoder); | |
283 p_schro_params->eos_signalled = 1; | |
284 } | |
285 } else { | |
286 /* Allocate frame data to schro input buffer. */ | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
287 SchroFrame *in_frame = libschroedinger_frame_from_data(avccontext, |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
288 data); |
6738 | 289 /* Load next frame. */ |
290 schro_encoder_push_frame(encoder, in_frame); | |
291 } | |
292 | |
293 if (p_schro_params->eos_pulled) | |
294 go = 0; | |
295 | |
296 /* Now check to see if we have any output from the encoder. */ | |
297 while (go) { | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
298 SchroStateEnum state; |
6738 | 299 state = schro_encoder_wait(encoder); |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
300 switch (state) { |
6738 | 301 case SCHRO_STATE_HAVE_BUFFER: |
302 case SCHRO_STATE_END_OF_STREAM: | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
303 enc_buf = schro_encoder_pull(encoder, &presentation_frame); |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
304 assert(enc_buf->length > 0); |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
305 assert(enc_buf->length <= buf_size); |
7253
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
306 parse_code = enc_buf->data[4]; |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
307 |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
308 /* All non-frame data is prepended to actual frame data to |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
309 * be able to set the pts correctly. So we don't write data |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
310 * to the frame output queue until we actually have a frame |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
311 */ |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
312 p_schro_params->enc_buf = av_realloc(p_schro_params->enc_buf, |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
313 p_schro_params->enc_buf_size + enc_buf->length); |
7253
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
314 |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
315 memcpy(p_schro_params->enc_buf + p_schro_params->enc_buf_size, |
7253
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
316 enc_buf->data, enc_buf->length); |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
317 p_schro_params->enc_buf_size += enc_buf->length; |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
318 |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
319 |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
320 if (state == SCHRO_STATE_END_OF_STREAM) { |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
321 p_schro_params->eos_pulled = 1; |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
322 go = 0; |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
323 } |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
324 |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
325 if (!SCHRO_PARSE_CODE_IS_PICTURE(parse_code)) { |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
326 schro_buffer_unref(enc_buf); |
7253
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
327 break; |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
328 } |
6738 | 329 |
330 /* Create output frame. */ | |
331 p_frame_output = av_mallocz(sizeof(FfmpegDiracSchroEncodedFrame)); | |
332 /* Set output data. */ | |
7253
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
333 p_frame_output->size = p_schro_params->enc_buf_size; |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
334 p_frame_output->p_encbuf = p_schro_params->enc_buf; |
6738 | 335 if (SCHRO_PARSE_CODE_IS_INTRA(parse_code) && |
10056
646065f63290
Remove useless braces around if/for/while expressions.
diego
parents:
10055
diff
changeset
|
336 SCHRO_PARSE_CODE_IS_REFERENCE(parse_code)) |
6738 | 337 p_frame_output->key_frame = 1; |
338 | |
339 /* Parse the coded frame number from the bitstream. Bytes 14 | |
340 * through 17 represesent the frame number. */ | |
11684 | 341 p_frame_output->frame_num = AV_RB32(enc_buf->data + 13); |
6738 | 342 |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
343 ff_dirac_schro_queue_push_back(&p_schro_params->enc_frame_queue, |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
344 p_frame_output); |
7253
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
345 p_schro_params->enc_buf_size = 0; |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
346 p_schro_params->enc_buf = NULL; |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
347 |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
348 schro_buffer_unref(enc_buf); |
6738 | 349 |
350 break; | |
351 | |
352 case SCHRO_STATE_NEED_FRAME: | |
353 go = 0; | |
354 break; | |
355 | |
356 case SCHRO_STATE_AGAIN: | |
357 break; | |
358 | |
359 default: | |
360 av_log(avccontext, AV_LOG_ERROR, "Unknown Schro Encoder state\n"); | |
361 return -1; | |
362 } | |
363 } | |
364 | |
365 /* Copy 'next' frame in queue. */ | |
7253
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
366 |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
367 if (p_schro_params->enc_frame_queue.size == 1 && |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
368 p_schro_params->eos_pulled) |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
369 last_frame_in_sequence = 1; |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
370 |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
371 p_frame_output = ff_dirac_schro_queue_pop(&p_schro_params->enc_frame_queue); |
6738 | 372 |
10055 | 373 if (!p_frame_output) |
6738 | 374 return 0; |
375 | |
376 memcpy(frame, p_frame_output->p_encbuf, p_frame_output->size); | |
377 avccontext->coded_frame->key_frame = p_frame_output->key_frame; | |
378 /* Use the frame number of the encoded frame as the pts. It is OK to | |
379 * do so since Dirac is a constant frame rate codec. It expects input | |
380 * to be of constant frame rate. */ | |
381 avccontext->coded_frame->pts = p_frame_output->frame_num; | |
382 enc_size = p_frame_output->size; | |
383 | |
7253
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
384 /* Append the end of sequence information to the last frame in the |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
385 * sequence. */ |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
386 if (last_frame_in_sequence && p_schro_params->enc_buf_size > 0) { |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
387 memcpy(frame + enc_size, p_schro_params->enc_buf, |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
388 p_schro_params->enc_buf_size); |
7253
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
389 enc_size += p_schro_params->enc_buf_size; |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
390 av_freep(&p_schro_params->enc_buf); |
7253
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
391 p_schro_params->enc_buf_size = 0; |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
392 } |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
393 |
6738 | 394 /* free frame */ |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
395 SchroedingerFreeFrame(p_frame_output); |
6738 | 396 |
397 return enc_size; | |
398 } | |
399 | |
400 | |
401 static int libschroedinger_encode_close(AVCodecContext *avccontext) | |
402 { | |
403 | |
404 FfmpegSchroEncoderParams* p_schro_params = avccontext->priv_data; | |
405 | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
406 /* Close the encoder. */ |
6738 | 407 schro_encoder_free(p_schro_params->encoder); |
408 | |
409 /* Free data in the output frame queue. */ | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
410 ff_dirac_schro_queue_free(&p_schro_params->enc_frame_queue, |
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
411 SchroedingerFreeFrame); |
6738 | 412 |
7253
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
413 |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
414 /* Free the encoder buffer. */ |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
415 if (p_schro_params->enc_buf_size) |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
416 av_freep(&p_schro_params->enc_buf); |
2f5b98d0aa13
Fix pts handling when encoding with libschroedinger, closes issue 453.
diego
parents:
7040
diff
changeset
|
417 |
6738 | 418 /* Free the video format structure. */ |
419 av_freep(&p_schro_params->format); | |
420 | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
421 return 0; |
6738 | 422 } |
423 | |
424 | |
425 AVCodec libschroedinger_encoder = { | |
426 "libschroedinger", | |
11560
8a4984c5cacc
Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents:
10146
diff
changeset
|
427 AVMEDIA_TYPE_VIDEO, |
6738 | 428 CODEC_ID_DIRAC, |
429 sizeof(FfmpegSchroEncoderParams), | |
430 libschroedinger_encode_init, | |
431 libschroedinger_encode_frame, | |
432 libschroedinger_encode_close, | |
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10058
diff
changeset
|
433 .capabilities = CODEC_CAP_DELAY, |
10146
38cfe222e1a4
Mark all pix_fmts and supported_framerates compound literals as const.
reimar
parents:
10061
diff
changeset
|
434 .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:
10058
diff
changeset
|
435 .long_name = NULL_IF_CONFIG_SMALL("libschroedinger Dirac 2.2"), |
6738 | 436 }; |