Commit b286383b authored by Michael Niedermayer's avatar Michael Niedermayer

Merge remote-tracking branch 'qatar/master'

* qatar/master:
  asfdec: read attached pictures.
  apetag: reindent
  apetag: export attached covers as video streams.
  apetag: fix the amount of data read from binary tags.
  apetag: make sure avio_get_str() doesn't read more than it should.
  mov: read itunes cover art.
  snow: remove VLA in mc_block()
  intfloat: Don't use designated initializers in the public headers
  snow: remove a VLA.
  doc: Remind devs to check return values, especially for malloc() et al
  MS ATC Screen (aka MSS3) decoder
  vf_yadif: move x86 init code to x86/yadif.c
  vf_gradfun: move x86 init code to x86/gradfun.c
  roqvideo: Remove a totally unused dspcontext
  smacker: remove some unused code
  dsicin: remove dead assignment
  aacdec: remove dead assignment
  rl2: remove dead assignment
  proresenc: make a variable local to the loop where it is used
  alsdec: remove dead assignments

Conflicts:
	Changelog
	doc/developer.texi
	libavcodec/allcodecs.c
	libavcodec/avcodec.h
	libavcodec/version.h
	libavfilter/gradfun.h
	libavfilter/x86/gradfun.c
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents 7c84e7d3 5e745cef
...@@ -14,6 +14,7 @@ version next: ...@@ -14,6 +14,7 @@ version next:
- Microsoft Screen 1 decoder - Microsoft Screen 1 decoder
- join audio filter - join audio filter
- audio channel mapping filter - audio channel mapping filter
- Microsoft ATC Screen decoder
- showwaves filter - showwaves filter
- LucasArts SMUSH playback support - LucasArts SMUSH playback support
- SAMI demuxer and decoder - SAMI demuxer and decoder
......
...@@ -489,6 +489,10 @@ send a reminder by email. Your patch should eventually be dealt with. ...@@ -489,6 +489,10 @@ send a reminder by email. Your patch should eventually be dealt with.
Consider to add a regression test for your code. Consider to add a regression test for your code.
@item @item
If you added YASM code please check that things still work with --disable-yasm If you added YASM code please check that things still work with --disable-yasm
@item
Make sure you check the return values of function and return appropriate
error codes. Especially memory allocation functions like @code{malloc()}
are notoriously left unchecked, which is a serious problem.
@end enumerate @end enumerate
@section Patch review process @section Patch review process
......
...@@ -565,6 +565,8 @@ following image formats are supported: ...@@ -565,6 +565,8 @@ following image formats are supported:
@item LucasArts Smush @tab @tab X @item LucasArts Smush @tab @tab X
@tab Used in LucasArts games. @tab Used in LucasArts games.
@item lossless MJPEG @tab X @tab X @item lossless MJPEG @tab X @tab X
@item Microsoft ATC Screen @tab @tab X
@tab Also known as Microsoft Screen 3.
@item Microsoft RLE @tab @tab X @item Microsoft RLE @tab @tab X
@item Microsoft Screen 1 @tab @tab X @item Microsoft Screen 1 @tab @tab X
@tab Also known as Windows Media Video V7 Screen. @tab Also known as Windows Media Video V7 Screen.
......
...@@ -327,6 +327,7 @@ OBJS-$(CONFIG_MSMPEG4V3_ENCODER) += msmpeg4.o msmpeg4enc.o msmpeg4data.o \ ...@@ -327,6 +327,7 @@ OBJS-$(CONFIG_MSMPEG4V3_ENCODER) += msmpeg4.o msmpeg4enc.o msmpeg4data.o \
h263dec.o h263.o ituh263dec.o \ h263dec.o h263.o ituh263dec.o \
mpeg4videodec.o mpeg4videodec.o
OBJS-$(CONFIG_MSRLE_DECODER) += msrle.o msrledec.o OBJS-$(CONFIG_MSRLE_DECODER) += msrle.o msrledec.o
OBJS-$(CONFIG_MSA1_DECODER) += mss3.o
OBJS-$(CONFIG_MSS1_DECODER) += mss1.o OBJS-$(CONFIG_MSS1_DECODER) += mss1.o
OBJS-$(CONFIG_MSVIDEO1_DECODER) += msvideo1.o OBJS-$(CONFIG_MSVIDEO1_DECODER) += msvideo1.o
OBJS-$(CONFIG_MSVIDEO1_ENCODER) += msvideo1enc.o elbg.o OBJS-$(CONFIG_MSVIDEO1_ENCODER) += msvideo1enc.o elbg.o
......
...@@ -1308,7 +1308,7 @@ static inline float *VMUL4S(float *dst, const float *v, unsigned idx, ...@@ -1308,7 +1308,7 @@ static inline float *VMUL4S(float *dst, const float *v, unsigned idx,
t.i = s.i ^ (sign & 1U<<31); t.i = s.i ^ (sign & 1U<<31);
*dst++ = v[idx>>4 & 3] * t.f; *dst++ = v[idx>>4 & 3] * t.f;
sign <<= nz & 1; nz >>= 1; sign <<= nz & 1;
t.i = s.i ^ (sign & 1U<<31); t.i = s.i ^ (sign & 1U<<31);
*dst++ = v[idx>>6 & 3] * t.f; *dst++ = v[idx>>6 & 3] * t.f;
......
...@@ -165,6 +165,7 @@ void avcodec_register_all(void) ...@@ -165,6 +165,7 @@ void avcodec_register_all(void)
REGISTER_DECODER (MPEG_VDPAU, mpeg_vdpau); REGISTER_DECODER (MPEG_VDPAU, mpeg_vdpau);
REGISTER_DECODER (MPEG1_VDPAU, mpeg1_vdpau); REGISTER_DECODER (MPEG1_VDPAU, mpeg1_vdpau);
REGISTER_DECODER (MPEG2_CRYSTALHD, mpeg2_crystalhd); REGISTER_DECODER (MPEG2_CRYSTALHD, mpeg2_crystalhd);
REGISTER_DECODER (MSA1, msa1);
REGISTER_DECODER (MSMPEG4_CRYSTALHD, msmpeg4_crystalhd); REGISTER_DECODER (MSMPEG4_CRYSTALHD, msmpeg4_crystalhd);
REGISTER_DECODER (MSMPEG4V1, msmpeg4v1); REGISTER_DECODER (MSMPEG4V1, msmpeg4v1);
REGISTER_ENCDEC (MSMPEG4V2, msmpeg4v2); REGISTER_ENCDEC (MSMPEG4V2, msmpeg4v2);
......
...@@ -770,7 +770,7 @@ static int read_var_block_data(ALSDecContext *ctx, ALSBlockData *bd) ...@@ -770,7 +770,7 @@ static int read_var_block_data(ALSDecContext *ctx, ALSBlockData *bd)
int delta[8]; int delta[8];
unsigned int k [8]; unsigned int k [8];
unsigned int b = av_clip((av_ceil_log2(bd->block_length) - 3) >> 1, 0, 5); unsigned int b = av_clip((av_ceil_log2(bd->block_length) - 3) >> 1, 0, 5);
unsigned int i = start; unsigned int i;
// read most significant bits // read most significant bits
unsigned int high; unsigned int high;
...@@ -781,7 +781,7 @@ static int read_var_block_data(ALSDecContext *ctx, ALSBlockData *bd) ...@@ -781,7 +781,7 @@ static int read_var_block_data(ALSDecContext *ctx, ALSBlockData *bd)
current_res = bd->raw_samples + start; current_res = bd->raw_samples + start;
for (sb = 0; sb < sub_blocks; sb++, i = 0) { for (sb = 0; sb < sub_blocks; sb++) {
k [sb] = s[sb] > b ? s[sb] - b : 0; k [sb] = s[sb] > b ? s[sb] - b : 0;
delta[sb] = 5 - s[sb] + k[sb]; delta[sb] = 5 - s[sb] + k[sb];
......
...@@ -258,6 +258,7 @@ enum CodecID { ...@@ -258,6 +258,7 @@ enum CodecID {
CODEC_ID_XBM, CODEC_ID_XBM,
CODEC_ID_ZEROCODEC, CODEC_ID_ZEROCODEC,
CODEC_ID_MSS1, CODEC_ID_MSS1,
CODEC_ID_MSA1,
CODEC_ID_Y41P = MKBETAG('Y','4','1','P'), CODEC_ID_Y41P = MKBETAG('Y','4','1','P'),
CODEC_ID_ESCAPE130 = MKBETAG('E','1','3','0'), CODEC_ID_ESCAPE130 = MKBETAG('E','1','3','0'),
CODEC_ID_EXR = MKBETAG('0','E','X','R'), CODEC_ID_EXR = MKBETAG('0','E','X','R'),
......
...@@ -122,7 +122,7 @@ static int cin_decode_huffman(const unsigned char *src, int src_size, unsigned c ...@@ -122,7 +122,7 @@ static int cin_decode_huffman(const unsigned char *src, int src_size, unsigned c
unsigned char *dst_end = dst + dst_size; unsigned char *dst_end = dst + dst_size;
const unsigned char *src_end = src + src_size; const unsigned char *src_end = src + src_size;
memcpy(huff_code_table, src, 15); src += 15; src_size -= 15; memcpy(huff_code_table, src, 15); src += 15;
while (src < src_end) { while (src < src_end) {
huff_code = *src++; huff_code = *src++;
......
This diff is collapsed.
...@@ -726,7 +726,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, ...@@ -726,7 +726,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
int sizes[4] = { 0 }; int sizes[4] = { 0 };
int slice_hdr_size = 2 + 2 * (ctx->num_planes - 1); int slice_hdr_size = 2 + 2 * (ctx->num_planes - 1);
int frame_size, picture_size, slice_size; int frame_size, picture_size, slice_size;
int mbs_per_slice = ctx->mbs_per_slice;
int pkt_size, ret; int pkt_size, ret;
*avctx->coded_frame = *pic; *avctx->coded_frame = *pic;
...@@ -792,7 +791,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, ...@@ -792,7 +791,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
} }
for (y = 0; y < ctx->mb_height; y++) { for (y = 0; y < ctx->mb_height; y++) {
mbs_per_slice = ctx->mbs_per_slice; int mbs_per_slice = ctx->mbs_per_slice;
for (x = mb = 0; x < ctx->mb_width; x += mbs_per_slice, mb++) { for (x = mb = 0; x < ctx->mb_width; x += mbs_per_slice, mb++) {
q = ctx->force_quant ? ctx->force_quant q = ctx->force_quant ? ctx->force_quant
: ctx->slice_q[mb + y * ctx->slices_width]; : ctx->slice_q[mb + y * ctx->slices_width];
......
...@@ -64,7 +64,7 @@ static void rl2_rle_decode(Rl2Context *s,const unsigned char* in,int size, ...@@ -64,7 +64,7 @@ static void rl2_rle_decode(Rl2Context *s,const unsigned char* in,int size,
const unsigned char* back_frame = s->back_frame; const unsigned char* back_frame = s->back_frame;
const unsigned char* in_end = in + size; const unsigned char* in_end = in + size;
const unsigned char* out_end = out + stride * s->avctx->height; const unsigned char* out_end = out + stride * s->avctx->height;
unsigned char* line_end = out + s->avctx->width; unsigned char* line_end;
/** copy start of the background frame */ /** copy start of the background frame */
for(i=0;i<=base_y;i++){ for(i=0;i<=base_y;i++){
......
...@@ -45,7 +45,6 @@ struct RoqTempData; ...@@ -45,7 +45,6 @@ struct RoqTempData;
typedef struct RoqContext { typedef struct RoqContext {
AVCodecContext *avctx; AVCodecContext *avctx;
DSPContext dsp;
AVFrame frames[2]; AVFrame frames[2];
AVFrame *last_frame; AVFrame *last_frame;
AVFrame *current_frame; AVFrame *current_frame;
......
...@@ -137,13 +137,9 @@ static int smacker_decode_bigtree(GetBitContext *gb, HuffContext *hc, DBCtx *ctx ...@@ -137,13 +137,9 @@ static int smacker_decode_bigtree(GetBitContext *gb, HuffContext *hc, DBCtx *ctx
return -1; return -1;
} }
if(!get_bits1(gb)){ //Leaf if(!get_bits1(gb)){ //Leaf
int val, i1, i2, b1, b2; int val, i1, i2;
b1 = get_bits_count(gb);
i1 = ctx->v1->table ? get_vlc2(gb, ctx->v1->table, SMKTREE_BITS, 3) : 0; i1 = ctx->v1->table ? get_vlc2(gb, ctx->v1->table, SMKTREE_BITS, 3) : 0;
b1 = get_bits_count(gb) - b1;
b2 = get_bits_count(gb);
i2 = ctx->v2->table ? get_vlc2(gb, ctx->v2->table, SMKTREE_BITS, 3) : 0; i2 = ctx->v2->table ? get_vlc2(gb, ctx->v2->table, SMKTREE_BITS, 3) : 0;
b2 = get_bits_count(gb) - b2;
if (i1 < 0 || i2 < 0) if (i1 < 0 || i2 < 0)
return -1; return -1;
val = ctx->recode1[i1] | (ctx->recode2[i2] << 8); val = ctx->recode1[i1] | (ctx->recode2[i2] << 8);
......
...@@ -140,7 +140,7 @@ static void mc_block(Plane *p, uint8_t *dst, const uint8_t *src, int stride, int ...@@ -140,7 +140,7 @@ static void mc_block(Plane *p, uint8_t *dst, const uint8_t *src, int stride, int
int x, y, b, r, l; int x, y, b, r, l;
int16_t tmpIt [64*(32+HTAPS_MAX)]; int16_t tmpIt [64*(32+HTAPS_MAX)];
uint8_t tmp2t[3][stride*(32+HTAPS_MAX)]; uint8_t tmp2t[3][64*(32+HTAPS_MAX)];
int16_t *tmpI= tmpIt; int16_t *tmpI= tmpIt;
uint8_t *tmp2= tmp2t[0]; uint8_t *tmp2= tmp2t[0];
const uint8_t *hpel[11]; const uint8_t *hpel[11];
...@@ -178,7 +178,7 @@ static void mc_block(Plane *p, uint8_t *dst, const uint8_t *src, int stride, int ...@@ -178,7 +178,7 @@ static void mc_block(Plane *p, uint8_t *dst, const uint8_t *src, int stride, int
tmp2[x]= am; tmp2[x]= am;
} }
tmpI+= 64; tmpI+= 64;
tmp2+= stride; tmp2+= 64;
src += stride; src += stride;
} }
src -= stride*y; src -= stride*y;
...@@ -207,7 +207,7 @@ static void mc_block(Plane *p, uint8_t *dst, const uint8_t *src, int stride, int ...@@ -207,7 +207,7 @@ static void mc_block(Plane *p, uint8_t *dst, const uint8_t *src, int stride, int
tmp2[x]= am; tmp2[x]= am;
} }
src += stride; src += stride;
tmp2+= stride; tmp2+= 64;
} }
src -= stride*y; src -= stride*y;
} }
...@@ -234,12 +234,12 @@ static void mc_block(Plane *p, uint8_t *dst, const uint8_t *src, int stride, int ...@@ -234,12 +234,12 @@ static void mc_block(Plane *p, uint8_t *dst, const uint8_t *src, int stride, int
tmp2[x]= am; tmp2[x]= am;
} }
tmpI+= 64; tmpI+= 64;
tmp2+= stride; tmp2+= 64;
} }
} }
hpel[ 0]= src; hpel[ 0]= src;
hpel[ 1]= tmp2t[0] + stride*(HTAPS_MAX/2-1); hpel[ 1]= tmp2t[0] + 64*(HTAPS_MAX/2-1);
hpel[ 2]= src + 1; hpel[ 2]= src + 1;
hpel[ 4]= tmp2t[1]; hpel[ 4]= tmp2t[1];
...@@ -247,14 +247,21 @@ static void mc_block(Plane *p, uint8_t *dst, const uint8_t *src, int stride, int ...@@ -247,14 +247,21 @@ static void mc_block(Plane *p, uint8_t *dst, const uint8_t *src, int stride, int
hpel[ 6]= tmp2t[1] + 1; hpel[ 6]= tmp2t[1] + 1;
hpel[ 8]= src + stride; hpel[ 8]= src + stride;
hpel[ 9]= hpel[1] + stride; hpel[ 9]= hpel[1] + 64;
hpel[10]= hpel[8] + 1; hpel[10]= hpel[8] + 1;
#define MC_STRIDE(x) (needs[x] ? 64 : stride)
if(b==15){ if(b==15){
const uint8_t *src1= hpel[dx/8 + dy/8*4 ]; int dxy = dx / 8 + dy / 8 * 4;
const uint8_t *src2= hpel[dx/8 + dy/8*4+1]; const uint8_t *src1 = hpel[dxy ];
const uint8_t *src3= hpel[dx/8 + dy/8*4+4]; const uint8_t *src2 = hpel[dxy + 1];
const uint8_t *src4= hpel[dx/8 + dy/8*4+5]; const uint8_t *src3 = hpel[dxy + 4];
const uint8_t *src4 = hpel[dxy + 5];
int stride1 = MC_STRIDE(dxy);
int stride2 = MC_STRIDE(dxy + 1);
int stride3 = MC_STRIDE(dxy + 4);
int stride4 = MC_STRIDE(dxy + 5);
dx&=7; dx&=7;
dy&=7; dy&=7;
for(y=0; y < b_h; y++){ for(y=0; y < b_h; y++){
...@@ -262,23 +269,25 @@ static void mc_block(Plane *p, uint8_t *dst, const uint8_t *src, int stride, int ...@@ -262,23 +269,25 @@ static void mc_block(Plane *p, uint8_t *dst, const uint8_t *src, int stride, int
dst[x]= ((8-dx)*(8-dy)*src1[x] + dx*(8-dy)*src2[x]+ dst[x]= ((8-dx)*(8-dy)*src1[x] + dx*(8-dy)*src2[x]+
(8-dx)* dy *src3[x] + dx* dy *src4[x]+32)>>6; (8-dx)* dy *src3[x] + dx* dy *src4[x]+32)>>6;
} }
src1+=stride; src1+=stride1;
src2+=stride; src2+=stride2;
src3+=stride; src3+=stride3;
src4+=stride; src4+=stride4;
dst +=stride; dst +=stride;
} }
}else{ }else{
const uint8_t *src1= hpel[l]; const uint8_t *src1= hpel[l];
const uint8_t *src2= hpel[r]; const uint8_t *src2= hpel[r];
int stride1 = MC_STRIDE(l);
int stride2 = MC_STRIDE(r);
int a= weight[((dx&7) + (8*(dy&7)))]; int a= weight[((dx&7) + (8*(dy&7)))];
int b= 8-a; int b= 8-a;
for(y=0; y < b_h; y++){ for(y=0; y < b_h; y++){
for(x=0; x < b_w; x++){ for(x=0; x < b_w; x++){
dst[x]= (a*src1[x] + b*src2[x] + 4)>>3; dst[x]= (a*src1[x] + b*src2[x] + 4)>>3;
} }
src1+=stride; src1+=stride1;
src2+=stride; src2+=stride2;
dst +=stride; dst +=stride;
} }
} }
......
...@@ -666,7 +666,7 @@ static inline int get_block_bits(SnowContext *s, int x, int y, int w){ ...@@ -666,7 +666,7 @@ static inline int get_block_bits(SnowContext *s, int x, int y, int w){
} }
} }
static int get_block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index, const uint8_t *obmc_edged){ static int get_block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index, uint8_t (*obmc_edged)[MB_SIZE * 2]){
Plane *p= &s->plane[plane_index]; Plane *p= &s->plane[plane_index];
const int block_size = MB_SIZE >> s->block_max_depth; const int block_size = MB_SIZE >> s->block_max_depth;
const int block_w = plane_index ? block_size>>s->chroma_h_shift : block_size; const int block_w = plane_index ? block_size>>s->chroma_h_shift : block_size;
...@@ -698,7 +698,7 @@ static int get_block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index, con ...@@ -698,7 +698,7 @@ static int get_block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index, con
ff_snow_pred_block(s, cur, tmp, ref_stride, sx, sy, block_w*2, block_h*2, &s->block[mb_x + mb_y*b_stride], plane_index, w, h); ff_snow_pred_block(s, cur, tmp, ref_stride, sx, sy, block_w*2, block_h*2, &s->block[mb_x + mb_y*b_stride], plane_index, w, h);
for(y=y0; y<y1; y++){ for(y=y0; y<y1; y++){
const uint8_t *obmc1= obmc_edged + y*obmc_stride; const uint8_t *obmc1= obmc_edged[y];
const IDWTELEM *pred1 = pred + y*obmc_stride; const IDWTELEM *pred1 = pred + y*obmc_stride;
uint8_t *cur1 = cur + y*ref_stride; uint8_t *cur1 = cur + y*ref_stride;
uint8_t *dst1 = dst + sx + (sy+y)*ref_stride; uint8_t *dst1 = dst + sx + (sy+y)*ref_stride;
...@@ -962,7 +962,7 @@ static int encode_subband(SnowContext *s, SubBand *b, const IDWTELEM *src, const ...@@ -962,7 +962,7 @@ static int encode_subband(SnowContext *s, SubBand *b, const IDWTELEM *src, const
// encode_subband_dzr(s, b, src, parent, stride, orientation); // encode_subband_dzr(s, b, src, parent, stride, orientation);
} }
static av_always_inline int check_block(SnowContext *s, int mb_x, int mb_y, int p[3], int intra, const uint8_t *obmc_edged, int *best_rd){ static av_always_inline int check_block(SnowContext *s, int mb_x, int mb_y, int p[3], int intra, uint8_t (*obmc_edged)[MB_SIZE * 2], int *best_rd){
const int b_stride= s->b_width << s->block_max_depth; const int b_stride= s->b_width << s->block_max_depth;
BlockNode *block= &s->block[mb_x + mb_y * b_stride]; BlockNode *block= &s->block[mb_x + mb_y * b_stride];
BlockNode backup= *block; BlockNode backup= *block;
...@@ -1003,7 +1003,7 @@ static av_always_inline int check_block(SnowContext *s, int mb_x, int mb_y, int ...@@ -1003,7 +1003,7 @@ static av_always_inline int check_block(SnowContext *s, int mb_x, int mb_y, int
/* special case for int[2] args we discard afterwards, /* special case for int[2] args we discard afterwards,
* fixes compilation problem with gcc 2.95 */ * fixes compilation problem with gcc 2.95 */
static av_always_inline int check_block_inter(SnowContext *s, int mb_x, int mb_y, int p0, int p1, const uint8_t *obmc_edged, int *best_rd){ static av_always_inline int check_block_inter(SnowContext *s, int mb_x, int mb_y, int p0, int p1, uint8_t (*obmc_edged)[MB_SIZE * 2], int *best_rd){
int p[2] = {p0, p1}; int p[2] = {p0, p1};
return check_block(s, mb_x, mb_y, p, 0, obmc_edged, best_rd); return check_block(s, mb_x, mb_y, p, 0, obmc_edged, best_rd);
} }
...@@ -1083,7 +1083,7 @@ static void iterative_me(SnowContext *s){ ...@@ -1083,7 +1083,7 @@ static void iterative_me(SnowContext *s){
BlockNode *blb= mb_x && mb_y+1<b_height ? &s->block[index+b_stride-1] : NULL; BlockNode *blb= mb_x && mb_y+1<b_height ? &s->block[index+b_stride-1] : NULL;
BlockNode *brb= mb_x+1<b_width && mb_y+1<b_height ? &s->block[index+b_stride+1] : NULL; BlockNode *brb= mb_x+1<b_width && mb_y+1<b_height ? &s->block[index+b_stride+1] : NULL;
const int b_w= (MB_SIZE >> s->block_max_depth); const int b_w= (MB_SIZE >> s->block_max_depth);
uint8_t obmc_edged[b_w*2][b_w*2]; uint8_t obmc_edged[MB_SIZE * 2][MB_SIZE * 2];
if(pass && (block->type & BLOCK_OPT)) if(pass && (block->type & BLOCK_OPT))
continue; continue;
...@@ -1098,7 +1098,8 @@ static void iterative_me(SnowContext *s){ ...@@ -1098,7 +1098,8 @@ static void iterative_me(SnowContext *s){
//FIXME precalculate //FIXME precalculate
{ {
int x, y; int x, y;
memcpy(obmc_edged, ff_obmc_tab[s->block_max_depth], b_w*b_w*4); for (y = 0; y < b_w * 2; y++)
memcpy(obmc_edged[y], ff_obmc_tab[s->block_max_depth] + y * b_w * 2, b_w * 2);
if(mb_x==0) if(mb_x==0)
for(y=0; y<b_w*2; y++) for(y=0; y<b_w*2; y++)
memset(obmc_edged[y], obmc_edged[y][0] + obmc_edged[y][b_w-1], b_w); memset(obmc_edged[y], obmc_edged[y][0] + obmc_edged[y][b_w-1], b_w);
...@@ -1153,9 +1154,9 @@ static void iterative_me(SnowContext *s){ ...@@ -1153,9 +1154,9 @@ static void iterative_me(SnowContext *s){
// get previous score (cannot be cached due to OBMC) // get previous score (cannot be cached due to OBMC)
if(pass > 0 && (block->type&BLOCK_INTRA)){ if(pass > 0 && (block->type&BLOCK_INTRA)){
int color0[3]= {block->color[0], block->color[1], block->color[2]}; int color0[3]= {block->color[0], block->color[1], block->color[2]};
check_block(s, mb_x, mb_y, color0, 1, *obmc_edged, &best_rd); check_block(s, mb_x, mb_y, color0, 1, obmc_edged, &best_rd);
}else }else
check_block_inter(s, mb_x, mb_y, block->mx, block->my, *obmc_edged, &best_rd); check_block_inter(s, mb_x, mb_y, block->mx, block->my, obmc_edged, &best_rd);
ref_b= *block; ref_b= *block;
ref_rd= best_rd; ref_rd= best_rd;
...@@ -1166,16 +1167,16 @@ static void iterative_me(SnowContext *s){ ...@@ -1166,16 +1167,16 @@ static void iterative_me(SnowContext *s){
block->ref= ref; block->ref= ref;
best_rd= INT_MAX; best_rd= INT_MAX;
check_block_inter(s, mb_x, mb_y, mvr[0][0], mvr[0][1], *obmc_edged, &best_rd); check_block_inter(s, mb_x, mb_y, mvr[0][0], mvr[0][1], obmc_edged, &best_rd);
check_block_inter(s, mb_x, mb_y, 0, 0, *obmc_edged, &best_rd); check_block_inter(s, mb_x, mb_y, 0, 0, obmc_edged, &best_rd);
if(tb) if(tb)
check_block_inter(s, mb_x, mb_y, mvr[-b_stride][0], mvr[-b_stride][1], *obmc_edged, &best_rd); check_block_inter(s, mb_x, mb_y, mvr[-b_stride][0], mvr[-b_stride][1], obmc_edged, &best_rd);
if(lb) if(lb)
check_block_inter(s, mb_x, mb_y, mvr[-1][0], mvr[-1][1], *obmc_edged, &best_rd); check_block_inter(s, mb_x, mb_y, mvr[-1][0], mvr[-1][1], obmc_edged, &best_rd);
if(rb) if(rb)
check_block_inter(s, mb_x, mb_y, mvr[1][0], mvr[1][1], *obmc_edged, &best_rd); check_block_inter(s, mb_x, mb_y, mvr[1][0], mvr[1][1], obmc_edged, &best_rd);
if(bb) if(bb)
check_block_inter(s, mb_x, mb_y, mvr[b_stride][0], mvr[b_stride][1], *obmc_edged, &best_rd); check_block_inter(s, mb_x, mb_y, mvr[b_stride][0], mvr[b_stride][1], obmc_edged, &best_rd);
/* fullpel ME */ /* fullpel ME */
//FIXME avoid subpel interpolation / round to nearest integer //FIXME avoid subpel interpolation / round to nearest integer
...@@ -1183,10 +1184,10 @@ static void iterative_me(SnowContext *s){ ...@@ -1183,10 +1184,10 @@ static void iterative_me(SnowContext *s){
dia_change=0; dia_change=0;
for(i=0; i<FFMAX(s->avctx->dia_size, 1); i++){ for(i=0; i<FFMAX(s->avctx->dia_size, 1); i++){
for(j=0; j<i; j++){ for(j=0; j<i; j++){
dia_change |= check_block_inter(s, mb_x, mb_y, block->mx+4*(i-j), block->my+(4*j), *obmc_edged, &best_rd); dia_change |= check_block_inter(s, mb_x, mb_y, block->mx+4*(i-j), block->my+(4*j), obmc_edged, &best_rd);
dia_change |= check_block_inter(s, mb_x, mb_y, block->mx-4*(i-j), block->my-(4*j), *obmc_edged, &best_rd); dia_change |= check_block_inter(s, mb_x, mb_y, block->mx-4*(i-j), block->my-(4*j), obmc_edged, &best_rd);
dia_change |= check_block_inter(s, mb_x, mb_y, block->mx+4*(i-j), block->my-(4*j), *obmc_edged, &best_rd); dia_change |= check_block_inter(s, mb_x, mb_y, block->mx+4*(i-j), block->my-(4*j), obmc_edged, &best_rd);
dia_change |= check_block_inter(s, mb_x, mb_y, block->mx-4*(i-j), block->my+(4*j), *obmc_edged, &best_rd); dia_change |= check_block_inter(s, mb_x, mb_y, block->mx-4*(i-j), block->my+(4*j), obmc_edged, &best_rd);
} }
} }
}while(dia_change); }while(dia_change);
...@@ -1195,7 +1196,7 @@ static void iterative_me(SnowContext *s){ ...@@ -1195,7 +1196,7 @@ static void iterative_me(SnowContext *s){
static const int square[8][2]= {{+1, 0},{-1, 0},{ 0,+1},{ 0,-1},{+1,+1},{-1,-1},{+1,-1},{-1,+1},}; static const int square[8][2]= {{+1, 0},{-1, 0},{ 0,+1},{ 0,-1},{+1,+1},{-1,-1},{+1,-1},{-1,+1},};
dia_change=0; dia_change=0;
for(i=0; i<8; i++) for(i=0; i<8; i++)
dia_change |= check_block_inter(s, mb_x, mb_y, block->mx+square[i][0], block->my+square[i][1], *obmc_edged, &best_rd); dia_change |= check_block_inter(s, mb_x, mb_y, block->mx+square[i][0], block->my+square[i][1], obmc_edged, &best_rd);
}while(dia_change); }while(dia_change);
//FIXME or try the standard 2 pass qpel or similar //FIXME or try the standard 2 pass qpel or similar
...@@ -1208,7 +1209,7 @@ static void iterative_me(SnowContext *s){ ...@@ -1208,7 +1209,7 @@ static void iterative_me(SnowContext *s){
} }
best_rd= ref_rd; best_rd= ref_rd;
*block= ref_b; *block= ref_b;
check_block(s, mb_x, mb_y, color, 1, *obmc_edged, &best_rd); check_block(s, mb_x, mb_y, color, 1, obmc_edged, &best_rd);
//FIXME RD style color selection //FIXME RD style color selection
if(!same_block(block, &backup)){ if(!same_block(block, &backup)){
if(tb ) tb ->type &= ~BLOCK_OPT; if(tb ) tb ->type &= ~BLOCK_OPT;
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
*/ */
#define LIBAVCODEC_VERSION_MAJOR 54 #define LIBAVCODEC_VERSION_MAJOR 54
#define LIBAVCODEC_VERSION_MINOR 31 #define LIBAVCODEC_VERSION_MINOR 32
#define LIBAVCODEC_VERSION_MICRO 100 #define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
......
...@@ -37,12 +37,9 @@ typedef struct { ...@@ -37,12 +37,9 @@ typedef struct {
void (*blur_line) (uint16_t *dc, uint16_t *buf, const uint16_t *buf1, const uint8_t *src, int src_linesize, int width); void (*blur_line) (uint16_t *dc, uint16_t *buf, const uint16_t *buf1, const uint8_t *src, int src_linesize, int width);
} GradFunContext; } GradFunContext;
void ff_gradfun_init_x86(GradFunContext *gf);
void ff_gradfun_filter_line_c(uint8_t *dst, const uint8_t *src, const uint16_t *dc, int width, int thresh, const uint16_t *dithers); void ff_gradfun_filter_line_c(uint8_t *dst, const uint8_t *src, const uint16_t *dc, int width, int thresh, const uint16_t *dithers);
void ff_gradfun_blur_line_c(uint16_t *dc, uint16_t *buf, const uint16_t *buf1, const uint8_t *src, int src_linesize, int width); void ff_gradfun_blur_line_c(uint16_t *dc, uint16_t *buf, const uint16_t *buf1, const uint8_t *src, int src_linesize, int width);
void ff_gradfun_filter_line_mmx2(uint8_t *dst, const uint8_t *src, const uint16_t *dc, int width, int thresh, const uint16_t *dithers);
void ff_gradfun_filter_line_ssse3(uint8_t *dst, const uint8_t *src, const uint16_t *dc, int width, int thresh, const uint16_t *dithers);
void ff_gradfun_blur_line_sse2(uint16_t *dc, uint16_t *buf, const uint16_t *buf1, const uint8_t *src, int src_linesize, int width);
#endif /* AVFILTER_GRADFUN_H */ #endif /* AVFILTER_GRADFUN_H */
...@@ -123,7 +123,6 @@ static av_cold int init(AVFilterContext *ctx, const char *args) ...@@ -123,7 +123,6 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
GradFunContext *gf = ctx->priv; GradFunContext *gf = ctx->priv;
float thresh = 1.2; float thresh = 1.2;
int radius = 16; int radius = 16;
int cpu_flags = av_get_cpu_flags();
if (args) if (args)
sscanf(args, "%f:%d", &thresh, &radius); sscanf(args, "%f:%d", &thresh, &radius);
...@@ -135,12 +134,8 @@ static av_cold int init(AVFilterContext *ctx, const char *args) ...@@ -135,12 +134,8 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
gf->blur_line = ff_gradfun_blur_line_c; gf->blur_line = ff_gradfun_blur_line_c;
gf->filter_line = ff_gradfun_filter_line_c; gf->filter_line = ff_gradfun_filter_line_c;
if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX2) if (HAVE_MMX)
gf->filter_line = ff_gradfun_filter_line_mmx2; ff_gradfun_init_x86(gf);
if (HAVE_SSSE3 && cpu_flags & AV_CPU_FLAG_SSSE3)
gf->filter_line = ff_gradfun_filter_line_ssse3;
if (HAVE_SSE && cpu_flags & AV_CPU_FLAG_SSE2)
gf->blur_line = ff_gradfun_blur_line_sse2;
av_log(ctx, AV_LOG_VERBOSE, "threshold:%.2f radius:%d\n", thresh, gf->radius); av_log(ctx, AV_LOG_VERBOSE, "threshold:%.2f radius:%d\n", thresh, gf->radius);
......
...@@ -30,42 +30,6 @@ ...@@ -30,42 +30,6 @@
#undef NDEBUG #undef NDEBUG
#include <assert.h> #include <assert.h>
typedef struct {
/**
* 0: send 1 frame for each frame
* 1: send 1 frame for each field
* 2: like 0 but skips spatial interlacing check
* 3: like 1 but skips spatial interlacing check
*/
int mode;
/**
* 0: top field first
* 1: bottom field first
* -1: auto-detection
*/
int parity;
int frame_pending;
/**
* 0: deinterlace all frames
* 1: only deinterlace frames marked as interlaced
*/
int auto_enable;
AVFilterBufferRef *cur;
AVFilterBufferRef *next;
AVFilterBufferRef *prev;
AVFilterBufferRef *out;
void (*filter_line)(uint8_t *dst,
uint8_t *prev, uint8_t *cur, uint8_t *next,
int w, int prefs, int mrefs, int parity, int mode);
const AVPixFmtDescriptor *csp;
int eof;
} YADIFContext;
#define CHECK(j)\ #define CHECK(j)\
{ int score = FFABS(cur[mrefs-1+(j)] - cur[prefs-1-(j)])\ { int score = FFABS(cur[mrefs-1+(j)] - cur[prefs-1-(j)])\
+ FFABS(cur[mrefs +(j)] - cur[prefs -(j)])\ + FFABS(cur[mrefs +(j)] - cur[prefs -(j)])\
...@@ -400,7 +364,6 @@ static int query_formats(AVFilterContext *ctx) ...@@ -400,7 +364,6 @@ static int query_formats(AVFilterContext *ctx)
static av_cold int init(AVFilterContext *ctx, const char *args) static av_cold int init(AVFilterContext *ctx, const char *args)
{ {
YADIFContext *yadif = ctx->priv; YADIFContext *yadif = ctx->priv;
int cpu_flags = av_get_cpu_flags();
yadif->mode = 0; yadif->mode = 0;
yadif->parity = -1; yadif->parity = -1;
...@@ -410,12 +373,9 @@ static av_cold int init(AVFilterContext *ctx, const char *args) ...@@ -410,12 +373,9 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
if (args) sscanf(args, "%d:%d:%d", &yadif->mode, &yadif->parity, &yadif->auto_enable); if (args) sscanf(args, "%d:%d:%d", &yadif->mode, &yadif->parity, &yadif->auto_enable);
yadif->filter_line = filter_line_c; yadif->filter_line = filter_line_c;
if (HAVE_SSSE3 && cpu_flags & AV_CPU_FLAG_SSSE3)
yadif->filter_line = ff_yadif_filter_line_ssse3; if (HAVE_MMX)
else if (HAVE_SSE && cpu_flags & AV_CPU_FLAG_SSE2) ff_yadif_init_x86(yadif);
yadif->filter_line = ff_yadif_filter_line_sse2;
else if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX)
yadif->filter_line = ff_yadif_filter_line_mmx;
av_log(ctx, AV_LOG_VERBOSE, "mode:%d parity:%d auto_enable:%d\n", yadif->mode, yadif->parity, yadif->auto_enable); av_log(ctx, AV_LOG_VERBOSE, "mode:%d parity:%d auto_enable:%d\n", yadif->mode, yadif->parity, yadif->auto_enable);
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "libavutil/attributes.h"
#include "libavutil/cpu.h" #include "libavutil/cpu.h"
#include "libavutil/x86_cpu.h" #include "libavutil/x86_cpu.h"
#include "libavfilter/gradfun.h" #include "libavfilter/gradfun.h"
...@@ -25,9 +26,9 @@ ...@@ -25,9 +26,9 @@
DECLARE_ALIGNED(16, static const uint16_t, pw_7f)[8] = {0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F}; DECLARE_ALIGNED(16, static const uint16_t, pw_7f)[8] = {0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F};
DECLARE_ALIGNED(16, static const uint16_t, pw_ff)[8] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}; DECLARE_ALIGNED(16, static const uint16_t, pw_ff)[8] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
void ff_gradfun_filter_line_mmx2(uint8_t *dst, const uint8_t *src, const uint16_t *dc, int width, int thresh, const uint16_t *dithers) #if HAVE_MMX2
static void gradfun_filter_line_mmx2(uint8_t *dst, const uint8_t *src, const uint16_t *dc, int width, int thresh, const uint16_t *dithers)
{ {
#if HAVE_MMX
intptr_t x; intptr_t x;
if (width & 3) { if (width & 3) {
x = width & ~3; x = width & ~3;
...@@ -70,12 +71,12 @@ void ff_gradfun_filter_line_mmx2(uint8_t *dst, const uint8_t *src, const uint16_ ...@@ -70,12 +71,12 @@ void ff_gradfun_filter_line_mmx2(uint8_t *dst, const uint8_t *src, const uint16_
"rm"(thresh), "m"(*dithers), "m"(*pw_7f) "rm"(thresh), "m"(*dithers), "m"(*pw_7f)
:"memory" :"memory"
); );
#endif
} }
#endif
void ff_gradfun_filter_line_ssse3(uint8_t *dst, const uint8_t *src, const uint16_t *dc, int width, int thresh, const uint16_t *dithers)
{
#if HAVE_SSSE3 #if HAVE_SSSE3
static void gradfun_filter_line_ssse3(uint8_t *dst, const uint8_t *src, const uint16_t *dc, int width, int thresh, const uint16_t *dithers)
{
intptr_t x; intptr_t x;
if (width & 7) { if (width & 7) {
// could be 10% faster if I somehow eliminated this // could be 10% faster if I somehow eliminated this
...@@ -117,12 +118,12 @@ void ff_gradfun_filter_line_ssse3(uint8_t *dst, const uint8_t *src, const uint16 ...@@ -117,12 +118,12 @@ void ff_gradfun_filter_line_ssse3(uint8_t *dst, const uint8_t *src, const uint16
"rm"(thresh), "m"(*dithers), "m"(*pw_7f) "rm"(thresh), "m"(*dithers), "m"(*pw_7f)
:"memory" :"memory"
); );
#endif // HAVE_SSSE3
} }
#endif // HAVE_SSSE3
void ff_gradfun_blur_line_sse2(uint16_t *dc, uint16_t *buf, const uint16_t *buf1, const uint8_t *src, int src_linesize, int width)
{
#if HAVE_SSE #if HAVE_SSE
static void gradfun_blur_line_sse2(uint16_t *dc, uint16_t *buf, const uint16_t *buf1, const uint8_t *src, int src_linesize, int width)
{
#define BLURV(load)\ #define BLURV(load)\
intptr_t x = -2*width;\ intptr_t x = -2*width;\
__asm__ volatile(\ __asm__ volatile(\
...@@ -160,5 +161,17 @@ void ff_gradfun_blur_line_sse2(uint16_t *dc, uint16_t *buf, const uint16_t *buf1 ...@@ -160,5 +161,17 @@ void ff_gradfun_blur_line_sse2(uint16_t *dc, uint16_t *buf, const uint16_t *buf1
} else { } else {
BLURV("movdqa"); BLURV("movdqa");
} }
}
#endif // HAVE_SSE #endif // HAVE_SSE
av_cold void ff_gradfun_init_x86(GradFunContext *gf)
{
int cpu_flags = av_get_cpu_flags();
if (HAVE_MMX2 && cpu_flags & AV_CPU_FLAG_MMX2)
gf->filter_line = gradfun_filter_line_mmx2;
if (HAVE_SSSE3 && cpu_flags & AV_CPU_FLAG_SSSE3)
gf->filter_line = gradfun_filter_line_ssse3;
if (HAVE_SSE && cpu_flags & AV_CPU_FLAG_SSE2)
gf->blur_line = gradfun_blur_line_sse2;
} }
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include "libavutil/attributes.h"
#include "libavutil/cpu.h" #include "libavutil/cpu.h"
#include "libavutil/x86_cpu.h" #include "libavutil/x86_cpu.h"
#include "libavcodec/x86/dsputil_mmx.h" #include "libavcodec/x86/dsputil_mmx.h"
...@@ -47,3 +48,15 @@ DECLARE_ASM_CONST(16, const xmm_reg, pw_1) = {0x0001000100010001ULL, 0x000100010 ...@@ -47,3 +48,15 @@ DECLARE_ASM_CONST(16, const xmm_reg, pw_1) = {0x0001000100010001ULL, 0x000100010
#define RENAME(a) a ## _mmx #define RENAME(a) a ## _mmx
#include "yadif_template.c" #include "yadif_template.c"
#endif #endif
av_cold void ff_yadif_init_x86(YADIFContext *yadif)
{
int cpu_flags = av_get_cpu_flags();
if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX)
yadif->filter_line = yadif_filter_line_mmx;
if (HAVE_SSE && cpu_flags & AV_CPU_FLAG_SSE2)
yadif->filter_line = yadif_filter_line_sse2;
if (HAVE_SSSE3 && cpu_flags & AV_CPU_FLAG_SSSE3)
yadif->filter_line = yadif_filter_line_ssse3;
}
...@@ -103,9 +103,9 @@ ...@@ -103,9 +103,9 @@
"por "MM"5, "MM"3 \n\t"\ "por "MM"5, "MM"3 \n\t"\
MOVQ" "MM"3, "MM"1 \n\t" MOVQ" "MM"3, "MM"1 \n\t"
void RENAME(ff_yadif_filter_line)(uint8_t *dst, static void RENAME(yadif_filter_line)(uint8_t *dst, uint8_t *prev, uint8_t *cur,
uint8_t *prev, uint8_t *cur, uint8_t *next, uint8_t *next, int w, int prefs,
int w, int prefs, int mrefs, int parity, int mode) int mrefs, int parity, int mode)
{ {
uint8_t tmp[5*16]; uint8_t tmp[5*16];
uint8_t *tmpA= (uint8_t*)(((uint64_t)(tmp+15)) & ~15); uint8_t *tmpA= (uint8_t*)(((uint64_t)(tmp+15)) & ~15);
......
...@@ -19,18 +19,45 @@ ...@@ -19,18 +19,45 @@
#ifndef AVFILTER_YADIF_H #ifndef AVFILTER_YADIF_H
#define AVFILTER_YADIF_H #define AVFILTER_YADIF_H
#include "libavutil/pixdesc.h"
#include "avfilter.h" #include "avfilter.h"
void ff_yadif_filter_line_mmx(uint8_t *dst, typedef struct {
uint8_t *prev, uint8_t *cur, uint8_t *next, /**
int w, int prefs, int mrefs, int parity, int mode); * 0: send 1 frame for each frame
* 1: send 1 frame for each field
* 2: like 0 but skips spatial interlacing check
* 3: like 1 but skips spatial interlacing check
*/
int mode;
void ff_yadif_filter_line_sse2(uint8_t *dst, /**
uint8_t *prev, uint8_t *cur, uint8_t *next, * 0: top field first
int w, int prefs, int mrefs, int parity, int mode); * 1: bottom field first
* -1: auto-detection
*/
int parity;
void ff_yadif_filter_line_ssse3(uint8_t *dst, int frame_pending;
uint8_t *prev, uint8_t *cur, uint8_t *next,
int w, int prefs, int mrefs, int parity, int mode); /**
* 0: deinterlace all frames
* 1: only deinterlace frames marked as interlaced
*/
int auto_enable;
AVFilterBufferRef *cur;
AVFilterBufferRef *next;
AVFilterBufferRef *prev;
AVFilterBufferRef *out;
void (*filter_line)(uint8_t *dst,
uint8_t *prev, uint8_t *cur, uint8_t *next,
int w, int prefs, int mrefs, int parity, int mode);
const AVPixFmtDescriptor *csp;
int eof;
} YADIFContext;
void ff_yadif_init_x86(YADIFContext *yadif);
#endif /* AVFILTER_YADIF_H */ #endif /* AVFILTER_YADIF_H */
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "libavutil/dict.h" #include "libavutil/dict.h"
#include "avformat.h" #include "avformat.h"
#include "apetag.h" #include "apetag.h"
#include "internal.h"
#define APE_TAG_VERSION 2000 #define APE_TAG_VERSION 2000
#define APE_TAG_FOOTER_BYTES 32 #define APE_TAG_FOOTER_BYTES 32
...@@ -56,20 +57,47 @@ static int ape_tag_read_field(AVFormatContext *s) ...@@ -56,20 +57,47 @@ static int ape_tag_read_field(AVFormatContext *s)
return -1; return -1;
if (flags & APE_TAG_FLAG_IS_BINARY) { if (flags & APE_TAG_FLAG_IS_BINARY) {
uint8_t filename[1024]; uint8_t filename[1024];
enum CodecID id;
AVStream *st = avformat_new_stream(s, NULL); AVStream *st = avformat_new_stream(s, NULL);
if (!st) if (!st)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
avio_get_str(pb, INT_MAX, filename, sizeof(filename));
st->codec->extradata = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); size -= avio_get_str(pb, size, filename, sizeof(filename));
if (!st->codec->extradata) if (size <= 0) {
return AVERROR(ENOMEM); av_log(s, AV_LOG_WARNING, "Skipping binary tag '%s'.\n", key);
if (avio_read(pb, st->codec->extradata, size) != size) { return 0;
av_freep(&st->codec->extradata);
return AVERROR(EIO);
} }
st->codec->extradata_size = size;
av_dict_set(&st->metadata, key, filename, 0); av_dict_set(&st->metadata, key, filename, 0);
st->codec->codec_type = AVMEDIA_TYPE_ATTACHMENT;
if ((id = ff_guess_image2_codec(filename)) != CODEC_ID_NONE) {
AVPacket pkt;
int ret;
ret = av_get_packet(s->pb, &pkt, size);
if (ret < 0) {
av_log(s, AV_LOG_ERROR, "Error reading cover art.\n");
return ret;
}
st->disposition |= AV_DISPOSITION_ATTACHED_PIC;
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->codec->codec_id = id;
st->attached_pic = pkt;
st->attached_pic.stream_index = st->index;
st->attached_pic.flags |= AV_PKT_FLAG_KEY;
} else {
st->codec->extradata = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
if (!st->codec->extradata)
return AVERROR(ENOMEM);
if (avio_read(pb, st->codec->extradata, size) != size) {
av_freep(&st->codec->extradata);
return AVERROR(EIO);
}
st->codec->extradata_size = size;
st->codec->codec_type = AVMEDIA_TYPE_ATTACHMENT;
}
} else { } else {
value = av_malloc(size+1); value = av_malloc(size+1);
if (!value) if (!value)
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "avformat.h" #include "avformat.h"
#include "internal.h" #include "internal.h"
#include "avio_internal.h" #include "avio_internal.h"
#include "id3v2.h"
#include "riff.h" #include "riff.h"
#include "asf.h" #include "asf.h"
#include "asfcrypt.h" #include "asfcrypt.h"
...@@ -163,6 +164,101 @@ static int get_value(AVIOContext *pb, int type){ ...@@ -163,6 +164,101 @@ static int get_value(AVIOContext *pb, int type){
} }
} }
/* MSDN claims that this should be "compatible with the ID3 frame, APIC",
* but in reality this is only loosely similar */
static int asf_read_picture(AVFormatContext *s, int len)
{
AVPacket pkt = { 0 };
const CodecMime *mime = ff_id3v2_mime_tags;
enum CodecID id = CODEC_ID_NONE;
char mimetype[64];
uint8_t *desc = NULL;
ASFStream *ast = NULL;
AVStream *st = NULL;
int ret, type, picsize, desc_len;
/* type + picsize + mime + desc */
if (len < 1 + 4 + 2 + 2) {
av_log(s, AV_LOG_ERROR, "Invalid attached picture size: %d.\n", len);
return AVERROR_INVALIDDATA;
}
/* picture type */
type = avio_r8(s->pb);
len--;
if (type >= FF_ARRAY_ELEMS(ff_id3v2_picture_types) || type < 0) {
av_log(s, AV_LOG_WARNING, "Unknown attached picture type: %d.\n", type);
type = 0;
}
/* picture data size */
picsize = avio_rl32(s->pb);
len -= 4;
/* picture MIME type */
len -= avio_get_str16le(s->pb, len, mimetype, sizeof(mimetype));
while (mime->id != CODEC_ID_NONE) {
if (!strncmp(mime->str, mimetype, sizeof(mimetype))) {
id = mime->id;
break;
}
mime++;
}
if (id == CODEC_ID_NONE) {
av_log(s, AV_LOG_ERROR, "Unknown attached picture mimetype: %s.\n",
mimetype);
return 0;
}
if (picsize >= len) {
av_log(s, AV_LOG_ERROR, "Invalid attached picture data size: %d >= %d.\n",
picsize, len);
return AVERROR_INVALIDDATA;
}
/* picture description */
desc_len = (len - picsize) * 2 + 1;
desc = av_malloc(desc_len);
if (!desc)
return AVERROR(ENOMEM);
len -= avio_get_str16le(s->pb, len - picsize, desc, desc_len);
ret = av_get_packet(s->pb, &pkt, picsize);
if (ret < 0)
goto fail;
st = avformat_new_stream(s, NULL);
ast = av_mallocz(sizeof(*ast));
if (!st || !ast) {
ret = AVERROR(ENOMEM);
goto fail;
}
st->priv_data = ast;
st->disposition |= AV_DISPOSITION_ATTACHED_PIC;
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->codec->codec_id = id;
st->attached_pic = pkt;
st->attached_pic.stream_index = st->index;
st->attached_pic.flags |= AV_PKT_FLAG_KEY;
if (*desc)
av_dict_set(&st->metadata, "title", desc, AV_DICT_DONT_STRDUP_VAL);
else
av_freep(&desc);
av_dict_set(&st->metadata, "comment", ff_id3v2_picture_types[type], 0);
return 0;
fail:
av_freep(&ast);
av_freep(&desc);
av_free_packet(&pkt);
return ret;
}
static void get_tag(AVFormatContext *s, const char *key, int type, int len) static void get_tag(AVFormatContext *s, const char *key, int type, int len)
{ {
char *value; char *value;
...@@ -183,6 +279,9 @@ static void get_tag(AVFormatContext *s, const char *key, int type, int len) ...@@ -183,6 +279,9 @@ static void get_tag(AVFormatContext *s, const char *key, int type, int len)
} else if (type > 1 && type <= 5) { // boolean or DWORD or QWORD or WORD } else if (type > 1 && type <= 5) { // boolean or DWORD or QWORD or WORD
uint64_t num = get_value(s->pb, type); uint64_t num = get_value(s->pb, type);
snprintf(value, len, "%"PRIu64, num); snprintf(value, len, "%"PRIu64, num);
} else if (type == 1 && !strcmp(key, "WM/Picture")) { // handle cover art
asf_read_picture(s, len);
goto finish;
} else { } else {
av_log(s, AV_LOG_DEBUG, "Unsupported value type %d in tag %s.\n", type, key); av_log(s, AV_LOG_DEBUG, "Unsupported value type %d in tag %s.\n", type, key);
goto finish; goto finish;
......
...@@ -168,6 +168,48 @@ static int mov_read_mac_string(MOVContext *c, AVIOContext *pb, int len, ...@@ -168,6 +168,48 @@ static int mov_read_mac_string(MOVContext *c, AVIOContext *pb, int len,
return p - dst; return p - dst;
} }
static int mov_read_covr(MOVContext *c, AVIOContext *pb, int type, int len)
{
AVPacket pkt;
AVStream *st;
MOVStreamContext *sc;
enum CodecID id;
int ret;
switch (type) {
case 0xd: id = CODEC_ID_MJPEG; break;
case 0xe: id = CODEC_ID_PNG; break;
case 0x1b: id = CODEC_ID_BMP; break;
default:
av_log(c->fc, AV_LOG_WARNING, "Unknown cover type: 0x%x.\n", type);
avio_skip(pb, len);
return 0;
}
st = avformat_new_stream(c->fc, NULL);
if (!st)
return AVERROR(ENOMEM);
sc = av_mallocz(sizeof(*sc));
if (!sc)
return AVERROR(ENOMEM);
st->priv_data = sc;
ret = av_get_packet(pb, &pkt, len);
if (ret < 0)
return ret;
st->disposition |= AV_DISPOSITION_ATTACHED_PIC;
st->attached_pic = pkt;
st->attached_pic.stream_index = st->index;
st->attached_pic.flags |= AV_PKT_FLAG_KEY;
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->codec->codec_id = id;
return 0;
}
static int mov_read_udta_string(MOVContext *c, AVIOContext *pb, MOVAtom atom) static int mov_read_udta_string(MOVContext *c, AVIOContext *pb, MOVAtom atom)
{ {
#ifdef MOV_EXPORT_ALL_METADATA #ifdef MOV_EXPORT_ALL_METADATA
...@@ -228,6 +270,14 @@ static int mov_read_udta_string(MOVContext *c, AVIOContext *pb, MOVAtom atom) ...@@ -228,6 +270,14 @@ static int mov_read_udta_string(MOVContext *c, AVIOContext *pb, MOVAtom atom)
avio_rb32(pb); // unknown avio_rb32(pb); // unknown
str_size = data_size - 16; str_size = data_size - 16;
atom.size -= 16; atom.size -= 16;
if (atom.type == MKTAG('c', 'o', 'v', 'r')) {
int ret = mov_read_covr(c, pb, data_type, str_size);
if (ret < 0) {
av_log(c->fc, AV_LOG_ERROR, "Error parsing cover art.\n");
return ret;
}
}
} else return 0; } else return 0;
} else if (atom.size > 4 && key && !c->itunes_metadata) { } else if (atom.size > 4 && key && !c->itunes_metadata) {
str_size = avio_rb16(pb); // string length str_size = avio_rb16(pb); // string length
......
...@@ -308,6 +308,7 @@ const AVCodecTag ff_codec_bmp_tags[] = { ...@@ -308,6 +308,7 @@ const AVCodecTag ff_codec_bmp_tags[] = {
{ CODEC_ID_FLIC, MKTAG('A', 'F', 'L', 'C') }, { CODEC_ID_FLIC, MKTAG('A', 'F', 'L', 'C') },
{ CODEC_ID_EXR, MKTAG('e', 'x', 'r', ' ') }, { CODEC_ID_EXR, MKTAG('e', 'x', 'r', ' ') },
{ CODEC_ID_MSS1, MKTAG('M', 'S', 'S', '1') }, { CODEC_ID_MSS1, MKTAG('M', 'S', 'S', '1') },
{ CODEC_ID_MSA1, MKTAG('M', 'S', 'A', '1') },
{ CODEC_ID_NONE, 0 } { CODEC_ID_NONE, 0 }
}; };
......
...@@ -39,7 +39,8 @@ union av_intfloat64 { ...@@ -39,7 +39,8 @@ union av_intfloat64 {
*/ */
static av_always_inline float av_int2float(uint32_t i) static av_always_inline float av_int2float(uint32_t i)
{ {
union av_intfloat32 v = { .i = i }; union av_intfloat32 v;
v.i = i;
return v.f; return v.f;
} }
...@@ -48,7 +49,8 @@ static av_always_inline float av_int2float(uint32_t i) ...@@ -48,7 +49,8 @@ static av_always_inline float av_int2float(uint32_t i)
*/ */
static av_always_inline uint32_t av_float2int(float f) static av_always_inline uint32_t av_float2int(float f)
{ {
union av_intfloat32 v = { .f = f }; union av_intfloat32 v;
v.f = f;
return v.i; return v.i;
} }
...@@ -57,7 +59,8 @@ static av_always_inline uint32_t av_float2int(float f) ...@@ -57,7 +59,8 @@ static av_always_inline uint32_t av_float2int(float f)
*/ */
static av_always_inline double av_int2double(uint64_t i) static av_always_inline double av_int2double(uint64_t i)
{ {
union av_intfloat64 v = { .i = i }; union av_intfloat64 v;
v.i = i;
return v.f; return v.f;
} }
...@@ -66,7 +69,8 @@ static av_always_inline double av_int2double(uint64_t i) ...@@ -66,7 +69,8 @@ static av_always_inline double av_int2double(uint64_t i)
*/ */
static av_always_inline uint64_t av_double2int(double f) static av_always_inline uint64_t av_double2int(double f)
{ {
union av_intfloat64 v = { .f = f }; union av_intfloat64 v;
v.f = f;
return v.i; return v.i;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment