Skip to content

Commit 00c50a2

Browse files
averneBtbN
authored andcommitted
avcodec/nvdec_vc1: add marker insertion logic
This mirrors existing code in d3dxx and dxva hwaccels Signed-off-by: Timo Rothenpieler <[email protected]>
1 parent d073d0d commit 00c50a2

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

libavcodec/nvdec_vc1.c

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "config_components.h"
2424

25+
#include "libavutil/mem.h"
2526
#include "avcodec.h"
2627
#include "hwaccel_internal.h"
2728
#include "internal.h"
@@ -109,6 +110,48 @@ static int nvdec_vc1_start_frame(AVCodecContext *avctx,
109110
return 0;
110111
}
111112

113+
static int nvdec_vc1_decode_slice(AVCodecContext *avctx, const uint8_t *buffer,
114+
uint32_t size)
115+
{
116+
NVDECContext *ctx = avctx->internal->hwaccel_priv_data;
117+
const VC1Context *v = avctx->priv_data;
118+
uint32_t marker;
119+
int marker_size;
120+
void *tmp;
121+
122+
if (ctx->bitstream_len)
123+
marker = VC1_CODE_SLICE;
124+
else if (v->profile == PROFILE_ADVANCED && v->fcm == ILACE_FIELD && v->second_field)
125+
marker = VC1_CODE_FIELD;
126+
else
127+
marker = VC1_CODE_FRAME;
128+
129+
/* Only insert the marker if not already present in the bitstream */
130+
marker_size = (size >= sizeof(marker) && AV_RB32(buffer) != marker) ? sizeof(marker) : 0;
131+
132+
tmp = av_fast_realloc(ctx->bitstream_internal, &ctx->bitstream_allocated,
133+
ctx->bitstream_len + size + marker_size);
134+
if (!tmp)
135+
return AVERROR(ENOMEM);
136+
ctx->bitstream = ctx->bitstream_internal = tmp;
137+
138+
tmp = av_fast_realloc(ctx->slice_offsets, &ctx->slice_offsets_allocated,
139+
(ctx->nb_slices + 1) * sizeof(*ctx->slice_offsets));
140+
if (!tmp)
141+
return AVERROR(ENOMEM);
142+
ctx->slice_offsets = tmp;
143+
144+
if (marker_size)
145+
AV_WB32(ctx->bitstream_internal + ctx->bitstream_len, marker);
146+
147+
memcpy(ctx->bitstream_internal + ctx->bitstream_len + marker_size, buffer, size);
148+
ctx->slice_offsets[ctx->nb_slices] = ctx->bitstream_len;
149+
ctx->bitstream_len += size + marker_size;
150+
ctx->nb_slices++;
151+
152+
return 0;
153+
}
154+
112155
static int nvdec_vc1_frame_params(AVCodecContext *avctx,
113156
AVBufferRef *hw_frames_ctx)
114157
{
@@ -123,7 +166,7 @@ const FFHWAccel ff_vc1_nvdec_hwaccel = {
123166
.p.pix_fmt = AV_PIX_FMT_CUDA,
124167
.start_frame = nvdec_vc1_start_frame,
125168
.end_frame = ff_nvdec_simple_end_frame,
126-
.decode_slice = ff_nvdec_simple_decode_slice,
169+
.decode_slice = nvdec_vc1_decode_slice,
127170
.frame_params = nvdec_vc1_frame_params,
128171
.init = ff_nvdec_decode_init,
129172
.uninit = ff_nvdec_decode_uninit,

0 commit comments

Comments
 (0)