History

avcodec/mpegvideo_dec: Don't memset twice

This has been done for the luma plane of missing FLV1 and H263 references. Also remove code duplication by reusing gray_frame(), which has been renamed to color_frame() for this purpose.

Andreas Rheinhardt committed 3 years ago

Commit 06388251 parent 3ede6cc1 file · +5 −23Browse files

Unified · Split

libavcodec/mpegvideo_dec.c+5−23
@@ -245,12 +245,12 @@ static int alloc_picture(MpegEncContext *s, Picture *pic) · 244 unmodified lines
245 &s->linesize, &s->uvlinesize);245 &s->linesize, &s->uvlinesize);
246}246}
247 247
248static void gray_frame(AVFrame *frame)248static void color_frame(AVFrame *frame, int luma)
249{249{
250 int h_chroma_shift, v_chroma_shift;250 int h_chroma_shift, v_chroma_shift;
251 251
252 for (int i = 0; i < frame->height; i++)252 for (int i = 0; i < frame->height; i++)
253 memset(frame->data[0] + frame->linesize[0] * i, 0x80, frame->width);253 memset(frame->data[0] + frame->linesize[0] * i, luma, frame->width);
254 254
255 if (!frame->data[1])255 if (!frame->data[1])
256 return;256 return;
@@ -365,9 +365,6 @@ FF_ENABLE_DEPRECATION_WARNINGS · 108 unmodified lines
365 365
366 if ((!s->last_picture_ptr || !s->last_picture_ptr->f->buf[0]) &&366 if ((!s->last_picture_ptr || !s->last_picture_ptr->f->buf[0]) &&
367 (s->pict_type != AV_PICTURE_TYPE_I)) {367 (s->pict_type != AV_PICTURE_TYPE_I)) {
368 int h_chroma_shift, v_chroma_shift;
369 av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt,
370 &h_chroma_shift, &v_chroma_shift);
371 if (s->pict_type == AV_PICTURE_TYPE_B && s->next_picture_ptr && s->next_picture_ptr->f->buf[0])368 if (s->pict_type == AV_PICTURE_TYPE_B && s->next_picture_ptr && s->next_picture_ptr->f->buf[0])
372 av_log(avctx, AV_LOG_DEBUG,369 av_log(avctx, AV_LOG_DEBUG,
373 "allocating dummy last picture for B frame\n");370 "allocating dummy last picture for B frame\n");
@@ -393,23 +390,8 @@ FF_ENABLE_DEPRECATION_WARNINGS · 19 unmodified lines
393 }390 }
394 391
395 if (!avctx->hwaccel) {392 if (!avctx->hwaccel) {
396 for (int i = 0; i < avctx->height; i++)393 int luma_val = s->codec_id == AV_CODEC_ID_FLV1 || s->codec_id == AV_CODEC_ID_H263 ? 16 : 0x80;
397 memset(s->last_picture_ptr->f->data[0] + s->last_picture_ptr->f->linesize[0]*i,394 color_frame(s->last_picture_ptr->f, luma_val);
398 0x80, avctx->width);
399 if (s->last_picture_ptr->f->data[2]) {
400 for (int i = 0; i < AV_CEIL_RSHIFT(avctx->height, v_chroma_shift); i++) {
401 memset(s->last_picture_ptr->f->data[1] + s->last_picture_ptr->f->linesize[1]*i,
402 0x80, AV_CEIL_RSHIFT(avctx->width, h_chroma_shift));
403 memset(s->last_picture_ptr->f->data[2] + s->last_picture_ptr->f->linesize[2]*i,
404 0x80, AV_CEIL_RSHIFT(avctx->width, h_chroma_shift));
405 }
406 }
407
408 if (s->codec_id == AV_CODEC_ID_FLV1 || s->codec_id == AV_CODEC_ID_H263) {
409 for (int i = 0; i < avctx->height; i++)
410 memset(s->last_picture_ptr->f->data[0] + s->last_picture_ptr->f->linesize[0] * i,
411 16, avctx->width);
412 }
413 }395 }
414 396
415 ff_thread_report_progress(&s->last_picture_ptr->tf, INT_MAX, 0);397 ff_thread_report_progress(&s->last_picture_ptr->tf, INT_MAX, 0);
@@ -480,7 +462,7 @@ FF_ENABLE_DEPRECATION_WARNINGS · 64 unmodified lines
480 }462 }
481 463
482 if (s->avctx->debug & FF_DEBUG_NOMC)464 if (s->avctx->debug & FF_DEBUG_NOMC)
483 gray_frame(s->current_picture_ptr->f);465 color_frame(s->current_picture_ptr->f, 0x80);
484 466
485 return 0;467 return 0;
486}468}

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