From 41ecbbc7aa3d491cc9d8d425634c5901eefa088a Mon Sep 17 00:00:00 2001 From: Martin Storsjö Date: Fri, 27 Jul 2012 20:22:51 +0300 Subject: tls: Return AVERROR_EOF if the TLS_read/write functions return 0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OpenSSL returns 0 when the peer has closed the connection. GnuTLS doesn't return that though, but returns GNUTLS_E_UNEXPECTED_PACKET_LENGTH if the connection simply is closed without a clean close notify packet. Tested-by: Antti Seppälä Signed-off-by: Martin Storsjö --- libavformat/tls.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libavformat') diff --git a/libavformat/tls.c b/libavformat/tls.c index fb84fa82b6..866e55f2ba 100644 --- a/libavformat/tls.c +++ b/libavformat/tls.c @@ -209,7 +209,7 @@ static int tls_read(URLContext *h, uint8_t *buf, int size) if (ret > 0) return ret; if (ret == 0) - return AVERROR(EIO); + return AVERROR_EOF; if ((ret = do_tls_poll(h, ret)) < 0) return ret; } @@ -224,7 +224,7 @@ static int tls_write(URLContext *h, const uint8_t *buf, int size) if (ret > 0) return ret; if (ret == 0) - return AVERROR(EIO); + return AVERROR_EOF; if ((ret = do_tls_poll(h, ret)) < 0) return ret; } -- cgit v1.2.3 From 8ebacfb598933f66ff34ad1b12cb1aa14928ac73 Mon Sep 17 00:00:00 2001 From: Martin Storsjö Date: Fri, 27 Jul 2012 20:24:53 +0300 Subject: hls: Proceed to the next segment at any error code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, we returned any error code except AVERROR_EOF to the caller - only if AVERROR_EOF or 0 was returned, we proceeded to the next segment. With some setups of web servers, using Connection: close in https and GnuTLS, we don't get a clean error code at the end of segments. In those cases, just proceed to the next segment. Tested-by: Antti Seppälä Signed-off-by: Martin Storsjö --- libavformat/hls.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'libavformat') diff --git a/libavformat/hls.c b/libavformat/hls.c index 253463edf6..cda65cd362 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -420,8 +420,6 @@ reload: ret = ffurl_read(v->input, buf, buf_size); if (ret > 0) return ret; - if (ret < 0 && ret != AVERROR_EOF) - return ret; ffurl_close(v->input); v->input = NULL; v->cur_seq_no++; -- cgit v1.2.3 From c4ef6a3e4ba50b7e3746a46b51c2f8d16e8cba7b Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 27 Jul 2012 16:28:36 +0200 Subject: Add missing libavutil/time.h includes. --- libavdevice/fbdev.c | 1 + libavdevice/jack_audio.c | 1 + libavdevice/oss_audio.c | 1 + libavdevice/x11grab.c | 1 + libavformat/rtpdec.c | 1 + libavformat/rtsp.c | 1 + libavformat/rtspdec.c | 1 + libavformat/rtspenc.c | 1 + libavformat/sapenc.c | 1 + libavformat/utils.c | 1 + 10 files changed, 10 insertions(+) (limited to 'libavformat') diff --git a/libavdevice/fbdev.c b/libavdevice/fbdev.c index d789d41afa..9de1a3b555 100644 --- a/libavdevice/fbdev.c +++ b/libavdevice/fbdev.c @@ -39,6 +39,7 @@ #include "libavutil/log.h" #include "libavutil/mem.h" #include "libavutil/opt.h" +#include "libavutil/time.h" #include "libavutil/parseutils.h" #include "libavutil/pixdesc.h" #include "libavformat/avformat.h" diff --git a/libavdevice/jack_audio.c b/libavdevice/jack_audio.c index 85f9f09740..7b2ceef1bb 100644 --- a/libavdevice/jack_audio.c +++ b/libavdevice/jack_audio.c @@ -27,6 +27,7 @@ #include "libavutil/log.h" #include "libavutil/fifo.h" #include "libavutil/opt.h" +#include "libavutil/time.h" #include "libavcodec/avcodec.h" #include "libavformat/avformat.h" #include "libavformat/internal.h" diff --git a/libavdevice/oss_audio.c b/libavdevice/oss_audio.c index 60432c5fc5..b5fbb318dc 100644 --- a/libavdevice/oss_audio.c +++ b/libavdevice/oss_audio.c @@ -36,6 +36,7 @@ #include "libavutil/log.h" #include "libavutil/opt.h" +#include "libavutil/time.h" #include "libavcodec/avcodec.h" #include "libavformat/avformat.h" #include "libavformat/internal.h" diff --git a/libavdevice/x11grab.c b/libavdevice/x11grab.c index dd432b3fd5..d7c8c8f548 100644 --- a/libavdevice/x11grab.c +++ b/libavdevice/x11grab.c @@ -42,6 +42,7 @@ #include "libavutil/log.h" #include "libavutil/opt.h" #include "libavutil/parseutils.h" +#include "libavutil/time.h" #include #include #include diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c index 87d92557db..2c5e6c8176 100644 --- a/libavformat/rtpdec.c +++ b/libavformat/rtpdec.c @@ -21,6 +21,7 @@ #include "libavutil/mathematics.h" #include "libavutil/avstring.h" +#include "libavutil/time.h" #include "libavcodec/get_bits.h" #include "avformat.h" #include "mpegts.h" diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index f6f5ac7146..4cf7a90329 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -27,6 +27,7 @@ #include "libavutil/random_seed.h" #include "libavutil/dict.h" #include "libavutil/opt.h" +#include "libavutil/time.h" #include "avformat.h" #include "avio_internal.h" diff --git a/libavformat/rtspdec.c b/libavformat/rtspdec.c index a3565557d4..a125cc6e9e 100644 --- a/libavformat/rtspdec.c +++ b/libavformat/rtspdec.c @@ -23,6 +23,7 @@ #include "libavutil/intreadwrite.h" #include "libavutil/mathematics.h" #include "libavutil/random_seed.h" +#include "libavutil/time.h" #include "avformat.h" #include "internal.h" diff --git a/libavformat/rtspenc.c b/libavformat/rtspenc.c index c7fb2fa9d9..902076d25d 100644 --- a/libavformat/rtspenc.c +++ b/libavformat/rtspenc.c @@ -31,6 +31,7 @@ #include "avio_internal.h" #include "libavutil/intreadwrite.h" #include "libavutil/avstring.h" +#include "libavutil/time.h" #include "url.h" #define SDP_MAX_SIZE 16384 diff --git a/libavformat/sapenc.c b/libavformat/sapenc.c index 7e84a3fb99..235c71105c 100644 --- a/libavformat/sapenc.c +++ b/libavformat/sapenc.c @@ -24,6 +24,7 @@ #include "libavutil/random_seed.h" #include "libavutil/avstring.h" #include "libavutil/intreadwrite.h" +#include "libavutil/time.h" #include "internal.h" #include "network.h" #include "os_support.h" diff --git a/libavformat/utils.c b/libavformat/utils.c index 156c527e25..4d5f4ccaaf 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -35,6 +35,7 @@ #include "libavutil/avstring.h" #include "libavutil/mathematics.h" #include "libavutil/parseutils.h" +#include "libavutil/time.h" #include "riff.h" #include "audiointerleave.h" #include "url.h" -- cgit v1.2.3 From efd34918badd466161a2a2e170ca6d24a7b9b06f Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 28 Jun 2012 13:33:12 +0200 Subject: lavf: remove commented out cruft in avformat_find_stream_info() --- libavformat/utils.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'libavformat') diff --git a/libavformat/utils.c b/libavformat/utils.c index 4d5f4ccaaf..4ec70b7f51 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -2404,8 +2404,6 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) int64_t duration= pkt->dts - last; double dur= duration * av_q2d(st->time_base); -// if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO) -// av_log(NULL, AV_LOG_ERROR, "%f\n", dur); if (st->info->duration_count < 2) memset(st->info->duration_error, 0, sizeof(st->info->duration_error)); for (i=1; iinfo->duration_error); i++) { @@ -2467,17 +2465,13 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) if (tb_unreliable(st->codec) && st->info->duration_count > 15 && st->info->duration_gcd > 1 && !st->r_frame_rate.num) av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, st->time_base.den, st->time_base.num * st->info->duration_gcd, INT_MAX); if (st->info->duration_count && !st->r_frame_rate.num - && tb_unreliable(st->codec) /*&& - //FIXME we should not special-case MPEG-2, but this needs testing with non-MPEG-2 ... - st->time_base.num*duration_sum[i]/st->info->duration_count*101LL > st->time_base.den*/){ + && tb_unreliable(st->codec)) { int num = 0; double best_error= 2*av_q2d(st->time_base); best_error = best_error*best_error*st->info->duration_count*1000*12*30; for (j=1; jinfo->duration_error); j++) { double error = st->info->duration_error[j] * get_std_framerate(j); -// if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO) -// av_log(NULL, AV_LOG_ERROR, "%f %f\n", get_std_framerate(j) / 12.0/1001, error); if(error < best_error){ best_error= error; num = get_std_framerate(j); -- cgit v1.2.3 From 61f8bb74f33931c899482f5cca17ded571b07d4e Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 28 Jul 2012 12:18:51 +0200 Subject: mp3dec: remove commented out cruft. --- libavformat/mp3dec.c | 1 - 1 file changed, 1 deletion(-) (limited to 'libavformat') diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index 39875201e3..4344e8efcf 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -186,7 +186,6 @@ static int mp3_read_header(AVFormatContext *s) static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt) { int ret, size; - // AVStream *st = s->streams[0]; size= MP3_PACKET_SIZE; -- cgit v1.2.3 From 67b1156fe8d80c1858a222e85c5be75e0f040ea1 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 28 Jul 2012 12:20:08 +0200 Subject: mp3dec: remove a pointless local variable. --- libavformat/mp3dec.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'libavformat') diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index 4344e8efcf..11e684d7f3 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -185,11 +185,9 @@ static int mp3_read_header(AVFormatContext *s) static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt) { - int ret, size; + int ret; - size= MP3_PACKET_SIZE; - - ret= av_get_packet(s->pb, pkt, size); + ret = av_get_packet(s->pb, pkt, MP3_PACKET_SIZE); pkt->stream_index = 0; if (ret <= 0) { -- cgit v1.2.3 From f73e3938ac70524826664855210446c3739c4a5e Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 28 Jul 2012 12:21:21 +0200 Subject: mp3dec: forward errors for av_get_packet(). Don't invent a bogus EIO error. The code now doesn't check for ret == 0, but that check is redundant, av_get_packet() never returns 0. --- libavformat/mp3dec.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'libavformat') diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index 11e684d7f3..a208488930 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -188,11 +188,10 @@ static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt) int ret; ret = av_get_packet(s->pb, pkt, MP3_PACKET_SIZE); + if (ret < 0) + return ret; pkt->stream_index = 0; - if (ret <= 0) { - return AVERROR(EIO); - } if (ret > ID3v1_TAG_SIZE && memcmp(&pkt->data[ret - ID3v1_TAG_SIZE], "TAG", 3) == 0) -- cgit v1.2.3 From ccc10acb5b941973acab49d64459bb110cc0a529 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 28 Jul 2012 12:23:04 +0200 Subject: wv: return AVERROR_EOF on EOF, not EIO. --- libavformat/wv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libavformat') diff --git a/libavformat/wv.c b/libavformat/wv.c index 49ca486a93..0b6a406654 100644 --- a/libavformat/wv.c +++ b/libavformat/wv.c @@ -254,7 +254,7 @@ static int wv_read_packet(AVFormatContext *s, uint32_t block_samples; if (s->pb->eof_reached) - return AVERROR(EIO); + return AVERROR_EOF; if(wc->block_parsed){ if(wv_read_block_header(s, s->pb, 0) < 0) return -1; -- cgit v1.2.3 From c1d865d5633e8e9eb9ee2bfa876fbcae4cd41cfd Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 28 Jul 2012 12:28:05 +0200 Subject: wv: return meaningful error codes. --- libavformat/wv.c | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) (limited to 'libavformat') diff --git a/libavformat/wv.c b/libavformat/wv.c index 0b6a406654..b31144907f 100644 --- a/libavformat/wv.c +++ b/libavformat/wv.c @@ -90,17 +90,17 @@ static int wv_read_block_header(AVFormatContext *ctx, AVIOContext *pb, int appen if(!append){ tag = avio_rl32(pb); if (tag != MKTAG('w', 'v', 'p', 'k')) - return -1; + return AVERROR_INVALIDDATA; size = avio_rl32(pb); if(size < 24 || size > WV_BLOCK_LIMIT){ av_log(ctx, AV_LOG_ERROR, "Incorrect block size %i\n", size); - return -1; + return AVERROR_INVALIDDATA; } wc->blksize = size; ver = avio_rl16(pb); if(ver < 0x402 || ver > 0x410){ av_log(ctx, AV_LOG_ERROR, "Unsupported version %03X\n", ver); - return -1; + return AVERROR_PATCHWELCOME; } avio_r8(pb); // track no avio_r8(pb); // track sub index @@ -128,7 +128,7 @@ static int wv_read_block_header(AVFormatContext *ctx, AVIOContext *pb, int appen int64_t block_end = avio_tell(pb) + wc->blksize - 24; if(!pb->seekable){ av_log(ctx, AV_LOG_ERROR, "Cannot determine additional parameters\n"); - return -1; + return AVERROR_INVALIDDATA; } while(avio_tell(pb) < block_end){ int id, size; @@ -141,7 +141,7 @@ static int wv_read_block_header(AVFormatContext *ctx, AVIOContext *pb, int appen case 0xD: if(size <= 1){ av_log(ctx, AV_LOG_ERROR, "Insufficient channel information\n"); - return -1; + return AVERROR_INVALIDDATA; } chan = avio_r8(pb); switch(size - 2){ @@ -164,7 +164,7 @@ static int wv_read_block_header(AVFormatContext *ctx, AVIOContext *pb, int appen break; default: av_log(ctx, AV_LOG_ERROR, "Invalid channel info size %d\n", size); - return -1; + return AVERROR_INVALIDDATA; } break; case 0x27: @@ -178,7 +178,7 @@ static int wv_read_block_header(AVFormatContext *ctx, AVIOContext *pb, int appen } if(rate == -1){ av_log(ctx, AV_LOG_ERROR, "Cannot determine custom sampling rate\n"); - return -1; + return AVERROR_INVALIDDATA; } avio_seek(pb, block_end - wc->blksize + 24, SEEK_SET); } @@ -189,15 +189,15 @@ static int wv_read_block_header(AVFormatContext *ctx, AVIOContext *pb, int appen if(wc->flags && bpp != wc->bpp){ av_log(ctx, AV_LOG_ERROR, "Bits per sample differ, this block: %i, header block: %i\n", bpp, wc->bpp); - return -1; + return AVERROR_INVALIDDATA; } if(wc->flags && !wc->multichannel && chan != wc->chan){ av_log(ctx, AV_LOG_ERROR, "Channels differ, this block: %i, header block: %i\n", chan, wc->chan); - return -1; + return AVERROR_INVALIDDATA; } if(wc->flags && rate != -1 && rate != wc->rate){ av_log(ctx, AV_LOG_ERROR, "Sampling rate differ, this block: %i, header block: %i\n", rate, wc->rate); - return -1; + return AVERROR_INVALIDDATA; } wc->blksize = size - 24; return 0; @@ -208,11 +208,12 @@ static int wv_read_header(AVFormatContext *s) AVIOContext *pb = s->pb; WVContext *wc = s->priv_data; AVStream *st; + int ret; wc->block_parsed = 0; for(;;){ - if(wv_read_block_header(s, pb, 0) < 0) - return -1; + if ((ret = wv_read_block_header(s, pb, 0)) < 0) + return ret; if(!AV_RN32(wc->extra)) avio_skip(pb, wc->blksize - 24); else @@ -222,7 +223,7 @@ static int wv_read_header(AVFormatContext *s) /* now we are ready: build format streams */ st = avformat_new_stream(s, NULL); if (!st) - return -1; + return AVERROR(ENOMEM); st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_WAVPACK; st->codec->channels = wc->chan; @@ -256,8 +257,8 @@ static int wv_read_packet(AVFormatContext *s, if (s->pb->eof_reached) return AVERROR_EOF; if(wc->block_parsed){ - if(wv_read_block_header(s, s->pb, 0) < 0) - return -1; + if ((ret = wv_read_block_header(s, s->pb, 0)) < 0) + return ret; } pos = wc->pos; @@ -275,7 +276,7 @@ static int wv_read_packet(AVFormatContext *s, while(!(wc->flags & WV_END_BLOCK)){ if(avio_rl32(s->pb) != MKTAG('w', 'v', 'p', 'k')){ av_free_packet(pkt); - return -1; + return AVERROR_INVALIDDATA; } if((ret = av_append_packet(s->pb, pkt, 4)) < 0){ av_free_packet(pkt); @@ -285,14 +286,14 @@ static int wv_read_packet(AVFormatContext *s, if(size < 24 || size > WV_BLOCK_LIMIT){ av_free_packet(pkt); av_log(s, AV_LOG_ERROR, "Incorrect block size %d\n", size); - return -1; + return AVERROR_INVALIDDATA; } wc->blksize = size; ver = avio_rl16(s->pb); if(ver < 0x402 || ver > 0x410){ av_free_packet(pkt); av_log(s, AV_LOG_ERROR, "Unsupported version %03X\n", ver); - return -1; + return AVERROR_PATCHWELCOME; } avio_r8(s->pb); // track no avio_r8(s->pb); // track sub index @@ -304,9 +305,9 @@ static int wv_read_packet(AVFormatContext *s, } memcpy(wc->extra, pkt->data + pkt->size - WV_EXTRA_SIZE, WV_EXTRA_SIZE); - if(wv_read_block_header(s, s->pb, 1) < 0){ + if ((ret = wv_read_block_header(s, s->pb, 1)) < 0){ av_free_packet(pkt); - return -1; + return ret; } ret = av_append_packet(s->pb, pkt, wc->blksize); if(ret < 0){ @@ -345,14 +346,14 @@ static int wv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, } /* if timestamp is out of bounds, return error */ if(timestamp < 0 || timestamp >= s->duration) - return -1; + return AVERROR(EINVAL); pos = avio_tell(s->pb); do{ ret = av_read_frame(s, pkt); if (ret < 0){ avio_seek(s->pb, pos, SEEK_SET); - return -1; + return ret; } pts = pkt->pts; av_free_packet(pkt); -- cgit v1.2.3