Commit 9200514a authored by Anton Khirnov's avatar Anton Khirnov

lavf: replace AVStream.codec with AVStream.codecpar

Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.

In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.

There are multiple important problems with this approach:
    - the fields in AVCodecContext are in general one of
        * stream parameters
        * codec options
        * codec state
      However, it's not clear which ones are which. It is consequently
      unclear which fields are a demuxer allowed to set or a muxer allowed to
      read. This leads to erratic behaviour depending on whether decoding or
      encoding is being performed or not (and whether it uses the AVStream
      embedded codec context).
    - various synchronization issues arising from the fact that the same
      context is used by several different APIs (muxers/demuxers,
      parsers, bitstream filters and encoders/decoders) simultaneously, with
      there being no clear rules for who can modify what and the different
      processes being typically delayed with respect to each other.
    - avformat_find_stream_info() making it necessary to support opening
      and closing a single codec context multiple times, thus
      complicating the semantics of freeing various allocated objects in the
      codec context.

Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
parent a8068346
......@@ -194,7 +194,7 @@ av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode,
snd_pcm_t *h;
snd_pcm_hw_params_t *hw_params;
snd_pcm_uframes_t buffer_size, period_size;
uint64_t layout = ctx->streams[0]->codec->channel_layout;
uint64_t layout = ctx->streams[0]->codecpar->channel_layout;
if (ctx->filename[0] == 0) audio_device = "default";
else audio_device = ctx->filename;
......
......@@ -101,10 +101,10 @@ static av_cold int audio_read_header(AVFormatContext *s1)
}
/* take real parameters */
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_id = codec_id;
st->codec->sample_rate = s->sample_rate;
st->codec->channels = s->channels;
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
st->codecpar->codec_id = codec_id;
st->codecpar->sample_rate = s->sample_rate;
st->codecpar->channels = s->channels;
avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
return 0;
......@@ -144,9 +144,9 @@ static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)
snd_pcm_htimestamp(s->h, &ts_delay, &timestamp);
ts_delay += res;
pkt->pts = timestamp.tv_sec * 1000000LL
+ (timestamp.tv_nsec * st->codec->sample_rate
- (int64_t)ts_delay * 1000000000LL + st->codec->sample_rate * 500LL)
/ (st->codec->sample_rate * 1000LL);
+ (timestamp.tv_nsec * st->codecpar->sample_rate
- (int64_t)ts_delay * 1000000000LL + st->codecpar->sample_rate * 500LL)
/ (st->codecpar->sample_rate * 1000LL);
pkt->size = res * s->frame_size;
......
......@@ -54,14 +54,14 @@ static av_cold int audio_write_header(AVFormatContext *s1)
int res;
st = s1->streams[0];
sample_rate = st->codec->sample_rate;
codec_id = st->codec->codec_id;
sample_rate = st->codecpar->sample_rate;
codec_id = st->codecpar->codec_id;
res = ff_alsa_open(s1, SND_PCM_STREAM_PLAYBACK, &sample_rate,
st->codec->channels, &codec_id);
if (sample_rate != st->codec->sample_rate) {
st->codecpar->channels, &codec_id);
if (sample_rate != st->codecpar->sample_rate) {
av_log(s1, AV_LOG_ERROR,
"sample rate %d not available, nearest is %d\n",
st->codec->sample_rate, sample_rate);
st->codecpar->sample_rate, sample_rate);
goto fail;
}
......
......@@ -295,13 +295,12 @@ static int grab_read_header(AVFormatContext *s1)
s->height = height;
s->per_frame = ((uint64_t)1000000 * framerate.den) / framerate.num;
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->codec->pix_fmt = AV_PIX_FMT_YUV420P;
st->codec->codec_id = AV_CODEC_ID_RAWVIDEO;
st->codec->width = width;
st->codec->height = height;
st->codec->time_base.den = framerate.num;
st->codec->time_base.num = framerate.den;
st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
st->codecpar->format = AV_PIX_FMT_YUV420P;
st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
st->codecpar->width = width;
st->codecpar->height = height;
st->avg_frame_rate = framerate;
if (bktr_init(s1->filename, width, height, s->standard,
......
......@@ -164,21 +164,21 @@ static av_cold int fbdev_read_header(AVFormatContext *avctx)
goto fail;
}
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->codec->codec_id = AV_CODEC_ID_RAWVIDEO;
st->codec->width = fbdev->width;
st->codec->height = fbdev->height;
st->codec->pix_fmt = pix_fmt;
st->codec->time_base = (AVRational){fbdev->framerate_q.den, fbdev->framerate_q.num};
st->codec->bit_rate =
st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
st->codecpar->width = fbdev->width;
st->codecpar->height = fbdev->height;
st->codecpar->format = pix_fmt;
st->codecpar->bit_rate =
fbdev->width * fbdev->height * fbdev->bytes_per_pixel * av_q2d(fbdev->framerate_q) * 8;
st->avg_frame_rate = fbdev->framerate_q;
av_log(avctx, AV_LOG_INFO,
"w:%d h:%d bpp:%d pixfmt:%s fps:%d/%d bit_rate:%d\n",
fbdev->width, fbdev->height, fbdev->varinfo.bits_per_pixel,
av_get_pix_fmt_name(pix_fmt),
fbdev->framerate_q.num, fbdev->framerate_q.den,
st->codec->bit_rate);
st->codecpar->bit_rate);
return 0;
fail:
......
......@@ -254,14 +254,14 @@ static int audio_read_header(AVFormatContext *context)
return AVERROR(ENOMEM);
}
stream->codec->codec_type = AVMEDIA_TYPE_AUDIO;
stream->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
#if HAVE_BIGENDIAN
stream->codec->codec_id = AV_CODEC_ID_PCM_F32BE;
stream->codecpar->codec_id = AV_CODEC_ID_PCM_F32BE;
#else
stream->codec->codec_id = AV_CODEC_ID_PCM_F32LE;
stream->codecpar->codec_id = AV_CODEC_ID_PCM_F32LE;
#endif
stream->codec->sample_rate = self->sample_rate;
stream->codec->channels = self->nports;
stream->codecpar->sample_rate = self->sample_rate;
stream->codecpar->channels = self->nports;
avpriv_set_pts_info(stream, 64, 1, 1000000); /* 64 bits pts in us */
return 0;
......
......@@ -85,19 +85,19 @@ static av_cold int read_header(AVFormatContext *ctx)
}
cdio_paranoia_modeset(s->paranoia, s->paranoia_mode);
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
if (s->drive->bigendianp)
st->codec->codec_id = AV_CODEC_ID_PCM_S16BE;
st->codecpar->codec_id = AV_CODEC_ID_PCM_S16BE;
else
st->codec->codec_id = AV_CODEC_ID_PCM_S16LE;
st->codec->sample_rate = 44100;
st->codec->channels = 2;
st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE;
st->codecpar->sample_rate = 44100;
st->codecpar->channels = 2;
if (s->drive->audio_last_sector != CDIO_INVALID_LSN &&
s->drive->audio_first_sector != CDIO_INVALID_LSN)
st->duration = s->drive->audio_last_sector - s->drive->audio_first_sector;
else if (s->drive->tracks)
st->duration = s->drive->disc_toc[s->drive->tracks].dwStartSector;
avpriv_set_pts_info(st, 64, CDIO_CD_FRAMESIZE_RAW, 2*st->codec->channels*st->codec->sample_rate);
avpriv_set_pts_info(st, 64, CDIO_CD_FRAMESIZE_RAW, 2 * st->codecpar->channels * st->codecpar->sample_rate);
for (i = 0; i < s->drive->tracks; i++) {
char title[16];
......
......@@ -170,13 +170,12 @@ static inline int dc1394_read_common(AVFormatContext *c,
goto out;
}
avpriv_set_pts_info(vst, 64, 1, 1000);
vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
vst->codec->codec_id = AV_CODEC_ID_RAWVIDEO;
vst->codec->time_base.den = framerate.num;
vst->codec->time_base.num = framerate.den;
vst->codec->width = fmt->width;
vst->codec->height = fmt->height;
vst->codec->pix_fmt = fmt->pix_fmt;
vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
vst->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
vst->codecpar->width = fmt->width;
vst->codecpar->height = fmt->height;
vst->codecpar->format = fmt->pix_fmt;
vst->avg_frame_rate = framerate;
/* packet init */
av_init_packet(&dc1394->packet);
......@@ -187,7 +186,7 @@ static inline int dc1394_read_common(AVFormatContext *c,
dc1394->current_frame = 0;
vst->codec->bit_rate = av_rescale(dc1394->packet.size * 8, fps->frame_rate, 1000);
vst->codecpar->bit_rate = av_rescale(dc1394->packet.size * 8, fps->frame_rate, 1000);
*select_fps = fps;
*select_fmt = fmt;
out:
......
......@@ -61,10 +61,10 @@ static int audio_read_header(AVFormatContext *s1)
}
/* take real parameters */
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_id = s->codec_id;
st->codec->sample_rate = s->sample_rate;
st->codec->channels = s->channels;
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
st->codecpar->codec_id = s->codec_id;
st->codecpar->sample_rate = s->sample_rate;
st->codecpar->channels = s->channels;
avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
return 0;
......
......@@ -47,8 +47,8 @@ static int audio_write_header(AVFormatContext *s1)
int ret;
st = s1->streams[0];
s->sample_rate = st->codec->sample_rate;
s->channels = st->codec->channels;
s->sample_rate = st->codecpar->sample_rate;
s->channels = st->codecpar->channels;
ret = ff_oss_audio_open(s1, 1, s1->filename);
if (ret < 0) {
return AVERROR(EIO);
......
......@@ -107,10 +107,10 @@ static av_cold int pulse_read_header(AVFormatContext *s)
return AVERROR(EIO);
}
/* take real parameters */
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_id = codec_id;
st->codec->sample_rate = pd->sample_rate;
st->codec->channels = pd->channels;
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
st->codecpar->codec_id = codec_id;
st->codecpar->sample_rate = pd->sample_rate;
st->codecpar->channels = pd->channels;
avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
pd->pts = AV_NOPTS_VALUE;
......
......@@ -46,10 +46,10 @@ static av_cold int audio_read_header(AVFormatContext *s1)
return ret;
/* take real parameters */
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_id = s->codec_id;
st->codec->sample_rate = s->sample_rate;
st->codec->channels = s->channels;
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
st->codecpar->codec_id = s->codec_id;
st->codecpar->sample_rate = s->sample_rate;
st->codecpar->channels = s->channels;
avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
......
......@@ -35,8 +35,8 @@ static av_cold int audio_write_header(AVFormatContext *s1)
int ret;
st = s1->streams[0];
s->sample_rate = st->codec->sample_rate;
s->channels = st->codec->channels;
s->sample_rate = st->codecpar->sample_rate;
s->channels = st->codecpar->channels;
ret = ff_sndio_open(s1, 1, s1->filename);
......
......@@ -827,8 +827,8 @@ static int v4l2_read_header(AVFormatContext *s1)
if ((res = v4l2_set_parameters(s1) < 0))
return res;
st->codec->pix_fmt = fmt_v4l2ff(desired_format, codec_id);
s->frame_size = av_image_get_buffer_size(st->codec->pix_fmt,
st->codecpar->format = fmt_v4l2ff(desired_format, codec_id);
s->frame_size = av_image_get_buffer_size(st->codecpar->format,
s->width, s->height, 1);
if ((res = mmap_init(s1)) ||
......@@ -839,14 +839,14 @@ static int v4l2_read_header(AVFormatContext *s1)
s->top_field_first = first_field(s->fd);
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->codec->codec_id = codec_id;
st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
st->codecpar->codec_id = codec_id;
if (codec_id == AV_CODEC_ID_RAWVIDEO)
st->codec->codec_tag =
avcodec_pix_fmt_to_codec_tag(st->codec->pix_fmt);
st->codec->width = s->width;
st->codec->height = s->height;
st->codec->bit_rate = s->frame_size * av_q2d(st->avg_frame_rate) * 8;
st->codecpar->codec_tag =
avcodec_pix_fmt_to_codec_tag(st->codecpar->format);
st->codecpar->width = s->width;
st->codecpar->height = s->height;
st->codecpar->bit_rate = s->frame_size * av_q2d(st->avg_frame_rate) * 8;
return 0;
}
......
......@@ -244,7 +244,7 @@ static int vfw_read_close(AVFormatContext *s)
static int vfw_read_header(AVFormatContext *s)
{
struct vfw_ctx *ctx = s->priv_data;
AVCodecContext *codec;
AVCodecParameters *par;
AVStream *st;
int devnum;
int bisize;
......@@ -373,29 +373,30 @@ static int vfw_read_header(AVFormatContext *s)
if(!ret)
goto fail_io;
codec = st->codec;
codec->time_base = (AVRational){framerate_q.den, framerate_q.num};
codec->codec_type = AVMEDIA_TYPE_VIDEO;
codec->width = bi->bmiHeader.biWidth;
codec->height = bi->bmiHeader.biHeight;
codec->pix_fmt = vfw_pixfmt(biCompression, biBitCount);
if(codec->pix_fmt == AV_PIX_FMT_NONE) {
codec->codec_id = vfw_codecid(biCompression);
if(codec->codec_id == AV_CODEC_ID_NONE) {
st->avg_frame_rate = framerate_q;
par = st->codecpar;
par->codec_type = AVMEDIA_TYPE_VIDEO;
par->width = bi->bmiHeader.biWidth;
par->height = bi->bmiHeader.biHeight;
par->format = vfw_pixfmt(biCompression, biBitCount);
if (par->format == AV_PIX_FMT_NONE) {
par->codec_id = vfw_codecid(biCompression);
if (par->codec_id == AV_CODEC_ID_NONE) {
av_log(s, AV_LOG_ERROR, "Unknown compression type. "
"Please report verbose (-v 9) debug information.\n");
vfw_read_close(s);
return AVERROR_PATCHWELCOME;
}
codec->bits_per_coded_sample = biBitCount;
par->bits_per_coded_sample = biBitCount;
} else {
codec->codec_id = AV_CODEC_ID_RAWVIDEO;
par->codec_id = AV_CODEC_ID_RAWVIDEO;
if(biCompression == BI_RGB) {
codec->bits_per_coded_sample = biBitCount;
codec->extradata = av_malloc(9 + AV_INPUT_BUFFER_PADDING_SIZE);
if (codec->extradata) {
codec->extradata_size = 9;
memcpy(codec->extradata, "BottomUp", 9);
par->bits_per_coded_sample = biBitCount;
par->extradata = av_malloc(9 + AV_INPUT_BUFFER_PADDING_SIZE);
if (par->extradata) {
par->extradata_size = 9;
memcpy(par->extradata, "BottomUp", 9);
}
}
}
......
......@@ -347,16 +347,17 @@ static int x11grab_read_header(AVFormatContext *s1)
x11grab->image = image;
x11grab->use_shm = use_shm;
ret = pixfmt_from_image(s1, image, &st->codec->pix_fmt);
ret = pixfmt_from_image(s1, image, &st->codecpar->format);
if (ret < 0)
goto out;
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->codec->codec_id = AV_CODEC_ID_RAWVIDEO;
st->codec->width = x11grab->width;
st->codec->height = x11grab->height;
st->codec->time_base = x11grab->time_base;
st->codec->bit_rate = x11grab->frame_size * 1 / av_q2d(x11grab->time_base) * 8;
st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
st->codecpar->width = x11grab->width;
st->codecpar->height = x11grab->height;
st->codecpar->bit_rate = x11grab->frame_size * 1 / av_q2d(x11grab->time_base) * 8;
st->avg_frame_rate = av_inv_q(x11grab->time_base);
out:
av_free(param);
......
......@@ -544,13 +544,12 @@ static int create_stream(AVFormatContext *s)
st->avg_frame_rate.num };
c->time_frame = av_gettime();
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->codec->codec_id = AV_CODEC_ID_RAWVIDEO;
st->codec->width = c->width;
st->codec->height = c->height;
st->codec->time_base = c->time_base;
st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
st->codecpar->width = c->width;
st->codecpar->height = c->height;
ret = pixfmt_from_pixmap_format(s, geo->depth, &st->codec->pix_fmt);
ret = pixfmt_from_pixmap_format(s, geo->depth, &st->codecpar->format);
free(geo);
......
......@@ -108,16 +108,16 @@ static int parse_vtrk(AVFormatContext *s,
fourxm->video_stream_index = st->index;
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->codec->codec_id = AV_CODEC_ID_4XM;
st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
st->codecpar->codec_id = AV_CODEC_ID_4XM;
st->codec->extradata = av_mallocz(4 + AV_INPUT_BUFFER_PADDING_SIZE);
if (!st->codec->extradata)
st->codecpar->extradata = av_mallocz(4 + AV_INPUT_BUFFER_PADDING_SIZE);
if (!st->codecpar->extradata)
return AVERROR(ENOMEM);
st->codec->extradata_size = 4;
AV_WL32(st->codec->extradata, AV_RL32(buf + 16));
st->codec->width = AV_RL32(buf + 36);
st->codec->height = AV_RL32(buf + 40);
st->codecpar->extradata_size = 4;
AV_WL32(st->codecpar->extradata, AV_RL32(buf + 16));
st->codecpar->width = AV_RL32(buf + 36);
st->codecpar->height = AV_RL32(buf + 40);
return 0;
}
......@@ -165,23 +165,23 @@ static int parse_strk(AVFormatContext *s,
fourxm->tracks[track].stream_index = st->index;
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_tag = 0;
st->codec->channels = fourxm->tracks[track].channels;
st->codec->sample_rate = fourxm->tracks[track].sample_rate;
st->codec->bits_per_coded_sample = fourxm->tracks[track].bits;
st->codec->bit_rate = st->codec->channels *
st->codec->sample_rate *
st->codec->bits_per_coded_sample;
st->codec->block_align = st->codec->channels *
st->codec->bits_per_coded_sample;
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
st->codecpar->codec_tag = 0;
st->codecpar->channels = fourxm->tracks[track].channels;
st->codecpar->sample_rate = fourxm->tracks[track].sample_rate;
st->codecpar->bits_per_coded_sample = fourxm->tracks[track].bits;
st->codecpar->bit_rate = st->codecpar->channels *
st->codecpar->sample_rate *
st->codecpar->bits_per_coded_sample;
st->codecpar->block_align = st->codecpar->channels *
st->codecpar->bits_per_coded_sample;
if (fourxm->tracks[track].adpcm){
st->codec->codec_id = AV_CODEC_ID_ADPCM_4XM;
} else if (st->codec->bits_per_coded_sample == 8) {
st->codec->codec_id = AV_CODEC_ID_PCM_U8;
st->codecpar->codec_id = AV_CODEC_ID_ADPCM_4XM;
} else if (st->codecpar->bits_per_coded_sample == 8) {
st->codecpar->codec_id = AV_CODEC_ID_PCM_U8;
} else
st->codec->codec_id = AV_CODEC_ID_PCM_S16LE;
st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE;
return 0;
}
......
......@@ -27,7 +27,7 @@
static int a64_write_header(AVFormatContext *s)
{
AVCodecContext *avctx = s->streams[0]->codec;
AVCodecParameters *par = s->streams[0]->codecpar;
uint8_t header[5] = {
0x00, //load
0x40, //address
......@@ -36,20 +36,20 @@ static int a64_write_header(AVFormatContext *s)
0x00 //fps in 50/fps;
};
if (avctx->extradata_size < 4) {
if (par->extradata_size < 4) {
av_log(s, AV_LOG_ERROR, "Missing extradata\n");
return AVERROR_INVALIDDATA;
}
switch (avctx->codec->id) {
switch (par->codec_id) {
case AV_CODEC_ID_A64_MULTI:
header[2] = 0x00;
header[3] = AV_RB32(avctx->extradata+0);
header[3] = AV_RB32(par->extradata+0);
header[4] = 2;
break;
case AV_CODEC_ID_A64_MULTI5:
header[2] = 0x01;
header[3] = AV_RB32(avctx->extradata+0);
header[3] = AV_RB32(par->extradata+0);
header[4] = 3;
break;
default:
......
......@@ -82,8 +82,8 @@ static int adts_aac_read_header(AVFormatContext *s)
if (!st)
return AVERROR(ENOMEM);
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_id = s->iformat->raw_codec_id;
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
st->codecpar->codec_id = s->iformat->raw_codec_id;
st->need_parsing = AVSTREAM_PARSE_FULL;
ff_id3v1_read(s);
......
......@@ -91,11 +91,11 @@ static int adts_decode_extradata(AVFormatContext *s, ADTSContext *adts, uint8_t
static int adts_write_header(AVFormatContext *s)
{
ADTSContext *adts = s->priv_data;
AVCodecContext *avc = s->streams[0]->codec;
AVCodecParameters *par = s->streams[0]->codecpar;
if (avc->extradata_size > 0)
return adts_decode_extradata(s, adts, avc->extradata,
avc->extradata_size);
if (par->extradata_size > 0)
return adts_decode_extradata(s, adts, par->extradata,
par->extradata_size);
return 0;
}
......
......@@ -37,10 +37,10 @@ typedef struct ADXDemuxerContext {
static int adx_read_packet(AVFormatContext *s, AVPacket *pkt)
{
ADXDemuxerContext *c = s->priv_data;
AVCodecContext *avctx = s->streams[0]->codec;
AVCodecParameters *par = s->streams[0]->codecpar;
int ret, size;
size = BLOCK_SIZE * avctx->channels;
size = BLOCK_SIZE * par->channels;
pkt->pos = avio_tell(s->pb);
pkt->stream_index = 0;
......@@ -64,43 +64,43 @@ static int adx_read_packet(AVFormatContext *s, AVPacket *pkt)
static int adx_read_header(AVFormatContext *s)
{
ADXDemuxerContext *c = s->priv_data;
AVCodecContext *avctx;
AVCodecParameters *par;
AVStream *st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
avctx = s->streams[0]->codec;
par = s->streams[0]->codecpar;
if (avio_rb16(s->pb) != 0x8000)
return AVERROR_INVALIDDATA;
c->header_size = avio_rb16(s->pb) + 4;
avio_seek(s->pb, -4, SEEK_CUR);
avctx->extradata = av_mallocz(c->header_size + AV_INPUT_BUFFER_PADDING_SIZE);
if (!avctx->extradata)
par->extradata = av_mallocz(c->header_size + AV_INPUT_BUFFER_PADDING_SIZE);
if (!par->extradata)
return AVERROR(ENOMEM);
if (avio_read(s->pb, avctx->extradata, c->header_size) < c->header_size) {
av_freep(&avctx->extradata);
if (avio_read(s->pb, par->extradata, c->header_size) < c->header_size) {
av_freep(&par->extradata);
return AVERROR(EIO);
}
avctx->extradata_size = c->header_size;
par->extradata_size = c->header_size;
if (avctx->extradata_size < 12) {
if (par->extradata_size < 12) {
av_log(s, AV_LOG_ERROR, "Invalid extradata size.\n");
return AVERROR_INVALIDDATA;
}
avctx->channels = AV_RB8(avctx->extradata + 7);
avctx->sample_rate = AV_RB32(avctx->extradata + 8);
par->channels = AV_RB8 (par->extradata + 7);
par->sample_rate = AV_RB32(par->extradata + 8);
if (avctx->channels <= 0) {
av_log(s, AV_LOG_ERROR, "invalid number of channels %d\n", avctx->channels);
if (par->channels <= 0) {
av_log(s, AV_LOG_ERROR, "invalid number of channels %d\n", par->channels);
return AVERROR_INVALIDDATA;
}
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_id = s->iformat->raw_codec_id;
par->codec_type = AVMEDIA_TYPE_AUDIO;
par->codec_id = s->iformat->raw_codec_id;
avpriv_set_pts_info(st, 64, BLOCK_SAMPLES, avctx->sample_rate);
avpriv_set_pts_info(st, 64, BLOCK_SAMPLES, par->sample_rate);
return 0;
}
......