From 64bde8056337bb656a11f3c9e2857c10b94e2871 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Wed, 2 May 2012 15:45:18 -0700 Subject: mp3/ac3 probe: search for PES headers to prevent probing MPEG-PS as MP3. --- libavformat/ac3dec.c | 30 +++++++++++++++++++++++++----- libavformat/mp3dec.c | 30 +++++++++++++++++++++++++----- 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/libavformat/ac3dec.c b/libavformat/ac3dec.c index 60c3cf97e4..c2e3301a23 100644 --- a/libavformat/ac3dec.c +++ b/libavformat/ac3dec.c @@ -57,11 +57,31 @@ static int ac3_eac3_probe(AVProbeData *p, enum CodecID expected_codec_id) if(codec_id != expected_codec_id) return 0; // keep this in sync with mp3 probe, both need to avoid // issues with MPEG-files! - if (first_frames>=4) return AVPROBE_SCORE_MAX/2+1; - else if(max_frames>500)return AVPROBE_SCORE_MAX/2; - else if(max_frames>=4) return AVPROBE_SCORE_MAX/4; - else if(max_frames>=1) return 1; - else return 0; + if (first_frames >= 4) return AVPROBE_SCORE_MAX / 2 + 1; + + if (max_frames) { + int pes = 0, i; + unsigned int code = -1; + +#define VIDEO_ID 0x000001e0 +#define AUDIO_ID 0x000001c0 + /* do a search for mpegps headers to be able to properly bias + * towards mpegps if we detect this stream as both. */ + for (i = 0; ibuf_size; i++) { + code = (code << 8) + p->buf[i]; + if ((code & 0xffffff00) == 0x100) { + if ((code & 0x1f0) == VIDEO_ID) pes++; + else if((code & 0x1e0) == AUDIO_ID) pes++; + } + } + + if (pes) + max_frames = (max_frames + pes - 1) / pes; + } + if (max_frames > 500) return AVPROBE_SCORE_MAX / 2; + else if (max_frames >= 4) return AVPROBE_SCORE_MAX / 4; + else if (max_frames >= 1) return 1; + else return 0; } #if CONFIG_AC3_DEMUXER diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index d233209f97..39875201e3 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -63,11 +63,31 @@ static int mp3_read_probe(AVProbeData *p) } // keep this in sync with ac3 probe, both need to avoid // issues with MPEG-files! - if (first_frames>=4) return AVPROBE_SCORE_MAX/2+1; - else if(max_frames>500)return AVPROBE_SCORE_MAX/2; - else if(max_frames>=4) return AVPROBE_SCORE_MAX/4; - else if(max_frames>=1) return 1; - else return 0; + if (first_frames >= 4) return AVPROBE_SCORE_MAX / 2 + 1; + + if (max_frames) { + int pes = 0, i; + unsigned int code = -1; + +#define VIDEO_ID 0x000001e0 +#define AUDIO_ID 0x000001c0 + /* do a search for mpegps headers to be able to properly bias + * towards mpegps if we detect this stream as both. */ + for (i = 0; ibuf_size; i++) { + code = (code << 8) + p->buf[i]; + if ((code & 0xffffff00) == 0x100) { + if ((code & 0x1f0) == VIDEO_ID) pes++; + else if((code & 0x1e0) == AUDIO_ID) pes++; + } + } + + if (pes) + max_frames = (max_frames + pes - 1) / pes; + } + if (max_frames > 500) return AVPROBE_SCORE_MAX / 2; + else if (max_frames >= 4) return AVPROBE_SCORE_MAX / 4; + else if (max_frames >= 1) return 1; + else return 0; //mpegps_mp3_unrecognized_format.mpg has max_frames=3 } -- cgit v1.2.3 From 6163d880c0ac8b84b45d1f7a94719c5a0a6b5cb9 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Tue, 29 May 2012 10:56:15 -0700 Subject: vp8: move block coeff arithcoder on stack. This prevents gcc from assuming that contents of it may have changed between calls to vp56_range_get_prob(), thus preventing countless (and unnecessary) movs. Decoding of sintel trailer goes from (avg+SG) 9.796 +/- 0.003 to 9.635 +/- 0.010. --- libavcodec/vp8.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c index d9fdd4da44..94200f68ac 100644 --- a/libavcodec/vp8.c +++ b/libavcodec/vp8.c @@ -707,56 +707,58 @@ void decode_mb_mode(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y, uint8_ * @return 0 if no coeffs were decoded * otherwise, the index of the last coeff decoded plus one */ -static int decode_block_coeffs_internal(VP56RangeCoder *c, DCTELEM block[16], +static int decode_block_coeffs_internal(VP56RangeCoder *r, DCTELEM block[16], uint8_t probs[16][3][NUM_DCT_TOKENS-1], int i, uint8_t *token_prob, int16_t qmul[2]) { + VP56RangeCoder c = *r; goto skip_eob; do { int coeff; - if (!vp56_rac_get_prob_branchy(c, token_prob[0])) // DCT_EOB - return i; + if (!vp56_rac_get_prob_branchy(&c, token_prob[0])) // DCT_EOB + break; skip_eob: - if (!vp56_rac_get_prob_branchy(c, token_prob[1])) { // DCT_0 + if (!vp56_rac_get_prob_branchy(&c, token_prob[1])) { // DCT_0 if (++i == 16) - return i; // invalid input; blocks should end with EOB + break; // invalid input; blocks should end with EOB token_prob = probs[i][0]; goto skip_eob; } - if (!vp56_rac_get_prob_branchy(c, token_prob[2])) { // DCT_1 + if (!vp56_rac_get_prob_branchy(&c, token_prob[2])) { // DCT_1 coeff = 1; token_prob = probs[i+1][1]; } else { - if (!vp56_rac_get_prob_branchy(c, token_prob[3])) { // DCT 2,3,4 - coeff = vp56_rac_get_prob_branchy(c, token_prob[4]); + if (!vp56_rac_get_prob_branchy(&c, token_prob[3])) { // DCT 2,3,4 + coeff = vp56_rac_get_prob_branchy(&c, token_prob[4]); if (coeff) - coeff += vp56_rac_get_prob(c, token_prob[5]); + coeff += vp56_rac_get_prob(&c, token_prob[5]); coeff += 2; } else { // DCT_CAT* - if (!vp56_rac_get_prob_branchy(c, token_prob[6])) { - if (!vp56_rac_get_prob_branchy(c, token_prob[7])) { // DCT_CAT1 - coeff = 5 + vp56_rac_get_prob(c, vp8_dct_cat1_prob[0]); + if (!vp56_rac_get_prob_branchy(&c, token_prob[6])) { + if (!vp56_rac_get_prob_branchy(&c, token_prob[7])) { // DCT_CAT1 + coeff = 5 + vp56_rac_get_prob(&c, vp8_dct_cat1_prob[0]); } else { // DCT_CAT2 coeff = 7; - coeff += vp56_rac_get_prob(c, vp8_dct_cat2_prob[0]) << 1; - coeff += vp56_rac_get_prob(c, vp8_dct_cat2_prob[1]); + coeff += vp56_rac_get_prob(&c, vp8_dct_cat2_prob[0]) << 1; + coeff += vp56_rac_get_prob(&c, vp8_dct_cat2_prob[1]); } } else { // DCT_CAT3 and up - int a = vp56_rac_get_prob(c, token_prob[8]); - int b = vp56_rac_get_prob(c, token_prob[9+a]); + int a = vp56_rac_get_prob(&c, token_prob[8]); + int b = vp56_rac_get_prob(&c, token_prob[9+a]); int cat = (a<<1) + b; coeff = 3 + (8< Date: Wed, 30 May 2012 08:48:26 -0400 Subject: lavfi: amix: check active input count before calling request_samples fixes use of the amix filter with only 1 input --- libavfilter/af_amix.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/libavfilter/af_amix.c b/libavfilter/af_amix.c index 3399b7c051..d4af9a4234 100644 --- a/libavfilter/af_amix.c +++ b/libavfilter/af_amix.c @@ -389,6 +389,10 @@ static int request_frame(AVFilterLink *outlink) int ret; int wanted_samples, available_samples; + ret = calc_active_inputs(s); + if (ret < 0) + return ret; + if (s->input_state[0] == INPUT_OFF) { ret = request_samples(ctx, 1); if (ret < 0) @@ -419,15 +423,16 @@ static int request_frame(AVFilterLink *outlink) av_assert0(s->frame_list->nb_frames > 0); wanted_samples = frame_list_next_frame_size(s->frame_list); - ret = request_samples(ctx, wanted_samples); - if (ret < 0) - return ret; - - ret = calc_active_inputs(s); - if (ret < 0) - return ret; if (s->active_inputs > 1) { + ret = request_samples(ctx, wanted_samples); + if (ret < 0) + return ret; + + ret = calc_active_inputs(s); + if (ret < 0) + return ret; + available_samples = get_available_samples(s); if (!available_samples) return 0; -- cgit v1.2.3 From 1876e7c0c2ec0d4a9c2daa45e0ab311b1c2ac413 Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Wed, 30 May 2012 11:27:18 +0200 Subject: http: Add 'post_data', a new option which sets custom HTTP post data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows doing http posts with a content-length header sent in advance, avoiding chunked encoding. Signed-off-by: Martin Storsjö --- libavformat/http.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/libavformat/http.c b/libavformat/http.c index 65c031e163..bcb1227ddb 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -54,6 +54,8 @@ typedef struct { int end_chunked_post; /**< A flag which indicates if the end of chunked encoding has been sent. */ int end_header; /**< A flag which indicates we have finished to read POST reply. */ int multiple_requests; /**< A flag which indicates if we use persistent connections. */ + uint8_t *post_data; + int post_datalen; } HTTPContext; #define OFFSET(x) offsetof(HTTPContext, x) @@ -63,6 +65,7 @@ static const AVOption options[] = { {"chunked_post", "use chunked transfer-encoding for posts", OFFSET(chunked_post), AV_OPT_TYPE_INT, {.dbl = 1}, 0, 1, E }, {"headers", "custom HTTP headers, can override built in default headers", OFFSET(headers), AV_OPT_TYPE_STRING, { 0 }, 0, 0, D|E }, {"multiple_requests", "use persistent connections", OFFSET(multiple_requests), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 1, D|E }, +{"post_data", "custom HTTP post data", OFFSET(post_data), AV_OPT_TYPE_BINARY, .flags = D|E }, {NULL} }; #define HTTP_CLASS(flavor)\ @@ -382,6 +385,14 @@ static int http_connect(URLContext *h, const char *path, const char *local_path, /* send http header */ post = h->flags & AVIO_FLAG_WRITE; + + if (s->post_data) { + /* force POST method and disable chunked encoding when + * custom HTTP post data is set */ + post = 1; + s->chunked_post = 0; + } + method = post ? "POST" : "GET"; authstr = ff_http_auth_create_response(&s->auth_state, auth, local_path, method); @@ -412,6 +423,9 @@ static int http_connect(URLContext *h, const char *path, const char *local_path, if (!has_header(s->headers, "\r\nHost: ")) len += av_strlcatf(headers + len, sizeof(headers) - len, "Host: %s\r\n", hoststr); + if (!has_header(s->headers, "\r\nContent-Length: ") && s->post_data) + len += av_strlcatf(headers + len, sizeof(headers) - len, + "Content-Length: %d\r\n", s->post_datalen); /* now add in custom headers */ if (s->headers) @@ -436,6 +450,10 @@ static int http_connect(URLContext *h, const char *path, const char *local_path, if (ffurl_write(s->hd, s->buffer, strlen(s->buffer)) < 0) return AVERROR(EIO); + if (s->post_data) + if ((err = ffurl_write(s->hd, s->post_data, s->post_datalen)) < 0) + return err; + /* init input buffer */ s->buf_ptr = s->buffer; s->buf_end = s->buffer; @@ -445,7 +463,7 @@ static int http_connect(URLContext *h, const char *path, const char *local_path, s->willclose = 0; s->end_chunked_post = 0; s->end_header = 0; - if (post) { + if (post && !s->post_data) { /* Pretend that it did work. We didn't read any header yet, since * we've still to send the POST data, but the code calling this * function will check http_code after we return. */ -- cgit v1.2.3 From 9613240f72651018734c14517b679ff5fe50bc99 Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Wed, 30 May 2012 11:52:11 +0200 Subject: http: Pass the proper return code of net IO operations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/http.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libavformat/http.c b/libavformat/http.c index bcb1227ddb..22600b4e4a 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -227,7 +227,7 @@ static int http_getc(HTTPContext *s) if (s->buf_ptr >= s->buf_end) { len = ffurl_read(s->hd, s->buffer, BUFFER_SIZE); if (len < 0) { - return AVERROR(EIO); + return len; } else if (len == 0) { return -1; } else { @@ -247,7 +247,7 @@ static int http_get_line(HTTPContext *s, char *line, int line_size) for(;;) { ch = http_getc(s); if (ch < 0) - return AVERROR(EIO); + return ch; if (ch == '\n') { /* process line */ if (q > line && q[-1] == '\r') @@ -354,8 +354,8 @@ static int http_read_header(URLContext *h, int *new_location) int err = 0; for (;;) { - if (http_get_line(s, line, sizeof(line)) < 0) - return AVERROR(EIO); + if ((err = http_get_line(s, line, sizeof(line))) < 0) + return err; av_dlog(NULL, "header='%s'\n", line); @@ -447,8 +447,8 @@ static int http_connect(URLContext *h, const char *path, const char *local_path, av_freep(&authstr); av_freep(&proxyauthstr); - if (ffurl_write(s->hd, s->buffer, strlen(s->buffer)) < 0) - return AVERROR(EIO); + if ((err = ffurl_write(s->hd, s->buffer, strlen(s->buffer))) < 0) + return err; if (s->post_data) if ((err = ffurl_write(s->hd, s->post_data, s->post_datalen)) < 0) @@ -526,8 +526,8 @@ static int http_read(URLContext *h, uint8_t *buf, int size) for(;;) { do { - if (http_get_line(s, line, sizeof(line)) < 0) - return AVERROR(EIO); + if ((err = http_get_line(s, line, sizeof(line))) < 0) + return err; } while (!*line); /* skip CR LF from last chunk */ s->chunksize = strtoll(line, NULL, 16); -- cgit v1.2.3 From 0fcf3013c4aa4f70c39899b7b3bd8c451fe2e493 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Wed, 30 May 2012 12:54:22 +0200 Subject: fate: Fix fate-ac3-fixed-encode for pre-ssse3 x86 machines MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The default mmxext and sse implementations of apply_window_int16 aren't bitexact. Signed-off-by: Martin Storsjö --- tests/fate/ac3.mak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fate/ac3.mak b/tests/fate/ac3.mak index 4fafb053d8..6abda8099c 100644 --- a/tests/fate/ac3.mak +++ b/tests/fate/ac3.mak @@ -49,7 +49,7 @@ fate-eac3-encode: FUZZ = 3 FATE_AC3 += fate-ac3-fixed-encode fate-ac3-fixed-encode: tests/data/asynth-44100-2.wav fate-ac3-fixed-encode: SRC = $(TARGET_PATH)/tests/data/asynth-44100-2.wav -fate-ac3-fixed-encode: CMD = md5 -i $(SRC) -c ac3_fixed -b 128k -f ac3 +fate-ac3-fixed-encode: CMD = md5 -i $(SRC) -c ac3_fixed -b 128k -f ac3 -flags bitexact fate-ac3-fixed-encode: CMP = oneline fate-ac3-fixed-encode: REF = a1d1fc116463b771abf5aef7ed37d7b1 -- cgit v1.2.3