#include "libavcodec/get_bits.h"
#include "avformat.h"
+#include "internal.h"
#include "apetag.h"
#include "id3v1.h"
#include "libavutil/dict.h"
return 0;
}
-static int mpc_read_header(AVFormatContext *s, AVFormatParameters *ap)
+static int mpc_read_header(AVFormatContext *s)
{
MPCContext *c = s->priv_data;
AVStream *st;
if(avio_rl24(s->pb) != MKTAG('M', 'P', '+', 0)){
av_log(s, AV_LOG_ERROR, "Not a Musepack file\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
c->ver = avio_r8(s->pb);
if(c->ver != 0x07 && c->ver != 0x17){
av_log(s, AV_LOG_ERROR, "Can demux Musepack SV7, got version %02X\n", c->ver);
- return -1;
+ return AVERROR_INVALIDDATA;
}
c->fcount = avio_rl32(s->pb);
if((int64_t)c->fcount * sizeof(MPCFrame) >= UINT_MAX){
av_log(s, AV_LOG_ERROR, "Too many frames, seeking is not possible\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
if(c->fcount){
c->frames = av_malloc(c->fcount * sizeof(MPCFrame));
c->curbits = 8;
c->frames_noted = 0;
- st = av_new_stream(s, 0);
+ st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
- st->codec->codec_id = CODEC_ID_MUSEPACK7;
+ st->codec->codec_id = AV_CODEC_ID_MUSEPACK7;
st->codec->channels = 2;
st->codec->bits_per_coded_sample = 16;
st->codec->extradata = av_mallocz(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE);
avio_read(s->pb, st->codec->extradata, 16);
st->codec->sample_rate = mpc_rate[st->codec->extradata[2] & 3];
- av_set_pts_info(st, 32, MPC_FRAMESIZE, st->codec->sample_rate);
+ avpriv_set_pts_info(st, 32, MPC_FRAMESIZE, st->codec->sample_rate);
/* scan for seekpoints */
st->start_time = 0;
st->duration = c->fcount;
{
MPCContext *c = s->priv_data;
int ret, size, size2, curbits, cur = c->curframe;
- int64_t tmp, pos;
+ unsigned tmp;
+ int64_t pos;
if (c->curframe >= c->fcount && c->fcount)
- return -1;
+ return AVERROR_EOF;
if(c->curframe != c->lastframe + 1){
avio_seek(s->pb, c->frames[c->curframe].pos, SEEK_SET);
if(curbits <= 12){
size2 = (tmp >> (12 - curbits)) & 0xFFFFF;
}else{
- tmp = (tmp << 32) | avio_rl32(s->pb);
- size2 = (tmp >> (44 - curbits)) & 0xFFFFF;
+ size2 = (tmp << (curbits - 12) | avio_rl32(s->pb) >> (44 - curbits)) & 0xFFFFF;
}
curbits += 20;
avio_seek(s->pb, pos, SEEK_SET);
}
c->curbits = (curbits + size2) & 0x1F;
- if (av_new_packet(pkt, size) < 0)
- return AVERROR(EIO);
+ if ((ret = av_new_packet(pkt, size)) < 0)
+ return ret;
pkt->data[0] = curbits;
pkt->data[1] = (c->curframe > c->fcount) && c->fcount;
avio_seek(s->pb, -4, SEEK_CUR);
if(ret < size){
av_free_packet(pkt);
- return AVERROR(EIO);
+ return ret < 0 ? ret : AVERROR(EIO);
}
pkt->size = ret + 4;
ret = av_read_frame(s, pkt);
if (ret < 0){
c->curframe = lastframe;
- return -1;
+ return ret;
}
av_free_packet(pkt);
}
.read_packet = mpc_read_packet,
.read_close = mpc_read_close,
.read_seek = mpc_read_seek,
- .extensions = "mpc",
+ .extensions = "mpc",
};