History

Revert "lavc/nvenc: handle frame durations and AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE"

The implementation is flawed in that the frame opaque data is not in fact correctly reordered along with the packets, but is being output in packet input order, just like the dts are. This reverts commit 35538097038fd1e36577306d3165f38c8fa02466.

Timo Rothenpieler committed 3 years ago

Commit 6c418ae1 parent 73a22525 files · +23 −104Browse files

Showing the changes to libavcodec (5 of 5 files). Show all

Unified · Split

5 files
  1. libavcodec/nvenc.c +19 −97
  2. libavcodec/nvenc.h +1 −1
  3. libavcodec/nvenc_av1.c +1 −2
  4. libavcodec/nvenc_h264.c +1 −2
  5. libavcodec/nvenc_hevc.c +1 −2
libavcodec/nvenc.c+19−97
@@ -28,7 +28,6 @@ · 27 unmodified lines
2828 #include "av1.h"
2929 #endif
3030
31−#include "libavutil/buffer.h"
3231 #include "libavutil/hwcontext_cuda.h"
3332 #include "libavutil/hwcontext.h"
3433 #include "libavutil/cuda_check.h"
@@ -168,27 +167,6 @@ static int nvenc_print_error(AVCodecContext *avctx, NVENCSTATUS err, · 133 unmodified lines
168167 return ret;
169168 }
170169
171−typedef struct FrameData {
172− int64_t pts;
173− int64_t duration;
174−#if FF_API_REORDERED_OPAQUE
175− int64_t reordered_opaque;
176−#endif
177−
178− void *frame_opaque;
179− AVBufferRef *frame_opaque_ref;
180−} FrameData;
181−
182−static void reorder_queue_flush(AVFifo *queue)
183−{
184− FrameData fd;
185−
186− av_assert0(queue);
187−
188− while (av_fifo_read(queue, &fd, 1) >= 0)
189− av_buffer_unref(&fd.frame_opaque_ref);
190−}
191−
192170 typedef struct GUIDTuple {
193171 const GUID guid;
194172 int flags;
@@ -1789,8 +1767,8 @@ static av_cold int nvenc_setup_surfaces(AVCodecContext *avctx) · 1594 unmodified lines
17891767 if (!ctx->surfaces)
17901768 return AVERROR(ENOMEM);
17911769
1792− ctx->reorder_queue = av_fifo_alloc2(ctx->nb_surfaces, sizeof(FrameData), 0);
1793− if (!ctx->reorder_queue)
1770+ ctx->timestamp_list = av_fifo_alloc2(ctx->nb_surfaces, sizeof(int64_t), 0);
1771+ if (!ctx->timestamp_list)
17941772 return AVERROR(ENOMEM);
17951773
17961774 ctx->unused_surface_queue = av_fifo_alloc2(ctx->nb_surfaces, sizeof(NvencSurface*), 0);
@@ -1874,11 +1852,7 @@ av_cold int ff_nvenc_encode_close(AVCodecContext *avctx) · 77 unmodified lines
18741852 p_nvenc->nvEncEncodePicture(ctx->nvencoder, &params);
18751853 }
18761854
1877− if (ctx->reorder_queue) {
1878− reorder_queue_flush(ctx->reorder_queue);
1879− av_fifo_freep2(&ctx->reorder_queue);
1880− }
1881−
1855+ av_fifo_freep2(&ctx->timestamp_list);
18821856 av_fifo_freep2(&ctx->output_surface_ready_queue);
18831857 av_fifo_freep2(&ctx->output_surface_queue);
18841858 av_fifo_freep2(&ctx->unused_surface_queue);
@@ -2222,53 +2196,18 @@ static void nvenc_codec_specific_pic_params(AVCodecContext *avctx, · 337 unmodified lines
22222196 }
22232197 }
22242198
2225−static void reorder_queue_enqueue(AVFifo *queue, const AVCodecContext *avctx,
2226− const AVFrame *frame, AVBufferRef **opaque_ref)
2199+static inline void timestamp_queue_enqueue(AVFifo *queue, int64_t timestamp)
22272200 {
2228− FrameData fd;
2229−
2230− fd.pts = frame->pts;
2231− fd.duration = frame->duration;
2232−#if FF_API_REORDERED_OPAQUE
2233−FF_DISABLE_DEPRECATION_WARNINGS
2234− fd.reordered_opaque = frame->reordered_opaque;
2235−FF_ENABLE_DEPRECATION_WARNINGS
2236−#endif
2237− fd.frame_opaque = frame->opaque;
2238− fd.frame_opaque_ref = *opaque_ref;
2239−
2240− *opaque_ref = NULL;
2241−
2242− av_fifo_write(queue, &fd, 1);
2201+ av_fifo_write(queue, &timestamp, 1);
22432202 }
22442203
2245−static int64_t reorder_queue_dequeue(AVFifo *queue, AVCodecContext *avctx,
2246− AVPacket *pkt)
2204+static inline int64_t timestamp_queue_dequeue(AVFifo *queue)
22472205 {
2248− FrameData fd;
2249−
2206+ int64_t timestamp = AV_NOPTS_VALUE;
22502207 // The following call might fail if the queue is empty.
2251− if (av_fifo_read(queue, &fd, 1) < 0)
2252− return AV_NOPTS_VALUE;
2253−
2254− if (pkt) {
2255−#if FF_API_REORDERED_OPAQUE
2256−FF_DISABLE_DEPRECATION_WARNINGS
2257− avctx->reordered_opaque = fd.reordered_opaque;
2258−FF_ENABLE_DEPRECATION_WARNINGS
2259−#endif
2260− pkt->duration = fd.duration;
2208+ av_fifo_read(queue, &timestamp, 1);
22612209
2262− if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
2263− pkt->opaque = fd.frame_opaque;
2264− pkt->opaque_ref = fd.frame_opaque_ref;
2265− fd.frame_opaque_ref = NULL;
2266− }
2267− }
2268−
2269− av_buffer_unref(&fd.frame_opaque_ref);
2270−
2271− return fd.pts;
2210+ return timestamp;
22722211 }
22732212
22742213 static int nvenc_set_timestamp(AVCodecContext *avctx,
@@ -2276,15 +2215,12 @@ static int nvenc_set_timestamp(AVCodecContext *avctx, · 1 unmodified line
22762215 AVPacket *pkt)
22772216 {
22782217 NvencContext *ctx = avctx->priv_data;
2279− int64_t dts;
22802218
22812219 pkt->pts = params->outputTimeStamp;
22822220
2283− dts = reorder_queue_dequeue(ctx->reorder_queue, avctx, pkt);
2284−
22852221 if (avctx->codec_descriptor->props & AV_CODEC_PROP_REORDER) {
22862222 FF_DISABLE_DEPRECATION_WARNINGS
2287− pkt->dts = dts -
2223+ pkt->dts = timestamp_queue_dequeue(ctx->timestamp_list) -
22882224 #if FF_API_TICKS_PER_FRAME
22892225 FFMAX(avctx->ticks_per_frame, 1) *
22902226 #endif
@@ -2386,7 +2322,7 @@ static int process_output_surface(AVCodecContext *avctx, AVPacket *pkt, NvencSur · 95 unmodified lines
23862322 return 0;
23872323
23882324 error:
2389− reorder_queue_dequeue(ctx->reorder_queue, avctx, NULL);
2325+ timestamp_queue_dequeue(ctx->timestamp_list);
23902326
23912327 error2:
23922328 return res;
@@ -2616,8 +2552,6 @@ static int nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame) · 223 unmodified lines
26162552 int sei_count = 0;
26172553 int i;
26182554
2619− AVBufferRef *opaque_ref = NULL;
2620−
26212555 NvencContext *ctx = avctx->priv_data;
26222556 NvencDynLoadFunctions *dl_fn = &ctx->nvenc_dload_funcs;
26232557 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->nvenc_funcs;
@@ -2685,17 +2619,9 @@ static int nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame) · 61 unmodified lines
26852619 pic_params.encodePicFlags = NV_ENC_PIC_FLAG_EOS;
26862620 }
26872621
2688− // make a reference for enqueing in the reorder queue here,
2689− // so that reorder_queue_enqueue() cannot fail
2690− if (frame && frame->opaque_ref && avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
2691− opaque_ref = av_buffer_ref(frame->opaque_ref);
2692− if (!opaque_ref)
2693− return AVERROR(ENOMEM);
2694− }
2695−
26962622 res = nvenc_push_context(avctx);
26972623 if (res < 0)
2698− goto opaque_ref_fail;
2624+ return res;
26992625
27002626 nv_status = p_nvenc->nvEncEncodePicture(ctx->nvencoder, &pic_params);
27012627
@@ -2704,17 +2630,17 @@ static int nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame) · 2 unmodified lines
27042630
27052631 res = nvenc_pop_context(avctx);
27062632 if (res < 0)
2707− goto opaque_ref_fail;
2633+ return res;
27082634
27092635 if (nv_status != NV_ENC_SUCCESS &&
2710− nv_status != NV_ENC_ERR_NEED_MORE_INPUT) {
2711− res = nvenc_print_error(avctx, nv_status, "EncodePicture failed!");
2712− goto opaque_ref_fail;
2713− }
2636+ nv_status != NV_ENC_ERR_NEED_MORE_INPUT)
2637+ return nvenc_print_error(avctx, nv_status, "EncodePicture failed!");
27142638
27152639 if (frame && frame->buf[0]) {
27162640 av_fifo_write(ctx->output_surface_queue, &in_surf, 1);
2717− reorder_queue_enqueue(ctx->reorder_queue, avctx, frame, &opaque_ref);
2641+
2642+ if (avctx->codec_descriptor->props & AV_CODEC_PROP_REORDER)
2643+ timestamp_queue_enqueue(ctx->timestamp_list, frame->pts);
27182644 }
27192645
27202646 /* all the pending buffers are now ready for output */
@@ -2724,10 +2650,6 @@ static int nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame) · 3 unmodified lines
27242650 }
27252651
27262652 return 0;
2727−
2728−opaque_ref_fail:
2729− av_buffer_unref(&opaque_ref);
2730− return res;
27312653 }
27322654
27332655 int ff_nvenc_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
@@ -2786,5 +2708,5 @@ av_cold void ff_nvenc_encode_flush(AVCodecContext *avctx) · 52 unmodified lines
27862708 NvencContext *ctx = avctx->priv_data;
27872709
27882710 nvenc_send_frame(avctx, NULL);
2789− reorder_queue_flush(ctx->reorder_queue);
2711+ av_fifo_reset2(ctx->timestamp_list);
27902712 }
libavcodec/nvenc.h+1−1
@@ -176,7 +176,7 @@ typedef struct NvencContext · 175 unmodified lines
176176 AVFifo *unused_surface_queue;
177177 AVFifo *output_surface_queue;
178178 AVFifo *output_surface_ready_queue;
179− AVFifo *reorder_queue;
179+ AVFifo *timestamp_list;
180180
181181 NV_ENC_SEI_PAYLOAD *sei_data;
182182 int sei_data_size;
libavcodec/nvenc_av1.c+1−2
@@ -181,8 +181,7 @@ const FFCodec ff_av1_nvenc_encoder = { · 180 unmodified lines
181181 .defaults = defaults,
182182 .p.pix_fmts = ff_nvenc_pix_fmts,
183183 .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE |
184− AV_CODEC_CAP_ENCODER_FLUSH | AV_CODEC_CAP_DR1 |
185− AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
184+ AV_CODEC_CAP_ENCODER_FLUSH | AV_CODEC_CAP_DR1,
186185 .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
187186 FF_CODEC_CAP_INIT_CLEANUP,
188187 .p.wrapper_name = "nvenc",
libavcodec/nvenc_h264.c+1−2
@@ -244,8 +244,7 @@ const FFCodec ff_h264_nvenc_encoder = { · 243 unmodified lines
244244 .p.priv_class = &h264_nvenc_class,
245245 .defaults = defaults,
246246 .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE |
247− AV_CODEC_CAP_ENCODER_FLUSH | AV_CODEC_CAP_DR1 |
248− AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
247+ AV_CODEC_CAP_ENCODER_FLUSH | AV_CODEC_CAP_DR1,
249248 .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
250249 FF_CODEC_CAP_INIT_CLEANUP,
251250 .p.pix_fmts = ff_nvenc_pix_fmts,
libavcodec/nvenc_hevc.c+1−2
@@ -226,8 +226,7 @@ const FFCodec ff_hevc_nvenc_encoder = { · 225 unmodified lines
226226 .defaults = defaults,
227227 .p.pix_fmts = ff_nvenc_pix_fmts,
228228 .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE |
229− AV_CODEC_CAP_ENCODER_FLUSH | AV_CODEC_CAP_DR1 |
230− AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
229+ AV_CODEC_CAP_ENCODER_FLUSH | AV_CODEC_CAP_DR1,
231230 .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
232231 FF_CODEC_CAP_INIT_CLEANUP,
233232 .p.wrapper_name = "nvenc",

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