Commit 3e1a7ae4 authored by Michael Niedermayer's avatar Michael Niedermayer

Merge remote-tracking branch 'qatar/master'

* qatar/master:
  swfdec: Add support for sample_rate_code 0 (5512 Hz)
  dct-test: factor out some common code and do whas was likely intended
  doc: library versions need to be bumped in version.h
  Revert "ffmpeg: get rid of useless AVInputStream.nb_streams."
  Remove some forgotten AVCodecContext.palctrl usage.
  lavc/utils: move avcodec_init() higher in the file.
  lavc: replace some deprecated FF_*_TYPE with AV_PICTURE_TYPE_*
  ac3dec: actually use drc_scale private option
  lavc: undeprecate AVPALETTE_SIZE and AVPALETTE_COUNT macros
  alsa: add missing header
  msmpeg4: remove leftover unused debug variable declaration
  Fix assert() calls that need updates after FF_COMMON_FRAME macro elimination.
  Fix av_dlog invocations with wrong or missing logging context.
  vf_yadif: add support to yuva420p
  vf_yadif: correct documentation on the parity parameter
  vf_yadif: copy buffer properties like aspect for second frame as well
  oma: support for encrypted files
  id3v2: add support for non-text and GEOB type tag frames
  des: add possibility to calculate DES-CBC-MAC with small buffer

