22
22
23
23
#include "config_components.h"
24
24
25
+ #include "libavutil/mem.h"
25
26
#include "avcodec.h"
26
27
#include "hwaccel_internal.h"
27
28
#include "internal.h"
@@ -109,6 +110,48 @@ static int nvdec_vc1_start_frame(AVCodecContext *avctx,
109
110
return 0 ;
110
111
}
111
112
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
+
112
155
static int nvdec_vc1_frame_params (AVCodecContext * avctx ,
113
156
AVBufferRef * hw_frames_ctx )
114
157
{
@@ -123,7 +166,7 @@ const FFHWAccel ff_vc1_nvdec_hwaccel = {
123
166
.p .pix_fmt = AV_PIX_FMT_CUDA ,
124
167
.start_frame = nvdec_vc1_start_frame ,
125
168
.end_frame = ff_nvdec_simple_end_frame ,
126
- .decode_slice = ff_nvdec_simple_decode_slice ,
169
+ .decode_slice = nvdec_vc1_decode_slice ,
127
170
.frame_params = nvdec_vc1_frame_params ,
128
171
.init = ff_nvdec_decode_init ,
129
172
.uninit = ff_nvdec_decode_uninit ,
0 commit comments