History

mpegvideo_enc: K&R cosmetics

Aneesh Dogra committed 14 years ago

Commit bd96be61 parent 2702ec21 file · +580 −439Browse files

Unified · Split

libavcodec/mpegvideo_enc.c+580−439
@@ -59,16 +59,18 @@ static int dct_quantize_trellis_c(MpegEncContext *s, DCTELEM *block, int n, int · 58 unmodified lines
5959
6060 //#define DEBUG
6161
62−static uint8_t default_mv_penalty[MAX_FCODE+1][MAX_MV*2+1];
63−static uint8_t default_fcode_tab[MAX_MV*2+1];
62+static uint8_t default_mv_penalty[MAX_FCODE + 1][MAX_MV * 2 + 1];
63+static uint8_t default_fcode_tab[MAX_MV * 2 + 1];
6464
65−void ff_convert_matrix(DSPContext *dsp, int (*qmat)[64], uint16_t (*qmat16)[2][64],
66− const uint16_t *quant_matrix, int bias, int qmin, int qmax, int intra)
65+void ff_convert_matrix(DSPContext *dsp, int (*qmat)[64],
66+ uint16_t (*qmat16)[2][64],
67+ const uint16_t *quant_matrix,
68+ int bias, int qmin, int qmax, int intra)
6769 {
6870 int qscale;
69− int shift=0;
71+ int shift = 0;
7072
71− for(qscale=qmin; qscale<=qmax; qscale++){
73+ for (qscale = qmin; qscale <= qmax; qscale++) {
7274 int i;
7375 if (dsp->fdct == ff_jpeg_fdct_islow_8 ||
7476 dsp->fdct == ff_jpeg_fdct_islow_10
@@ -76,140 +78,169 @@ void ff_convert_matrix(DSPContext *dsp, int (*qmat)[64], uint16_t (*qmat16)[2][6 · 1 unmodified line
7678 || dsp->fdct == ff_faandct
7779 #endif
7880 ) {
79− for(i=0;i<64;i++) {
80− const int j= dsp->idct_permutation[i];
81− /* 16 <= qscale * quant_matrix[i] <= 7905 */
82− /* 19952 <= ff_aanscales[i] * qscale * quant_matrix[i] <= 249205026 */
83− /* (1 << 36) / 19952 >= (1 << 36) / (ff_aanscales[i] * qscale * quant_matrix[i]) >= (1 << 36) / 249205026 */
84− /* 3444240 >= (1 << 36) / (ff_aanscales[i] * qscale * quant_matrix[i]) >= 275 */
81+ for (i = 0; i < 64; i++) {
82+ const int j = dsp->idct_permutation[i];
83+ /* 16 <= qscale * quant_matrix[i] <= 7905
84+ * Assume x = ff_aanscales[i] * qscale * quant_matrix[i]
85+ * 19952 <= x <= 249205026
86+ * (1 << 36) / 19952 >= (1 << 36) / (x) >= (1 << 36) / 249205026
87+ * 3444240 >= (1 << 36) / (x) >= 275 */
8588
8689 qmat[qscale][i] = (int)((UINT64_C(1) << QMAT_SHIFT) /
87− (qscale * quant_matrix[j]));
90+ (qscale * quant_matrix[j]));
8891 }
8992 } else if (dsp->fdct == fdct_ifast
9093 #ifndef FAAN_POSTSCALE
9194 || dsp->fdct == ff_faandct
9295 #endif
9396 ) {
94− for(i=0;i<64;i++) {
95− const int j= dsp->idct_permutation[i];
96− /* 16 <= qscale * quant_matrix[i] <= 7905 */
97− /* 19952 <= ff_aanscales[i] * qscale * quant_matrix[i] <= 249205026 */
98− /* (1 << 36) / 19952 >= (1 << 36) / (ff_aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */
99− /* 3444240 >= (1 << 36) / (ff_aanscales[i] * qscale * quant_matrix[i]) >= 275 */
97+ for (i = 0; i < 64; i++) {
98+ const int j = dsp->idct_permutation[i];
99+ /* 16 <= qscale * quant_matrix[i] <= 7905
100+ * Assume x = ff_aanscales[i] * qscale * quant_matrix[i]
101+ * 19952 <= x <= 249205026
102+ * (1 << 36) / 19952 >= (1 << 36) / (x) >= (1 << 36) / 249205026
103+ * 3444240 >= (1 << 36) / (x) >= 275 */
100104
101105 qmat[qscale][i] = (int)((UINT64_C(1) << (QMAT_SHIFT + 14)) /
102− (ff_aanscales[i] * qscale * quant_matrix[j]));
106+ (ff_aanscales[i] * qscale *
107+ quant_matrix[j]));
103108 }
104109 } else {
105− for(i=0;i<64;i++) {
106− const int j= dsp->idct_permutation[i];
110+ for (i = 0; i < 64; i++) {
111+ const int j = dsp->idct_permutation[i];
107112 /* We can safely suppose that 16 <= quant_matrix[i] <= 255
108− So 16 <= qscale * quant_matrix[i] <= 7905
109− so (1<<19) / 16 >= (1<<19) / (qscale * quant_matrix[i]) >= (1<<19) / 7905
110− so 32768 >= (1<<19) / (qscale * quant_matrix[i]) >= 67
111− */
112− qmat[qscale][i] = (int)((UINT64_C(1) << QMAT_SHIFT) / (qscale * quant_matrix[j]));
113−// qmat [qscale][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[i]);
114− qmat16[qscale][0][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[j]);
113+ * Assume x = qscale * quant_matrix[i]
114+ * So 16 <= x <= 7905
115+ * so (1 << 19) / 16 >= (1 << 19) / (x) >= (1 << 19) / 7905
116+ * so 32768 >= (1 << 19) / (x) >= 67 */
117+ qmat[qscale][i] = (int)((UINT64_C(1) << QMAT_SHIFT) /
118+ (qscale * quant_matrix[j]));
119+ //qmat [qscale][i] = (1 << QMAT_SHIFT_MMX) /
120+ // (qscale * quant_matrix[i]);
121+ qmat16[qscale][0][i] = (1 << QMAT_SHIFT_MMX) /
122+ (qscale * quant_matrix[j]);
115123
116− if(qmat16[qscale][0][i]==0 || qmat16[qscale][0][i]==128*256) qmat16[qscale][0][i]=128*256-1;
117− qmat16[qscale][1][i]= ROUNDED_DIV(bias<<(16-QUANT_BIAS_SHIFT), qmat16[qscale][0][i]);
124+ if (qmat16[qscale][0][i] == 0 ||
125+ qmat16[qscale][0][i] == 128 * 256)
126+ qmat16[qscale][0][i] = 128 * 256 - 1;
127+ qmat16[qscale][1][i] =
128+ ROUNDED_DIV(bias << (16 - QUANT_BIAS_SHIFT),
129+ qmat16[qscale][0][i]);
118130 }
119131 }
120132
121− for(i=intra; i<64; i++){
122− int64_t max= 8191;
133+ for (i = intra; i < 64; i++) {
134+ int64_t max = 8191;
123135 if (dsp->fdct == fdct_ifast
124136 #ifndef FAAN_POSTSCALE
125− || dsp->fdct == ff_faandct
137+ || dsp->fdct == ff_faandct
126138 #endif
127− ) {
128− max = (8191LL*ff_aanscales[i]) >> 14;
139+ ) {
140+ max = (8191LL * ff_aanscales[i]) >> 14;
129141 }
130− while(((max * qmat[qscale][i]) >> shift) > INT_MAX){
142+ while (((max * qmat[qscale][i]) >> shift) > INT_MAX) {
131143 shift++;
132144 }
133145 }
134146 }
135− if(shift){
136− av_log(NULL, AV_LOG_INFO, "Warning, QMAT_SHIFT is larger than %d, overflows possible\n", QMAT_SHIFT - shift);
147+ if (shift) {
148+ av_log(NULL, AV_LOG_INFO,
149+ "Warning, QMAT_SHIFT is larger than %d, overflows possible\n",
150+ QMAT_SHIFT - shift);
137151 }
138152 }
139153
140−static inline void update_qscale(MpegEncContext *s){
141− s->qscale= (s->lambda*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7);
142− s->qscale= av_clip(s->qscale, s->avctx->qmin, s->avctx->qmax);
154+static inline void update_qscale(MpegEncContext *s)
155+{
156+ s->qscale = (s->lambda * 139 + FF_LAMBDA_SCALE * 64) >>
157+ (FF_LAMBDA_SHIFT + 7);
158+ s->qscale = av_clip(s->qscale, s->avctx->qmin, s->avctx->qmax);
143159
144− s->lambda2= (s->lambda*s->lambda + FF_LAMBDA_SCALE/2) >> FF_LAMBDA_SHIFT;
160+ s->lambda2 = (s->lambda * s->lambda + FF_LAMBDA_SCALE / 2) >>
161+ FF_LAMBDA_SHIFT;
145162 }
146163
147−void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix){
164+void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix)
165+{
148166 int i;
149167
150− if(matrix){
168+ if (matrix) {
151169 put_bits(pb, 1, 1);
152− for(i=0;i<64;i++) {
153− put_bits(pb, 8, matrix[ ff_zigzag_direct[i] ]);
170+ for (i = 0; i < 64; i++) {
171+ put_bits(pb, 8, matrix[ff_zigzag_direct[i]]);
154172 }
155− }else
173+ } else
156174 put_bits(pb, 1, 0);
157175 }
158176
159177 /**
160178 * init s->current_picture.qscale_table from s->lambda_table
161179 */
162−void ff_init_qscale_tab(MpegEncContext *s){
180+void ff_init_qscale_tab(MpegEncContext *s)
181+{
163182 int8_t * const qscale_table = s->current_picture.f.qscale_table;
164183 int i;
165184
166− for(i=0; i<s->mb_num; i++){
167− unsigned int lam= s->lambda_table[ s->mb_index2xy[i] ];
168− int qp= (lam*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7);
169− qscale_table[ s->mb_index2xy[i] ]= av_clip(qp, s->avctx->qmin, s->avctx->qmax);
185+ for (i = 0; i < s->mb_num; i++) {
186+ unsigned int lam = s->lambda_table[s->mb_index2xy[i]];
187+ int qp = (lam * 139 + FF_LAMBDA_SCALE * 64) >> (FF_LAMBDA_SHIFT + 7);
188+ qscale_table[s->mb_index2xy[i]] = av_clip(qp, s->avctx->qmin,
189+ s->avctx->qmax);
170190 }
171191 }
172192
173−static void copy_picture_attributes(MpegEncContext *s, AVFrame *dst, AVFrame *src){
193+static void copy_picture_attributes(MpegEncContext *s,
194+ AVFrame *dst,
195+ AVFrame *src)
196+{
174197 int i;
175198
176199 dst->pict_type = src->pict_type;
177200 dst->quality = src->quality;
178201 dst->coded_picture_number = src->coded_picture_number;
179202 dst->display_picture_number = src->display_picture_number;
180−// dst->reference = src->reference;
203+ //dst->reference = src->reference;
181204 dst->pts = src->pts;
182205 dst->interlaced_frame = src->interlaced_frame;
183206 dst->top_field_first = src->top_field_first;
184207
185− if(s->avctx->me_threshold){
186− if(!src->motion_val[0])
208+ if (s->avctx->me_threshold) {
209+ if (!src->motion_val[0])
187210 av_log(s->avctx, AV_LOG_ERROR, "AVFrame.motion_val not set!\n");
188− if(!src->mb_type)
211+ if (!src->mb_type)
189212 av_log(s->avctx, AV_LOG_ERROR, "AVFrame.mb_type not set!\n");
190− if(!src->ref_index[0])
213+ if (!src->ref_index[0])
191214 av_log(s->avctx, AV_LOG_ERROR, "AVFrame.ref_index not set!\n");
192− if(src->motion_subsample_log2 != dst->motion_subsample_log2)
193− av_log(s->avctx, AV_LOG_ERROR, "AVFrame.motion_subsample_log2 doesn't match! (%d!=%d)\n",
194− src->motion_subsample_log2, dst->motion_subsample_log2);
215+ if (src->motion_subsample_log2 != dst->motion_subsample_log2)
216+ av_log(s->avctx, AV_LOG_ERROR,
217+ "AVFrame.motion_subsample_log2 doesn't match! (%d!=%d)\n",
218+ src->motion_subsample_log2, dst->motion_subsample_log2);
195219
196− memcpy(dst->mb_type, src->mb_type, s->mb_stride * s->mb_height * sizeof(dst->mb_type[0]));
220+ memcpy(dst->mb_type, src->mb_type,
221+ s->mb_stride * s->mb_height * sizeof(dst->mb_type[0]));
197222
198− for(i=0; i<2; i++){
199− int stride= ((16*s->mb_width )>>src->motion_subsample_log2) + 1;
200− int height= ((16*s->mb_height)>>src->motion_subsample_log2);
223+ for (i = 0; i < 2; i++) {
224+ int stride = ((16 * s->mb_width ) >>
225+ src->motion_subsample_log2) + 1;
226+ int height = ((16 * s->mb_height) >> src->motion_subsample_log2);
201227
202− if(src->motion_val[i] && src->motion_val[i] != dst->motion_val[i]){
203− memcpy(dst->motion_val[i], src->motion_val[i], 2*stride*height*sizeof(int16_t));
228+ if (src->motion_val[i] &&
229+ src->motion_val[i] != dst->motion_val[i]) {
230+ memcpy(dst->motion_val[i], src->motion_val[i],
231+ 2 * stride * height * sizeof(int16_t));
204232 }
205− if(src->ref_index[i] && src->ref_index[i] != dst->ref_index[i]){
206− memcpy(dst->ref_index[i], src->ref_index[i], s->mb_stride*4*s->mb_height*sizeof(int8_t));
233+ if (src->ref_index[i] && src->ref_index[i] != dst->ref_index[i]) {
234+ memcpy(dst->ref_index[i], src->ref_index[i],
235+ s->mb_stride * 4 * s->mb_height * sizeof(int8_t));
207236 }
208237 }
209238 }
210239 }
211240
212−static void update_duplicate_context_after_me(MpegEncContext *dst, MpegEncContext *src){
241+static void update_duplicate_context_after_me(MpegEncContext *dst,
242+ MpegEncContext *src)
243+{
213244 #define COPY(a) dst->a= src->a
214245 COPY(pict_type);
215246 COPY(current_picture);
@@ -220,9 +251,9 @@ static void update_duplicate_context_after_me(MpegEncContext *dst, MpegEncContex · 4 unmodified lines
220251 COPY(lambda2);
221252 COPY(picture_in_gop_number);
222253 COPY(gop_picture_number);
223− COPY(frame_pred_frame_dct); //FIXME don't set in encode_header
224− COPY(progressive_frame); //FIXME don't set in encode_header
225− COPY(partitioned_frame); //FIXME don't set in encode_header
254+ COPY(frame_pred_frame_dct); // FIXME don't set in encode_header
255+ COPY(progressive_frame); // FIXME don't set in encode_header
256+ COPY(partitioned_frame); // FIXME don't set in encode_header
226257 #undef COPY
227258 }
228259
@@ -230,15 +261,16 @@ static void update_duplicate_context_after_me(MpegEncContext *dst, MpegEncContex · 1 unmodified line
230261 * Set the given MpegEncContext to defaults for encoding.
231262 * the changed fields will not depend upon the prior state of the MpegEncContext.
232263 */
233−static void MPV_encode_defaults(MpegEncContext *s){
264+static void MPV_encode_defaults(MpegEncContext *s)
265+{
234266 int i;
235267 MPV_common_defaults(s);
236268
237− for(i=-16; i<16; i++){
238− default_fcode_tab[i + MAX_MV]= 1;
269+ for (i = -16; i < 16; i++) {
270+ default_fcode_tab[i + MAX_MV] = 1;
239271 }
240− s->me.mv_penalty= default_mv_penalty;
241− s->fcode_tab= default_fcode_tab;
272+ s->me.mv_penalty = default_mv_penalty;
273+ s->fcode_tab = default_fcode_tab;
242274 }
243275
244276 /* init video encoder */
@@ -252,27 +284,38 @@ av_cold int MPV_encode_init(AVCodecContext *avctx) · 7 unmodified lines
252284
253285 switch (avctx->codec_id) {
254286 case CODEC_ID_MPEG2VIDEO:
255− if(avctx->pix_fmt != PIX_FMT_YUV420P && avctx->pix_fmt != PIX_FMT_YUV422P){
256− av_log(avctx, AV_LOG_ERROR, "only YUV420 and YUV422 are supported\n");
287+ if (avctx->pix_fmt != PIX_FMT_YUV420P &&
288+ avctx->pix_fmt != PIX_FMT_YUV422P) {
289+ av_log(avctx, AV_LOG_ERROR,
290+ "only YUV420 and YUV422 are supported\n");
257291 return -1;
258292 }
259293 break;
260294 case CODEC_ID_LJPEG:
261− if(avctx->pix_fmt != PIX_FMT_YUVJ420P && avctx->pix_fmt != PIX_FMT_YUVJ422P && avctx->pix_fmt != PIX_FMT_YUVJ444P && avctx->pix_fmt != PIX_FMT_BGRA &&
262− ((avctx->pix_fmt != PIX_FMT_YUV420P && avctx->pix_fmt != PIX_FMT_YUV422P && avctx->pix_fmt != PIX_FMT_YUV444P) || avctx->strict_std_compliance>FF_COMPLIANCE_UNOFFICIAL)){
295+ if (avctx->pix_fmt != PIX_FMT_YUVJ420P &&
296+ avctx->pix_fmt != PIX_FMT_YUVJ422P &&
297+ avctx->pix_fmt != PIX_FMT_YUVJ444P &&
298+ avctx->pix_fmt != PIX_FMT_BGRA &&
299+ ((avctx->pix_fmt != PIX_FMT_YUV420P &&
300+ avctx->pix_fmt != PIX_FMT_YUV422P &&
301+ avctx->pix_fmt != PIX_FMT_YUV444P) ||
302+ avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL)) {
263303 av_log(avctx, AV_LOG_ERROR, "colorspace not supported in LJPEG\n");
264304 return -1;
265305 }
266306 break;
267307 case CODEC_ID_MJPEG:
268− if(avctx->pix_fmt != PIX_FMT_YUVJ420P && avctx->pix_fmt != PIX_FMT_YUVJ422P &&
269− ((avctx->pix_fmt != PIX_FMT_YUV420P && avctx->pix_fmt != PIX_FMT_YUV422P) || avctx->strict_std_compliance>FF_COMPLIANCE_UNOFFICIAL)){
308+ if (avctx->pix_fmt != PIX_FMT_YUVJ420P &&
309+ avctx->pix_fmt != PIX_FMT_YUVJ422P &&
310+ ((avctx->pix_fmt != PIX_FMT_YUV420P &&
311+ avctx->pix_fmt != PIX_FMT_YUV422P) ||
312+ avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL)) {
270313 av_log(avctx, AV_LOG_ERROR, "colorspace not supported in jpeg\n");
271314 return -1;
272315 }
273316 break;
274317 default:
275− if(avctx->pix_fmt != PIX_FMT_YUV420P){
318+ if (avctx->pix_fmt != PIX_FMT_YUV420P) {
276319 av_log(avctx, AV_LOG_ERROR, "only YUV420 is supported\n");
277320 return -1;
278321 }
@@ -291,34 +334,36 @@ av_cold int MPV_encode_init(AVCodecContext *avctx) · 12 unmodified lines
291334 }
292335
293336 s->bit_rate = avctx->bit_rate;
294− s->width = avctx->width;
295− s->height = avctx->height;
296− if(avctx->gop_size > 600 && avctx->strict_std_compliance>FF_COMPLIANCE_EXPERIMENTAL){
297− av_log(avctx, AV_LOG_ERROR, "Warning keyframe interval too large! reducing it ...\n");
298− avctx->gop_size=600;
299− }
300− s->gop_size = avctx->gop_size;
301− s->avctx = avctx;
302− s->flags= avctx->flags;
303− s->flags2= avctx->flags2;
304− s->max_b_frames= avctx->max_b_frames;
305− s->codec_id= avctx->codec->id;
306− s->luma_elim_threshold = avctx->luma_elim_threshold;
307− s->chroma_elim_threshold= avctx->chroma_elim_threshold;
308− s->strict_std_compliance= avctx->strict_std_compliance;
337+ s->width = avctx->width;
338+ s->height = avctx->height;
339+ if (avctx->gop_size > 600 &&
340+ avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
341+ av_log(avctx, AV_LOG_ERROR,
342+ "Warning keyframe interval too large! reducing it ...\n");
343+ avctx->gop_size = 600;
344+ }
345+ s->gop_size = avctx->gop_size;
346+ s->avctx = avctx;
347+ s->flags = avctx->flags;
348+ s->flags2 = avctx->flags2;
349+ s->max_b_frames = avctx->max_b_frames;
350+ s->codec_id = avctx->codec->id;
351+ s->luma_elim_threshold = avctx->luma_elim_threshold;
352+ s->chroma_elim_threshold = avctx->chroma_elim_threshold;
353+ s->strict_std_compliance = avctx->strict_std_compliance;
309354 #if FF_API_MPEGVIDEO_GLOBAL_OPTS
310355 if (avctx->flags & CODEC_FLAG_PART)
311356 s->data_partitioning = 1;
312357 #endif
313− s->quarter_sample= (avctx->flags & CODEC_FLAG_QPEL)!=0;
314− s->mpeg_quant= avctx->mpeg_quant;
315− s->rtp_mode= !!avctx->rtp_payload_size;
316− s->intra_dc_precision= avctx->intra_dc_precision;
358+ s->quarter_sample = (avctx->flags & CODEC_FLAG_QPEL) != 0;
359+ s->mpeg_quant = avctx->mpeg_quant;
360+ s->rtp_mode = !!avctx->rtp_payload_size;
361+ s->intra_dc_precision = avctx->intra_dc_precision;
317362 s->user_specified_pts = AV_NOPTS_VALUE;
318363
319364 if (s->gop_size <= 1) {
320365 s->intra_only = 1;
321− s->gop_size = 12;
366+ s->gop_size = 12;
322367 } else {
323368 s->intra_only = 0;
324369 }
@@ -328,284 +373,349 @@ av_cold int MPV_encode_init(AVCodecContext *avctx) · 3 unmodified lines
328373 /* Fixed QSCALE */
329374 s->fixed_qscale = !!(avctx->flags & CODEC_FLAG_QSCALE);
330375
331− s->adaptive_quant= ( s->avctx->lumi_masking
332− || s->avctx->dark_masking
333− || s->avctx->temporal_cplx_masking
334− || s->avctx->spatial_cplx_masking
335− || s->avctx->p_masking
336− || s->avctx->border_masking
337− || (s->flags&CODEC_FLAG_QP_RD))
338− && !s->fixed_qscale;
376+ s->adaptive_quant = (s->avctx->lumi_masking ||
377+ s->avctx->dark_masking ||
378+ s->avctx->temporal_cplx_masking ||
379+ s->avctx->spatial_cplx_masking ||
380+ s->avctx->p_masking ||
381+ s->avctx->border_masking ||
382+ (s->flags & CODEC_FLAG_QP_RD)) &&
383+ !s->fixed_qscale;
339384
340− s->loop_filter= !!(s->flags & CODEC_FLAG_LOOP_FILTER);
385+ s->loop_filter = !!(s->flags & CODEC_FLAG_LOOP_FILTER);
341386 #if FF_API_MPEGVIDEO_GLOBAL_OPTS
342− s->alternate_scan= !!(s->flags & CODEC_FLAG_ALT_SCAN);
343− s->intra_vlc_format= !!(s->flags2 & CODEC_FLAG2_INTRA_VLC);
344− s->q_scale_type= !!(s->flags2 & CODEC_FLAG2_NON_LINEAR_QUANT);
345− s->obmc= !!(s->flags & CODEC_FLAG_OBMC);
387+ s->alternate_scan = !!(s->flags & CODEC_FLAG_ALT_SCAN);
388+ s->intra_vlc_format = !!(s->flags2 & CODEC_FLAG2_INTRA_VLC);
389+ s->q_scale_type = !!(s->flags2 & CODEC_FLAG2_NON_LINEAR_QUANT);
390+ s->obmc = !!(s->flags & CODEC_FLAG_OBMC);
346391 #endif
347392
348− if(avctx->rc_max_rate && !avctx->rc_buffer_size){
349− av_log(avctx, AV_LOG_ERROR, "a vbv buffer size is needed, for encoding with a maximum bitrate\n");
393+ if (avctx->rc_max_rate && !avctx->rc_buffer_size) {
394+ av_log(avctx, AV_LOG_ERROR,
395+ "a vbv buffer size is needed, "
396+ "for encoding with a maximum bitrate\n");
350397 return -1;
351398 }
352399
353− if(avctx->rc_min_rate && avctx->rc_max_rate != avctx->rc_min_rate){
354− av_log(avctx, AV_LOG_INFO, "Warning min_rate > 0 but min_rate != max_rate isn't recommended!\n");
400+ if (avctx->rc_min_rate && avctx->rc_max_rate != avctx->rc_min_rate) {
401+ av_log(avctx, AV_LOG_INFO,
402+ "Warning min_rate > 0 but min_rate != max_rate isn't recommended!\n");
355403 }
356404
357− if(avctx->rc_min_rate && avctx->rc_min_rate > avctx->bit_rate){
405+ if (avctx->rc_min_rate && avctx->rc_min_rate > avctx->bit_rate) {
358406 av_log(avctx, AV_LOG_ERROR, "bitrate below min bitrate\n");
359407 return -1;
360408 }
361409
362− if(avctx->rc_max_rate && avctx->rc_max_rate < avctx->bit_rate){
410+ if (avctx->rc_max_rate && avctx->rc_max_rate < avctx->bit_rate) {
363411 av_log(avctx, AV_LOG_INFO, "bitrate above max bitrate\n");
364412 return -1;
365413 }
366414
367− if(avctx->rc_max_rate && avctx->rc_max_rate == avctx->bit_rate && avctx->rc_max_rate != avctx->rc_min_rate){
368− av_log(avctx, AV_LOG_INFO, "impossible bitrate constraints, this will fail\n");
415+ if (avctx->rc_max_rate &&
416+ avctx->rc_max_rate == avctx->bit_rate &&
417+ avctx->rc_max_rate != avctx->rc_min_rate) {
418+ av_log(avctx, AV_LOG_INFO,
419+ "impossible bitrate constraints, this will fail\n");
369420 }
370421
371− if(avctx->rc_buffer_size && avctx->bit_rate*(int64_t)avctx->time_base.num > avctx->rc_buffer_size * (int64_t)avctx->time_base.den){
422+ if (avctx->rc_buffer_size &&
423+ avctx->bit_rate * (int64_t)avctx->time_base.num >
424+ avctx->rc_buffer_size * (int64_t)avctx->time_base.den) {
372425 av_log(avctx, AV_LOG_ERROR, "VBV buffer too small for bitrate\n");
373426 return -1;
374427 }
375428
376− if(!s->fixed_qscale && avctx->bit_rate*av_q2d(avctx->time_base) > avctx->bit_rate_tolerance){
377− av_log(avctx, AV_LOG_ERROR, "bitrate tolerance too small for bitrate\n");
429+ if (!s->fixed_qscale &&
430+ avctx->bit_rate * av_q2d(avctx->time_base) >
431+ avctx->bit_rate_tolerance) {
432+ av_log(avctx, AV_LOG_ERROR,
433+ "bitrate tolerance too small for bitrate\n");
378434 return -1;
379435 }
380436
381− if( s->avctx->rc_max_rate && s->avctx->rc_min_rate == s->avctx->rc_max_rate
382− && (s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO)
383− && 90000LL * (avctx->rc_buffer_size-1) > s->avctx->rc_max_rate*0xFFFFLL){
384−
385− av_log(avctx, AV_LOG_INFO, "Warning vbv_delay will be set to 0xFFFF (=VBR) as the specified vbv buffer is too large for the given bitrate!\n");
437+ if (s->avctx->rc_max_rate &&
438+ s->avctx->rc_min_rate == s->avctx->rc_max_rate &&
439+ (s->codec_id == CODEC_ID_MPEG1VIDEO ||
440+ s->codec_id == CODEC_ID_MPEG2VIDEO) &&
441+ 90000LL * (avctx->rc_buffer_size - 1) >
442+ s->avctx->rc_max_rate * 0xFFFFLL) {
443+ av_log(avctx, AV_LOG_INFO,
444+ "Warning vbv_delay will be set to 0xFFFF (=VBR) as the "
445+ "specified vbv buffer is too large for the given bitrate!\n");
386446 }
387447
388− if((s->flags & CODEC_FLAG_4MV) && s->codec_id != CODEC_ID_MPEG4
389− && s->codec_id != CODEC_ID_H263 && s->codec_id != CODEC_ID_H263P && s->codec_id != CODEC_ID_FLV1){
448+ if ((s->flags & CODEC_FLAG_4MV) && s->codec_id != CODEC_ID_MPEG4 &&
449+ s->codec_id != CODEC_ID_H263 && s->codec_id != CODEC_ID_H263P &&
450+ s->codec_id != CODEC_ID_FLV1) {
390451 av_log(avctx, AV_LOG_ERROR, "4MV not supported by codec\n");
391452 return -1;
392453 }
393454
394− if(s->obmc && s->avctx->mb_decision != FF_MB_DECISION_SIMPLE){
395− av_log(avctx, AV_LOG_ERROR, "OBMC is only supported with simple mb decision\n");
455+ if (s->obmc && s->avctx->mb_decision != FF_MB_DECISION_SIMPLE) {
456+ av_log(avctx, AV_LOG_ERROR,
457+ "OBMC is only supported with simple mb decision\n");
396458 return -1;
397459 }
398460
399461 #if FF_API_MPEGVIDEO_GLOBAL_OPTS
400− if(s->obmc && s->codec_id != CODEC_ID_H263 && s->codec_id != CODEC_ID_H263P){
462+ if (s->obmc && s->codec_id != CODEC_ID_H263 &&
463+ s->codec_id != CODEC_ID_H263P) {
401464 av_log(avctx, AV_LOG_ERROR, "OBMC is only supported with H263(+)\n");
402465 return -1;
403466 }
404467 #endif
405468
406− if(s->quarter_sample && s->codec_id != CODEC_ID_MPEG4){
469+ if (s->quarter_sample && s->codec_id != CODEC_ID_MPEG4) {
407470 av_log(avctx, AV_LOG_ERROR, "qpel not supported by codec\n");
408471 return -1;
409472 }
410473
411474 #if FF_API_MPEGVIDEO_GLOBAL_OPTS
412− if(s->data_partitioning && s->codec_id != CODEC_ID_MPEG4){
413− av_log(avctx, AV_LOG_ERROR, "data partitioning not supported by codec\n");
475+ if (s->data_partitioning && s->codec_id != CODEC_ID_MPEG4) {
476+ av_log(avctx, AV_LOG_ERROR,
477+ "data partitioning not supported by codec\n");
414478 return -1;
415479 }
416480 #endif
417481
418− if(s->max_b_frames && s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_MPEG1VIDEO && s->codec_id != CODEC_ID_MPEG2VIDEO){
482+ if (s->max_b_frames &&
483+ s->codec_id != CODEC_ID_MPEG4 &&
484+ s->codec_id != CODEC_ID_MPEG1VIDEO &&
485+ s->codec_id != CODEC_ID_MPEG2VIDEO) {
419486 av_log(avctx, AV_LOG_ERROR, "b frames not supported by codec\n");
420487 return -1;
421488 }
422489
423− if ((s->codec_id == CODEC_ID_MPEG4 || s->codec_id == CODEC_ID_H263 ||
490+ if ((s->codec_id == CODEC_ID_MPEG4 ||
491+ s->codec_id == CODEC_ID_H263 ||
424492 s->codec_id == CODEC_ID_H263P) &&
425− (avctx->sample_aspect_ratio.num > 255 || avctx->sample_aspect_ratio.den > 255)) {
426− av_log(avctx, AV_LOG_ERROR, "Invalid pixel aspect ratio %i/%i, limit is 255/255\n",
493+ (avctx->sample_aspect_ratio.num > 255 ||
494+ avctx->sample_aspect_ratio.den > 255)) {
495+ av_log(avctx, AV_LOG_ERROR,
496+ "Invalid pixel aspect ratio %i/%i, limit is 255/255\n",
427497 avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den);
428498 return -1;
429499 }
430500
431− if((s->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME|CODEC_FLAG_ALT_SCAN))
432− && s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_MPEG2VIDEO){
501+ if ((s->flags & (CODEC_FLAG_INTERLACED_DCT | CODEC_FLAG_INTERLACED_ME |
502+ CODEC_FLAG_ALT_SCAN)) &&
503+ s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_MPEG2VIDEO) {
433504 av_log(avctx, AV_LOG_ERROR, "interlacing not supported by codec\n");
434505 return -1;
435506 }
436507
437− if(s->mpeg_quant && s->codec_id != CODEC_ID_MPEG4){ //FIXME mpeg2 uses that too
438− av_log(avctx, AV_LOG_ERROR, "mpeg2 style quantization not supported by codec\n");
508+ // FIXME mpeg2 uses that too
509+ if (s->mpeg_quant && s->codec_id != CODEC_ID_MPEG4) {
510+ av_log(avctx, AV_LOG_ERROR,
511+ "mpeg2 style quantization not supported by codec\n");
439512 return -1;
440513 }
441514
442− if((s->flags & CODEC_FLAG_CBP_RD) && !avctx->trellis){
515+ if ((s->flags & CODEC_FLAG_CBP_RD) && !avctx->trellis) {
443516 av_log(avctx, AV_LOG_ERROR, "CBP RD needs trellis quant\n");
444517 return -1;
445518 }
446519
447− if((s->flags & CODEC_FLAG_QP_RD) && s->avctx->mb_decision != FF_MB_DECISION_RD){
520+ if ((s->flags & CODEC_FLAG_QP_RD) &&
521+ s->avctx->mb_decision != FF_MB_DECISION_RD) {
448522 av_log(avctx, AV_LOG_ERROR, "QP RD needs mbd=2\n");
449523 return -1;
450524 }
451525
452− if(s->avctx->scenechange_threshold < 1000000000 && (s->flags & CODEC_FLAG_CLOSED_GOP)){
453− av_log(avctx, AV_LOG_ERROR, "closed gop with scene change detection are not supported yet, set threshold to 1000000000\n");
526+ if (s->avctx->scenechange_threshold < 1000000000 &&
527+ (s->flags & CODEC_FLAG_CLOSED_GOP)) {
528+ av_log(avctx, AV_LOG_ERROR,
529+ "closed gop with scene change detection are not supported yet, "
530+ "set threshold to 1000000000\n");
454531 return -1;
455532 }
456533
457− if((s->flags2 & CODEC_FLAG2_INTRA_VLC) && s->codec_id != CODEC_ID_MPEG2VIDEO){
458− av_log(avctx, AV_LOG_ERROR, "intra vlc table not supported by codec\n");
534+ if ((s->flags2 & CODEC_FLAG2_INTRA_VLC) &&
535+ s->codec_id != CODEC_ID_MPEG2VIDEO) {
536+ av_log(avctx, AV_LOG_ERROR,
537+ "intra vlc table not supported by codec\n");
459538 return -1;
460539 }
461540
462− if(s->flags & CODEC_FLAG_LOW_DELAY){
463− if (s->codec_id != CODEC_ID_MPEG2VIDEO){
464− av_log(avctx, AV_LOG_ERROR, "low delay forcing is only available for mpeg2\n");
541+ if (s->flags & CODEC_FLAG_LOW_DELAY) {
542+ if (s->codec_id != CODEC_ID_MPEG2VIDEO) {
543+ av_log(avctx, AV_LOG_ERROR,
544+ "low delay forcing is only available for mpeg2\n");
465545 return -1;
466546 }
467− if (s->max_b_frames != 0){
468− av_log(avctx, AV_LOG_ERROR, "b frames cannot be used with low delay\n");
547+ if (s->max_b_frames != 0) {
548+ av_log(avctx, AV_LOG_ERROR,
549+ "b frames cannot be used with low delay\n");
469550 return -1;
470551 }
471552 }
472553
473− if(s->q_scale_type == 1){
554+ if (s->q_scale_type == 1) {
474555 #if FF_API_MPEGVIDEO_GLOBAL_OPTS
475− if(s->codec_id != CODEC_ID_MPEG2VIDEO){
476− av_log(avctx, AV_LOG_ERROR, "non linear quant is only available for mpeg2\n");
556+ if (s->codec_id != CODEC_ID_MPEG2VIDEO) {
557+ av_log(avctx, AV_LOG_ERROR,
558+ "non linear quant is only available for mpeg2\n");
477559 return -1;
478560 }
479561 #endif
480− if(avctx->qmax > 12){
481− av_log(avctx, AV_LOG_ERROR, "non linear quant only supports qmax <= 12 currently\n");
562+ if (avctx->qmax > 12) {
563+ av_log(avctx, AV_LOG_ERROR,
564+ "non linear quant only supports qmax <= 12 currently\n");
482565 return -1;
483566 }
484567 }
485568
486− if(s->avctx->thread_count > 1 && s->codec_id != CODEC_ID_MPEG4
487− && s->codec_id != CODEC_ID_MPEG1VIDEO && s->codec_id != CODEC_ID_MPEG2VIDEO
488− && (s->codec_id != CODEC_ID_H263P || !(s->flags & CODEC_FLAG_H263P_SLICE_STRUCT))){
489− av_log(avctx, AV_LOG_ERROR, "multi threaded encoding not supported by codec\n");
569+ if (s->avctx->thread_count > 1 &&
570+ s->codec_id != CODEC_ID_MPEG4 &&
571+ s->codec_id != CODEC_ID_MPEG1VIDEO &&
572+ s->codec_id != CODEC_ID_MPEG2VIDEO &&
573+ (s->codec_id != CODEC_ID_H263P ||
574+ !(s->flags & CODEC_FLAG_H263P_SLICE_STRUCT))) {
575+ av_log(avctx, AV_LOG_ERROR,
576+ "multi threaded encoding not supported by codec\n");
490577 return -1;
491578 }
492579
493− if(s->avctx->thread_count < 1){
494− av_log(avctx, AV_LOG_ERROR, "automatic thread number detection not supported by codec, patch welcome\n");
580+ if (s->avctx->thread_count < 1) {
581+ av_log(avctx, AV_LOG_ERROR,
582+ "automatic thread number detection not supported by codec,"
583+ "patch welcome\n");
495584 return -1;
496585 }
497586
498− if(s->avctx->thread_count > 1)
499− s->rtp_mode= 1;
587+ if (s->avctx->thread_count > 1)
588+ s->rtp_mode = 1;
500589
501− if(!avctx->time_base.den || !avctx->time_base.num){
590+ if (!avctx->time_base.den || !avctx->time_base.num) {
502591 av_log(avctx, AV_LOG_ERROR, "framerate not set\n");
503592 return -1;
504593 }
505594
506− i= (INT_MAX/2+128)>>8;
507− if(avctx->me_threshold >= i){
508− av_log(avctx, AV_LOG_ERROR, "me_threshold too large, max is %d\n", i - 1);
595+ i = (INT_MAX / 2 + 128) >> 8;
596+ if (avctx->me_threshold >= i) {
597+ av_log(avctx, AV_LOG_ERROR, "me_threshold too large, max is %d\n",
598+ i - 1);
509599 return -1;
510600 }
511− if(avctx->mb_threshold >= i){
512− av_log(avctx, AV_LOG_ERROR, "mb_threshold too large, max is %d\n", i - 1);
601+ if (avctx->mb_threshold >= i) {
602+ av_log(avctx, AV_LOG_ERROR, "mb_threshold too large, max is %d\n",
603+ i - 1);
513604 return -1;
514605 }
515606
516− if(avctx->b_frame_strategy && (avctx->flags&CODEC_FLAG_PASS2)){
517− av_log(avctx, AV_LOG_INFO, "notice: b_frame_strategy only affects the first pass\n");
607+ if (avctx->b_frame_strategy && (avctx->flags & CODEC_FLAG_PASS2)) {
608+ av_log(avctx, AV_LOG_INFO,
609+ "notice: b_frame_strategy only affects the first pass\n");
518610 avctx->b_frame_strategy = 0;
519611 }
520612
521− i= av_gcd(avctx->time_base.den, avctx->time_base.num);
522− if(i > 1){
613+ i = av_gcd(avctx->time_base.den, avctx->time_base.num);
614+ if (i > 1) {
523615 av_log(avctx, AV_LOG_INFO, "removing common factors from framerate\n");
524616 avctx->time_base.den /= i;
525617 avctx->time_base.num /= i;
526−// return -1;
527− }
528−
529− if(s->mpeg_quant || s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO || s->codec_id==CODEC_ID_MJPEG){
530− s->intra_quant_bias= 3<<(QUANT_BIAS_SHIFT-3); //(a + x*3/8)/x
531− s->inter_quant_bias= 0;
532− }else{
533− s->intra_quant_bias=0;
534− s->inter_quant_bias=-(1<<(QUANT_BIAS_SHIFT-2)); //(a - x/4)/x
618+ //return -1;
535619 }
536620
537− if(avctx->intra_quant_bias != FF_DEFAULT_QUANT_BIAS)
538− s->intra_quant_bias= avctx->intra_quant_bias;
539− if(avctx->inter_quant_bias != FF_DEFAULT_QUANT_BIAS)
540− s->inter_quant_bias= avctx->inter_quant_bias;
541−
542− avcodec_get_chroma_sub_sample(avctx->pix_fmt, &chroma_h_shift, &chroma_v_shift);
543−
544− if(avctx->codec_id == CODEC_ID_MPEG4 && s->avctx->time_base.den > (1<<16)-1){
545− av_log(avctx, AV_LOG_ERROR, "timebase %d/%d not supported by MPEG 4 standard, "
546− "the maximum admitted value for the timebase denominator is %d\n",
547− s->avctx->time_base.num, s->avctx->time_base.den, (1<<16)-1);
621+ if (s->mpeg_quant || s->codec_id == CODEC_ID_MPEG1VIDEO ||
622+ s->codec_id == CODEC_ID_MPEG2VIDEO || s->codec_id == CODEC_ID_MJPEG) {
623+ // (a + x * 3 / 8) / x
624+ s->intra_quant_bias = 3 << (QUANT_BIAS_SHIFT - 3);
625+ s->inter_quant_bias = 0;
626+ } else {
627+ s->intra_quant_bias = 0;
628+ // (a - x / 4) / x
629+ s->inter_quant_bias = -(1 << (QUANT_BIAS_SHIFT - 2));
630+ }
631+
632+ if (avctx->intra_quant_bias != FF_DEFAULT_QUANT_BIAS)
633+ s->intra_quant_bias = avctx->intra_quant_bias;
634+ if (avctx->inter_quant_bias != FF_DEFAULT_QUANT_BIAS)
635+ s->inter_quant_bias = avctx->inter_quant_bias;
636+
637+ avcodec_get_chroma_sub_sample(avctx->pix_fmt, &chroma_h_shift,
638+ &chroma_v_shift);
639+
640+ if (avctx->codec_id == CODEC_ID_MPEG4 &&
641+ s->avctx->time_base.den > (1 << 16) - 1) {
642+ av_log(avctx, AV_LOG_ERROR,
643+ "timebase %d/%d not supported by MPEG 4 standard, "
644+ "the maximum admitted value for the timebase denominator "
645+ "is %d\n", s->avctx->time_base.num, s->avctx->time_base.den,
646+ (1 << 16) - 1);
548647 return -1;
549648 }
550649 s->time_increment_bits = av_log2(s->avctx->time_base.den - 1) + 1;
551650
552− switch(avctx->codec->id) {
651+ switch (avctx->codec->id) {
553652 case CODEC_ID_MPEG1VIDEO:
554653 s->out_format = FMT_MPEG1;
555− s->low_delay= !!(s->flags & CODEC_FLAG_LOW_DELAY);
556− avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1);
654+ s->low_delay = !!(s->flags & CODEC_FLAG_LOW_DELAY);
655+ avctx->delay = s->low_delay ? 0 : (s->max_b_frames + 1);
557656 break;
558657 case CODEC_ID_MPEG2VIDEO:
559658 s->out_format = FMT_MPEG1;
560− s->low_delay= !!(s->flags & CODEC_FLAG_LOW_DELAY);
561− avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1);
562− s->rtp_mode= 1;
659+ s->low_delay = !!(s->flags & CODEC_FLAG_LOW_DELAY);
660+ avctx->delay = s->low_delay ? 0 : (s->max_b_frames + 1);
661+ s->rtp_mode = 1;
563662 break;
564663 case CODEC_ID_LJPEG:
565664 case CODEC_ID_MJPEG:
566665 s->out_format = FMT_MJPEG;
567666 s->intra_only = 1; /* force intra only for jpeg */
568− if(avctx->codec->id == CODEC_ID_LJPEG && avctx->pix_fmt == PIX_FMT_BGRA){
667+ if (avctx->codec->id == CODEC_ID_LJPEG &&
668+ avctx->pix_fmt == PIX_FMT_BGRA) {
569669 s->mjpeg_vsample[0] = s->mjpeg_hsample[0] =
570670 s->mjpeg_vsample[1] = s->mjpeg_hsample[1] =
571671 s->mjpeg_vsample[2] = s->mjpeg_hsample[2] = 1;
572− }else{
672+ } else {
573673 s->mjpeg_vsample[0] = 2;
574− s->mjpeg_vsample[1] = 2>>chroma_v_shift;
575− s->mjpeg_vsample[2] = 2>>chroma_v_shift;
674+ s->mjpeg_vsample[1] = 2 >> chroma_v_shift;
675+ s->mjpeg_vsample[2] = 2 >> chroma_v_shift;
576676 s->mjpeg_hsample[0] = 2;
577− s->mjpeg_hsample[1] = 2>>chroma_h_shift;
578− s->mjpeg_hsample[2] = 2>>chroma_h_shift;
677+ s->mjpeg_hsample[1] = 2 >> chroma_h_shift;
678+ s->mjpeg_hsample[2] = 2 >> chroma_h_shift;
579679 }
580− if (!(CONFIG_MJPEG_ENCODER || CONFIG_LJPEG_ENCODER)
581− || ff_mjpeg_encode_init(s) < 0)
680+ if (!(CONFIG_MJPEG_ENCODER || CONFIG_LJPEG_ENCODER) ||
681+ ff_mjpeg_encode_init(s) < 0)
582682 return -1;
583− avctx->delay=0;
584− s->low_delay=1;
683+ avctx->delay = 0;
684+ s->low_delay = 1;
585685 break;
586686 case CODEC_ID_H261:
587− if (!CONFIG_H261_ENCODER) return -1;
687+ if (!CONFIG_H261_ENCODER)
688+ return -1;
588689 if (ff_h261_get_picture_format(s->width, s->height) < 0) {
589− av_log(avctx, AV_LOG_ERROR, "The specified picture size of %dx%d is not valid for the H.261 codec.\nValid sizes are 176x144, 352x288\n", s->width, s->height);
690+ av_log(avctx, AV_LOG_ERROR,
691+ "The specified picture size of %dx%d is not valid for the "
692+ "H.261 codec.\nValid sizes are 176x144, 352x288\n",
693+ s->width, s->height);
590694 return -1;
591695 }
592696 s->out_format = FMT_H261;
593− avctx->delay=0;
594− s->low_delay=1;
697+ avctx->delay = 0;
698+ s->low_delay = 1;
595699 break;
596700 case CODEC_ID_H263:
597− if (!CONFIG_H263_ENCODER) return -1;
598− if (ff_match_2uint16(h263_format, FF_ARRAY_ELEMS(h263_format), s->width, s->height) == 8) {
599− av_log(avctx, AV_LOG_INFO, "The specified picture size of %dx%d is not valid for the H.263 codec.\nValid sizes are 128x96, 176x144, 352x288, 704x576, and 1408x1152. Try H.263+.\n", s->width, s->height);
701+ if (!CONFIG_H263_ENCODER)
702+ return -1;
703+ if (ff_match_2uint16(h263_format, FF_ARRAY_ELEMS(h263_format),
704+ s->width, s->height) == 8) {
705+ av_log(avctx, AV_LOG_INFO,
706+ "The specified picture size of %dx%d is not valid for "
707+ "the H.263 codec.\nValid sizes are 128x96, 176x144, "
708+ "352x288, 704x576, and 1408x1152."
709+ "Try H.263+.\n", s->width, s->height);
600710 return -1;
601711 }
602712 s->out_format = FMT_H263;
603− avctx->delay=0;
604− s->low_delay=1;
713+ avctx->delay = 0;
714+ s->low_delay = 1;
605715 break;
606716 case CODEC_ID_H263P:
607717 s->out_format = FMT_H263;
608− s->h263_plus = 1;
718+ s->h263_plus = 1;
609719 /* Fx */
610720 #if FF_API_MPEGVIDEO_GLOBAL_OPTS
611721 if (avctx->flags & CODEC_FLAG_H263P_UMV)
@@ -615,108 +725,110 @@ av_cold int MPV_encode_init(AVCodecContext *avctx) · 3 unmodified lines
615725 if (avctx->flags & CODEC_FLAG_H263P_SLICE_STRUCT)
616726 s->h263_slice_structured = 1;
617727 #endif
618− s->h263_aic= (avctx->flags & CODEC_FLAG_AC_PRED) ? 1:0;
619− s->modified_quant= s->h263_aic;
620− s->loop_filter= (avctx->flags & CODEC_FLAG_LOOP_FILTER) ? 1:0;
621− s->unrestricted_mv= s->obmc || s->loop_filter || s->umvplus;
728+ s->h263_aic = (avctx->flags & CODEC_FLAG_AC_PRED) ? 1 : 0;
729+ s->modified_quant = s->h263_aic;
730+ s->loop_filter = (avctx->flags & CODEC_FLAG_LOOP_FILTER) ? 1 : 0;
731+ s->unrestricted_mv = s->obmc || s->loop_filter || s->umvplus;
622732
623733 /* /Fx */
624734 /* These are just to be sure */
625− avctx->delay=0;
626− s->low_delay=1;
735+ avctx->delay = 0;
736+ s->low_delay = 1;
627737 break;
628738 case CODEC_ID_FLV1:
629− s->out_format = FMT_H263;
630− s->h263_flv = 2; /* format = 1; 11-bit codes */
739+ s->out_format = FMT_H263;
740+ s->h263_flv = 2; /* format = 1; 11-bit codes */
631741 s->unrestricted_mv = 1;
632− s->rtp_mode=0; /* don't allow GOB */
633− avctx->delay=0;
634− s->low_delay=1;
742+ s->rtp_mode = 0; /* don't allow GOB */
743+ avctx->delay = 0;
744+ s->low_delay = 1;
635745 break;
636746 case CODEC_ID_RV10:
637747 s->out_format = FMT_H263;
638− avctx->delay=0;
639− s->low_delay=1;
748+ avctx->delay = 0;
749+ s->low_delay = 1;
640750 break;
641751 case CODEC_ID_RV20:
642− s->out_format = FMT_H263;
643− avctx->delay=0;
644− s->low_delay=1;
645− s->modified_quant=1;
646− s->h263_aic=1;
647− s->h263_plus=1;
648− s->loop_filter=1;
649− s->unrestricted_mv= 0;
752+ s->out_format = FMT_H263;
753+ avctx->delay = 0;
754+ s->low_delay = 1;
755+ s->modified_quant = 1;
756+ s->h263_aic = 1;
757+ s->h263_plus = 1;
758+ s->loop_filter = 1;
759+ s->unrestricted_mv = 0;
650760 break;
651761 case CODEC_ID_MPEG4:
652− s->out_format = FMT_H263;
653− s->h263_pred = 1;
762+ s->out_format = FMT_H263;
763+ s->h263_pred = 1;
654764 s->unrestricted_mv = 1;
655− s->low_delay= s->max_b_frames ? 0 : 1;
656− avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1);
765+ s->low_delay = s->max_b_frames ? 0 : 1;
766+ avctx->delay = s->low_delay ? 0 : (s->max_b_frames + 1);
657767 break;
658768 case CODEC_ID_MSMPEG4V2:
659− s->out_format = FMT_H263;
660− s->h263_pred = 1;
769+ s->out_format = FMT_H263;
770+ s->h263_pred = 1;
661771 s->unrestricted_mv = 1;
662− s->msmpeg4_version= 2;
663− avctx->delay=0;
664− s->low_delay=1;
772+ s->msmpeg4_version = 2;
773+ avctx->delay = 0;
774+ s->low_delay = 1;
665775 break;
666776 case CODEC_ID_MSMPEG4V3:
667− s->out_format = FMT_H263;
668− s->h263_pred = 1;
669− s->unrestricted_mv = 1;
670− s->msmpeg4_version= 3;
671− s->flipflop_rounding=1;
672− avctx->delay=0;
673− s->low_delay=1;
777+ s->out_format = FMT_H263;
778+ s->h263_pred = 1;
779+ s->unrestricted_mv = 1;
780+ s->msmpeg4_version = 3;
781+ s->flipflop_rounding = 1;
782+ avctx->delay = 0;
783+ s->low_delay = 1;
674784 break;
675785 case CODEC_ID_WMV1:
676− s->out_format = FMT_H263;
677− s->h263_pred = 1;
678− s->unrestricted_mv = 1;
679− s->msmpeg4_version= 4;
680− s->flipflop_rounding=1;
681− avctx->delay=0;
682− s->low_delay=1;
786+ s->out_format = FMT_H263;
787+ s->h263_pred = 1;
788+ s->unrestricted_mv = 1;
789+ s->msmpeg4_version = 4;
790+ s->flipflop_rounding = 1;
791+ avctx->delay = 0;
792+ s->low_delay = 1;
683793 break;
684794 case CODEC_ID_WMV2:
685− s->out_format = FMT_H263;
686− s->h263_pred = 1;
687− s->unrestricted_mv = 1;
688− s->msmpeg4_version= 5;
689− s->flipflop_rounding=1;
690− avctx->delay=0;
691− s->low_delay=1;
795+ s->out_format = FMT_H263;
796+ s->h263_pred = 1;
797+ s->unrestricted_mv = 1;
798+ s->msmpeg4_version = 5;
799+ s->flipflop_rounding = 1;
800+ avctx->delay = 0;
801+ s->low_delay = 1;
692802 break;
693803 default:
694804 return -1;
695805 }
696806
697− avctx->has_b_frames= !s->low_delay;
807+ avctx->has_b_frames = !s->low_delay;
698808
699809 s->encoding = 1;
700810
701− s->progressive_frame=
702− s->progressive_sequence= !(avctx->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME|CODEC_FLAG_ALT_SCAN));
811+ s->progressive_frame =
812+ s->progressive_sequence = !(avctx->flags & (CODEC_FLAG_INTERLACED_DCT |
813+ CODEC_FLAG_INTERLACED_ME |
814+ CODEC_FLAG_ALT_SCAN));
703815
704816 /* init */
705817 if (MPV_common_init(s) < 0)
706818 return -1;
707819
708− if(!s->dct_quantize)
820+ if (!s->dct_quantize)
709821 s->dct_quantize = dct_quantize_c;
710− if(!s->denoise_dct)
711− s->denoise_dct = denoise_dct_c;
822+ if (!s->denoise_dct)
823+ s->denoise_dct = denoise_dct_c;
712824 s->fast_dct_quantize = s->dct_quantize;
713− if(avctx->trellis)
714− s->dct_quantize = dct_quantize_trellis_c;
825+ if (avctx->trellis)
826+ s->dct_quantize = dct_quantize_trellis_c;
715827
716− if((CONFIG_H263P_ENCODER || CONFIG_RV20_ENCODER) && s->modified_quant)
717− s->chroma_qscale_table= ff_h263_chroma_qscale_table;
828+ if ((CONFIG_H263P_ENCODER || CONFIG_RV20_ENCODER) && s->modified_quant)
829+ s->chroma_qscale_table = ff_h263_chroma_qscale_table;
718830
719− s->quant_precision=5;
831+ s->quant_precision = 5;
720832
721833 ff_set_cmp(&s->dsp, s->dsp.ildct_cmp, s->avctx->ildct_cmp);
722834 ff_set_cmp(&s->dsp, s->dsp.frame_skip_cmp, s->avctx->frame_skip_cmp);
@@ -732,22 +844,23 @@ av_cold int MPV_encode_init(AVCodecContext *avctx) · 9 unmodified lines
732844 ff_mpeg1_encode_init(s);
733845
734846 /* init q matrix */
735− for(i=0;i<64;i++) {
736− int j= s->dsp.idct_permutation[i];
737− if(CONFIG_MPEG4_ENCODER && s->codec_id==CODEC_ID_MPEG4 && s->mpeg_quant){
847+ for (i = 0; i < 64; i++) {
848+ int j = s->dsp.idct_permutation[i];
849+ if (CONFIG_MPEG4_ENCODER && s->codec_id == CODEC_ID_MPEG4 &&
850+ s->mpeg_quant) {
738851 s->intra_matrix[j] = ff_mpeg4_default_intra_matrix[i];
739852 s->inter_matrix[j] = ff_mpeg4_default_non_intra_matrix[i];
740− }else if(s->out_format == FMT_H263 || s->out_format == FMT_H261){
853+ } else if (s->out_format == FMT_H263 || s->out_format == FMT_H261) {
741854 s->intra_matrix[j] =
742855 s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i];
743− }else
744− { /* mpeg1/2 */
856+ } else {
857+ /* mpeg1/2 */
745858 s->intra_matrix[j] = ff_mpeg1_default_intra_matrix[i];
746859 s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i];
747860 }
748− if(s->avctx->intra_matrix)
861+ if (s->avctx->intra_matrix)
749862 s->intra_matrix[j] = s->avctx->intra_matrix[i];
750− if(s->avctx->inter_matrix)
863+ if (s->avctx->inter_matrix)
751864 s->inter_matrix[j] = s->avctx->inter_matrix[i];
752865 }
753866
@@ -755,12 +868,14 @@ av_cold int MPV_encode_init(AVCodecContext *avctx) · 1 unmodified line
755868 /* for mjpeg, we do include qscale in the matrix */
756869 if (s->out_format != FMT_MJPEG) {
757870 ff_convert_matrix(&s->dsp, s->q_intra_matrix, s->q_intra_matrix16,
758− s->intra_matrix, s->intra_quant_bias, avctx->qmin, 31, 1);
871+ s->intra_matrix, s->intra_quant_bias, avctx->qmin,
872+ 31, 1);
759873 ff_convert_matrix(&s->dsp, s->q_inter_matrix, s->q_inter_matrix16,
760− s->inter_matrix, s->inter_quant_bias, avctx->qmin, 31, 0);
874+ s->inter_matrix, s->inter_quant_bias, avctx->qmin,
875+ 31, 0);
761876 }
762877
763− if(ff_rate_control_init(s) < 0)
878+ if (ff_rate_control_init(s) < 0)
764879 return -1;
765880
766881 return 0;
@@ -773,7 +888,8 @@ av_cold int MPV_encode_end(AVCodecContext *avctx) · 6 unmodified lines
773888 ff_rate_control_uninit(s);
774889
775890 MPV_common_end(s);
776− if ((CONFIG_MJPEG_ENCODER || CONFIG_LJPEG_ENCODER) && s->out_format == FMT_MJPEG)
891+ if ((CONFIG_MJPEG_ENCODER || CONFIG_LJPEG_ENCODER) &&
892+ s->out_format == FMT_MJPEG)
777893 ff_mjpeg_encode_close(s);
778894
779895 av_freep(&avctx->extradata);
@@ -781,133 +897,148 @@ av_cold int MPV_encode_end(AVCodecContext *avctx) · 1 unmodified line
781897 return 0;
782898 }
783899
784−static int get_sae(uint8_t *src, int ref, int stride){
900+static int get_sae(uint8_t *src, int ref, int stride)
901+{
785902 int x,y;
786− int acc=0;
903+ int acc = 0;
787904
788− for(y=0; y<16; y++){
789− for(x=0; x<16; x++){
790− acc+= FFABS(src[x+y*stride] - ref);
905+ for (y = 0; y < 16; y++) {
906+ for (x = 0; x < 16; x++) {
907+ acc += FFABS(src[x + y * stride] - ref);
791908 }
792909 }
793910
794911 return acc;
795912 }
796913
797−static int get_intra_count(MpegEncContext *s, uint8_t *src, uint8_t *ref, int stride){
914+static int get_intra_count(MpegEncContext *s, uint8_t *src,
915+ uint8_t *ref, int stride)
916+{
798917 int x, y, w, h;
799− int acc=0;
918+ int acc = 0;
800919
801− w= s->width &~15;
802− h= s->height&~15;
920+ w = s->width & ~15;
921+ h = s->height & ~15;
803922
804− for(y=0; y<h; y+=16){
805− for(x=0; x<w; x+=16){
806− int offset= x + y*stride;
807− int sad = s->dsp.sad[0](NULL, src + offset, ref + offset, stride, 16);
808− int mean= (s->dsp.pix_sum(src + offset, stride) + 128)>>8;
809− int sae = get_sae(src + offset, mean, stride);
923+ for (y = 0; y < h; y += 16) {
924+ for (x = 0; x < w; x += 16) {
925+ int offset = x + y * stride;
926+ int sad = s->dsp.sad[0](NULL, src + offset, ref + offset, stride,
927+ 16);
928+ int mean = (s->dsp.pix_sum(src + offset, stride) + 128) >> 8;
929+ int sae = get_sae(src + offset, mean, stride);
810930
811− acc+= sae + 500 < sad;
931+ acc += sae + 500 < sad;
812932 }
813933 }
814934 return acc;
815935 }
816936
817937
818−static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg){
819− AVFrame *pic=NULL;
938+static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg)
939+{
940+ AVFrame *pic = NULL;
820941 int64_t pts;
821942 int i;
822− const int encoding_delay= s->max_b_frames;
823− int direct=1;
824−
825− if(pic_arg){
826− pts= pic_arg->pts;
827− pic_arg->display_picture_number= s->input_picture_number++;
828−
829− if(pts != AV_NOPTS_VALUE){
830− if(s->user_specified_pts != AV_NOPTS_VALUE){
831− int64_t time= pts;
832− int64_t last= s->user_specified_pts;
833−
834− if(time <= last){
835− av_log(s->avctx, AV_LOG_ERROR, "Error, Invalid timestamp=%"PRId64", last=%"PRId64"\n", pts, s->user_specified_pts);
943+ const int encoding_delay = s->max_b_frames;
944+ int direct = 1;
945+
946+ if (pic_arg) {
947+ pts = pic_arg->pts;
948+ pic_arg->display_picture_number = s->input_picture_number++;
949+
950+ if (pts != AV_NOPTS_VALUE) {
951+ if (s->user_specified_pts != AV_NOPTS_VALUE) {
952+ int64_t time = pts;
953+ int64_t last = s->user_specified_pts;
954+
955+ if (time <= last) {
956+ av_log(s->avctx, AV_LOG_ERROR,
957+ "Error, Invalid timestamp=%"PRId64", "
958+ "last=%"PRId64"\n", pts, s->user_specified_pts);
836959 return -1;
837960 }
838961 }
839− s->user_specified_pts= pts;
840− }else{
841− if(s->user_specified_pts != AV_NOPTS_VALUE){
842− s->user_specified_pts=
843− pts= s->user_specified_pts + 1;
844− av_log(s->avctx, AV_LOG_INFO, "Warning: AVFrame.pts=? trying to guess (%"PRId64")\n", pts);
845− }else{
846− pts= pic_arg->display_picture_number;
962+ s->user_specified_pts = pts;
963+ } else {
964+ if (s->user_specified_pts != AV_NOPTS_VALUE) {
965+ s->user_specified_pts =
966+ pts = s->user_specified_pts + 1;
967+ av_log(s->avctx, AV_LOG_INFO,
968+ "Warning: AVFrame.pts=? trying to guess (%"PRId64")\n",
969+ pts);
970+ } else {
971+ pts = pic_arg->display_picture_number;
847972 }
848973 }
849974 }
850975
851− if(pic_arg){
852− if(encoding_delay && !(s->flags&CODEC_FLAG_INPUT_PRESERVED)) direct=0;
853− if(pic_arg->linesize[0] != s->linesize) direct=0;
854− if(pic_arg->linesize[1] != s->uvlinesize) direct=0;
855− if(pic_arg->linesize[2] != s->uvlinesize) direct=0;
976+ if (pic_arg) {
977+ if (encoding_delay && !(s->flags & CODEC_FLAG_INPUT_PRESERVED))
978+ direct = 0;
979+ if (pic_arg->linesize[0] != s->linesize)
980+ direct = 0;
981+ if (pic_arg->linesize[1] != s->uvlinesize)
982+ direct = 0;
983+ if (pic_arg->linesize[2] != s->uvlinesize)
984+ direct = 0;
856985
857−// av_log(AV_LOG_DEBUG, "%d %d %d %d\n",pic_arg->linesize[0], pic_arg->linesize[1], s->linesize, s->uvlinesize);
986+ //av_log(AV_LOG_DEBUG, "%d %d %d %d\n",pic_arg->linesize[0],
987+ // pic_arg->linesize[1], s->linesize, s->uvlinesize);
858988
859− if(direct){
860− i= ff_find_unused_picture(s, 1);
989+ if (direct) {
990+ i = ff_find_unused_picture(s, 1);
861991 if (i < 0)
862992 return i;
863993
864− pic= (AVFrame*)&s->picture[i];
865− pic->reference= 3;
994+ pic = (AVFrame *) &s->picture[i];
995+ pic->reference = 3;
866996
867− for(i=0; i<4; i++){
868− pic->data[i]= pic_arg->data[i];
869− pic->linesize[i]= pic_arg->linesize[i];
997+ for (i = 0; i < 4; i++) {
998+ pic->data[i] = pic_arg->data[i];
999+ pic->linesize[i] = pic_arg->linesize[i];
8701000 }
871− if(ff_alloc_picture(s, (Picture*)pic, 1) < 0){
1001+ if (ff_alloc_picture(s, (Picture *) pic, 1) < 0) {
8721002 return -1;
8731003 }
874− }else{
875− i= ff_find_unused_picture(s, 0);
1004+ } else {
1005+ i = ff_find_unused_picture(s, 0);
8761006 if (i < 0)
8771007 return i;
8781008
879− pic= (AVFrame*)&s->picture[i];
880− pic->reference= 3;
1009+ pic = (AVFrame *) &s->picture[i];
1010+ pic->reference = 3;
8811011
882− if(ff_alloc_picture(s, (Picture*)pic, 0) < 0){
1012+ if (ff_alloc_picture(s, (Picture *) pic, 0) < 0) {
8831013 return -1;
8841014 }
8851015
886− if( pic->data[0] + INPLACE_OFFSET == pic_arg->data[0]
887− && pic->data[1] + INPLACE_OFFSET == pic_arg->data[1]
888− && pic->data[2] + INPLACE_OFFSET == pic_arg->data[2]){
889− // empty
890− }else{
1016+ if (pic->data[0] + INPLACE_OFFSET == pic_arg->data[0] &&
1017+ pic->data[1] + INPLACE_OFFSET == pic_arg->data[1] &&
1018+ pic->data[2] + INPLACE_OFFSET == pic_arg->data[2]) {
1019+ // empty
1020+ } else {
8911021 int h_chroma_shift, v_chroma_shift;
892− avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &h_chroma_shift, &v_chroma_shift);
893−
894− for(i=0; i<3; i++){
895− int src_stride= pic_arg->linesize[i];
896− int dst_stride= i ? s->uvlinesize : s->linesize;
897− int h_shift= i ? h_chroma_shift : 0;
898− int v_shift= i ? v_chroma_shift : 0;
899− int w= s->width >>h_shift;
900− int h= s->height>>v_shift;
901− uint8_t *src= pic_arg->data[i];
902− uint8_t *dst= pic->data[i];
903−
904− if(!s->avctx->rc_buffer_size)
905− dst +=INPLACE_OFFSET;
906−
907− if(src_stride==dst_stride)
908− memcpy(dst, src, src_stride*h);
909− else{
910− while(h--){
1022+ avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &h_chroma_shift,
1023+ &v_chroma_shift);
1024+
1025+ for (i = 0; i < 3; i++) {
1026+ int src_stride = pic_arg->linesize[i];
1027+ int dst_stride = i ? s->uvlinesize : s->linesize;
1028+ int h_shift = i ? h_chroma_shift : 0;
1029+ int v_shift = i ? v_chroma_shift : 0;
1030+ int w = s->width >> h_shift;
1031+ int h = s->height >> v_shift;
1032+ uint8_t *src = pic_arg->data[i];
1033+ uint8_t *dst = pic->data[i];
1034+
1035+ if (!s->avctx->rc_buffer_size)
1036+ dst += INPLACE_OFFSET;
1037+
1038+ if (src_stride == dst_stride)
1039+ memcpy(dst, src, src_stride * h);
1040+ else {
1041+ while (h--) {
9111042 memcpy(dst, src, w);
9121043 dst += dst_stride;
9131044 src += src_stride;
@@ -917,81 +1048,91 @@ static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg){ · 3 unmodified lines
9171048 }
9181049 }
9191050 copy_picture_attributes(s, pic, pic_arg);
920− pic->pts= pts; //we set this here to avoid modifiying pic_arg
1051+ pic->pts = pts; // we set this here to avoid modifiying pic_arg
9211052 }
9221053
9231054 /* shift buffer entries */
924− for(i=1; i<MAX_PICTURE_COUNT /*s->encoding_delay+1*/; i++)
925− s->input_picture[i-1]= s->input_picture[i];
1055+ for (i = 1; i < MAX_PICTURE_COUNT /*s->encoding_delay + 1*/; i++)
1056+ s->input_picture[i - 1] = s->input_picture[i];
9261057
927− s->input_picture[encoding_delay]= (Picture*)pic;
1058+ s->input_picture[encoding_delay] = (Picture*) pic;
9281059
9291060 return 0;
9301061 }
9311062
932−static int skip_check(MpegEncContext *s, Picture *p, Picture *ref){
1063+static int skip_check(MpegEncContext *s, Picture *p, Picture *ref)
1064+{
9331065 int x, y, plane;
934− int score=0;
935− int64_t score64=0;
1066+ int score = 0;
1067+ int64_t score64 = 0;
9361068
937− for(plane=0; plane<3; plane++){
1069+ for (plane = 0; plane < 3; plane++) {
9381070 const int stride = p->f.linesize[plane];
939− const int bw= plane ? 1 : 2;
940− for(y=0; y<s->mb_height*bw; y++){
941− for(x=0; x<s->mb_width*bw; x++){
942− int off = p->f.type == FF_BUFFER_TYPE_SHARED ? 0: 16;
943− int v = s->dsp.frame_skip_cmp[1](s, p->f.data[plane] + 8*(x + y*stride)+off, ref->f.data[plane] + 8*(x + y*stride), stride, 8);
944−
945− switch(s->avctx->frame_skip_exp){
946− case 0: score= FFMAX(score, v); break;
947− case 1: score+= FFABS(v);break;
948− case 2: score+= v*v;break;
949− case 3: score64+= FFABS(v*v*(int64_t)v);break;
950− case 4: score64+= v*v*(int64_t)(v*v);break;
1071+ const int bw = plane ? 1 : 2;
1072+ for (y = 0; y < s->mb_height * bw; y++) {
1073+ for (x = 0; x < s->mb_width * bw; x++) {
1074+ int off = p->f.type == FF_BUFFER_TYPE_SHARED ? 0 : 16;
1075+ uint8_t *dptr = p->f.data[plane] + 8 * (x + y * stride) + off;
1076+ uint8_t *rptr = ref->f.data[plane] + 8 * (x + y * stride);
1077+ int v = s->dsp.frame_skip_cmp[1](s, dptr, rptr, stride, 8);
1078+
1079+ switch (s->avctx->frame_skip_exp) {
1080+ case 0: score = FFMAX(score, v); break;
1081+ case 1: score += FFABS(v); break;
1082+ case 2: score += v * v; break;
1083+ case 3: score64 += FFABS(v * v * (int64_t)v); break;
1084+ case 4: score64 += v * v * (int64_t)(v * v); break;
9511085 }
9521086 }
9531087 }
9541088 }
9551089
956− if(score) score64= score;
1090+ if (score)
1091+ score64 = score;
9571092
958− if(score64 < s->avctx->frame_skip_threshold)
1093+ if (score64 < s->avctx->frame_skip_threshold)
9591094 return 1;
960− if(score64 < ((s->avctx->frame_skip_factor * (int64_t)s->lambda)>>8))
1095+ if (score64 < ((s->avctx->frame_skip_factor * (int64_t)s->lambda) >> 8))
9611096 return 1;
9621097 return 0;
9631098 }
9641099
965−static int estimate_best_b_count(MpegEncContext *s){
966− AVCodec *codec= avcodec_find_encoder(s->avctx->codec_id);
1100+static int estimate_best_b_count(MpegEncContext *s)
1101+{
1102+ AVCodec *codec = avcodec_find_encoder(s->avctx->codec_id);
9671103 AVCodecContext *c = avcodec_alloc_context3(NULL);
968− AVFrame input[FF_MAX_B_FRAMES+2];
969− const int scale= s->avctx->brd_scale;
1104+ AVFrame input[FF_MAX_B_FRAMES + 2];
1105+ const int scale = s->avctx->brd_scale;
9701106 int i, j, out_size, p_lambda, b_lambda, lambda2;
971− int outbuf_size= s->width * s->height; //FIXME
972− uint8_t *outbuf= av_malloc(outbuf_size);
973− int64_t best_rd= INT64_MAX;
974− int best_b_count= -1;
975−
976− assert(scale>=0 && scale <=3);
977−
978−// emms_c();
979− p_lambda= s->last_lambda_for[AV_PICTURE_TYPE_P]; //s->next_picture_ptr->quality;
980− b_lambda= s->last_lambda_for[AV_PICTURE_TYPE_B]; //p_lambda *FFABS(s->avctx->b_quant_factor) + s->avctx->b_quant_offset;
981− if(!b_lambda) b_lambda= p_lambda; //FIXME we should do this somewhere else
982− lambda2= (b_lambda*b_lambda + (1<<FF_LAMBDA_SHIFT)/2 ) >> FF_LAMBDA_SHIFT;
983−
984− c->width = s->width >> scale;
985− c->height= s->height>> scale;
986− c->flags= CODEC_FLAG_QSCALE | CODEC_FLAG_PSNR | CODEC_FLAG_INPUT_PRESERVED /*| CODEC_FLAG_EMU_EDGE*/;
987− c->flags|= s->avctx->flags & CODEC_FLAG_QPEL;
988− c->mb_decision= s->avctx->mb_decision;
989− c->me_cmp= s->avctx->me_cmp;
990− c->mb_cmp= s->avctx->mb_cmp;
991− c->me_sub_cmp= s->avctx->me_sub_cmp;
992− c->pix_fmt = PIX_FMT_YUV420P;
993− c->time_base= s->avctx->time_base;
994− c->max_b_frames= s->max_b_frames;
1107+ int outbuf_size = s->width * s->height; // FIXME
1108+ uint8_t *outbuf = av_malloc(outbuf_size);
1109+ int64_t best_rd = INT64_MAX;
1110+ int best_b_count = -1;
1111+
1112+ assert(scale >= 0 && scale <= 3);
1113+
1114+ //emms_c();
1115+ //s->next_picture_ptr->quality;
1116+ p_lambda = s->last_lambda_for[AV_PICTURE_TYPE_P];
1117+ //p_lambda * FFABS(s->avctx->b_quant_factor) + s->avctx->b_quant_offset;
1118+ b_lambda = s->last_lambda_for[AV_PICTURE_TYPE_B];
1119+ if (!b_lambda) // FIXME we should do this somewhere else
1120+ b_lambda = p_lambda;
1121+ lambda2 = (b_lambda * b_lambda + (1 << FF_LAMBDA_SHIFT) / 2) >>
1122+ FF_LAMBDA_SHIFT;
1123+
1124+ c->width = s->width >> scale;
1125+ c->height = s->height >> scale;
1126+ c->flags = CODEC_FLAG_QSCALE | CODEC_FLAG_PSNR |
1127+ CODEC_FLAG_INPUT_PRESERVED /*| CODEC_FLAG_EMU_EDGE*/;
1128+ c->flags |= s->avctx->flags & CODEC_FLAG_QPEL;
1129+ c->mb_decision = s->avctx->mb_decision;
1130+ c->me_cmp = s->avctx->me_cmp;
1131+ c->mb_cmp = s->avctx->mb_cmp;
1132+ c->me_sub_cmp = s->avctx->me_sub_cmp;
1133+ c->pix_fmt = PIX_FMT_YUV420P;
1134+ c->time_base = s->avctx->time_base;
1135+ c->max_b_frames = s->max_b_frames;
9951136
9961137 if (avcodec_open2(c, codec, NULL) < 0)
9971138 return -1;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t