Merge remote-tracking branch 'qatar/release/0.7' into release/0.8

* qatar/release/0.7:
  vorbis: Validate that the floor 1 X values contain no duplicates.
  vorbisenc: check all allocations for failure
  lavfi: avfilter_merge_formats: handle case where inputs are same
  alsdec: check opt_order.
  lavf: don't segfault when a NULL filename is passed to avformat_open_input()
  mpegvideo: Don't use ff_mspel_motion() for vc1
  imgconvert: avoid undefined left shift in avcodec_find_best_pix_fmt
  nuv: check RTjpeg header for validity
  vc1dec: add flush function for WMV9 and VC-1 decoders
  ffmpeg: fix -force_key_frames
  mov: set AVCodecContext.width/height for h264
  h264: allow cropping to AVCodecContext.width/height

Conflicts:
	libavcodec/mpegvideo_common.h
	libavcodec/nuv.c
	libavcodec/vorbisenc.c
	libavfilter/formats.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2012-10-16 16:43:59 +02:00
commit e28814e0e1
14 changed files with 146 additions and 51 deletions

View File

@ -313,6 +313,7 @@ typedef struct AVOutputStream {
#endif
int sws_flags;
char *forced_key_frames;
} AVOutputStream;
static AVOutputStream **output_streams_for_file[MAX_FILES] = { NULL };
@ -2336,6 +2337,9 @@ static int transcode(AVFormatContext **output_files,
"Please consider specifiying a lower framerate, a different muxer or -vsync 2\n");
}
if (ost->forced_key_frames)
parse_forced_key_frames(ost->forced_key_frames, ost, codec);
#if CONFIG_AVFILTER
if (configure_video_filters(ist, ost)) {
fprintf(stderr, "Error opening filters!\n");
@ -2857,6 +2861,7 @@ static int transcode(AVFormatContext **output_files,
av_freep(&ost->st->codec->subtitle_header);
av_free(ost->resample_frame.data[0]);
av_free(ost->forced_kf_pts);
av_free(ost->forced_key_frames);
if (ost->video_resample)
sws_freeContext(ost->img_resample_ctx);
if (ost->resample)
@ -3655,8 +3660,10 @@ static void new_video_stream(AVFormatContext *oc, int file_idx)
}
}
if (forced_key_frames)
parse_forced_key_frames(forced_key_frames, ost, video_enc);
if (forced_key_frames) {
ost->forced_key_frames = forced_key_frames;
forced_key_frames = NULL;
}
}
if (video_language) {
av_dict_set(&st->metadata, "language", video_language, 0);
@ -3666,7 +3673,6 @@ static void new_video_stream(AVFormatContext *oc, int file_idx)
/* reset some key parameters */
video_disable = 0;
av_freep(&video_codec_name);
av_freep(&forced_key_frames);
video_stream_copy = 0;
frame_pix_fmt = PIX_FMT_NONE;
}

View File

@ -662,6 +662,11 @@ static int read_var_block_data(ALSDecContext *ctx, ALSBlockData *bd)
int opt_order_length = av_ceil_log2(av_clip((bd->block_length >> 3) - 1,
2, sconf->max_order + 1));
*bd->opt_order = get_bits(gb, opt_order_length);
if (*bd->opt_order > sconf->max_order) {
*bd->opt_order = sconf->max_order;
av_log(avctx, AV_LOG_ERROR, "Predictor order too large!\n");
return AVERROR_INVALIDDATA;
}
} else {
*bd->opt_order = sconf->max_order;
}

View File

