History

avcodec/mpeg12dec: Remove disabled frame-threading code

The MPEG-1 decoder has an update_thread_context function set, yet it was never enabled (missing AV_CODEC_CAP_FRAME_THREADS flag). So remove it and also the ff_thread_finish_setup() call as well as the progress reporting. (Simply setting the flag would not be enough. The main problems are: a) The update_thread_context function relies on memcpy'ing the whole context instead of only copying the necessary fields. This leads to data races which is undefined behaviour. (Btw: The check for whether the non-MpegEncContext fields of Mpeg1Context should be copied has been broken in 7f0efe232475d7a704924a3cb308281973e8add3.) b) Even an AVBufferRef* is simply copied, without creating a new reference. c) Copying the whole context happens only during init; when parameters change lateron, the change is not propagated to the next thread. This affects at least the quant matrix (for MPEG-1). d) The MPEG-1/2 decoders are made to decode both MPEG-1 and MPEG-2. When MPEG-2 is decoded, another complication arises: In case of coded fields, both fields can be in one AVPacket or they can be in separate AVPackets. One would need to parse enough of the data to be able to determine whether the next thread needs to start a new frame or decode the second field of the current frame; for this one would need to either postpone calling ff_thread_finish_setup() for coded slices altogether or implement some form of ff_h2645_packet_split(). One would also need a second ThreadProgress to signal progress of each field. e) One would need to reenable waiting in ff_mpv_reconstruct_mb() for MPEG-1/2 (and H.261). f) Probably lots of other stuff for invalid input that I am currently not thinking about. If this were done, nothing from the current update_thread_context would remain, so one can just nuke it altogether.)

Andreas Rheinhardt committed 1 year ago

Commit 554b52b1 parent 763b7ce1 file · +0 −28Browse files

Unified · Split

libavcodec/mpeg12dec.c+0−28
@@ -58,7 +58,6 @@ · 57 unmodified lines
58#include "mpegvideodec.h"58#include "mpegvideodec.h"
59#include "profiles.h"59#include "profiles.h"
60#include "startcode.h"60#include "startcode.h"
61#include "thread.h"
62 61
63#define A53_MAX_CC_COUNT 200062#define A53_MAX_CC_COUNT 2000
64 63
@@ -786,28 +785,6 @@ static av_cold int mpeg_decode_init(AVCodecContext *avctx) · 721 unmodified lines
786 return 0;785 return 0;
787}786}
788 787
789#if HAVE_THREADS
790static int mpeg_decode_update_thread_context(AVCodecContext *avctx,
791 const AVCodecContext *avctx_from)
792{
793 Mpeg1Context *ctx = avctx->priv_data, *ctx_from = avctx_from->priv_data;
794 MpegEncContext *s = &ctx->mpeg_enc_ctx, *s1 = &ctx_from->mpeg_enc_ctx;
795 int err;
796
797 if (avctx == avctx_from || !s1->context_initialized)
798 return 0;
799
800 err = ff_mpeg_update_thread_context(avctx, avctx_from);
801 if (err)
802 return err;
803
804 if (!s->context_initialized)
805 memcpy(s + 1, s1 + 1, sizeof(Mpeg1Context) - sizeof(MpegEncContext));
806
807 return 0;
808}
809#endif
810
811static const enum AVPixelFormat mpeg1_hwaccel_pixfmt_list_420[] = {788static const enum AVPixelFormat mpeg1_hwaccel_pixfmt_list_420[] = {
812#if CONFIG_MPEG1_NVDEC_HWACCEL789#if CONFIG_MPEG1_NVDEC_HWACCEL
813 AV_PIX_FMT_CUDA,790 AV_PIX_FMT_CUDA,
@@ -1321,9 +1298,6 @@ static int mpeg_field_start(Mpeg1Context *s1, const uint8_t *buf, int buf_size) · 507 unmodified lines
1321 *sd->data = s1->afd;1298 *sd->data = s1->afd;
1322 s1->has_afd = 0;1299 s1->has_afd = 0;
1323 }1300 }
1324
1325 if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_FRAME))
1326 ff_thread_finish_setup(avctx);
1327 } else { // second field1301 } else { // second field
1328 second_field = 1;1302 second_field = 1;
1329 if (!s->cur_pic.ptr) {1303 if (!s->cur_pic.ptr) {
@@ -1528,7 +1502,6 @@ static int mpeg_decode_slice(MpegEncContext *s, int mb_y, · 198 unmodified lines
1528 int left;1502 int left;
1529 1503
1530 ff_mpeg_draw_horiz_band(s, mb_size * (s->mb_y >> field_pic), mb_size);1504 ff_mpeg_draw_horiz_band(s, mb_size * (s->mb_y >> field_pic), mb_size);
1531 ff_mpv_report_decode_progress(s);
1532 1505
1533 s->mb_x = 0;1506 s->mb_x = 0;
1534 s->mb_y += 1 << field_pic;1507 s->mb_y += 1 << field_pic;
@@ -2667,7 +2640,6 @@ const FFCodec ff_mpeg1video_decoder = { · 1132 unmodified lines
2667 .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,2640 .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
2668 .flush = flush,2641 .flush = flush,
2669 .p.max_lowres = 3,2642 .p.max_lowres = 3,
2670 UPDATE_THREAD_CONTEXT(mpeg_decode_update_thread_context),
2671 .hw_configs = (const AVCodecHWConfigInternal *const []) {2643 .hw_configs = (const AVCodecHWConfigInternal *const []) {
2672#if CONFIG_MPEG1_NVDEC_HWACCEL2644#if CONFIG_MPEG1_NVDEC_HWACCEL
2673 HWACCEL_NVDEC(mpeg1),2645 HWACCEL_NVDEC(mpeg1),

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