1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-04-02 20:35:37 +02:00

Merge remote-tracking branch 'qatar/master'

* qatar/master:
  yuv4mpeg: reject unsupported codecs
  nutenc: K&R formatting cosmetics
  assdec: fix qsort() callback signature
  configure: detect sparc64 automatically
  vp8: fix memset() crossing array boundary
  h264: fix invalid pointer arithmetic
  amrwbdec: fix invalid pointer arithmetic

Conflicts:
	libavformat/nutenc.c
	libavformat/yuv4mpeg.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2012-10-28 14:04:43 +01:00
commit c73fcc8de3
6 changed files with 415 additions and 377 deletions

9
configure vendored
View File

@ -2745,9 +2745,8 @@ case "$arch" in
sh4|sh) sh4|sh)
arch="sh4" arch="sh4"
;; ;;
sun4u|sparc64) sun4u|sparc*)
arch="sparc" arch="sparc"
subarch="sparc64"
;; ;;
tilegx|tile-gx) tilegx|tile-gx)
arch="tilegx" arch="tilegx"
@ -2965,7 +2964,7 @@ check_64bit(){
} }
case "$arch" in case "$arch" in
alpha|ia64|sparc) alpha|ia64)
spic=$shared spic=$shared
;; ;;
mips) mips)
@ -2979,6 +2978,10 @@ case "$arch" in
ppc) ppc)
check_64bit ppc ppc64 'sizeof(void *) > 4' check_64bit ppc ppc64 'sizeof(void *) > 4'
;; ;;
sparc)
check_64bit sparc sparc64 'sizeof(void *) > 4'
spic=$shared
;;
x86) x86)
check_64bit x86_32 x86_64 'sizeof(void *) > 4' check_64bit x86_32 x86_64 'sizeof(void *) > 4'
if test "$subarch" = "x86_64"; then if test "$subarch" = "x86_64"; then

View File

@ -918,10 +918,9 @@ static float auto_correlation(float *diff_isf, float mean, int lag)
static void extrapolate_isf(float isf[LP_ORDER_16k]) static void extrapolate_isf(float isf[LP_ORDER_16k])
{ {
float diff_isf[LP_ORDER - 2], diff_mean; float diff_isf[LP_ORDER - 2], diff_mean;
float *diff_hi = diff_isf - LP_ORDER + 1; // diff array for extrapolated indexes
float corr_lag[3]; float corr_lag[3];
float est, scale; float est, scale;
int i, i_max_corr; int i, j, i_max_corr;
isf[LP_ORDER_16k - 1] = isf[LP_ORDER - 1]; isf[LP_ORDER_16k - 1] = isf[LP_ORDER - 1];
@ -952,20 +951,20 @@ static void extrapolate_isf(float isf[LP_ORDER_16k])
scale = 0.5 * (FFMIN(est, 7600) - isf[LP_ORDER - 2]) / scale = 0.5 * (FFMIN(est, 7600) - isf[LP_ORDER - 2]) /
(isf[LP_ORDER_16k - 2] - isf[LP_ORDER - 2]); (isf[LP_ORDER_16k - 2] - isf[LP_ORDER - 2]);
for (i = LP_ORDER - 1; i < LP_ORDER_16k - 1; i++) for (i = LP_ORDER - 1, j = 0; i < LP_ORDER_16k - 1; i++, j++)
diff_hi[i] = scale * (isf[i] - isf[i - 1]); diff_isf[j] = scale * (isf[i] - isf[i - 1]);
/* Stability insurance */ /* Stability insurance */
for (i = LP_ORDER; i < LP_ORDER_16k - 1; i++) for (i = 1; i < LP_ORDER_16k - LP_ORDER; i++)
if (diff_hi[i] + diff_hi[i - 1] < 5.0) { if (diff_isf[i] + diff_isf[i - 1] < 5.0) {
if (diff_hi[i] > diff_hi[i - 1]) { if (diff_isf[i] > diff_isf[i - 1]) {
diff_hi[i - 1] = 5.0 - diff_hi[i]; diff_isf[i - 1] = 5.0 - diff_isf[i];
} else } else
diff_hi[i] = 5.0 - diff_hi[i - 1]; diff_isf[i] = 5.0 - diff_isf[i - 1];
} }
for (i = LP_ORDER - 1; i < LP_ORDER_16k - 1; i++) for (i = LP_ORDER - 1, j = 0; i < LP_ORDER_16k - 1; i++, j++)
isf[i] = isf[i - 1] + diff_hi[i] * (1.0f / (1 << 15)); isf[i] = isf[i - 1] + diff_isf[j] * (1.0f / (1 << 15));
/* Scale the ISF vector for 16000 Hz */ /* Scale the ISF vector for 16000 Hz */
for (i = 0; i < LP_ORDER_16k - 1; i++) for (i = 0; i < LP_ORDER_16k - 1; i++)

View File

@ -1965,7 +1965,8 @@ static int vp8_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
// top edge of 127 for intra prediction // top edge of 127 for intra prediction
if (!(avctx->flags & CODEC_FLAG_EMU_EDGE)) { if (!(avctx->flags & CODEC_FLAG_EMU_EDGE)) {
s->top_border[0][15] = s->top_border[0][23] = 127; s->top_border[0][15] = s->top_border[0][23] = 127;
memset(s->top_border[1]-1, 127, s->mb_width*sizeof(*s->top_border)+1); s->top_border[0][31] = 127;
memset(s->top_border[1], 127, s->mb_width*sizeof(*s->top_border));
} }
memset(s->ref_count, 0, sizeof(s->ref_count)); memset(s->ref_count, 0, sizeof(s->ref_count));

View File

@ -68,8 +68,9 @@ static int64_t get_pts(const uint8_t *p)
return sec*100+hsec; return sec*100+hsec;
} }
static int event_cmp(uint8_t **a, uint8_t **b) static int event_cmp(const void *_a, const void *_b)
{ {
const uint8_t *const *a = _a, *const *b = _b;
return get_pts(*a) - get_pts(*b); return get_pts(*a) - get_pts(*b);
} }
@ -131,7 +132,7 @@ static int read_header(AVFormatContext *s)
p++; p++;
} }
qsort(ass->event, ass->event_count, sizeof(*ass->event), (void*)event_cmp); qsort(ass->event, ass->event_count, sizeof(*ass->event), event_cmp);
return 0; return 0;