@ -2617,6 +2617,12 @@ static int decode_slice_header(H264Context *h, H264Context *h0){
else
s->height= 16*s->mb_height - (4>>CHROMA444)*FFMIN(h->sps.crop_bottom, (8<<CHROMA444)-1);
if (FFALIGN(s->avctx->width, 16) == s->width &&
FFALIGN(s->avctx->height, 16) == s->height) {
s->width = s->avctx->width;
s->height = s->avctx->height;
}
if (s->context_initialized
&& ( s->width != s->avctx->width || s->height != s->avctx->height
|| av_cmp_q(h->sps.sar, s->avctx->sample_aspect_ratio))) {

View File

@ -625,7 +625,8 @@ static enum PixelFormat avcodec_find_best_pix_fmt1(int64_t pix_fmt_mask,
/* find exact color match with smallest size */
dst_pix_fmt = PIX_FMT_NONE;
min_dist = 0x7fffffff;
for(i = 0;i < PIX_FMT_NB; i++) {
/* test only the first 64 pixel formats to avoid undefined behaviour */
for (i = 0; i < 64; i++) {
if (pix_fmt_mask & (1ULL << i)) {
loss = avcodec_get_pix_fmt_loss(i, src_pix_fmt, has_alpha) & loss_mask;
if (loss == 0) {

View File

@ -725,7 +725,8 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s,
0, 0, 0,
ref_picture, pix_op, qpix_op,
s->mv[dir][0][0], s->mv[dir][0][1], 16);
}else if(!is_mpeg12 && (CONFIG_WMV2_DECODER || CONFIG_WMV2_ENCODER) && s->mspel && s->codec_id == CODEC_ID_WMV2){
} else if (!is_mpeg12 && (CONFIG_WMV2_DECODER || CONFIG_WMV2_ENCODER) &&
s->mspel && s->codec_id == CODEC_ID_WMV2) {
ff_mspel_motion(s, dest_y, dest_cb, dest_cr,
ref_picture, pix_op,
s->mv[dir][0][0], s->mv[dir][0][1], 16);

View File

@ -191,9 +191,10 @@ retry:
}
if (c->codec_frameheader) {
int w, h, q, res;
if (buf_size < 12) {
if (buf_size < RTJPEG_HEADER_SIZE || buf[4] != RTJPEG_HEADER_SIZE ||
buf[5] != RTJPEG_FILE_VERSION) {
av_log(avctx, AV_LOG_ERROR, "invalid nuv video frame\n");
return -1;
return AVERROR_INVALIDDATA;
}
w = AV_RL16(&buf[6]);
h = AV_RL16(&buf[8]);
@ -207,8 +208,8 @@ retry:
size_change = 1;
goto retry;
}
buf = &buf[12];
buf_size -= 12;
buf = &buf[RTJPEG_HEADER_SIZE];
buf_size -= RTJPEG_HEADER_SIZE;
}
if ((size_change || keyframe) && c->pic.data[0])

View File

@ -25,6 +25,9 @@
#include <stdint.h>
#include "dsputil.h"
#define RTJPEG_FILE_VERSION 0
#define RTJPEG_HEADER_SIZE 12
typedef struct {
int w, h;
DSPContext *dsp;

View File

@ -3840,6 +3840,7 @@ AVCodec ff_vc1_decoder = {
vc1_decode_frame,
CODEC_CAP_DR1 | CODEC_CAP_DELAY,
NULL,
.flush = ff_mpeg_flush,
.long_name = NULL_IF_CONFIG_SMALL("SMPTE VC-1"),
.pix_fmts = ff_hwaccel_pixfmt_list_420,
.profiles = NULL_IF_CONFIG_SMALL(profiles)
@ -3857,6 +3858,7 @@ AVCodec ff_wmv3_decoder = {
vc1_decode_frame,
CODEC_CAP_DR1 | CODEC_CAP_DELAY,
NULL,
.flush = ff_mpeg_flush,
.long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9"),
.pix_fmts = ff_hwaccel_pixfmt_list_420,
.profiles = NULL_IF_CONFIG_SMALL(profiles)

View File

@ -117,7 +117,8 @@ int ff_vorbis_len2vlc(uint8_t *bits, uint32_t *codes, unsigned num)
return 0;
}
void ff_vorbis_ready_floor1_list(vorbis_floor1_entry * list, int values)
int ff_vorbis_ready_floor1_list(AVCodecContext *avccontext,
vorbis_floor1_entry *list, int values)
{
int i;
list[0].sort = 0;
@ -141,6 +142,11 @@ void ff_vorbis_ready_floor1_list(vorbis_floor1_entry * list, int values)
for (i = 0; i < values - 1; i++) {
int j;
for (j = i + 1; j < values; j++) {
if (list[i].x == list[j].x) {
av_log(avccontext, AV_LOG_ERROR,
"Duplicate value found in floor 1 X coordinates\n");
return AVERROR_INVALIDDATA;
}
if (list[list[i].sort].x > list[list[j].sort].x) {
int tmp = list[i].sort;
list[i].sort = list[j].sort;
@ -148,6 +154,7 @@ void ff_vorbis_ready_floor1_list(vorbis_floor1_entry * list, int values)
}
}
}
return 0;
}
static inline void render_line_unrolled(intptr_t x, int y, int x1,

View File

@ -36,7 +36,8 @@ typedef struct {
uint16_t high;
} vorbis_floor1_entry;
void ff_vorbis_ready_floor1_list(vorbis_floor1_entry * list, int values);
int ff_vorbis_ready_floor1_list(AVCodecContext *avccontext,
vorbis_floor1_entry *list, int values);
unsigned int ff_vorbis_nth_root(unsigned int x, unsigned int n); // x^(1/n)
int ff_vorbis_len2vlc(uint8_t *bits, uint32_t *codes, unsigned num);
void ff_vorbis_floor1_render_list(vorbis_floor1_entry * list, int values,

View File

@ -559,7 +559,11 @@ static int vorbis_parse_setup_hdr_floors(vorbis_context *vc)
}
// Precalculate order of x coordinates - needed for decode
ff_vorbis_ready_floor1_list(floor_setup->data.t1.list, floor_setup->data.t1.x_list_dim);
if (ff_vorbis_ready_floor1_list(vc->avccontext,
floor_setup->data.t1.list,
floor_setup->data.t1.x_list_dim)) {
return AVERROR_INVALIDDATA;
}
} else if (floor_setup->floor_type == 0) {
unsigned max_codebook_dim = 0;

View File

@ -155,7 +155,7 @@ static int cb_lookup_vals(int lookup, int dimentions, int entries)
return 0;
}
static void ready_codebook(vorbis_enc_codebook *cb)
static int ready_codebook(vorbis_enc_codebook *cb)
{
int i;
@ -167,6 +167,8 @@ static void ready_codebook(vorbis_enc_codebook *cb)
int vals = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries);
cb->dimentions = av_malloc(sizeof(float) * cb->nentries * cb->ndimentions);
cb->pow2 = av_mallocz(sizeof(float) * cb->nentries);
if (!cb->dimentions || !cb->pow2)
return AVERROR(ENOMEM);
for (i = 0; i < cb->nentries; i++) {
float last = 0;
int j;
@ -187,13 +189,16 @@ static void ready_codebook(vorbis_enc_codebook *cb)
cb->pow2[i] /= 2.;
}
}
return 0;
}
static void ready_residue(vorbis_enc_residue *rc, vorbis_enc_context *venc)
static int ready_residue(vorbis_enc_residue *rc, vorbis_enc_context *venc)
{
int i;
assert(rc->type == 2);
rc->maxes = av_mallocz(sizeof(float[2]) * rc->classifications);
if (!rc->maxes)
return AVERROR(ENOMEM);
for (i = 0; i < rc->classifications; i++) {
int j;
vorbis_enc_codebook * cb;
@ -223,15 +228,16 @@ static void ready_residue(vorbis_enc_residue *rc, vorbis_enc_context *venc)
rc->maxes[i][0] += 0.8;
rc->maxes[i][1] += 0.8;
}
return 0;
}
static void create_vorbis_context(vorbis_enc_context *venc,
AVCodecContext *avccontext)
static int create_vorbis_context(vorbis_enc_context *venc,
AVCodecContext *avccontext)
{
vorbis_enc_floor *fc;
vorbis_enc_residue *rc;
vorbis_enc_mapping *mc;
int i, book;
int i, book, ret;
venc->channels = avccontext->channels;
venc->sample_rate = avccontext->sample_rate;
@ -239,6 +245,8 @@ static void create_vorbis_context(vorbis_enc_context *venc,
venc->ncodebooks = FF_ARRAY_ELEMS(cvectors);
venc->codebooks = av_malloc(sizeof(vorbis_enc_codebook) * venc->ncodebooks);
if (!venc->codebooks)
return AVERROR(ENOMEM);
// codebook 0..14 - floor1 book, values 0..255
// codebook 15 residue masterbook
@ -255,27 +263,36 @@ static void create_vorbis_context(vorbis_enc_context *venc,
cb->lens = av_malloc(sizeof(uint8_t) * cb->nentries);
cb->codewords = av_malloc(sizeof(uint32_t) * cb->nentries);
if (!cb->lens || !cb->codewords)
return AVERROR(ENOMEM);
memcpy(cb->lens, cvectors[book].clens, cvectors[book].len);
memset(cb->lens + cvectors[book].len, 0, cb->nentries - cvectors[book].len);
if (cb->lookup) {
vals = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries);
cb->quantlist = av_malloc(sizeof(int) * vals);
if (!cb->quantlist)
return AVERROR(ENOMEM);
for (i = 0; i < vals; i++)
cb->quantlist[i] = cvectors[book].quant[i];
} else {
cb->quantlist = NULL;
}
ready_codebook(cb);
if ((ret = ready_codebook(cb)) < 0)
return ret;
}
venc->nfloors = 1;
venc->floors = av_malloc(sizeof(vorbis_enc_floor) * venc->nfloors);
if (!venc->floors)
return AVERROR(ENOMEM);
// just 1 floor
fc = &venc->floors[0];
fc->partitions = NUM_FLOOR_PARTITIONS;
fc->partition_to_class = av_malloc(sizeof(int) * fc->partitions);
if (!fc->partition_to_class)
return AVERROR(ENOMEM);
fc->nclasses = 0;
for (i = 0; i < fc->partitions; i++) {
static const int a[] = {0, 1, 2, 2, 3, 3, 4, 4};
@ -284,6 +301,8 @@ static void create_vorbis_context(vorbis_enc_context *venc,
}
fc->nclasses++;
fc->classes = av_malloc(sizeof(vorbis_enc_floor_class) * fc->nclasses);
if (!fc->classes)
return AVERROR(ENOMEM);
for (i = 0; i < fc->nclasses; i++) {
vorbis_enc_floor_class * c = &fc->classes[i];
int j, books;
@ -292,6 +311,8 @@ static void create_vorbis_context(vorbis_enc_context *venc,
c->masterbook = floor_classes[i].masterbook;
books = (1 << c->subclass);
c->books = av_malloc(sizeof(int) * books);
if (!c->books)
return AVERROR(ENOMEM);
for (j = 0; j < books; j++)
c->books[j] = floor_classes[i].nbooks[j];
}
@ -303,6 +324,8 @@ static void create_vorbis_context(vorbis_enc_context *venc,
fc->values += fc->classes[fc->partition_to_class[i]].dim;
fc->list = av_malloc(sizeof(vorbis_floor1_entry) * fc->values);
if (!fc->list)
return AVERROR(ENOMEM);
fc->list[0].x = 0;
fc->list[1].x = 1 << fc->rangebits;
for (i = 2; i < fc->values; i++) {
@ -313,10 +336,13 @@ static void create_vorbis_context(vorbis_enc_context *venc,
};
fc->list[i].x = a[i - 2];
}
ff_vorbis_ready_floor1_list(fc->list, fc->values);
if (ff_vorbis_ready_floor1_list(avccontext, fc->list, fc->values))
return AVERROR(EINVAL);
venc->nresidues = 1;
venc->residues = av_malloc(sizeof(vorbis_enc_residue) * venc->nresidues);
if (!venc->residues)
return AVERROR(ENOMEM);
// single residue
rc = &venc->residues[0];
@ -327,6 +353,8 @@ static void create_vorbis_context(vorbis_enc_context *venc,
rc->classifications = 10;
rc->classbook = 15;
rc->books = av_malloc(sizeof(*rc->books) * rc->classifications);
if (!rc->books)
return AVERROR(ENOMEM);
{
static const int8_t a[10][8] = {
{ -1, -1, -1, -1, -1, -1, -1, -1, },
@ -342,19 +370,26 @@ static void create_vorbis_context(vorbis_enc_context *venc,
};
memcpy(rc->books, a, sizeof a);
}
ready_residue(rc, venc);
if ((ret = ready_residue(rc, venc)) < 0)
return ret;
venc->nmappings = 1;
venc->mappings = av_malloc(sizeof(vorbis_enc_mapping) * venc->nmappings);
if (!venc->mappings)
return AVERROR(ENOMEM);
// single mapping
mc = &venc->mappings[0];
mc->submaps = 1;
mc->mux = av_malloc(sizeof(int) * venc->channels);
if (!mc->mux)
return AVERROR(ENOMEM);
for (i = 0; i < venc->channels; i++)
mc->mux[i] = 0;
mc->floor = av_malloc(sizeof(int) * mc->submaps);
mc->residue = av_malloc(sizeof(int) * mc->submaps);
if (!mc->floor || !mc->residue)
return AVERROR(ENOMEM);
for (i = 0; i < mc->submaps; i++) {
mc->floor[i] = 0;
mc->residue[i] = 0;
@ -362,6 +397,8 @@ static void create_vorbis_context(vorbis_enc_context *venc,
mc->coupling_steps = venc->channels == 2 ? 1 : 0;
mc->magnitude = av_malloc(sizeof(int) * mc->coupling_steps);
mc->angle = av_malloc(sizeof(int) * mc->coupling_steps);
if (!mc->magnitude || !mc->angle)
return AVERROR(ENOMEM);
if (mc->coupling_steps) {
mc->magnitude[0] = 0;
mc->angle[0] = 1;
@ -369,6 +406,8 @@ static void create_vorbis_context(vorbis_enc_context *venc,
venc->nmodes = 1;
venc->modes = av_malloc(sizeof(vorbis_enc_mode) * venc->nmodes);
if (!venc->modes)
return AVERROR(ENOMEM);
// single mode
venc->modes[0].blockflag = 0;
@ -379,12 +418,18 @@ static void create_vorbis_context(vorbis_enc_context *venc,
venc->samples = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]));
venc->floor = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2);
venc->coeffs = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2);
if (!venc->saved || !venc->samples || !venc->floor || !venc->coeffs)
return AVERROR(ENOMEM);
venc->win[0] = ff_vorbis_vwin[venc->log2_blocksize[0] - 6];
venc->win[1] = ff_vorbis_vwin[venc->log2_blocksize[1] - 6];
ff_mdct_init(&venc->mdct[0], venc->log2_blocksize[0], 0, 1.0);
ff_mdct_init(&venc->mdct[1], venc->log2_blocksize[1], 0, 1.0);
if ((ret = ff_mdct_init(&venc->mdct[0], venc->log2_blocksize[0], 0, 1.0)) < 0)
return ret;
if ((ret = ff_mdct_init(&venc->mdct[1], venc->log2_blocksize[1], 0, 1.0)) < 0)
return ret;
return 0;
}
static void put_float(PutBitContext *pb, float f)
@ -647,6 +692,8 @@ static int put_main_header(vorbis_enc_context *venc, uint8_t **out)
len = hlens[0] + hlens[1] + hlens[2];
p = *out = av_mallocz(64 + len + len/255);
if (!p)
return AVERROR(ENOMEM);
*p++ = 2;
p += av_xiphlacing(p, hlens[0]);
@ -952,33 +999,6 @@ static int apply_window_and_mdct(vorbis_enc_context *venc, const signed short *a
return 1;
}
static av_cold int vorbis_encode_init(AVCodecContext *avccontext)
{
vorbis_enc_context *venc = avccontext->priv_data;
if (avccontext->channels != 2) {
av_log(avccontext, AV_LOG_ERROR, "Current FFmpeg Vorbis encoder only supports 2 channels.\n");
return -1;
}
create_vorbis_context(venc, avccontext);
if (avccontext->flags & CODEC_FLAG_QSCALE)
venc->quality = avccontext->global_quality / (float)FF_QP2LAMBDA / 10.;
else
venc->quality = 0.03;
venc->quality *= venc->quality;
avccontext->extradata_size = put_main_header(venc, (uint8_t**)&avccontext->extradata);
avccontext->frame_size = 1 << (venc->log2_blocksize[0] - 1);
avccontext->coded_frame = avcodec_alloc_frame();
avccontext->coded_frame->key_frame = 1;
return 0;
}
static int vorbis_encode_frame(AVCodecContext *avccontext,
unsigned char *packets,
int buf_size, void *data)
@ -1102,6 +1122,43 @@ static av_cold int vorbis_encode_close(AVCodecContext *avccontext)
return 0 ;
}
static av_cold int vorbis_encode_init(AVCodecContext *avccontext)
{
vorbis_enc_context *venc = avccontext->priv_data;
int ret;
if (avccontext->channels != 2) {
av_log(avccontext, AV_LOG_ERROR, "Current FFmpeg Vorbis encoder only supports 2 channels.\n");
return -1;
}
if ((ret = create_vorbis_context(venc, avccontext)) < 0)
goto error;
if (avccontext->flags & CODEC_FLAG_QSCALE)
venc->quality = avccontext->global_quality / (float)FF_QP2LAMBDA / 10.;
else
venc->quality = 0.03;
venc->quality *= venc->quality;
if ((ret = put_main_header(venc, (uint8_t**)&avccontext->extradata)) < 0)
goto error;
avccontext->extradata_size = ret;
avccontext->frame_size = 1 << (venc->log2_blocksize[0] - 1);
avccontext->coded_frame = avcodec_alloc_frame();
if (!avccontext->coded_frame) {
ret = AVERROR(ENOMEM);
goto error;
}
return 0;
error:
vorbis_encode_close(avccontext);
return ret;
}
AVCodec ff_vorbis_encoder = {
"vorbis",
AVMEDIA_TYPE_AUDIO,

View File

@ -45,7 +45,8 @@ AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b)
AVFilterFormats *ret;
unsigned i, j, k = 0;
if (a == b) return a;
if (a == b)
return a;
ret = av_mallocz(sizeof(AVFilterFormats));

View File

@ -649,7 +649,7 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputForma
}
s->duration = s->start_time = AV_NOPTS_VALUE;
av_strlcpy(s->filename, filename, sizeof(s->filename));
av_strlcpy(s->filename, filename ? filename : "", sizeof(s->filename));
/* allocate private data */
if (s->iformat->priv_data_size > 0) {