avformat/mpc: Simplify cleanup
Currently Musepack allocates an array that needs to be freed later in the demuxer's read_close-function; it is the sole reason for said function's existence. But it is unnecessary, because one can store this array in the stream's priv_data pointer, so that it will be freed generically. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
This commit is contained in:
@ -57,6 +57,7 @@ static int mpc_read_header(AVFormatContext *s)
|
|||||||
{
|
{
|
||||||
MPCContext *c = s->priv_data;
|
MPCContext *c = s->priv_data;
|
||||||
AVStream *st;
|
AVStream *st;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if(avio_rl24(s->pb) != MKTAG('M', 'P', '+', 0)){
|
if(avio_rl24(s->pb) != MKTAG('M', 'P', '+', 0)){
|
||||||
av_log(s, AV_LOG_ERROR, "Not a Musepack file\n");
|
av_log(s, AV_LOG_ERROR, "Not a Musepack file\n");
|
||||||
@ -72,15 +73,6 @@ static int mpc_read_header(AVFormatContext *s)
|
|||||||
av_log(s, AV_LOG_ERROR, "Too many frames, seeking is not possible\n");
|
av_log(s, AV_LOG_ERROR, "Too many frames, seeking is not possible\n");
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
}
|
}
|
||||||
if(c->fcount){
|
|
||||||
c->frames = av_malloc(c->fcount * sizeof(MPCFrame));
|
|
||||||
if(!c->frames){
|
|
||||||
av_log(s, AV_LOG_ERROR, "Cannot allocate seektable\n");
|
|
||||||
return AVERROR(ENOMEM);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
av_log(s, AV_LOG_WARNING, "Container reports no frames\n");
|
|
||||||
}
|
|
||||||
c->curframe = 0;
|
c->curframe = 0;
|
||||||
c->lastframe = -1;
|
c->lastframe = -1;
|
||||||
c->curbits = 8;
|
c->curbits = 8;
|
||||||
@ -88,15 +80,27 @@ static int mpc_read_header(AVFormatContext *s)
|
|||||||
|
|
||||||
st = avformat_new_stream(s, NULL);
|
st = avformat_new_stream(s, NULL);
|
||||||
if (!st)
|
if (!st)
|
||||||
goto mem_error;
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
|
if (c->fcount) {
|
||||||
|
c->frames = av_malloc(c->fcount * sizeof(MPCFrame));
|
||||||
|
if (!c->frames) {
|
||||||
|
av_log(s, AV_LOG_ERROR, "Cannot allocate seektable\n");
|
||||||
|
return AVERROR(ENOMEM);
|
||||||
|
}
|
||||||
|
st->priv_data = c->frames;
|
||||||
|
} else {
|
||||||
|
av_log(s, AV_LOG_WARNING, "Container reports no frames\n");
|
||||||
|
}
|
||||||
|
|
||||||
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
|
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
|
||||||
st->codecpar->codec_id = AV_CODEC_ID_MUSEPACK7;
|
st->codecpar->codec_id = AV_CODEC_ID_MUSEPACK7;
|
||||||
st->codecpar->channels = 2;
|
st->codecpar->channels = 2;
|
||||||
st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
|
st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
|
||||||
st->codecpar->bits_per_coded_sample = 16;
|
st->codecpar->bits_per_coded_sample = 16;
|
||||||
|
|
||||||
if (ff_get_extradata(s, st->codecpar, s->pb, 16) < 0)
|
if ((ret = ff_get_extradata(s, st->codecpar, s->pb, 16)) < 0)
|
||||||
goto mem_error;
|
return ret;
|
||||||
st->codecpar->sample_rate = mpc_rate[st->codecpar->extradata[2] & 3];
|
st->codecpar->sample_rate = mpc_rate[st->codecpar->extradata[2] & 3];
|
||||||
avpriv_set_pts_info(st, 32, MPC_FRAMESIZE, st->codecpar->sample_rate);
|
avpriv_set_pts_info(st, 32, MPC_FRAMESIZE, st->codecpar->sample_rate);
|
||||||
/* scan for seekpoints */
|
/* scan for seekpoints */
|
||||||
@ -113,9 +117,6 @@ static int mpc_read_header(AVFormatContext *s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
mem_error:
|
|
||||||
av_freep(&c->frames);
|
|
||||||
return AVERROR(ENOMEM);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mpc_read_packet(AVFormatContext *s, AVPacket *pkt)
|
static int mpc_read_packet(AVFormatContext *s, AVPacket *pkt)
|
||||||
@ -176,14 +177,6 @@ static int mpc_read_packet(AVFormatContext *s, AVPacket *pkt)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mpc_read_close(AVFormatContext *s)
|
|
||||||
{
|
|
||||||
MPCContext *c = s->priv_data;
|
|
||||||
|
|
||||||
av_freep(&c->frames);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Seek to the given position
|
* Seek to the given position
|
||||||
* If position is unknown but is within the limits of file
|
* If position is unknown but is within the limits of file
|
||||||
@ -232,7 +225,6 @@ AVInputFormat ff_mpc_demuxer = {
|
|||||||
.read_probe = mpc_probe,
|
.read_probe = mpc_probe,
|
||||||
.read_header = mpc_read_header,
|
.read_header = mpc_read_header,
|
||||||
.read_packet = mpc_read_packet,
|
.read_packet = mpc_read_packet,
|
||||||
.read_close = mpc_read_close,
|
|
||||||
.read_seek = mpc_read_seek,
|
.read_seek = mpc_read_seek,
|
||||||
.extensions = "mpc",
|
.extensions = "mpc",
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user