X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fmpc.c;h=ac6733788f934badecc5f0be0875aac17c1946c0;hb=ab332d013301266e95e9c85ffe878bca2bfaf10d;hp=f06cba762985c9eaeb947a13655ecf9cc8609685;hpb=0587b0cacde5d65f0edd9e5e4509fbdb21dfe37f;p=ffmpeg diff --git a/libavformat/mpc.c b/libavformat/mpc.c index f06cba76298..ac6733788f9 100644 --- a/libavformat/mpc.c +++ b/libavformat/mpc.c @@ -16,12 +16,13 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "avformat.h" #include "bitstream.h" #define MPC_FRAMESIZE 1152 +#define DELAY_FRAMES 32 static const int mpc_rate[4] = { 44100, 48000, 37800, 32000 }; typedef struct { @@ -41,8 +42,6 @@ typedef struct { static int mpc_probe(AVProbeData *p) { const uint8_t *d = p->buf; - if (p->buf_size < 32) - return 0; if (d[0] == 'M' && d[1] == 'P' && d[2] == '+' && (d[3] == 0x17 || d[3] == 0x7)) return AVPROBE_SCORE_MAX; if (d[0] == 'I' && d[1] == 'D' && d[2] == '3') @@ -93,7 +92,7 @@ static int mpc_read_header(AVFormatContext *s, AVFormatParameters *ap) st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); st->codec->codec_type = CODEC_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_MUSEPACK7; st->codec->channels = 2; @@ -117,7 +116,7 @@ static int mpc_read_packet(AVFormatContext *s, AVPacket *pkt) int ret, size, size2, curbits, cur = c->curframe; int64_t tmp, pos; - if (c->curframe > c->fcount) + if (c->curframe >= c->fcount) return -1; if(c->curframe != c->lastframe + 1){ @@ -149,18 +148,19 @@ static int mpc_read_packet(AVFormatContext *s, AVPacket *pkt) c->curbits = (curbits + size2) & 0x1F; if (av_new_packet(pkt, size) < 0) - return AVERROR_IO; + return AVERROR(EIO); pkt->data[0] = curbits; pkt->data[1] = (c->curframe > c->fcount); pkt->stream_index = 0; + pkt->pts = cur; ret = get_buffer(&s->pb, pkt->data + 4, size); if(c->curbits) url_fseek(&s->pb, -4, SEEK_CUR); if(ret < size){ av_free_packet(pkt); - return AVERROR_IO; + return AVERROR(EIO); } pkt->size = ret + 4; @@ -188,7 +188,7 @@ static int mpc_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp MPCContext *c = s->priv_data; AVPacket pkt1, *pkt = &pkt1; int ret; - int index = av_index_search_timestamp(st, timestamp, flags); + int index = av_index_search_timestamp(st, timestamp - DELAY_FRAMES, flags); uint32_t lastframe; /* if found, seek there */ @@ -199,6 +199,7 @@ static int mpc_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp /* if timestamp is out of bounds, return error */ if(timestamp < 0 || timestamp >= c->fcount) return -1; + timestamp -= DELAY_FRAMES; /* seek to the furthest known position and read packets until we reach desired position */ lastframe = c->curframe;