Commit 8bf95e8b authored by Michael Niedermayer's avatar Michael Niedermayer

Merge remote-tracking branch 'qatar/master'

* qatar/master:
  avc: Add a function for converting mp4 style extradata to annex b
  pthread: free progress if buffer allocation failed.
  lavc/avconv: support changing frame sizes in codecs with frame mt.
  libavformat: Document who sets the AVStream.id field
  utvideo: mark output picture as keyframe.
  sunrast: Add support for negative linesize.
  vp8: fix update_lf_deltas in libavcodec/vp8.c
  ralf: read Huffman code lengths without GetBitContext

Conflicts:
	ffmpeg.c
	libavcodec/sunrastenc.c
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents f4c380a5 d5ed5e7d
...@@ -476,7 +476,7 @@ static void reset_options(OptionsContext *o, int is_input) ...@@ -476,7 +476,7 @@ static void reset_options(OptionsContext *o, int is_input)
init_opts(); init_opts();
} }
static int alloc_buffer(AVCodecContext *s, InputStream *ist, FrameBuffer **pbuf) static int alloc_buffer(InputStream *ist, AVCodecContext *s, FrameBuffer **pbuf)
{ {
FrameBuffer *buf = av_mallocz(sizeof(*buf)); FrameBuffer *buf = av_mallocz(sizeof(*buf));
int i, ret; int i, ret;
...@@ -556,7 +556,7 @@ static int codec_get_buffer(AVCodecContext *s, AVFrame *frame) ...@@ -556,7 +556,7 @@ static int codec_get_buffer(AVCodecContext *s, AVFrame *frame)
if(av_image_check_size(s->width, s->height, 0, s) || s->pix_fmt<0) if(av_image_check_size(s->width, s->height, 0, s) || s->pix_fmt<0)
return -1; return -1;
if (!ist->buffer_pool && (ret = alloc_buffer(s, ist, &ist->buffer_pool)) < 0) if (!ist->buffer_pool && (ret = alloc_buffer(ist, s, &ist->buffer_pool)) < 0)
return ret; return ret;
buf = ist->buffer_pool; buf = ist->buffer_pool;
...@@ -566,7 +566,7 @@ static int codec_get_buffer(AVCodecContext *s, AVFrame *frame) ...@@ -566,7 +566,7 @@ static int codec_get_buffer(AVCodecContext *s, AVFrame *frame)
av_freep(&buf->base[0]); av_freep(&buf->base[0]);
av_free(buf); av_free(buf);
ist->dr1 = 0; ist->dr1 = 0;
if ((ret = alloc_buffer(s, ist, &buf)) < 0) if ((ret = alloc_buffer(ist, s, &buf)) < 0)
return ret; return ret;
} }
buf->refcount++; buf->refcount++;
...@@ -575,6 +575,10 @@ static int codec_get_buffer(AVCodecContext *s, AVFrame *frame) ...@@ -575,6 +575,10 @@ static int codec_get_buffer(AVCodecContext *s, AVFrame *frame)
frame->type = FF_BUFFER_TYPE_USER; frame->type = FF_BUFFER_TYPE_USER;
frame->extended_data = frame->data; frame->extended_data = frame->data;
frame->pkt_pts = s->pkt ? s->pkt->pts : AV_NOPTS_VALUE; frame->pkt_pts = s->pkt ? s->pkt->pts : AV_NOPTS_VALUE;
frame->width = buf->w;
frame->height = buf->h;
frame->format = buf->pix_fmt;
frame->sample_aspect_ratio = s->sample_aspect_ratio;
for (i = 0; i < FF_ARRAY_ELEMS(buf->data); i++) { for (i = 0; i < FF_ARRAY_ELEMS(buf->data); i++) {
frame->base[i] = buf->base[i]; // XXX h264.c uses base though it shouldn't frame->base[i] = buf->base[i]; // XXX h264.c uses base though it shouldn't
......
...@@ -646,10 +646,6 @@ int ff_thread_decode_frame(AVCodecContext *avctx, ...@@ -646,10 +646,6 @@ int ff_thread_decode_frame(AVCodecContext *avctx,
*picture = p->frame; *picture = p->frame;
*got_picture_ptr = p->got_frame; *got_picture_ptr = p->got_frame;
picture->pkt_dts = p->avpkt.dts; picture->pkt_dts = p->avpkt.dts;
picture->sample_aspect_ratio = avctx->sample_aspect_ratio;
picture->width = avctx->width;
picture->height = avctx->height;
picture->format = avctx->pix_fmt;
/* /*
* A later call with avkpt->size == 0 may loop over all threads, * A later call with avkpt->size == 0 may loop over all threads,
...@@ -995,6 +991,10 @@ int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f) ...@@ -995,6 +991,10 @@ int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f)
ff_thread_finish_setup(avctx); ff_thread_finish_setup(avctx);
} }
if (err) {
free_progress(f);
f->thread_opaque = NULL;
}
pthread_mutex_unlock(&p->parent->buffer_mutex); pthread_mutex_unlock(&p->parent->buffer_mutex);
return err; return err;
......
...@@ -80,17 +80,17 @@ static int init_ralf_vlc(VLC *vlc, const uint8_t *data, int elems) ...@@ -80,17 +80,17 @@ static int init_ralf_vlc(VLC *vlc, const uint8_t *data, int elems)
int counts[17], prefixes[18]; int counts[17], prefixes[18];
int i, cur_len; int i, cur_len;
int max_bits = 0; int max_bits = 0;
GetBitContext gb; int nb = 0;
init_get_bits(&gb, data, elems * 4);
for (i = 0; i <= 16; i++) for (i = 0; i <= 16; i++)
counts[i] = 0; counts[i] = 0;
for (i = 0; i < elems; i++) { for (i = 0; i < elems; i++) {
cur_len = get_bits(&gb, 4) + 1; cur_len = (nb ? *data & 0xF : *data >> 4) + 1;
counts[cur_len]++; counts[cur_len]++;
max_bits = FFMAX(max_bits, cur_len); max_bits = FFMAX(max_bits, cur_len);
lens[i] = cur_len; lens[i] = cur_len;
data += nb;
nb ^= 1;
} }
prefixes[1] = 0; prefixes[1] = 0;
for (i = 1; i <= 16; i++) for (i = 1; i <= 16; i++)
......
...@@ -425,11 +425,6 @@ static int video_get_buffer(AVCodecContext *s, AVFrame *pic) ...@@ -425,11 +425,6 @@ static int video_get_buffer(AVCodecContext *s, AVFrame *pic)
buf = &avci->buffer[avci->buffer_count]; buf = &avci->buffer[avci->buffer_count];
if(buf->base[0] && (buf->width != w || buf->height != h || buf->pix_fmt != s->pix_fmt)){ if(buf->base[0] && (buf->width != w || buf->height != h || buf->pix_fmt != s->pix_fmt)){
if(s->active_thread_type&FF_THREAD_FRAME) {
av_log_missing_feature(s, "Width/height changing with frame threads is", 0);
return -1;
}
for (i = 0; i < AV_NUM_DATA_POINTERS; i++) { for (i = 0; i < AV_NUM_DATA_POINTERS; i++) {
av_freep(&buf->base[i]); av_freep(&buf->base[i]);
buf->data[i]= NULL; buf->data[i]= NULL;
...@@ -513,6 +508,10 @@ static int video_get_buffer(AVCodecContext *s, AVFrame *pic) ...@@ -513,6 +508,10 @@ static int video_get_buffer(AVCodecContext *s, AVFrame *pic)
} }
pic->extended_data = pic->data; pic->extended_data = pic->data;
avci->buffer_count++; avci->buffer_count++;
pic->width = buf->width;
pic->height = buf->height;
pic->format = buf->pix_fmt;
pic->sample_aspect_ratio = s->sample_aspect_ratio;
if (s->pkt) { if (s->pkt) {
pic->pkt_pts = s->pkt->pts; pic->pkt_pts = s->pkt->pts;
......
...@@ -490,6 +490,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac ...@@ -490,6 +490,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
break; break;
} }
c->pic.key_frame = 1;
c->pic.pict_type = AV_PICTURE_TYPE_I;
*data_size = sizeof(AVFrame); *data_size = sizeof(AVFrame);
*(AVFrame*)data = c->pic; *(AVFrame*)data = c->pic;
......
...@@ -162,11 +162,23 @@ static void update_lf_deltas(VP8Context *s) ...@@ -162,11 +162,23 @@ static void update_lf_deltas(VP8Context *s)
VP56RangeCoder *c = &s->c; VP56RangeCoder *c = &s->c;
int i; int i;
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++) {
s->lf_delta.ref[i] = vp8_rac_get_sint(c, 6); if (vp8_rac_get(c)) {
s->lf_delta.ref[i] = vp8_rac_get_uint(c, 6);
if (vp8_rac_get(c))
s->lf_delta.ref[i] = -s->lf_delta.ref[i];
}
}
for (i = MODE_I4x4; i <= VP8_MVMODE_SPLIT; i++) {
if (vp8_rac_get(c)) {
s->lf_delta.mode[i] = vp8_rac_get_uint(c, 6);
for (i = MODE_I4x4; i <= VP8_MVMODE_SPLIT; i++) if (vp8_rac_get(c))
s->lf_delta.mode[i] = vp8_rac_get_sint(c, 6); s->lf_delta.mode[i] = -s->lf_delta.mode[i];
}
}
} }
static int setup_partitions(VP8Context *s, const uint8_t *buf, int buf_size) static int setup_partitions(VP8Context *s, const uint8_t *buf, int buf_size)
......
...@@ -160,3 +160,34 @@ int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len) ...@@ -160,3 +160,34 @@ int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len)
} }
return 0; return 0;
} }
int ff_avc_write_annexb_extradata(const uint8_t *in, uint8_t **buf, int *size)
{
uint16_t sps_size, pps_size;
uint8_t *out;
int out_size;
*buf = NULL;
if (*size >= 4 && (AV_RB32(in) == 0x00000001 || AV_RB24(in) == 0x000001))
return 0;
if (*size < 11 || in[0] != 1)
return AVERROR_INVALIDDATA;
sps_size = AV_RB16(&in[6]);
if (11 + sps_size > *size)
return AVERROR_INVALIDDATA;
pps_size = AV_RB16(&in[9 + sps_size]);
if (11 + sps_size + pps_size > *size)
return AVERROR_INVALIDDATA;
out_size = 8 + sps_size + pps_size;
out = av_mallocz(out_size);
if (!out)
return AVERROR(ENOMEM);
AV_WB32(&out[0], 0x00000001);
memcpy(out + 4, &in[8], sps_size);
AV_WB32(&out[4 + sps_size], 0x00000001);
memcpy(out + 8 + sps_size, &in[11 + sps_size], pps_size);
*buf = out;
*size = out_size;
return 0;
}
...@@ -29,5 +29,6 @@ int ff_avc_parse_nal_units(AVIOContext *s, const uint8_t *buf, int size); ...@@ -29,5 +29,6 @@ int ff_avc_parse_nal_units(AVIOContext *s, const uint8_t *buf, int size);
int ff_avc_parse_nal_units_buf(const uint8_t *buf_in, uint8_t **buf, int *size); int ff_avc_parse_nal_units_buf(const uint8_t *buf_in, uint8_t **buf, int *size);
int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len); int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len);
const uint8_t *ff_avc_find_startcode(const uint8_t *p, const uint8_t *end); const uint8_t *ff_avc_find_startcode(const uint8_t *p, const uint8_t *end);
int ff_avc_write_annexb_extradata(const uint8_t *in, uint8_t **buf, int *size);
#endif /* AVFORMAT_AVC_H */ #endif /* AVFORMAT_AVC_H */
...@@ -558,7 +558,12 @@ typedef struct AVIndexEntry { ...@@ -558,7 +558,12 @@ typedef struct AVIndexEntry {
*/ */
typedef struct AVStream { typedef struct AVStream {
int index; /**< stream index in AVFormatContext */ int index; /**< stream index in AVFormatContext */
int id; /**< format-specific stream ID */ /**
* Format-specific stream ID.
* decoding: set by libavformat
* encoding: set by the user
*/
int id;
AVCodecContext *codec; /**< codec context */ AVCodecContext *codec; /**< codec context */
/** /**
* Real base framerate of the stream. * Real base framerate of the stream.
......
...@@ -2158,26 +2158,6 @@ static void param_write_hex(AVIOContext *pb, const char *name, const uint8_t *va ...@@ -2158,26 +2158,6 @@ static void param_write_hex(AVIOContext *pb, const char *name, const uint8_t *va
avio_printf(pb, "<param name=\"%s\" value=\"%s\" valuetype=\"data\"/>\n", name, buf); avio_printf(pb, "<param name=\"%s\" value=\"%s\" valuetype=\"data\"/>\n", name, buf);
} }
static void write_h264_extradata(AVIOContext *pb, AVCodecContext *enc)
{
uint16_t sps_size, pps_size, len;
char buf[150];
sps_size = AV_RB16(&enc->extradata[6]);
if (11 + sps_size > enc->extradata_size)
return;
pps_size = AV_RB16(&enc->extradata[9 + sps_size]);
if (11 + sps_size + pps_size > enc->extradata_size)
return;
len = FFMIN(sizeof(buf)/2 - 1, sps_size);
ff_data_to_hex(buf, &enc->extradata[8], len, 0);
buf[2*len] = '\0';
avio_printf(pb, "<param name=\"CodecPrivateData\" value=\"00000001%s", buf);
len = FFMIN(sizeof(buf)/2 - 1, pps_size);
ff_data_to_hex(buf, &enc->extradata[11 + sps_size], len, 0);
buf[2*len] = '\0';
avio_printf(pb, "00000001%s\" valuetype=\"data\"/>\n", buf);
}
static int mov_write_isml_manifest(AVIOContext *pb, MOVMuxContext *mov) static int mov_write_isml_manifest(AVIOContext *pb, MOVMuxContext *mov)
{ {
int64_t pos = avio_tell(pb); int64_t pos = avio_tell(pb);
...@@ -2219,10 +2199,16 @@ static int mov_write_isml_manifest(AVIOContext *pb, MOVMuxContext *mov) ...@@ -2219,10 +2199,16 @@ static int mov_write_isml_manifest(AVIOContext *pb, MOVMuxContext *mov)
param_write_int(pb, "systemBitrate", track->enc->bit_rate); param_write_int(pb, "systemBitrate", track->enc->bit_rate);
param_write_int(pb, "trackID", track_id); param_write_int(pb, "trackID", track_id);
if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) { if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) {
if (track->enc->codec_id == CODEC_ID_H264 && if (track->enc->codec_id == CODEC_ID_H264) {
track->enc->extradata_size >= 11 && uint8_t *ptr;
track->enc->extradata[0] == 1) { int size = track->enc->extradata_size;
write_h264_extradata(pb, track->enc); if (!ff_avc_write_annexb_extradata(track->enc->extradata, &ptr,
&size)) {
param_write_hex(pb, "CodecPrivateData",
ptr ? ptr : track->enc->extradata,
size);
av_free(ptr);
}
} else { } else {
param_write_hex(pb, "CodecPrivateData", track->enc->extradata, param_write_hex(pb, "CodecPrivateData", track->enc->extradata,
track->enc->extradata_size); track->enc->extradata_size);
......
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