View File

@ -29,7 +29,9 @@
#include "internal.h" #include "internal.h"
#include "avio_internal.h" #include "avio_internal.h"
static int find_expected_header(AVCodecContext *c, int size, int key_frame, uint8_t out[64]){ static int find_expected_header(AVCodecContext *c, int size, int key_frame,
uint8_t out[64])
{
int sample_rate = c->sample_rate; int sample_rate = c->sample_rate;
if (size > 4096) if (size > 4096)
@ -44,11 +46,13 @@ static int find_expected_header(AVCodecContext *c, int size, int key_frame, uint
out[3] = 0xB6; out[3] = 0xB6;
return 4; return 4;
} }
}else if(c->codec_id == AV_CODEC_ID_MPEG1VIDEO || c->codec_id == AV_CODEC_ID_MPEG2VIDEO){ } else if (c->codec_id == AV_CODEC_ID_MPEG1VIDEO ||
c->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
return 3; return 3;
} else if (c->codec_id == AV_CODEC_ID_H264) { } else if (c->codec_id == AV_CODEC_ID_H264) {
return 3; return 3;
}else if(c->codec_id == AV_CODEC_ID_MP3 || c->codec_id == AV_CODEC_ID_MP2){ } else if (c->codec_id == AV_CODEC_ID_MP3 ||
c->codec_id == AV_CODEC_ID_MP2) {
int lsf, mpeg25, sample_rate_index, bitrate_index, frame_size; int lsf, mpeg25, sample_rate_index, bitrate_index, frame_size;
int layer = c->codec_id == AV_CODEC_ID_MP3 ? 3 : 2; int layer = c->codec_id == AV_CODEC_ID_MP3 ? 3 : 2;
unsigned int header = 0xFFF00000; unsigned int header = 0xFFF00000;
@ -63,8 +67,10 @@ static int find_expected_header(AVCodecContext *c, int size, int key_frame, uint
sample_rate = avpriv_mpa_freq_tab[sample_rate_index] >> (lsf + mpeg25); sample_rate = avpriv_mpa_freq_tab[sample_rate_index] >> (lsf + mpeg25);
for (bitrate_index = 2; bitrate_index < 30; bitrate_index++) { for (bitrate_index = 2; bitrate_index < 30; bitrate_index++) {
frame_size = avpriv_mpa_bitrate_tab[lsf][layer-1][bitrate_index>>1]; frame_size =
frame_size = (frame_size * 144000) / (sample_rate << lsf) + (bitrate_index&1); avpriv_mpa_bitrate_tab[lsf][layer - 1][bitrate_index >> 1];
frame_size = (frame_size * 144000) / (sample_rate << lsf) +
(bitrate_index & 1);
if (frame_size == size) if (frame_size == size)
break; break;
@ -90,22 +96,24 @@ static int find_expected_header(AVCodecContext *c, int size, int key_frame, uint
return 0; return 0;
} }
static int find_header_idx(AVFormatContext *s, AVCodecContext *c, int size, int frame_type){ static int find_header_idx(AVFormatContext *s, AVCodecContext *c, int size, int frame_type)
{
NUTContext *nut = s->priv_data; NUTContext *nut = s->priv_data;
uint8_t out[64]; uint8_t out[64];
int i; int i;
int len = find_expected_header(c, size, frame_type, out); int len = find_expected_header(c, size, frame_type, out);
for (i = 1; i < nut->header_count; i++) { for (i = 1; i < nut->header_count; i++) {
if( len == nut->header_len[i] if (len == nut->header_len[i] && !memcmp(out, nut->header[i], len)) {
&& !memcmp(out, nut->header[i], len)){
return i; return i;
} }
} }
return 0; return 0;
} }
static void build_elision_headers(AVFormatContext *s){ static void build_elision_headers(AVFormatContext *s)
{
NUTContext *nut = s->priv_data; NUTContext *nut = s->priv_data;
int i; int i;
//FIXME this is lame //FIXME this is lame
@ -126,7 +134,8 @@ static void build_elision_headers(AVFormatContext *s){
} }
} }
static void build_frame_code(AVFormatContext *s){ static void build_frame_code(AVFormatContext *s)
{
NUTContext *nut = s->priv_data; NUTContext *nut = s->priv_data;
int key_frame, index, pred, stream_id; int key_frame, index, pred, stream_id;
int start = 1; int start = 1;
@ -171,10 +180,7 @@ static void build_frame_code(AVFormatContext *s){
frame_size = 1; frame_size = 1;
for (key_frame = 0; key_frame < 2; key_frame++) { for (key_frame = 0; key_frame < 2; key_frame++) {
if(intra_only && keyframe_0_esc && key_frame==0) if (!intra_only || !keyframe_0_esc || key_frame != 0) {
continue;
{
FrameCode *ft = &nut->frame_code[start2]; FrameCode *ft = &nut->frame_code[start2];
ft->flags = FLAG_KEY * key_frame; ft->flags = FLAG_KEY * key_frame;
ft->flags |= FLAG_SIZE_MSB | FLAG_CODED_PTS; ft->flags |= FLAG_SIZE_MSB | FLAG_CODED_PTS;
@ -189,7 +195,8 @@ static void build_frame_code(AVFormatContext *s){
key_frame = intra_only; key_frame = intra_only;
#if 1 #if 1
if (is_audio) { if (is_audio) {
int frame_bytes= codec->frame_size*(int64_t)codec->bit_rate / (8*codec->sample_rate); int frame_bytes = codec->frame_size * (int64_t)codec->bit_rate /
(8 * codec->sample_rate);
int pts; int pts;
for (pts = 0; pts < 2; pts++) { for (pts = 0; pts < 2; pts++) {
for (pred = 0; pred < 2; pred++) { for (pred = 0; pred < 2; pred++) {
@ -256,23 +263,25 @@ static void build_frame_code(AVFormatContext *s){
nut->frame_code['N'].flags = FLAG_INVALID; nut->frame_code['N'].flags = FLAG_INVALID;
} }
static void put_tt(NUTContext *nut, AVRational *time_base, AVIOContext *bc, uint64_t val){ static void put_tt(NUTContext *nut, AVRational *time_base, AVIOContext *bc, uint64_t val)
{
val *= nut->time_base_count; val *= nut->time_base_count;
val += time_base - nut->time_base; val += time_base - nut->time_base;
ff_put_v(bc, val); ff_put_v(bc, val);
} }
/** /**
* Store a string as vb. * Store a string as vb.
*/ */
static void put_str(AVIOContext *bc, const char *string){ static void put_str(AVIOContext *bc, const char *string)
{
int len = strlen(string); int len = strlen(string);
ff_put_v(bc, len); ff_put_v(bc, len);
avio_write(bc, string, len); avio_write(bc, string, len);
} }
static void put_s(AVIOContext *bc, int64_t val){ static void put_s(AVIOContext *bc, int64_t val)
{
ff_put_v(bc, 2 * FFABS(val) - (val > 0)); ff_put_v(bc, 2 * FFABS(val) - (val > 0));
} }
@ -285,8 +294,7 @@ static inline void ff_put_v_trace(AVIOContext *bc, uint64_t v, const char *file,
ff_put_v(bc, v); ff_put_v(bc, v);
} }
static inline void put_s_trace(AVIOContext *bc, int64_t v, const char *file, static inline void put_s_trace(AVIOContext *bc, int64_t v, const char *file, const char *func, int line)
const char *func, int line)
{ {
av_log(NULL, AV_LOG_DEBUG, "put_s %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line); av_log(NULL, AV_LOG_DEBUG, "put_s %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line);
@ -297,7 +305,9 @@ static inline void put_s_trace(AVIOContext *bc, int64_t v, const char *file,
#endif #endif
//FIXME remove calculate_checksum //FIXME remove calculate_checksum
static void put_packet(NUTContext *nut, AVIOContext *bc, AVIOContext *dyn_bc, int calculate_checksum, uint64_t startcode){ static void put_packet(NUTContext *nut, AVIOContext *bc, AVIOContext *dyn_bc,
int calculate_checksum, uint64_t startcode)
{
uint8_t *dyn_buf = NULL; uint8_t *dyn_buf = NULL;
int dyn_size = avio_close_dyn_buf(dyn_bc, &dyn_buf); int dyn_size = avio_close_dyn_buf(dyn_bc, &dyn_buf);
int forw_ptr = dyn_size + 4 * calculate_checksum; int forw_ptr = dyn_size + 4 * calculate_checksum;
@ -318,8 +328,10 @@ static void put_packet(NUTContext *nut, AVIOContext *bc, AVIOContext *dyn_bc, in
av_free(dyn_buf); av_free(dyn_buf);
} }
static void write_mainheader(NUTContext *nut, AVIOContext *bc){ static void write_mainheader(NUTContext *nut, AVIOContext *bc)
int i, j, tmp_pts, tmp_flags, tmp_stream, tmp_mul, tmp_size, tmp_fields, tmp_head_idx; {
int i, j, tmp_pts, tmp_flags, tmp_stream, tmp_mul, tmp_size, tmp_fields,
tmp_head_idx;
int64_t tmp_match; int64_t tmp_match;
ff_put_v(bc, 3); /* version */ ff_put_v(bc, 3); /* version */
@ -361,15 +373,17 @@ static void write_mainheader(NUTContext *nut, AVIOContext *bc){
j--; j--;
continue; continue;
} }
if(nut->frame_code[i].pts_delta != tmp_pts ) break; if (nut->frame_code[i].pts_delta != tmp_pts ||
if(nut->frame_code[i].flags != tmp_flags ) break; nut->frame_code[i].flags != tmp_flags ||
if(nut->frame_code[i].stream_id != tmp_stream) break; nut->frame_code[i].stream_id != tmp_stream ||
if(nut->frame_code[i].size_mul != tmp_mul ) break; nut->frame_code[i].size_mul != tmp_mul ||
if(nut->frame_code[i].size_lsb != tmp_size+j) break; nut->frame_code[i].size_lsb != tmp_size + j ||
// if(nut->frame_code[i].res != tmp_res ) break; // nut->frame_code[i].res != tmp_res ||
if(nut->frame_code[i].header_idx!= tmp_head_idx) break; nut->frame_code[i].header_idx != tmp_head_idx)
break;
} }
if(j != tmp_mul - tmp_size) tmp_fields=6; if (j != tmp_mul - tmp_size)
tmp_fields = 6;
ff_put_v(bc, tmp_flags); ff_put_v(bc, tmp_flags);
ff_put_v(bc, tmp_fields); ff_put_v(bc, tmp_fields);
@ -389,9 +403,12 @@ static void write_mainheader(NUTContext *nut, AVIOContext *bc){
} }
} }
static int write_streamheader(AVFormatContext *avctx, AVIOContext *bc, AVStream *st, int i){ static int write_streamheader(AVFormatContext *avctx, AVIOContext *bc,
AVStream *st, int i)
{
NUTContext *nut = avctx->priv_data; NUTContext *nut = avctx->priv_data;
AVCodecContext *codec = st->codec; AVCodecContext *codec = st->codec;
ff_put_v(bc, i); ff_put_v(bc, i);
switch (codec->codec_type) { switch (codec->codec_type) {
case AVMEDIA_TYPE_VIDEO: ff_put_v(bc, 0); break; case AVMEDIA_TYPE_VIDEO: ff_put_v(bc, 0); break;
@ -426,7 +443,8 @@ static int write_streamheader(AVFormatContext *avctx, AVIOContext *bc, AVStream
ff_put_v(bc, codec->width); ff_put_v(bc, codec->width);
ff_put_v(bc, codec->height); ff_put_v(bc, codec->height);
if(st->sample_aspect_ratio.num<=0 || st->sample_aspect_ratio.den<=0){ if (st->sample_aspect_ratio.num <= 0 ||
st->sample_aspect_ratio.den <= 0) {
ff_put_v(bc, 0); ff_put_v(bc, 0);
ff_put_v(bc, 0); ff_put_v(bc, 0);
} else { } else {
@ -441,14 +459,16 @@ static int write_streamheader(AVFormatContext *avctx, AVIOContext *bc, AVStream
return 0; return 0;
} }
static int add_info(AVIOContext *bc, const char *type, const char *value){ static int add_info(AVIOContext *bc, const char *type, const char *value)
{
put_str(bc, type); put_str(bc, type);
put_s(bc, -1); put_s(bc, -1);
put_str(bc, value); put_str(bc, value);
return 1; return 1;
} }
static int write_globalinfo(NUTContext *nut, AVIOContext *bc){ static int write_globalinfo(NUTContext *nut, AVIOContext *bc)
{
AVFormatContext *s = nut->avf; AVFormatContext *s = nut->avf;
AVDictionaryEntry *t = NULL; AVDictionaryEntry *t = NULL;
AVIOContext *dyn_bc; AVIOContext *dyn_bc;
@ -586,7 +606,8 @@ static int write_index(NUTContext *nut, AVIOContext *bc){
return 0; return 0;
} }
static int write_headers(AVFormatContext *avctx, AVIOContext *bc){ static int write_headers(AVFormatContext *avctx, AVIOContext *bc)
{
NUTContext *nut = avctx->priv_data; NUTContext *nut = avctx->priv_data;
AVIOContext *dyn_bc; AVIOContext *dyn_bc;
int i, ret; int i, ret;
@ -603,7 +624,8 @@ static int write_headers(AVFormatContext *avctx, AVIOContext *bc){
ret = avio_open_dyn_buf(&dyn_bc); ret = avio_open_dyn_buf(&dyn_bc);
if (ret < 0) if (ret < 0)
return ret; return ret;
if ((ret = write_streamheader(avctx, dyn_bc, nut->avf->streams[i], i)) < 0) ret = write_streamheader(avctx, dyn_bc, nut->avf->streams[i], i);
if (ret < 0)
return ret; return ret;
put_packet(nut, bc, dyn_bc, 1, STREAM_STARTCODE); put_packet(nut, bc, dyn_bc, 1, STREAM_STARTCODE);
} }
@ -649,7 +671,8 @@ static int write_headers(AVFormatContext *avctx, AVIOContext *bc){
return 0; return 0;
} }
static int nut_write_header(AVFormatContext *s){ static int nut_write_header(AVFormatContext *s)
{
NUTContext *nut = s->priv_data; NUTContext *nut = s->priv_data;
AVIOContext *bc = s->pb; AVIOContext *bc = s->pb;
int i, j, ret; int i, j, ret;
@ -681,11 +704,10 @@ static int nut_write_header(AVFormatContext *s){
avpriv_set_pts_info(st, 64, time_base.num, time_base.den); avpriv_set_pts_info(st, 64, time_base.num, time_base.den);
for(j=0; j<nut->time_base_count; j++){ for (j = 0; j < nut->time_base_count; j++)
if (!memcmp(&time_base, &nut->time_base[j], sizeof(AVRational))) { if (!memcmp(&time_base, &nut->time_base[j], sizeof(AVRational))) {
break; break;
} }
}
nut->time_base[j] = time_base; nut->time_base[j] = time_base;
nut->stream[i].time_base = &nut->time_base[j]; nut->stream[i].time_base = &nut->time_base[j];
if (j == nut->time_base_count) if (j == nut->time_base_count)
@ -695,16 +717,16 @@ static int nut_write_header(AVFormatContext *s){
nut->stream[i].msb_pts_shift = 7; nut->stream[i].msb_pts_shift = 7;
else else
nut->stream[i].msb_pts_shift = 14; nut->stream[i].msb_pts_shift = 14;
nut->stream[i].max_pts_distance= FFMAX(time_base.den, time_base.num) / time_base.num; nut->stream[i].max_pts_distance =
FFMAX(time_base.den, time_base.num) / time_base.num;
} }
for (i = 0; i < s->nb_chapters; i++) { for (i = 0; i < s->nb_chapters; i++) {
AVChapter *ch = s->chapters[i]; AVChapter *ch = s->chapters[i];
for (j = 0; j < nut->time_base_count; j++) { for (j = 0; j < nut->time_base_count; j++)
if (!memcmp(&ch->time_base, &nut->time_base[j], sizeof(AVRational))) if (!memcmp(&ch->time_base, &nut->time_base[j], sizeof(AVRational)))
break; break;
}
nut->time_base[j] = ch->time_base; nut->time_base[j] = ch->time_base;
nut->chapter[i].time_base = &nut->time_base[j]; nut->chapter[i].time_base = &nut->time_base[j];
@ -731,25 +753,34 @@ static int nut_write_header(AVFormatContext *s){
return 0; return 0;
} }
static int get_needed_flags(NUTContext *nut, StreamContext *nus, FrameCode *fc, AVPacket *pkt){ static int get_needed_flags(NUTContext *nut, StreamContext *nus, FrameCode *fc,
AVPacket *pkt)
{
int flags = 0; int flags = 0;
if(pkt->flags & AV_PKT_FLAG_KEY ) flags |= FLAG_KEY; if (pkt->flags & AV_PKT_FLAG_KEY)
if(pkt->stream_index != fc->stream_id ) flags |= FLAG_STREAM_ID; flags |= FLAG_KEY;
if(pkt->size / fc->size_mul ) flags |= FLAG_SIZE_MSB; if (pkt->stream_index != fc->stream_id)
if(pkt->pts - nus->last_pts != fc->pts_delta) flags |= FLAG_CODED_PTS; flags |= FLAG_STREAM_ID;
if(pkt->size > 2*nut->max_distance ) flags |= FLAG_CHECKSUM; if (pkt->size / fc->size_mul)
if(FFABS(pkt->pts - nus->last_pts) flags |= FLAG_SIZE_MSB;
> nus->max_pts_distance) flags |= FLAG_CHECKSUM; if (pkt->pts - nus->last_pts != fc->pts_delta)
if( pkt->size < nut->header_len[fc->header_idx] flags |= FLAG_CODED_PTS;
|| (pkt->size > 4096 && fc->header_idx) if (pkt->size > 2 * nut->max_distance)
|| memcmp(pkt->data, nut->header[fc->header_idx], nut->header_len[fc->header_idx])) flags |= FLAG_CHECKSUM;
if (FFABS(pkt->pts - nus->last_pts) > nus->max_pts_distance)
flags |= FLAG_CHECKSUM;
if (pkt->size < nut->header_len[fc->header_idx] ||
(pkt->size > 4096 && fc->header_idx) ||
memcmp(pkt->data, nut->header[fc->header_idx],
nut->header_len[fc->header_idx]))
flags |= FLAG_HEADER_IDX; flags |= FLAG_HEADER_IDX;
return flags | (fc->flags & FLAG_CODED); return flags | (fc->flags & FLAG_CODED);
} }
static int find_best_header_idx(NUTContext *nut, AVPacket *pkt){ static int find_best_header_idx(NUTContext *nut, AVPacket *pkt)
{
int i; int i;
int best_i = 0; int best_i = 0;
int best_len = 0; int best_len = 0;
@ -757,24 +788,25 @@ static int find_best_header_idx(NUTContext *nut, AVPacket *pkt){
if (pkt->size > 4096) if (pkt->size > 4096)
return 0; return 0;
for(i=1; i<nut->header_count; i++){ for (i = 1; i < nut->header_count; i++)
if (pkt->size >= nut->header_len[i] if (pkt->size >= nut->header_len[i]
&& nut->header_len[i] > best_len && nut->header_len[i] > best_len
&& !memcmp(pkt->data, nut->header[i], nut->header_len[i])) { && !memcmp(pkt->data, nut->header[i], nut->header_len[i])) {
best_i = i; best_i = i;
best_len = nut->header_len[i]; best_len = nut->header_len[i];
} }
}
return best_i; return best_i;
} }
static int nut_write_packet(AVFormatContext *s, AVPacket *pkt){ static int nut_write_packet(AVFormatContext *s, AVPacket *pkt)
{
NUTContext *nut = s->priv_data; NUTContext *nut = s->priv_data;
StreamContext *nus = &nut->stream[pkt->stream_index]; StreamContext *nus = &nut->stream[pkt->stream_index];
AVIOContext *bc = s->pb, *dyn_bc; AVIOContext *bc = s->pb, *dyn_bc;
FrameCode *fc; FrameCode *fc;
int64_t coded_pts; int64_t coded_pts;
int best_length, frame_code, flags, needed_flags, i, header_idx, best_header_idx; int best_length, frame_code, flags, needed_flags, i, header_idx;
int best_header_idx;
int key_frame = !!(pkt->flags & AV_PKT_FLAG_KEY); int key_frame = !!(pkt->flags & AV_PKT_FLAG_KEY);
int store_sp = 0; int store_sp = 0;
int ret; int ret;
@ -805,8 +837,10 @@ static int nut_write_packet(AVFormatContext *s, AVPacket *pkt){
nus->time_base->num * (int64_t)nut->stream[i].time_base->den, nus->time_base->num * (int64_t)nut->stream[i].time_base->den,
nus->time_base->den * (int64_t)nut->stream[i].time_base->num, nus->time_base->den * (int64_t)nut->stream[i].time_base->num,
AV_ROUND_DOWN); AV_ROUND_DOWN);
int index= av_index_search_timestamp(st, dts_tb, AVSEEK_FLAG_BACKWARD); int index = av_index_search_timestamp(st, dts_tb,
if(index>=0) dummy.pos= FFMIN(dummy.pos, st->index_entries[index].pos); AVSEEK_FLAG_BACKWARD);
if (index >= 0)
dummy.pos = FFMIN(dummy.pos, st->index_entries[index].pos);
} }
if (dummy.pos == INT64_MAX) if (dummy.pos == INT64_MAX)
dummy.pos = 0; dummy.pos = 0;
@ -943,7 +977,8 @@ static int nut_write_packet(AVFormatContext *s, AVPacket *pkt){
return 0; return 0;
} }
static int nut_write_trailer(AVFormatContext *s){ static int nut_write_trailer(AVFormatContext *s)
{
NUTContext *nut = s->priv_data; NUTContext *nut = s->priv_data;
AVIOContext *bc = s->pb, *dyn_bc; AVIOContext *bc = s->pb, *dyn_bc;
int i, ret; int i, ret;

View File

@ -216,9 +216,8 @@ static int yuv4_write_header(AVFormatContext *s)
return AVERROR(EIO); return AVERROR(EIO);
if (s->streams[0]->codec->codec_id != AV_CODEC_ID_RAWVIDEO) { if (s->streams[0]->codec->codec_id != AV_CODEC_ID_RAWVIDEO) {
av_log(s, AV_LOG_ERROR, av_log(s, AV_LOG_ERROR, "ERROR: Only rawvideo supported.\n");
"A non-rawvideo stream was selected, but yuv4mpeg only handles rawvideo streams\n"); return AVERROR_INVALIDDATA;
return AVERROR(EINVAL);
} }
switch (s->streams[0]->codec->pix_fmt) { switch (s->streams[0]->codec->pix_fmt) {