Conflicts:
	ffmpeg.c
	libavcodec/dct-test.c
	libavformat/mpegts.c
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents 358d837d 05fc9e40
...@@ -310,7 +310,7 @@ send a reminder by email. Your patch should eventually be dealt with. ...@@ -310,7 +310,7 @@ send a reminder by email. Your patch should eventually be dealt with.
AVInputFormat/AVOutputFormat struct? AVInputFormat/AVOutputFormat struct?
@item @item
Did you bump the minor version number (and reset the micro version Did you bump the minor version number (and reset the micro version
number) in @file{avcodec.h} or @file{avformat.h}? number) in @file{libavcodec/version.h} or @file{libavformat/version.h}?
@item @item
Did you register it in @file{allcodecs.c} or @file{allformats.c}? Did you register it in @file{allcodecs.c} or @file{allformats.c}?
@item @item
......
...@@ -176,6 +176,11 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx) ...@@ -176,6 +176,11 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx)
AC3DecodeContext *s = avctx->priv_data; AC3DecodeContext *s = avctx->priv_data;
s->avctx = avctx; s->avctx = avctx;
#if FF_API_DRC_SCALE
if (avctx->drc_scale)
s->drc_scale = avctx->drc_scale;
#endif
ff_ac3_common_init(); ff_ac3_common_init();
ac3_tables_init(); ac3_tables_init();
ff_mdct_init(&s->imdct_256, 8, 1, 1.0); ff_mdct_init(&s->imdct_256, 8, 1, 1.0);
...@@ -788,7 +793,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) ...@@ -788,7 +793,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk)
do { do {
if(get_bits1(gbc)) { if(get_bits1(gbc)) {
s->dynamic_range[i] = ((dynamic_range_tab[get_bits(gbc, 8)]-1.0) * s->dynamic_range[i] = ((dynamic_range_tab[get_bits(gbc, 8)]-1.0) *
s->avctx->drc_scale)+1.0; s->drc_scale)+1.0;
} else if(blk == 0) { } else if(blk == 0) {
s->dynamic_range[i] = 1.0f; s->dynamic_range[i] = 1.0f;
} }
......
...@@ -3149,6 +3149,8 @@ typedef struct AVPicture { ...@@ -3149,6 +3149,8 @@ typedef struct AVPicture {
int linesize[4]; ///< number of bytes per line int linesize[4]; ///< number of bytes per line
} AVPicture; } AVPicture;
#define AVPALETTE_SIZE 1024
#define AVPALETTE_COUNT 256
#if FF_API_PALETTE_CONTROL #if FF_API_PALETTE_CONTROL
/** /**
* AVPaletteControl * AVPaletteControl
...@@ -3158,8 +3160,6 @@ typedef struct AVPicture { ...@@ -3158,8 +3160,6 @@ typedef struct AVPicture {
* @deprecated Use AVPacket to send palette changes instead. * @deprecated Use AVPacket to send palette changes instead.
* This is totally broken. * This is totally broken.
*/ */
#define AVPALETTE_SIZE 1024
#define AVPALETTE_COUNT 256
typedef struct AVPaletteControl { typedef struct AVPaletteControl {
/* Demuxer sets this to 1 to indicate the palette has changed; /* Demuxer sets this to 1 to indicate the palette has changed;
......
...@@ -199,6 +199,55 @@ static inline void mmx_emms(void) ...@@ -199,6 +199,55 @@ static inline void mmx_emms(void)
#endif #endif
} }
static void init_block(DCTELEM block[64], int test, int is_idct, AVLFG *prng, int vals)
{
int i, j;
memset(block, 0, 64 * sizeof(*block));
switch (test) {
case 0:
for (i = 0; i < 64; i++)
block[i] = (av_lfg_get(prng) % (2*vals)) -vals;
if (is_idct) {
ff_ref_fdct(block);
for (i = 0; i < 64; i++)
block[i] >>= 3;
}
break;
case 1:
j = av_lfg_get(prng) % 10 + 1;
for (i = 0; i < j; i++)
block[av_lfg_get(prng) % 64] = av_lfg_get(prng) % (2*vals) -vals;
break;
case 2:
block[ 0] = av_lfg_get(prng) % (16*vals) - (8*vals);
block[63] = (block[0] & 1) ^ 1;
break;
}
}
static void permute(DCTELEM dst[64], const DCTELEM src[64], int perm)
{
int i;
if (perm == MMX_PERM) {
for (i = 0; i < 64; i++)
dst[idct_mmx_perm[i]] = src[i];
} else if (perm == MMX_SIMPLE_PERM) {
for (i = 0; i < 64; i++)
dst[idct_simple_mmx_perm[i]] = src[i];
} else if (perm == SSE2_PERM) {
for (i = 0; i < 64; i++)
dst[(i & 0x38) | idct_sse2_row_perm[i & 7]] = src[i];
} else if (perm == PARTTRANS_PERM) {
for (i = 0; i < 64; i++)
dst[(i & 0x24) | ((i & 3) << 3) | ((i >> 3) & 3)] = src[i];
} else {
for (i = 0; i < 64; i++)
dst[i] = src[i];
}
}
static int dct_error(const struct algo *dct, int test, int is_idct, int speed, const int bits) static int dct_error(const struct algo *dct, int test, int is_idct, int speed, const int bits)
{ {
...@@ -221,46 +270,8 @@ static int dct_error(const struct algo *dct, int test, int is_idct, int speed, c ...@@ -221,46 +270,8 @@ static int dct_error(const struct algo *dct, int test, int is_idct, int speed, c
for (i = 0; i < 64; i++) for (i = 0; i < 64; i++)
sysErr[i] = 0; sysErr[i] = 0;
for (it = 0; it < NB_ITS; it++) { for (it = 0; it < NB_ITS; it++) {
for (i = 0; i < 64; i++) init_block(block1, test, is_idct, &prng, vals);
block1[i] = 0; permute(block, block1, dct->format);
switch (test) {
case 0:
for (i = 0; i < 64; i++)
block1[i] = (av_lfg_get(&prng) % (2*vals)) -vals;
if (is_idct) {
ff_ref_fdct(block1);
for (i = 0; i < 64; i++)
block1[i] >>= 3;
}
break;
case 1: {
int num = av_lfg_get(&prng) % 10 + 1;
for (i = 0; i < num; i++)
block1[av_lfg_get(&prng) % 64] = av_lfg_get(&prng) % (2*vals) -vals;
}
break;
case 2:
block1[0] = av_lfg_get(&prng) % (16*vals) - (8*vals);
block1[63] = (block1[0] & 1) ^ 1;
break;
}
if (dct->format == MMX_PERM) {
for (i = 0; i < 64; i++)
block[idct_mmx_perm[i]] = block1[i];
} else if (dct->format == MMX_SIMPLE_PERM) {
for (i = 0; i < 64; i++)
block[idct_simple_mmx_perm[i]] = block1[i];
} else if (dct->format == SSE2_PERM) {
for (i = 0; i < 64; i++)
block[(i & 0x38) | idct_sse2_row_perm[i & 7]] = block1[i];
} else if (dct->format == PARTTRANS_PERM) {
for (i = 0; i < 64; i++)
block[(i & 0x24) | ((i & 3) << 3) | ((i >> 3) & 3)] = block1[i];
} else {
for (i = 0; i < 64; i++)
block[i] = block1[i];
}
dct->func(block); dct->func(block);
mmx_emms(); mmx_emms();
...@@ -317,45 +328,15 @@ static int dct_error(const struct algo *dct, int test, int is_idct, int speed, c ...@@ -317,45 +328,15 @@ static int dct_error(const struct algo *dct, int test, int is_idct, int speed, c
return 0; return 0;
/* speed test */ /* speed test */
for (i = 0; i < 64; i++)
block1[i] = 0;
switch (test) {
case 0:
for (i = 0; i < 64; i++)
block1[i] = av_lfg_get(&prng) % (2*vals) -vals;
if (is_idct) {
ff_ref_fdct(block1);
for (i = 0; i < 64; i++)
block1[i] >>= 3;
}
break;
case 1:
case 2:
block1[0] = av_lfg_get(&prng) % (2*vals) -vals;
block1[1] = av_lfg_get(&prng) % (2*vals) -vals;
block1[2] = av_lfg_get(&prng) % (2*vals) -vals;
block1[3] = av_lfg_get(&prng) % (2*vals) -vals;
break;
}
if (dct->format == MMX_PERM) { init_block(block, test, is_idct, &prng, vals);
for (i = 0; i < 64; i++) permute(block1, block, dct->format);
block[idct_mmx_perm[i]] = block1[i];
} else if (dct->format == MMX_SIMPLE_PERM) {
for (i = 0; i < 64; i++)
block[idct_simple_mmx_perm[i]] = block1[i];
} else {
for (i = 0; i < 64; i++)
block[i] = block1[i];
}
ti = gettime(); ti = gettime();
it1 = 0; it1 = 0;
do { do {
for (it = 0; it < NB_ITS_SPEED; it++) { for (it = 0; it < NB_ITS_SPEED; it++) {
for (i = 0; i < 64; i++) memcpy(block, block1, sizeof(block));
block[i] = block1[i];
dct->func(block); dct->func(block);
} }
it1 += NB_ITS_SPEED; it1 += NB_ITS_SPEED;
......
...@@ -620,8 +620,8 @@ retry: ...@@ -620,8 +620,8 @@ retry:
} }
MPV_frame_end(s); MPV_frame_end(s);
assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type); assert(s->current_picture.f.pict_type == s->current_picture_ptr->f.pict_type);
assert(s->current_picture.pict_type == s->pict_type); assert(s->current_picture.f.pict_type == s->pict_type);
*pict= *(AVFrame*)s->current_picture_ptr; *pict= *(AVFrame*)s->current_picture_ptr;
ff_print_debug_info(s, pict); ff_print_debug_info(s, pict);
......
...@@ -2774,7 +2774,7 @@ static int decode_slice_header(H264Context *h, H264Context *h0){ ...@@ -2774,7 +2774,7 @@ static int decode_slice_header(H264Context *h, H264Context *h0){
if (s0->first_field) { if (s0->first_field) {
assert(s0->current_picture_ptr); assert(s0->current_picture_ptr);
assert(s0->current_picture_ptr->f.data[0]); assert(s0->current_picture_ptr->f.data[0]);
assert(s0->current_picture_ptr->reference != DELAYED_PIC_REF); assert(s0->current_picture_ptr->f.reference != DELAYED_PIC_REF);
/* figure out if we have a complementary field pair */ /* figure out if we have a complementary field pair */
if (!FIELD_PICTURE || s->picture_structure == last_pic_structure) { if (!FIELD_PICTURE || s->picture_structure == last_pic_structure) {
......
...@@ -172,7 +172,7 @@ static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){ ...@@ -172,7 +172,7 @@ static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){
int mv[2]; int mv[2];
int list; int list;
assert(h->ref_list[1][0].reference&3); assert(h->ref_list[1][0].f.reference & 3);
await_reference_mb_row(h, &h->ref_list[1][0], s->mb_y + !!IS_INTERLACED(*mb_type)); await_reference_mb_row(h, &h->ref_list[1][0], s->mb_y + !!IS_INTERLACED(*mb_type));
...@@ -416,7 +416,7 @@ static void pred_temp_direct_motion(H264Context * const h, int *mb_type){ ...@@ -416,7 +416,7 @@ static void pred_temp_direct_motion(H264Context * const h, int *mb_type){
unsigned int sub_mb_type; unsigned int sub_mb_type;
int i8, i4; int i8, i4;
assert(h->ref_list[1][0].reference&3); assert(h->ref_list[1][0].f.reference & 3);
await_reference_mb_row(h, &h->ref_list[1][0], s->mb_y + !!IS_INTERLACED(*mb_type)); await_reference_mb_row(h, &h->ref_list[1][0], s->mb_y + !!IS_INTERLACED(*mb_type));
......
...@@ -1176,7 +1176,7 @@ static int mpeg_decode_update_thread_context(AVCodecContext *avctx, const AVCode ...@@ -1176,7 +1176,7 @@ static int mpeg_decode_update_thread_context(AVCodecContext *avctx, const AVCode
if (!ctx->mpeg_enc_ctx_allocated) if (!ctx->mpeg_enc_ctx_allocated)
memcpy(s + 1, s1 + 1, sizeof(Mpeg1Context) - sizeof(MpegEncContext)); memcpy(s + 1, s1 + 1, sizeof(Mpeg1Context) - sizeof(MpegEncContext));
if (!(s->pict_type == FF_B_TYPE || s->low_delay)) if (!(s->pict_type == AV_PICTURE_TYPE_B || s->low_delay))
s->picture_number++; s->picture_number++;
return 0; return 0;
......
...@@ -225,7 +225,7 @@ static int alloc_frame_buffer(MpegEncContext *s, Picture *pic) ...@@ -225,7 +225,7 @@ static int alloc_frame_buffer(MpegEncContext *s, Picture *pic)
int r; int r;
if (s->avctx->hwaccel) { if (s->avctx->hwaccel) {
assert(!pic->hwaccel_picture_private); assert(!pic->f.hwaccel_picture_private);
if (s->avctx->hwaccel->priv_data_size) { if (s->avctx->hwaccel->priv_data_size) {
pic->f.hwaccel_picture_private = av_mallocz(s->avctx->hwaccel->priv_data_size); pic->f.hwaccel_picture_private = av_mallocz(s->avctx->hwaccel->priv_data_size);
if (!pic->f.hwaccel_picture_private) { if (!pic->f.hwaccel_picture_private) {
...@@ -276,7 +276,7 @@ int ff_alloc_picture(MpegEncContext *s, Picture *pic, int shared){ ...@@ -276,7 +276,7 @@ int ff_alloc_picture(MpegEncContext *s, Picture *pic, int shared){
if(shared){ if(shared){
assert(pic->f.data[0]); assert(pic->f.data[0]);
assert(pic->type == 0 || pic->type == FF_BUFFER_TYPE_SHARED); assert(pic->f.type == 0 || pic->f.type == FF_BUFFER_TYPE_SHARED);
pic->f.type = FF_BUFFER_TYPE_SHARED; pic->f.type = FF_BUFFER_TYPE_SHARED;
}else{ }else{
assert(!pic->f.data[0]); assert(!pic->f.data[0]);
...@@ -539,7 +539,7 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst, const AVCodecContext *src ...@@ -539,7 +539,7 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst, const AVCodecContext *src
s->last_pict_type= s1->pict_type; s->last_pict_type= s1->pict_type;
if (s1->current_picture_ptr) s->last_lambda_for[s1->pict_type] = s1->current_picture_ptr->f.quality; if (s1->current_picture_ptr) s->last_lambda_for[s1->pict_type] = s1->current_picture_ptr->f.quality;
if(s1->pict_type!=FF_B_TYPE){ if (s1->pict_type != AV_PICTURE_TYPE_B) {
s->last_non_b_pict_type= s1->pict_type; s->last_non_b_pict_type= s1->pict_type;
} }
} }
...@@ -2662,6 +2662,6 @@ void ff_set_qscale(MpegEncContext * s, int qscale) ...@@ -2662,6 +2662,6 @@ void ff_set_qscale(MpegEncContext * s, int qscale)
void MPV_report_decode_progress(MpegEncContext *s) void MPV_report_decode_progress(MpegEncContext *s)
{ {
if (s->pict_type != FF_B_TYPE && !s->partitioned_frame && !s->error_occurred) if (s->pict_type != AV_PICTURE_TYPE_B && !s->partitioned_frame && !s->error_occurred)
ff_thread_report_progress((AVFrame*)s->current_picture_ptr, s->mb_y, 0); ff_thread_report_progress((AVFrame*)s->current_picture_ptr, s->mb_y, 0);
} }
...@@ -1093,8 +1093,8 @@ static int select_input_picture(MpegEncContext *s){ ...@@ -1093,8 +1093,8 @@ static int select_input_picture(MpegEncContext *s){
s->input_picture[0]->f.data[i] = NULL; s->input_picture[0]->f.data[i] = NULL;
s->input_picture[0]->f.type = 0; s->input_picture[0]->f.type = 0;
}else{ }else{
assert( s->input_picture[0]->type==FF_BUFFER_TYPE_USER assert( s->input_picture[0]->f.type == FF_BUFFER_TYPE_USER
|| s->input_picture[0]->type==FF_BUFFER_TYPE_INTERNAL); || s->input_picture[0]->f.type == FF_BUFFER_TYPE_INTERNAL);
s->avctx->release_buffer(s->avctx, (AVFrame*)s->input_picture[0]); s->avctx->release_buffer(s->avctx, (AVFrame*)s->input_picture[0]);
} }
...@@ -1220,8 +1220,8 @@ no_output_pic: ...@@ -1220,8 +1220,8 @@ no_output_pic:
}else{ }else{
// input is not a shared pix -> reuse buffer for current_pix // input is not a shared pix -> reuse buffer for current_pix
assert( s->reordered_input_picture[0]->type==FF_BUFFER_TYPE_USER assert( s->reordered_input_picture[0]->f.type == FF_BUFFER_TYPE_USER
|| s->reordered_input_picture[0]->type==FF_BUFFER_TYPE_INTERNAL); || s->reordered_input_picture[0]->f.type == FF_BUFFER_TYPE_INTERNAL);
s->current_picture_ptr= s->reordered_input_picture[0]; s->current_picture_ptr= s->reordered_input_picture[0];
for(i=0; i<4; i++){ for(i=0; i<4; i++){
...@@ -2757,7 +2757,7 @@ static int estimate_qp(MpegEncContext *s, int dry_run){ ...@@ -2757,7 +2757,7 @@ static int estimate_qp(MpegEncContext *s, int dry_run){
/* must be called before writing the header */ /* must be called before writing the header */
static void set_frame_distances(MpegEncContext * s){ static void set_frame_distances(MpegEncContext * s){
assert(s->current_picture_ptr->pts != AV_NOPTS_VALUE); assert(s->current_picture_ptr->f.pts != AV_NOPTS_VALUE);
s->time = s->current_picture_ptr->f.pts * s->avctx->time_base.num; s->time = s->current_picture_ptr->f.pts * s->avctx->time_base.num;
if(s->pict_type==AV_PICTURE_TYPE_B){ if(s->pict_type==AV_PICTURE_TYPE_B){
......
...@@ -62,10 +62,6 @@ static uint32_t v2_dc_chroma_table[512][2]; ...@@ -62,10 +62,6 @@ static uint32_t v2_dc_chroma_table[512][2];
/* vc1 externs */ /* vc1 externs */
extern const uint8_t wmv3_dc_scale_table[32]; extern const uint8_t wmv3_dc_scale_table[32];
#ifdef DEBUG
int frame_count = 0;
#endif
#include "msmpeg4data.h" #include "msmpeg4data.h"
#if CONFIG_ENCODERS //strangely gcc includes this even if it is not referenced #if CONFIG_ENCODERS //strangely gcc includes this even if it is not referenced
......
...@@ -448,7 +448,7 @@ static const AVOption options[]={ ...@@ -448,7 +448,7 @@ static const AVOption options[]={
{"request_channels", "set desired number of audio channels", OFFSET(request_channels), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, A|D}, {"request_channels", "set desired number of audio channels", OFFSET(request_channels), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, A|D},
#endif #endif
#if FF_API_DRC_SCALE #if FF_API_DRC_SCALE
{"drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), FF_OPT_TYPE_FLOAT, {.dbl = 1.0 }, 0.0, 1.0, A|D}, {"drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), FF_OPT_TYPE_FLOAT, {.dbl = 0.0 }, 0.0, 1.0, A|D},
#endif #endif
#if FF_API_LAME_GLOBAL_OPTS #if FF_API_LAME_GLOBAL_OPTS
{"reservoir", "use bit reservoir", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_BIT_RESERVOIR }, INT_MIN, INT_MAX, A|E, "flags2"}, {"reservoir", "use bit reservoir", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_BIT_RESERVOIR }, INT_MIN, INT_MAX, A|E, "flags2"},
...@@ -544,7 +544,6 @@ void avcodec_get_context_defaults2(AVCodecContext *s, enum AVMediaType codec_typ ...@@ -544,7 +544,6 @@ void avcodec_get_context_defaults2(AVCodecContext *s, enum AVMediaType codec_typ
s->pix_fmt= PIX_FMT_NONE; s->pix_fmt= PIX_FMT_NONE;
s->sample_fmt= AV_SAMPLE_FMT_NONE; s->sample_fmt= AV_SAMPLE_FMT_NONE;
s->palctrl = NULL;
s->reget_buffer= avcodec_default_reget_buffer; s->reget_buffer= avcodec_default_reget_buffer;
s->reordered_opaque= AV_NOPTS_VALUE; s->reordered_opaque= AV_NOPTS_VALUE;
} }
...@@ -623,7 +622,6 @@ int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src) ...@@ -623,7 +622,6 @@ int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)
/* set values specific to opened codecs back to their default state */ /* set values specific to opened codecs back to their default state */
dest->priv_data = NULL; dest->priv_data = NULL;
dest->codec = NULL; dest->codec = NULL;
dest->palctrl = NULL;
dest->slice_offset = NULL; dest->slice_offset = NULL;
dest->internal_buffer = NULL; dest->internal_buffer = NULL;
dest->hwaccel = NULL; dest->hwaccel = NULL;
......
...@@ -85,6 +85,20 @@ AVCodec *av_codec_next(AVCodec *c){ ...@@ -85,6 +85,20 @@ AVCodec *av_codec_next(AVCodec *c){
else return first_avcodec; else return first_avcodec;
} }
#if !FF_API_AVCODEC_INIT
static
#endif
void avcodec_init(void)
{
static int initialized = 0;
if (initialized != 0)
return;
initialized = 1;
dsputil_static_init();
}
void avcodec_register(AVCodec *codec) void avcodec_register(AVCodec *codec)
{ {
AVCodec **p; AVCodec **p;
...@@ -1144,20 +1158,6 @@ const char *avcodec_license(void) ...@@ -1144,20 +1158,6 @@ const char *avcodec_license(void)
return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1; return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
} }
#if !FF_API_AVCODEC_INIT
static
#endif
void avcodec_init(void)
{
static int initialized = 0;
if (initialized != 0)
return;
initialized = 1;
dsputil_static_init();
}
void avcodec_flush_buffers(AVCodecContext *avctx) void avcodec_flush_buffers(AVCodecContext *avctx)
{ {
if(HAVE_PTHREADS && avctx->active_thread_type&FF_THREAD_FRAME) if(HAVE_PTHREADS && avctx->active_thread_type&FF_THREAD_FRAME)
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <alsa/asoundlib.h> #include <alsa/asoundlib.h>
#include "avdevice.h" #include "avdevice.h"
#include "libavutil/avassert.h" #include "libavutil/avassert.h"
#include "libavutil/audioconvert.h"
#include "alsa-audio.h" #include "alsa-audio.h"
......
This diff is collapsed.
...@@ -45,6 +45,27 @@ enum ID3v2Encoding { ...@@ -45,6 +45,27 @@ enum ID3v2Encoding {
ID3v2_ENCODING_UTF8 = 3, ID3v2_ENCODING_UTF8 = 3,
}; };
typedef struct ID3v2ExtraMeta {
const char *tag;
void *data;
struct ID3v2ExtraMeta *next;
} ID3v2ExtraMeta;
typedef struct ID3v2ExtraMetaGEOB {
uint32_t datasize;
uint8_t *mime_type;
uint8_t *file_name;
uint8_t *description;
uint8_t *data;
} ID3v2ExtraMetaGEOB;
typedef struct ID3v2EMFunc {
const char *tag3;
const char *tag4;
void (*read)(AVFormatContext*, AVIOContext*, int, char*, ID3v2ExtraMeta **);
void (*free)();
} ID3v2EMFunc;
/** /**
* Detect ID3v2 Header. * Detect ID3v2 Header.
* @param buf must be ID3v2_HEADER_SIZE byte long * @param buf must be ID3v2_HEADER_SIZE byte long
...@@ -61,10 +82,25 @@ int ff_id3v2_match(const uint8_t *buf, const char *magic); ...@@ -61,10 +82,25 @@ int ff_id3v2_match(const uint8_t *buf, const char *magic);
int ff_id3v2_tag_len(const uint8_t *buf); int ff_id3v2_tag_len(const uint8_t *buf);
/** /**
* Read an ID3v2 tag * Read an ID3v2 tag (text tags only)
*/ */
void ff_id3v2_read(AVFormatContext *s, const char *magic); void ff_id3v2_read(AVFormatContext *s, const char *magic);
/**
* Read an ID3v2 tag, including supported extra metadata (currently only GEOB)
* @param extra_meta If not NULL, extra metadata is parsed into a list of
* ID3v2ExtraMeta structs and *extra_meta points to the head of the list
*/
void ff_id3v2_read_all(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta);
/**
* Free memory allocated parsing special (non-text) metadata.
* @param extra_meta Pointer to a pointer to the head of a ID3v2ExtraMeta list, *extra_meta is set to NULL.
*/
void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta);
extern const ID3v2EMFunc ff_id3v2_extra_meta_funcs[];
extern const AVMetadataConv ff_id3v2_34_metadata_conv[]; extern const AVMetadataConv ff_id3v2_34_metadata_conv[];
extern const AVMetadataConv ff_id3v2_4_metadata_conv[]; extern const AVMetadataConv ff_id3v2_4_metadata_conv[];
extern const AVMetadataConv ff_id3v2_2_metadata_conv[]; extern const AVMetadataConv ff_id3v2_2_metadata_conv[];
......
...@@ -2629,8 +2629,6 @@ static int mov_read_close(AVFormatContext *s) ...@@ -2629,8 +2629,6 @@ static int mov_read_close(AVFormatContext *s)
av_freep(&sc->drefs); av_freep(&sc->drefs);
if (sc->pb && sc->pb != s->pb) if (sc->pb && sc->pb != s->pb)
avio_close(sc->pb); avio_close(sc->pb);
av_freep(&st->codec->palctrl);
} }
if (mov->dv_demux) { if (mov->dv_demux) {
......
...@@ -1444,7 +1444,7 @@ static int handle_packets(MpegTSContext *ts, int nb_packets) ...@@ -1444,7 +1444,7 @@ static int handle_packets(MpegTSContext *ts, int nb_packets)
if (avio_tell(s->pb) != ts->last_pos) { if (avio_tell(s->pb) != ts->last_pos) {
int i; int i;
// av_dlog("Skipping after seek\n"); av_dlog(ts->stream, "Skipping after seek\n");
/* seek detected, flush pes buffer */ /* seek detected, flush pes buffer */
for (i = 0; i < NB_PID_MAX; i++) { for (i = 0; i < NB_PID_MAX; i++) {
if (ts->pids[i]) { if (ts->pids[i]) {
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
* *
* Copyright (c) 2008 Maxim Poliakovski * Copyright (c) 2008 Maxim Poliakovski
* 2008 Benjamin Larsson * 2008 Benjamin Larsson
* 2011 David Goldwich
* *
* This file is part of FFmpeg. * This file is part of FFmpeg.
* *
...@@ -36,20 +37,19 @@ ...@@ -36,20 +37,19 @@
* - Sound data organized in packets follow the EA3 header * - Sound data organized in packets follow the EA3 header
* (can be encrypted using the Sony DRM!). * (can be encrypted using the Sony DRM!).
* *
* LIMITATIONS: This version supports only plain (unencrypted) OMA files.
* If any DRM-protected (encrypted) file is encountered you will get the
* corresponding error message. Try to remove the encryption using any
* Sony software (for example SonicStage).
* CODEC SUPPORT: Only ATRAC3 codec is currently supported! * CODEC SUPPORT: Only ATRAC3 codec is currently supported!
*/ */
#include "avformat.h" #include "avformat.h"
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
#include "libavutil/des.h"
#include "pcm.h" #include "pcm.h"
#include "riff.h" #include "riff.h"
#include "id3v2.h" #include "id3v2.h"
#define EA3_HEADER_SIZE 96 #define EA3_HEADER_SIZE 96
#define ID3v2_EA3_MAGIC "ea3"
#define OMA_ENC_HEADER_SIZE 16
enum { enum {
OMA_CODECID_ATRAC3 = 0, OMA_CODECID_ATRAC3 = 0,
...@@ -65,7 +65,211 @@ static const AVCodecTag codec_oma_tags[] = { ...@@ -65,7 +65,211 @@ static const AVCodecTag codec_oma_tags[] = {
{ CODEC_ID_MP3, OMA_CODECID_MP3 }, { CODEC_ID_MP3, OMA_CODECID_MP3 },
}; };
#define ID3v2_EA3_MAGIC "ea3" static const uint64_t leaf_table[] = {
0xd79e8283acea4620, 0x7a9762f445afd0d8,
0x354d60a60b8c79f1, 0x584e1cde00b07aee,
0x1573cd93da7df623, 0x47f98d79620dd535
};
typedef struct OMAContext {
uint64_t content_start;
int encrypted;
uint16_t k_size;
uint16_t e_size;
uint16_t i_size;
uint16_t s_size;
uint32_t rid;
uint8_t r_val[24];
uint8_t n_val[24];
uint8_t m_val[8];
uint8_t s_val[8];
uint8_t sm_val[8];
uint8_t e_val[8];
uint8_t iv[8];
struct AVDES av_des;
} OMAContext;
static void hex_log(AVFormatContext *s, int level, const char *name, const uint8_t *value, int len)
{
char buf[33];
len = FFMIN(len, 16);
if (av_log_get_level() < level)
return;
ff_data_to_hex(buf, value, len, 1);
buf[len<<1] = '\0';
av_log(s, level, "%s: %s\n", name, buf);
}
static int kset(AVFormatContext *s, const uint8_t *r_val, const uint8_t *n_val, int len)
{
OMAContext *oc = s->priv_data;
if (!r_val && !n_val)
return -1;
len = FFMIN(len, 16);
/* use first 64 bits in the third round again */
if (r_val) {
if (r_val != oc->r_val) {
memset(oc->r_val, 0, 24);
memcpy(oc->r_val, r_val, len);
}
memcpy(&oc->r_val[16], r_val, 8);
}
if (n_val) {
if (n_val != oc->n_val) {
memset(oc->n_val, 0, 24);
memcpy(oc->n_val, n_val, len);
}
memcpy(&oc->n_val[16], n_val, 8);
}
return 0;
}
static int rprobe(AVFormatContext *s, uint8_t *enc_header, const uint8_t *r_val)
{
OMAContext *oc = s->priv_data;
unsigned int pos;
struct AVDES av_des;
if (!enc_header || !r_val)
return -1;
/* m_val */
av_des_init(&av_des, r_val, 192, 1);
av_des_crypt(&av_des, oc->m_val, &enc_header[48], 1, NULL, 1);
/* s_val */
av_des_init(&av_des, oc->m_val, 64, 0);
av_des_crypt(&av_des, oc->s_val, NULL, 1, NULL, 0);
/* sm_val */
pos = OMA_ENC_HEADER_SIZE + oc->k_size + oc->e_size;
av_des_init(&av_des, oc->s_val, 64, 0);
av_des_mac(&av_des, oc->sm_val, &enc_header[pos], (oc->i_size >> 3));
pos += oc->i_size;
return memcmp(&enc_header[pos], oc->sm_val, 8) ? -1 : 0;
}
static int nprobe(AVFormatContext *s, uint8_t *enc_header, const uint8_t *n_val)
{
OMAContext *oc = s->priv_data;
uint32_t pos, taglen, datalen;
struct AVDES av_des;
if (!enc_header || !n_val)
return -1;
pos = OMA_ENC_HEADER_SIZE + oc->k_size;
if (!memcmp(&enc_header[pos], "EKB ", 4))
pos += 32;
if (AV_RB32(&enc_header[pos]) != oc->rid)
av_log(s, AV_LOG_DEBUG, "Mismatching RID\n");
taglen = AV_RB32(&enc_header[pos+32]);
datalen = AV_RB32(&enc_header[pos+36]) >> 4;
pos += 44 + taglen;
av_des_init(&av_des, n_val, 192, 1);
while (datalen-- > 0) {
av_des_crypt(&av_des, oc->r_val, &enc_header[pos], 2, NULL, 1);
kset(s, oc->r_val, NULL, 16);
if (!rprobe(s, enc_header, oc->r_val))
return 0;
pos += 16;
}
return -1;
}
static int decrypt_init(AVFormatContext *s, ID3v2ExtraMeta *em, uint8_t *header)
{
OMAContext *oc = s->priv_data;
ID3v2ExtraMetaGEOB *geob = NULL;
uint8_t *gdata;
oc->encrypted = 1;
av_log(s, AV_LOG_INFO, "File is encrypted\n");
/* find GEOB metadata */
while (em) {
if (!strcmp(em->tag, "GEOB") &&
(geob = em->data) &&
!strcmp(geob->description, "OMG_LSI") ||
!strcmp(geob->description, "OMG_BKLSI")) {
break;
}
em = em->next;
}
if (!em) {
av_log(s, AV_LOG_ERROR, "No encryption header found\n");
return -1;
}
if (geob->datasize < 64) {
av_log(s, AV_LOG_ERROR, "Invalid GEOB data size: %u\n", geob->datasize);
return -1;
}
gdata = geob->data;
if (AV_RB16(gdata) != 1)
av_log(s, AV_LOG_WARNING, "Unknown version in encryption header\n");
oc->k_size = AV_RB16(&gdata[2]);
oc->e_size = AV_RB16(&gdata[4]);
oc->i_size = AV_RB16(&gdata[6]);
oc->s_size = AV_RB16(&gdata[8]);
if (memcmp(&gdata[OMA_ENC_HEADER_SIZE], "KEYRING ", 12)) {
av_log(s, AV_LOG_ERROR, "Invalid encryption header\n");
return -1;
}
oc->rid = AV_RB32(&gdata[OMA_ENC_HEADER_SIZE + 28]);
av_log(s, AV_LOG_DEBUG, "RID: %.8x\n", oc->rid);
memcpy(oc->iv, &header[0x58], 8);
hex_log(s, AV_LOG_DEBUG, "IV", oc->iv, 8);
hex_log(s, AV_LOG_DEBUG, "CBC-MAC", &gdata[OMA_ENC_HEADER_SIZE+oc->k_size+oc->e_size+oc->i_size], 8);
if (s->keylen > 0) {
kset(s, s->key, s->key, s->keylen);
}
if (!memcmp(oc->r_val, (const uint8_t[8]){0}, 8) ||
rprobe(s, gdata, oc->r_val) < 0 &&
nprobe(s, gdata, oc->n_val) < 0) {
int i;
for (i = 0; i < sizeof(leaf_table); i += 2) {
uint8_t buf[16];
AV_WL64(buf, leaf_table[i]);
AV_WL64(&buf[8], leaf_table[i+1]);
kset(s, buf, buf, 16);
if (!rprobe(s, gdata, oc->r_val) || !nprobe(s, gdata, oc->n_val))
break;
}
if (i >= sizeof(leaf_table)) {
av_log(s, AV_LOG_ERROR, "Invalid key\n");
return -1;
}
}
/* e_val */
av_des_init(&oc->av_des, oc->m_val, 64, 0);
av_des_crypt(&oc->av_des, oc->e_val, &gdata[OMA_ENC_HEADER_SIZE + 40], 1, NULL, 0);
hex_log(s, AV_LOG_DEBUG, "EK", oc->e_val, 8);
/* init e_val */
av_des_init(&oc->av_des, oc->e_val, 64, 1);
return 0;
}
static int oma_read_header(AVFormatContext *s, static int oma_read_header(AVFormatContext *s,
AVFormatParameters *ap) AVFormatParameters *ap)
...@@ -77,8 +281,10 @@ static int oma_read_header(AVFormatContext *s, ...@@ -77,8 +281,10 @@ static int oma_read_header(AVFormatContext *s,
uint8_t buf[EA3_HEADER_SIZE]; uint8_t buf[EA3_HEADER_SIZE];
uint8_t *edata; uint8_t *edata;
AVStream *st; AVStream *st;
ID3v2ExtraMeta *extra_meta = NULL;
OMAContext *oc = s->priv_data;
ff_id3v2_read(s, ID3v2_EA3_MAGIC); ff_id3v2_read_all(s, ID3v2_EA3_MAGIC, &extra_meta);
ret = avio_read(s->pb, buf, EA3_HEADER_SIZE); ret = avio_read(s->pb, buf, EA3_HEADER_SIZE);
if (ret < EA3_HEADER_SIZE) if (ret < EA3_HEADER_SIZE)
return -1; return -1;
...@@ -88,12 +294,17 @@ static int oma_read_header(AVFormatContext *s, ...@@ -88,12 +294,17 @@ static int oma_read_header(AVFormatContext *s,
return -1; return -1;
} }
oc->content_start = avio_tell(s->pb);
/* encrypted file */
eid = AV_RB16(&buf[6]); eid = AV_RB16(&buf[6]);
if (eid != -1 && eid != -128) { if (eid != -1 && eid != -128 && decrypt_init(s, extra_meta, buf) < 0) {
av_log(s, AV_LOG_ERROR, "Encrypted file! Eid: %d\n", eid); ff_id3v2_free_extra_meta(&extra_meta);
return -1; return -1;
} }
ff_id3v2_free_extra_meta(&extra_meta);
codec_params = AV_RB24(&buf[33]); codec_params = AV_RB24(&buf[33]);
st = av_new_stream(s, 0); st = av_new_stream(s, 0);
...@@ -159,12 +370,20 @@ static int oma_read_header(AVFormatContext *s, ...@@ -159,12 +370,20 @@ static int oma_read_header(AVFormatContext *s,
static int oma_read_packet(AVFormatContext *s, AVPacket *pkt) static int oma_read_packet(AVFormatContext *s, AVPacket *pkt)
{ {
int ret = av_get_packet(s->pb, pkt, s->streams[0]->codec->block_align); OMAContext *oc = s->priv_data;
int packet_size = s->streams[0]->codec->block_align;
int ret = av_get_packet(s->pb, pkt, packet_size);
pkt->stream_index = 0;
if (ret <= 0) if (ret <= 0)
return AVERROR(EIO); return AVERROR(EIO);
pkt->stream_index = 0;
if (oc->encrypted) {
/* previous unencrypted block saved in IV for the next packet (CBC mode) */
av_des_crypt(&oc->av_des, pkt->data, pkt->data, (packet_size >> 3), oc->iv, 1);
}
return ret; return ret;
} }
...@@ -190,16 +409,38 @@ static int oma_read_probe(AVProbeData *p) ...@@ -190,16 +409,38 @@ static int oma_read_probe(AVProbeData *p)
return 0; return 0;
} }
static int oma_read_seek(struct AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
{
OMAContext *oc = s->priv_data;
pcm_read_seek(s, stream_index, timestamp, flags);
if (oc->encrypted) {
/* readjust IV for CBC */
int64_t pos = avio_tell(s->pb);
if (pos < oc->content_start)
memset(oc->iv, 0, 8);
else {
if (avio_seek(s->pb, -8, SEEK_CUR) < 0 || avio_read(s->pb, oc->iv, 8) < 8) {
memset(oc->iv, 0, 8);
return -1;
}
}
}
return 0;
}
AVInputFormat ff_oma_demuxer = { AVInputFormat ff_oma_demuxer = {
.name = "oma", .name = "oma",
.long_name = NULL_IF_CONFIG_SMALL("Sony OpenMG audio"), .long_name = NULL_IF_CONFIG_SMALL("Sony OpenMG audio"),
.priv_data_size = sizeof(OMAContext),
.read_probe = oma_read_probe, .read_probe = oma_read_probe,
.read_header = oma_read_header, .read_header = oma_read_header,
.read_packet = oma_read_packet, .read_packet = oma_read_packet,
.read_seek = pcm_read_seek, .read_seek = oma_read_seek,
.flags= AVFMT_GENERIC_INDEX, .flags = AVFMT_GENERIC_INDEX,
.extensions = "oma,aa3", .extensions = "oma,omg,aa3",
.codec_tag= (const AVCodecTag* const []){codec_oma_tags, 0}, .codec_tag = (const AVCodecTag* const []){codec_oma_tags, 0},
}; };
...@@ -136,8 +136,9 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -136,8 +136,9 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
ast->need_parsing = AVSTREAM_PARSE_FULL; ast->need_parsing = AVSTREAM_PARSE_FULL;
sample_rate_code= (v>>2) & 3; sample_rate_code= (v>>2) & 3;
if (!sample_rate_code) if (!sample_rate_code)
return AVERROR(EIO); ast->codec->sample_rate = 5512;
ast->codec->sample_rate = 11025 << (sample_rate_code-1); else
ast->codec->sample_rate = 11025 << (sample_rate_code-1);
av_set_pts_info(ast, 64, 1, ast->codec->sample_rate); av_set_pts_info(ast, 64, 1, ast->codec->sample_rate);
len -= 4; len -= 4;
} else if (tag == TAG_VIDEOFRAME) { } else if (tag == TAG_VIDEOFRAME) {
......
...@@ -298,7 +298,7 @@ int av_des_init(AVDES *d, const uint8_t *key, int key_bits, int decrypt) { ...@@ -298,7 +298,7 @@ int av_des_init(AVDES *d, const uint8_t *key, int key_bits, int decrypt) {
return 0; return 0;
} }
void av_des_crypt(AVDES *d, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt) { static void av_des_crypt_mac(AVDES *d, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt, int mac) {
uint64_t iv_val = iv ? AV_RB64(iv) : 0; uint64_t iv_val = iv ? AV_RB64(iv) : 0;
while (count-- > 0) { while (count-- > 0) {
uint64_t dst_val; uint64_t dst_val;
...@@ -321,12 +321,21 @@ void av_des_crypt(AVDES *d, uint8_t *dst, const uint8_t *src, int count, uint8_t ...@@ -321,12 +321,21 @@ void av_des_crypt(AVDES *d, uint8_t *dst, const uint8_t *src, int count, uint8_t
} }
AV_WB64(dst, dst_val); AV_WB64(dst, dst_val);
src += 8; src += 8;
dst += 8; if (!mac)
dst += 8;
} }
if (iv) if (iv)
AV_WB64(iv, iv_val); AV_WB64(iv, iv_val);
} }
void av_des_crypt(AVDES *d, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt) {
av_des_crypt_mac(d, dst, src, count, iv, decrypt, 0);
}
void av_des_mac(AVDES *d, uint8_t *dst, const uint8_t *src, int count) {
av_des_crypt_mac(d, dst, src, count, (uint8_t[8]){0}, 0, 1);
}
#ifdef TEST #ifdef TEST
#undef printf #undef printf
#undef rand #undef rand
......
...@@ -33,7 +33,7 @@ struct AVDES { ...@@ -33,7 +33,7 @@ struct AVDES {
* @brief Initializes an AVDES context. * @brief Initializes an AVDES context.
* *
* @param key_bits must be 64 or 192 * @param key_bits must be 64 or 192
* @param decrypt 0 for encryption, 1 for decryption * @param decrypt 0 for encryption/CBC-MAC, 1 for decryption
*/ */
int av_des_init(struct AVDES *d, const uint8_t *key, int key_bits, int decrypt); int av_des_init(struct AVDES *d, const uint8_t *key, int key_bits, int decrypt);
...@@ -49,4 +49,13 @@ int av_des_init(struct AVDES *d, const uint8_t *key, int key_bits, int decrypt); ...@@ -49,4 +49,13 @@ int av_des_init(struct AVDES *d, const uint8_t *key, int key_bits, int decrypt);
*/ */
void av_des_crypt(struct AVDES *d, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt); void av_des_crypt(struct AVDES *d, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt);
/**
* @brief Calculates CBC-MAC using the DES algorithm.
*
* @param count number of 8 byte blocks
* @param dst destination array, can be equal to src, must be 8-byte aligned
* @param src source array, can be equal to dst, must be 8-byte aligned, may be NULL
*/
void av_des_mac(struct AVDES *d, uint8_t *dst, const uint8_t *src, int count);
#endif /* AVUTIL_DES_H */ #endif /* AVUTIL_DES_H */
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