43 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
45 typedef struct SpriteData {
59 int effect_type, effect_flag;
60 int effect_pcount1, effect_pcount2;
61 int effect_params1[15], effect_params2[10];
69 static void vc1_sprite_parse_transform(
GetBitContext* gb,
int c[7])
76 c[2] = get_fp_val(gb);
80 c[0] = c[4] = get_fp_val(gb);
81 c[2] = get_fp_val(gb);
84 c[0] = get_fp_val(gb);
85 c[2] = get_fp_val(gb);
86 c[4] = get_fp_val(gb);
89 c[0] = get_fp_val(gb);
90 c[1] = get_fp_val(gb);
91 c[2] = get_fp_val(gb);
92 c[3] = get_fp_val(gb);
93 c[4] = get_fp_val(gb);
96 c[5] = get_fp_val(gb);
98 c[6] = get_fp_val(gb);
108 for (sprite = 0; sprite <= v->
two_sprites; sprite++) {
109 vc1_sprite_parse_transform(gb, sd->coefs[sprite]);
110 if (sd->coefs[sprite][1] || sd->coefs[sprite][3])
113 for (i = 0; i < 7; i++)
115 sd->coefs[sprite][i] / (1<<16),
116 (abs(sd->coefs[sprite][i]) & 0xFFFF) * 1000 / (1 << 16));
122 switch (sd->effect_pcount1 =
get_bits(gb, 4)) {
124 vc1_sprite_parse_transform(gb, sd->effect_params1);
127 vc1_sprite_parse_transform(gb, sd->effect_params1);
128 vc1_sprite_parse_transform(gb, sd->effect_params1 + 7);
131 for (i = 0; i < sd->effect_pcount1; i++)
132 sd->effect_params1[i] = get_fp_val(gb);
134 if (sd->effect_type != 13 || sd->effect_params1[0] != sd->coefs[0][6]) {
137 for (i = 0; i < sd->effect_pcount1; i++)
139 sd->effect_params1[i] / (1 << 16),
140 (abs(sd->effect_params1[i]) & 0xFFFF) * 1000 / (1 << 16));
144 sd->effect_pcount2 =
get_bits(gb, 16);
145 if (sd->effect_pcount2 > 10) {
148 }
else if (sd->effect_pcount2) {
151 while (++i < sd->effect_pcount2) {
152 sd->effect_params2[i] = get_fp_val(gb);
154 sd->effect_params2[i] / (1 << 16),
155 (abs(sd->effect_params2[i]) & 0xFFFF) * 1000 / (1 << 16));
174 static void vc1_draw_sprites(
VC1Context *v, SpriteData* sd)
176 int i,
plane, row, sprite;
177 int sr_cache[2][2] = { { -1, -1 }, { -1, -1 } };
179 int xoff[2], xadv[2], yoff[2], yadv[2],
alpha;
184 xoff[i] = av_clip(sd->coefs[i][2], 0, v->
sprite_width-1 << 16);
185 xadv[i] = sd->coefs[i][0];
189 yoff[i] = av_clip(sd->coefs[i][5], 0, v->
sprite_height-1 << 16);
192 alpha = av_clip_uint16(sd->coefs[1][6]);
201 for (sprite = 0; sprite <= v->
two_sprites; sprite++) {
204 int ycoord = yoff[sprite] + yadv[sprite] * row;
205 int yline = ycoord >> 16;
207 ysub[sprite] = ycoord & 0xFFFF;
213 if (!(xoff[sprite] & 0xFFFF) && xadv[sprite] == 1 << 16) {
214 src_h[sprite][0] = iplane + (xoff[sprite] >> 16) + yline * iline;
216 src_h[sprite][1] = iplane + (xoff[sprite] >> 16) + next_line;
218 if (sr_cache[sprite][0] != yline) {
219 if (sr_cache[sprite][1] == yline) {
221 FFSWAP(
int, sr_cache[sprite][0], sr_cache[sprite][1]);
223 v->
vc1dsp.
sprite_h(v->
sr_rows[sprite][0], iplane + yline * iline, xoff[sprite], xadv[sprite], width);
224 sr_cache[sprite][0] = yline;
227 if (ysub[sprite] && sr_cache[sprite][1] != yline + 1) {
229 iplane + next_line, xoff[sprite],
230 xadv[sprite], width);
231 sr_cache[sprite][1] = yline + 1;
233 src_h[sprite][0] = v->
sr_rows[sprite][0];
234 src_h[sprite][1] = v->
sr_rows[sprite][1];
242 memcpy(dst, src_h[0][0], width);
245 if (ysub[0] && ysub[1]) {
247 src_h[1][0], src_h[1][1], ysub[1], alpha, width);
248 }
else if (ysub[0]) {
250 src_h[1][0], alpha, width);
251 }
else if (ysub[1]) {
253 src_h[0][0], (1<<16)-1-alpha, width);
278 memset(&sd, 0,
sizeof(sd));
280 ret = vc1_parse_sprites(v, gb, &sd);
298 vc1_draw_sprites(v, &sd);
318 plane ? 128 : 0, f->
linesize[plane]);
375 for (i = 0; i < 4; i++)
402 for (i = 0; i < 64; i++) {
403 #define transpose(x) (((x) >> 3) | (((x) & 7) << 3))
453 }
else if (count < 0) {
462 int seq_initialized = 0, ep_initialized = 0;
475 for (; next <
end; start = next) {
477 size = next - start - 4;
500 if (!seq_initialized || !ep_initialized) {
590 for (i = 0; i < 4; i++)
622 int buf_size = avpkt->
size, n_slices = 0, i, ret;
628 int mb_height, n_slices1=-1;
633 } *slices =
NULL, *tmp;
675 for (start = buf, end = buf + buf_size; next <
end; start = next) {
677 size = next - start - 4;
678 if (size <= 0)
continue;
696 buf_start_second_field =
start;
704 if (!slices[n_slices].buf) {
709 slices[n_slices].buf);
714 slices[n_slices].mby_start = s->
mb_height + 1 >> 1;
715 n_slices1 = n_slices - 1;
733 if (!slices[n_slices].buf) {
738 slices[n_slices].buf);
741 slices[n_slices].mby_start =
get_bits(&slices[n_slices].gb, 9);
747 }
else if (v->
interlace && ((buf[0] & 0xC0) == 0xC0)) {
762 buf_start_second_field = divider;
770 if (!slices[n_slices].buf) {
774 buf_size3 =
vc1_unescape_buffer(divider + 4, buf + buf_size - divider - 4, slices[n_slices].buf);
777 slices[n_slices].mby_start = s->
mb_height + 1 >> 1;
778 n_slices1 = n_slices - 1;
909 if ((CONFIG_VC1_VDPAU_DECODER)
911 if (v->
field_mode && buf_start_second_field) {
920 if (v->
field_mode && buf_start_second_field) {
923 if ((ret = avctx->
hwaccel->
start_frame(avctx, buf_start, buf_start_second_field - buf_start)) < 0)
925 if ((ret = avctx->
hwaccel->
decode_slice(avctx, buf_start, buf_start_second_field - buf_start)) < 0)
931 s->
gb = slices[n_slices1 + 1].gb;
942 if ((ret = avctx->
hwaccel->
start_frame(avctx, buf_start_second_field, (buf + buf_size) - buf_start_second_field)) < 0)
944 if ((ret = avctx->
hwaccel->
decode_slice(avctx, buf_start_second_field, (buf + buf_size) - buf_start_second_field)) < 0)
950 if ((ret = avctx->
hwaccel->
start_frame(avctx, buf_start, (buf + buf_size) - buf_start)) < 0)
952 if ((ret = avctx->
hwaccel->
decode_slice(avctx, buf_start, (buf + buf_size) - buf_start)) < 0)
962 v->
bits = buf_size * 8;
975 for (i = 0; i <= n_slices; i++) {
976 if (i > 0 && slices[i - 1].mby_start >= mb_height) {
979 "picture boundary (%d >= %d)\n", i,
980 slices[i - 1].mby_start, mb_height);
1015 s->
start_mb_y = (i == 0) ? 0 :
FFMAX(0, slices[i-1].mby_start % mb_height);
1017 s->
end_mb_y = (i == n_slices ) ? mb_height :
FFMIN(mb_height, slices[i].mby_start % mb_height);
1019 if (i >= n_slices) {
1023 s->
end_mb_y = (i <= n_slices1 + 1) ? mb_height :
FFMIN(mb_height, slices[i].mby_start % mb_height);
1035 s->
gb = slices[i].gb;
1069 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
1070 if ((ret = vc1_decode_sprites(v, &s->
gb)) < 0)
1092 for (i = 0; i < n_slices; i++)
1099 for (i = 0; i < n_slices; i++)
1115 #if CONFIG_VC1_DXVA2_HWACCEL
1118 #if CONFIG_VC1_D3D11VA_HWACCEL
1121 #if CONFIG_VC1_VAAPI_HWACCEL
1124 #if CONFIG_VC1_VDPAU_HWACCEL
1142 .
pix_fmts = vc1_hwaccel_pixfmt_list_420,
1146 #if CONFIG_WMV3_DECODER
1158 .
pix_fmts = vc1_hwaccel_pixfmt_list_420,
1163 #if CONFIG_WMV3_VDPAU_DECODER && FF_API_VDPAU
1164 AVCodec ff_wmv3_vdpau_decoder = {
1165 .
name =
"wmv3_vdpau",
1179 #if CONFIG_VC1_VDPAU_DECODER && FF_API_VDPAU
1180 AVCodec ff_vc1_vdpau_decoder = {
1181 .
name =
"vc1_vdpau",
1195 #if CONFIG_WMV3IMAGE_DECODER
1196 AVCodec ff_wmv3image_decoder = {
1197 .
name =
"wmv3image",
1206 .
flush = vc1_sprite_flush,
1214 #if CONFIG_VC1IMAGE_DECODER
1215 AVCodec ff_vc1image_decoder = {
1225 .
flush = vc1_sprite_flush,
int color_prim
8bits, chroma coordinates of the color primaries
in the bitstream is reported as 00b
const struct AVCodec * codec
discard all frames except keyframes
int(* start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size)
Called at the beginning of each frame or field picture.
qpel_mc_func avg_qpel_pixels_tab[2][16]
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
int start_mb_y
start mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y) ...
static void flush(AVCodecContext *avctx)
int coded_width
Bitstream width / height, may be different from width/height e.g.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_LOG_WARNING
Something somehow does not look correct.
int ff_msmpeg4_decode_init(AVCodecContext *avctx)
int end_mb_y
end mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y) ...
static av_cold int init(AVCodecContext *avctx)
int max_b_frames
maximum number of B-frames between non-B-frames Note: The output will be delayed by max_b_frames+1 re...
int v_edge_pos
horizontal / vertical position of the right/bottom edge (pixel replication)
void ff_er_frame_end(ERContext *s)
void(* sprite_v_double_onescale)(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset1, const uint8_t *src2a, int alpha, int width)
enum AVColorRange color_range
MPEG vs JPEG YUV range.
int repeat_pict
When decoding, this signals how much the picture must be delayed.
int transfer_char
8bits, Opto-electronic transfer characteristics
int field_picture
whether or not the picture was encoded in separate fields
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
uint8_t zz_8x8[4][64]
Zigzag table for TT_8x8, permuted for IDCT.
av_cold void ff_h264chroma_init(H264ChromaContext *c, int bit_depth)
uint8_t * mv_f[2]
0: MV obtained from same field, 1: opposite field
int end_mb_x
Horizontal macroblock limit (used only by mss2)
enum AVDiscard skip_frame
Skip decoding for selected frames.
struct AVHWAccel * hwaccel
Hardware accelerator in use.
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
uint8_t * acpred_plane
AC prediction flags bitplane.
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
static const AVProfile profiles[]
int matrix_coef
8bits, Color primaries->YCbCr transform matrix
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
int first_pic_header_flag
av_cold int ff_vc1_init_common(VC1Context *v)
Init VC-1 specific tables and VC1Context members.
void(* sprite_v_double_twoscale)(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset1, const uint8_t *src2a, const uint8_t *src2b, int offset2, int alpha, int width)
#define FF_DEBUG_PICT_INFO
static av_cold int end(AVCodecContext *avctx)
int interlace
Progressive/interlaced (RPTFTM syntax element)
qpel_mc_func(* qpel_put)[16]
#define AV_CODEC_FLAG_LOW_DELAY
Force low delay.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Picture current_picture
copy of the current picture structure.
int profile
Sequence header data for all Profiles TODO: choose between ints, uint8_ts and monobit flags...
#define PICT_BOTTOM_FIELD
static int get_bits_count(const GetBitContext *s)
char av_get_picture_type_char(enum AVPictureType pict_type)
Return a single letter to describe the given picture type pict_type.
#define AV_CODEC_CAP_HWACCEL_VDPAU
Codec can export data for HW decoding (VDPAU).
bitstream reader API header.
uint8_t * forward_mb_plane
bitplane for "forward" MBs
WMV3 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstrea...
int interlaced_frame
The content of the picture is interlaced.
int mb_height
number of MBs horizontally & vertically
int ff_vc1_decode_sequence_header(AVCodecContext *avctx, VC1Context *v, GetBitContext *gb)
Decode Simple/Main Profiles sequence header.
uint8_t * over_flags_plane
Overflags bitplane.
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
static double alpha(void *priv, double x, double y)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int has_b_frames
Size of the frame reordering buffer in the decoder.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static av_cold int vc1_decode_init(AVCodecContext *avctx)
Initialize a VC1/WMV3 decoder.
int capabilities
Codec capabilities.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int flags
AV_CODEC_FLAG_*.
simple assert() macros that are a bit more flexible than ISO C assert().
void ff_vc1_decode_blocks(VC1Context *v)
const char * name
Name of the codec implementation.
int low_delay
no reordering needed / has no b-frames
qpel_mc_func put_qpel_pixels_tab[2][16]
void ff_mpv_common_end(MpegEncContext *s)
uint8_t * blk_mv_type
0: frame MV, 1: field MV (interlaced frame)
void ff_mpeg_flush(AVCodecContext *avctx)
int ff_vc1_parse_frame_header_adv(VC1Context *v, GetBitContext *gb)
const uint8_t ff_vc1_adv_interlaced_8x8_zz[64]
const uint8_t ff_wmv1_scantable[WMV1_SCANTABLE_COUNT][64]
enum AVPixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
enum AVPictureType pict_type
Picture type of the frame.
av_cold int ff_vc1_decode_end(AVCodecContext *avctx)
Close a VC1/WMV3 decoder.
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
av_cold void ff_vc1_init_transposed_scantables(VC1Context *v)
int next_p_frame_damaged
set if the next p frame is damaged, to avoid showing trashed b frames
uint8_t * blk_mv_type_base
av_cold void ff_intrax8_common_init(IntraX8Context *w, MpegEncContext *const s)
Initialize IntraX8 frame decoder.
int field_mode
1 for interlaced field pictures
av_cold void ff_intrax8_common_end(IntraX8Context *w)
Destroy IntraX8 frame structure.
int width
picture width / height.
#define FF_PROFILE_VC1_MAIN
Picture * current_picture_ptr
pointer to the current picture
#define FF_PROFILE_UNKNOWN
void ff_mpeg_er_frame_start(MpegEncContext *s)
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
av_cold int ff_vc1_decode_init_alloc_tables(VC1Context *v)
int ff_vc1_parse_frame_header(VC1Context *v, GetBitContext *gb)
#define AV_EF_EXPLODE
abort decoding on minor error detection
#define FF_PROFILE_VC1_SIMPLE
int16_t(* luma_mv_base)[2]
VLC * cbpcy_vlc
CBPCY VLC table.
uint8_t * sr_rows[2][2]
Sprite resizer line cache.
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AV_LOG_INFO
Standard information.
int res_sprite
Simple/Main Profile sequence header.
int top_blk_sh
Either 3 or 0, positions of l/t in blk[].
Libavcodec external API header.
static av_always_inline int vc1_unescape_buffer(const uint8_t *src, int size, uint8_t *dst)
ptrdiff_t linesize
line size, in bytes, may be different from width
av_cold void ff_blockdsp_init(BlockDSPContext *c, AVCodecContext *avctx)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
int height
picture size. must be a multiple of 16
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
void ff_print_debug_info(MpegEncContext *s, Picture *p, AVFrame *pict)
void(* sprite_v_double_noscale)(uint8_t *dst, const uint8_t *src1a, const uint8_t *src2a, int alpha, int width)
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits(GetBitContext *s, int n)
enum AVColorSpace colorspace
YUV colorspace type.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
ptrdiff_t uvlinesize
line size, for chroma in bytes, may be different from width
int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx)
generic function called after decoding the header and before a frame is decoded.
#define FF_PROFILE_VC1_COMPLEX
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
uint8_t * direct_mb_plane
bitplane for "direct" MBs
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer. ...
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
static enum AVPixelFormat pix_fmts[]
static int vc1_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Decode a VC1/WMV3 frame.
uint8_t * mv_type_mb_plane
bitplane for mv_type == (4MV)
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
qpel_mc_func(* qpel_avg)[16]
int b8_stride
2*mb_width+1 used for some 8x8 block arrays to allow simple addressing
the normal 219*2^(n-8) "MPEG" YUV ranges
Picture * next_picture_ptr
pointer to the next picture (for bidir pred)
struct AVCodecContext * avctx
VC-1 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstrea...
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
discard all non reference
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
int mb_stride
mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11 ...
static enum AVPixelFormat vc1_hwaccel_pixfmt_list_420[]
enum FrameCodingMode fcm
Frame decoding info for Advanced profile.
Picture last_picture
copy of the previous picture structure.
Picture * last_picture_ptr
pointer to the previous picture.
int res_fasttx
reserved, always 1
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
int * ttblk
Transform type at the block level.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
int ff_vc1_decode_entry_point(AVCodecContext *avctx, VC1Context *v, GetBitContext *gb)
#define FF_PROFILE_VC1_ADVANCED
int top_field_first
If the content is interlaced, is top field displayed first.
AVFrame * sprite_output_frame
void ff_mpv_frame_end(MpegEncContext *s)
void(* sprite_v_single)(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset, int width)
int key_frame
1 -> keyframe, 0-> not
H264ChromaContext h264chroma
int level
Advanced Profile.
HW decoding through Direct3D11, Picture.data[3] contains a ID3D11VideoDecoderOutputView pointer...
int new_sprite
Frame decoding info for sprite modes.
av_cold void ff_qpeldsp_init(QpelDSPContext *c)
#define FFSWAP(type, a, b)
int(* decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size)
Callback for each slice.
int(* end_frame)(AVCodecContext *avctx)
Called at the end of each frame or field picture.
void ff_vdpau_vc1_decode_picture(MpegEncContext *s, const uint8_t *buf, int buf_size)
AVPixelFormat
Pixel format.
This structure stores compressed data.
static av_always_inline const uint8_t * find_next_marker(const uint8_t *src, const uint8_t *end)
Find VC-1 marker in buffer.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
void(* sprite_h)(uint8_t *dst, const uint8_t *src, int offset, int advance, int count)