* 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: Michael Niedermayer <michaelni@gmx.at>
... | ... |
@@ -476,7 +476,7 @@ static void reset_options(OptionsContext *o, int is_input) |
476 | 476 |
init_opts(); |
477 | 477 |
} |
478 | 478 |
|
479 |
-static int alloc_buffer(AVCodecContext *s, InputStream *ist, FrameBuffer **pbuf) |
|
479 |
+static int alloc_buffer(InputStream *ist, AVCodecContext *s, FrameBuffer **pbuf) |
|
480 | 480 |
{ |
481 | 481 |
FrameBuffer *buf = av_mallocz(sizeof(*buf)); |
482 | 482 |
int i, ret; |
... | ... |
@@ -556,7 +556,7 @@ static int codec_get_buffer(AVCodecContext *s, AVFrame *frame) |
556 | 556 |
if(av_image_check_size(s->width, s->height, 0, s) || s->pix_fmt<0) |
557 | 557 |
return -1; |
558 | 558 |
|
559 |
- if (!ist->buffer_pool && (ret = alloc_buffer(s, ist, &ist->buffer_pool)) < 0) |
|
559 |
+ if (!ist->buffer_pool && (ret = alloc_buffer(ist, s, &ist->buffer_pool)) < 0) |
|
560 | 560 |
return ret; |
561 | 561 |
|
562 | 562 |
buf = ist->buffer_pool; |
... | ... |
@@ -566,7 +566,7 @@ static int codec_get_buffer(AVCodecContext *s, AVFrame *frame) |
566 | 566 |
av_freep(&buf->base[0]); |
567 | 567 |
av_free(buf); |
568 | 568 |
ist->dr1 = 0; |
569 |
- if ((ret = alloc_buffer(s, ist, &buf)) < 0) |
|
569 |
+ if ((ret = alloc_buffer(ist, s, &buf)) < 0) |
|
570 | 570 |
return ret; |
571 | 571 |
} |
572 | 572 |
buf->refcount++; |
... | ... |
@@ -575,6 +575,10 @@ static int codec_get_buffer(AVCodecContext *s, AVFrame *frame) |
575 | 575 |
frame->type = FF_BUFFER_TYPE_USER; |
576 | 576 |
frame->extended_data = frame->data; |
577 | 577 |
frame->pkt_pts = s->pkt ? s->pkt->pts : AV_NOPTS_VALUE; |
578 |
+ frame->width = buf->w; |
|
579 |
+ frame->height = buf->h; |
|
580 |
+ frame->format = buf->pix_fmt; |
|
581 |
+ frame->sample_aspect_ratio = s->sample_aspect_ratio; |
|
578 | 582 |
|
579 | 583 |
for (i = 0; i < FF_ARRAY_ELEMS(buf->data); i++) { |
580 | 584 |
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 | 646 |
*picture = p->frame; |
647 | 647 |
*got_picture_ptr = p->got_frame; |
648 | 648 |
picture->pkt_dts = p->avpkt.dts; |
649 |
- picture->sample_aspect_ratio = avctx->sample_aspect_ratio; |
|
650 |
- picture->width = avctx->width; |
|
651 |
- picture->height = avctx->height; |
|
652 |
- picture->format = avctx->pix_fmt; |
|
653 | 649 |
|
654 | 650 |
/* |
655 | 651 |
* 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 | 995 |
ff_thread_finish_setup(avctx); |
996 | 996 |
} |
997 | 997 |
|
998 |
+ if (err) { |
|
999 |
+ free_progress(f); |
|
1000 |
+ f->thread_opaque = NULL; |
|
1001 |
+ } |
|
998 | 1002 |
pthread_mutex_unlock(&p->parent->buffer_mutex); |
999 | 1003 |
|
1000 | 1004 |
return err; |
... | ... |
@@ -80,17 +80,17 @@ static int init_ralf_vlc(VLC *vlc, const uint8_t *data, int elems) |
80 | 80 |
int counts[17], prefixes[18]; |
81 | 81 |
int i, cur_len; |
82 | 82 |
int max_bits = 0; |
83 |
- GetBitContext gb; |
|
84 |
- |
|
85 |
- init_get_bits(&gb, data, elems * 4); |
|
83 |
+ int nb = 0; |
|
86 | 84 |
|
87 | 85 |
for (i = 0; i <= 16; i++) |
88 | 86 |
counts[i] = 0; |
89 | 87 |
for (i = 0; i < elems; i++) { |
90 |
- cur_len = get_bits(&gb, 4) + 1; |
|
88 |
+ cur_len = (nb ? *data & 0xF : *data >> 4) + 1; |
|
91 | 89 |
counts[cur_len]++; |
92 | 90 |
max_bits = FFMAX(max_bits, cur_len); |
93 | 91 |
lens[i] = cur_len; |
92 |
+ data += nb; |
|
93 |
+ nb ^= 1; |
|
94 | 94 |
} |
95 | 95 |
prefixes[1] = 0; |
96 | 96 |
for (i = 1; i <= 16; i++) |
... | ... |
@@ -425,11 +425,6 @@ static int video_get_buffer(AVCodecContext *s, AVFrame *pic) |
425 | 425 |
buf = &avci->buffer[avci->buffer_count]; |
426 | 426 |
|
427 | 427 |
if(buf->base[0] && (buf->width != w || buf->height != h || buf->pix_fmt != s->pix_fmt)){ |
428 |
- if(s->active_thread_type&FF_THREAD_FRAME) { |
|
429 |
- av_log_missing_feature(s, "Width/height changing with frame threads is", 0); |
|
430 |
- return -1; |
|
431 |
- } |
|
432 |
- |
|
433 | 428 |
for (i = 0; i < AV_NUM_DATA_POINTERS; i++) { |
434 | 429 |
av_freep(&buf->base[i]); |
435 | 430 |
buf->data[i]= NULL; |
... | ... |
@@ -513,6 +508,10 @@ static int video_get_buffer(AVCodecContext *s, AVFrame *pic) |
513 | 513 |
} |
514 | 514 |
pic->extended_data = pic->data; |
515 | 515 |
avci->buffer_count++; |
516 |
+ pic->width = buf->width; |
|
517 |
+ pic->height = buf->height; |
|
518 |
+ pic->format = buf->pix_fmt; |
|
519 |
+ pic->sample_aspect_ratio = s->sample_aspect_ratio; |
|
516 | 520 |
|
517 | 521 |
if (s->pkt) { |
518 | 522 |
pic->pkt_pts = s->pkt->pts; |
... | ... |
@@ -162,11 +162,23 @@ static void update_lf_deltas(VP8Context *s) |
162 | 162 |
VP56RangeCoder *c = &s->c; |
163 | 163 |
int i; |
164 | 164 |
|
165 |
- for (i = 0; i < 4; i++) |
|
166 |
- s->lf_delta.ref[i] = vp8_rac_get_sint(c, 6); |
|
165 |
+ for (i = 0; i < 4; i++) { |
|
166 |
+ if (vp8_rac_get(c)) { |
|
167 |
+ s->lf_delta.ref[i] = vp8_rac_get_uint(c, 6); |
|
168 |
+ |
|
169 |
+ if (vp8_rac_get(c)) |
|
170 |
+ s->lf_delta.ref[i] = -s->lf_delta.ref[i]; |
|
171 |
+ } |
|
172 |
+ } |
|
173 |
+ |
|
174 |
+ for (i = MODE_I4x4; i <= VP8_MVMODE_SPLIT; i++) { |
|
175 |
+ if (vp8_rac_get(c)) { |
|
176 |
+ s->lf_delta.mode[i] = vp8_rac_get_uint(c, 6); |
|
167 | 177 |
|
168 |
- for (i = MODE_I4x4; i <= VP8_MVMODE_SPLIT; i++) |
|
169 |
- s->lf_delta.mode[i] = vp8_rac_get_sint(c, 6); |
|
178 |
+ if (vp8_rac_get(c)) |
|
179 |
+ s->lf_delta.mode[i] = -s->lf_delta.mode[i]; |
|
180 |
+ } |
|
181 |
+ } |
|
170 | 182 |
} |
171 | 183 |
|
172 | 184 |
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 | 160 |
} |
161 | 161 |
return 0; |
162 | 162 |
} |
163 |
+ |
|
164 |
+int ff_avc_write_annexb_extradata(const uint8_t *in, uint8_t **buf, int *size) |
|
165 |
+{ |
|
166 |
+ uint16_t sps_size, pps_size; |
|
167 |
+ uint8_t *out; |
|
168 |
+ int out_size; |
|
169 |
+ |
|
170 |
+ *buf = NULL; |
|
171 |
+ if (*size >= 4 && (AV_RB32(in) == 0x00000001 || AV_RB24(in) == 0x000001)) |
|
172 |
+ return 0; |
|
173 |
+ if (*size < 11 || in[0] != 1) |
|
174 |
+ return AVERROR_INVALIDDATA; |
|
175 |
+ |
|
176 |
+ sps_size = AV_RB16(&in[6]); |
|
177 |
+ if (11 + sps_size > *size) |
|
178 |
+ return AVERROR_INVALIDDATA; |
|
179 |
+ pps_size = AV_RB16(&in[9 + sps_size]); |
|
180 |
+ if (11 + sps_size + pps_size > *size) |
|
181 |
+ return AVERROR_INVALIDDATA; |
|
182 |
+ out_size = 8 + sps_size + pps_size; |
|
183 |
+ out = av_mallocz(out_size); |
|
184 |
+ if (!out) |
|
185 |
+ return AVERROR(ENOMEM); |
|
186 |
+ AV_WB32(&out[0], 0x00000001); |
|
187 |
+ memcpy(out + 4, &in[8], sps_size); |
|
188 |
+ AV_WB32(&out[4 + sps_size], 0x00000001); |
|
189 |
+ memcpy(out + 8 + sps_size, &in[11 + sps_size], pps_size); |
|
190 |
+ *buf = out; |
|
191 |
+ *size = out_size; |
|
192 |
+ return 0; |
|
193 |
+} |
... | ... |
@@ -29,5 +29,6 @@ int ff_avc_parse_nal_units(AVIOContext *s, const uint8_t *buf, int size); |
29 | 29 |
int ff_avc_parse_nal_units_buf(const uint8_t *buf_in, uint8_t **buf, int *size); |
30 | 30 |
int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len); |
31 | 31 |
const uint8_t *ff_avc_find_startcode(const uint8_t *p, const uint8_t *end); |
32 |
+int ff_avc_write_annexb_extradata(const uint8_t *in, uint8_t **buf, int *size); |
|
32 | 33 |
|
33 | 34 |
#endif /* AVFORMAT_AVC_H */ |
... | ... |
@@ -558,7 +558,12 @@ typedef struct AVIndexEntry { |
558 | 558 |
*/ |
559 | 559 |
typedef struct AVStream { |
560 | 560 |
int index; /**< stream index in AVFormatContext */ |
561 |
- int id; /**< format-specific stream ID */ |
|
561 |
+ /** |
|
562 |
+ * Format-specific stream ID. |
|
563 |
+ * decoding: set by libavformat |
|
564 |
+ * encoding: set by the user |
|
565 |
+ */ |
|
566 |
+ int id; |
|
562 | 567 |
AVCodecContext *codec; /**< codec context */ |
563 | 568 |
/** |
564 | 569 |
* 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 | 2158 |
avio_printf(pb, "<param name=\"%s\" value=\"%s\" valuetype=\"data\"/>\n", name, buf); |
2159 | 2159 |
} |
2160 | 2160 |
|
2161 |
-static void write_h264_extradata(AVIOContext *pb, AVCodecContext *enc) |
|
2162 |
-{ |
|
2163 |
- uint16_t sps_size, pps_size, len; |
|
2164 |
- char buf[150]; |
|
2165 |
- sps_size = AV_RB16(&enc->extradata[6]); |
|
2166 |
- if (11 + sps_size > enc->extradata_size) |
|
2167 |
- return; |
|
2168 |
- pps_size = AV_RB16(&enc->extradata[9 + sps_size]); |
|
2169 |
- if (11 + sps_size + pps_size > enc->extradata_size) |
|
2170 |
- return; |
|
2171 |
- len = FFMIN(sizeof(buf)/2 - 1, sps_size); |
|
2172 |
- ff_data_to_hex(buf, &enc->extradata[8], len, 0); |
|
2173 |
- buf[2*len] = '\0'; |
|
2174 |
- avio_printf(pb, "<param name=\"CodecPrivateData\" value=\"00000001%s", buf); |
|
2175 |
- len = FFMIN(sizeof(buf)/2 - 1, pps_size); |
|
2176 |
- ff_data_to_hex(buf, &enc->extradata[11 + sps_size], len, 0); |
|
2177 |
- buf[2*len] = '\0'; |
|
2178 |
- avio_printf(pb, "00000001%s\" valuetype=\"data\"/>\n", buf); |
|
2179 |
-} |
|
2180 |
- |
|
2181 | 2161 |
static int mov_write_isml_manifest(AVIOContext *pb, MOVMuxContext *mov) |
2182 | 2162 |
{ |
2183 | 2163 |
int64_t pos = avio_tell(pb); |
... | ... |
@@ -2219,10 +2199,16 @@ static int mov_write_isml_manifest(AVIOContext *pb, MOVMuxContext *mov) |
2219 | 2219 |
param_write_int(pb, "systemBitrate", track->enc->bit_rate); |
2220 | 2220 |
param_write_int(pb, "trackID", track_id); |
2221 | 2221 |
if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) { |
2222 |
- if (track->enc->codec_id == CODEC_ID_H264 && |
|
2223 |
- track->enc->extradata_size >= 11 && |
|
2224 |
- track->enc->extradata[0] == 1) { |
|
2225 |
- write_h264_extradata(pb, track->enc); |
|
2222 |
+ if (track->enc->codec_id == CODEC_ID_H264) { |
|
2223 |
+ uint8_t *ptr; |
|
2224 |
+ int size = track->enc->extradata_size; |
|
2225 |
+ if (!ff_avc_write_annexb_extradata(track->enc->extradata, &ptr, |
|
2226 |
+ &size)) { |
|
2227 |
+ param_write_hex(pb, "CodecPrivateData", |
|
2228 |
+ ptr ? ptr : track->enc->extradata, |
|
2229 |
+ size); |
|
2230 |
+ av_free(ptr); |
|
2231 |
+ } |
|
2226 | 2232 |
} else { |
2227 | 2233 |
param_write_hex(pb, "CodecPrivateData", track->enc->extradata, |
2228 | 2234 |
track->enc->extradata_size); |