Skip to content

Commit 9200514

Browse files
committed
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.
1 parent a806834 commit 9200514

File tree

251 files changed

+4515
-4304
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

251 files changed

+4515
-4304
lines changed

libavdevice/alsa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode,
194194
snd_pcm_t *h;
195195
snd_pcm_hw_params_t *hw_params;
196196
snd_pcm_uframes_t buffer_size, period_size;
197-
uint64_t layout = ctx->streams[0]->codec->channel_layout;
197+
uint64_t layout = ctx->streams[0]->codecpar->channel_layout;
198198

199199
if (ctx->filename[0] == 0) audio_device = "default";
200200
else audio_device = ctx->filename;

libavdevice/alsa_dec.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ static av_cold int audio_read_header(AVFormatContext *s1)
101101
}
102102

103103
/* take real parameters */
104-
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
105-
st->codec->codec_id = codec_id;
106-
st->codec->sample_rate = s->sample_rate;
107-
st->codec->channels = s->channels;
104+
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
105+
st->codecpar->codec_id = codec_id;
106+
st->codecpar->sample_rate = s->sample_rate;
107+
st->codecpar->channels = s->channels;
108108
avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
109109

110110
return 0;
@@ -144,9 +144,9 @@ static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)
144144
snd_pcm_htimestamp(s->h, &ts_delay, &timestamp);
145145
ts_delay += res;
146146
pkt->pts = timestamp.tv_sec * 1000000LL
147-
+ (timestamp.tv_nsec * st->codec->sample_rate
148-
- (int64_t)ts_delay * 1000000000LL + st->codec->sample_rate * 500LL)
149-
/ (st->codec->sample_rate * 1000LL);
147+
+ (timestamp.tv_nsec * st->codecpar->sample_rate
148+
- (int64_t)ts_delay * 1000000000LL + st->codecpar->sample_rate * 500LL)
149+
/ (st->codecpar->sample_rate * 1000LL);
150150

151151
pkt->size = res * s->frame_size;
152152

libavdevice/alsa_enc.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ static av_cold int audio_write_header(AVFormatContext *s1)
5454
int res;
5555

5656
st = s1->streams[0];
57-
sample_rate = st->codec->sample_rate;
58-
codec_id = st->codec->codec_id;
57+
sample_rate = st->codecpar->sample_rate;
58+
codec_id = st->codecpar->codec_id;
5959
res = ff_alsa_open(s1, SND_PCM_STREAM_PLAYBACK, &sample_rate,
60-
st->codec->channels, &codec_id);
61-
if (sample_rate != st->codec->sample_rate) {
60+
st->codecpar->channels, &codec_id);
61+
if (sample_rate != st->codecpar->sample_rate) {
6262
av_log(s1, AV_LOG_ERROR,
6363
"sample rate %d not available, nearest is %d\n",
64-
st->codec->sample_rate, sample_rate);
64+
st->codecpar->sample_rate, sample_rate);
6565
goto fail;
6666
}
6767

libavdevice/bktr.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -295,13 +295,12 @@ static int grab_read_header(AVFormatContext *s1)
295295
s->height = height;
296296
s->per_frame = ((uint64_t)1000000 * framerate.den) / framerate.num;
297297

298-
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
299-
st->codec->pix_fmt = AV_PIX_FMT_YUV420P;
300-
st->codec->codec_id = AV_CODEC_ID_RAWVIDEO;
301-
st->codec->width = width;
302-
st->codec->height = height;
303-
st->codec->time_base.den = framerate.num;
304-
st->codec->time_base.num = framerate.den;
298+
st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
299+
st->codecpar->format = AV_PIX_FMT_YUV420P;
300+
st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
301+
st->codecpar->width = width;
302+
st->codecpar->height = height;
303+
st->avg_frame_rate = framerate;
305304

306305

307306
if (bktr_init(s1->filename, width, height, s->standard,

libavdevice/fbdev.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,21 +164,21 @@ static av_cold int fbdev_read_header(AVFormatContext *avctx)
164164
goto fail;
165165
}
166166

167-
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
168-
st->codec->codec_id = AV_CODEC_ID_RAWVIDEO;
169-
st->codec->width = fbdev->width;
170-
st->codec->height = fbdev->height;
171-
st->codec->pix_fmt = pix_fmt;
172-
st->codec->time_base = (AVRational){fbdev->framerate_q.den, fbdev->framerate_q.num};
173-
st->codec->bit_rate =
167+
st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
168+
st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
169+
st->codecpar->width = fbdev->width;
170+
st->codecpar->height = fbdev->height;
171+
st->codecpar->format = pix_fmt;
172+
st->codecpar->bit_rate =
174173
fbdev->width * fbdev->height * fbdev->bytes_per_pixel * av_q2d(fbdev->framerate_q) * 8;
174+
st->avg_frame_rate = fbdev->framerate_q;
175175

176176
av_log(avctx, AV_LOG_INFO,
177177
"w:%d h:%d bpp:%d pixfmt:%s fps:%d/%d bit_rate:%d\n",
178178
fbdev->width, fbdev->height, fbdev->varinfo.bits_per_pixel,
179179
av_get_pix_fmt_name(pix_fmt),
180180
fbdev->framerate_q.num, fbdev->framerate_q.den,
181-
st->codec->bit_rate);
181+
st->codecpar->bit_rate);
182182
return 0;
183183

184184
fail:

libavdevice/jack.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,14 @@ static int audio_read_header(AVFormatContext *context)
254254
return AVERROR(ENOMEM);
255255
}
256256

257-
stream->codec->codec_type = AVMEDIA_TYPE_AUDIO;
257+
stream->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
258258
#if HAVE_BIGENDIAN
259-
stream->codec->codec_id = AV_CODEC_ID_PCM_F32BE;
259+
stream->codecpar->codec_id = AV_CODEC_ID_PCM_F32BE;
260260
#else
261-
stream->codec->codec_id = AV_CODEC_ID_PCM_F32LE;
261+
stream->codecpar->codec_id = AV_CODEC_ID_PCM_F32LE;
262262
#endif
263-
stream->codec->sample_rate = self->sample_rate;
264-
stream->codec->channels = self->nports;
263+
stream->codecpar->sample_rate = self->sample_rate;
264+
stream->codecpar->channels = self->nports;
265265

266266
avpriv_set_pts_info(stream, 64, 1, 1000000); /* 64 bits pts in us */
267267
return 0;

libavdevice/libcdio.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,19 @@ static av_cold int read_header(AVFormatContext *ctx)
8585
}
8686
cdio_paranoia_modeset(s->paranoia, s->paranoia_mode);
8787

88-
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
88+
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
8989
if (s->drive->bigendianp)
90-
st->codec->codec_id = AV_CODEC_ID_PCM_S16BE;
90+
st->codecpar->codec_id = AV_CODEC_ID_PCM_S16BE;
9191
else
92-
st->codec->codec_id = AV_CODEC_ID_PCM_S16LE;
93-
st->codec->sample_rate = 44100;
94-
st->codec->channels = 2;
92+
st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE;
93+
st->codecpar->sample_rate = 44100;
94+
st->codecpar->channels = 2;
9595
if (s->drive->audio_last_sector != CDIO_INVALID_LSN &&
9696
s->drive->audio_first_sector != CDIO_INVALID_LSN)
9797
st->duration = s->drive->audio_last_sector - s->drive->audio_first_sector;
9898
else if (s->drive->tracks)
9999
st->duration = s->drive->disc_toc[s->drive->tracks].dwStartSector;
100-
avpriv_set_pts_info(st, 64, CDIO_CD_FRAMESIZE_RAW, 2*st->codec->channels*st->codec->sample_rate);
100+
avpriv_set_pts_info(st, 64, CDIO_CD_FRAMESIZE_RAW, 2 * st->codecpar->channels * st->codecpar->sample_rate);
101101

102102
for (i = 0; i < s->drive->tracks; i++) {
103103
char title[16];

libavdevice/libdc1394.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,12 @@ static inline int dc1394_read_common(AVFormatContext *c,
170170
goto out;
171171
}
172172
avpriv_set_pts_info(vst, 64, 1, 1000);
173-
vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
174-
vst->codec->codec_id = AV_CODEC_ID_RAWVIDEO;
175-
vst->codec->time_base.den = framerate.num;
176-
vst->codec->time_base.num = framerate.den;
177-
vst->codec->width = fmt->width;
178-
vst->codec->height = fmt->height;
179-
vst->codec->pix_fmt = fmt->pix_fmt;
173+
vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
174+
vst->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
175+
vst->codecpar->width = fmt->width;
176+
vst->codecpar->height = fmt->height;
177+
vst->codecpar->format = fmt->pix_fmt;
178+
vst->avg_frame_rate = framerate;
180179

181180
/* packet init */
182181
av_init_packet(&dc1394->packet);
@@ -187,7 +186,7 @@ static inline int dc1394_read_common(AVFormatContext *c,
187186

188187
dc1394->current_frame = 0;
189188

190-
vst->codec->bit_rate = av_rescale(dc1394->packet.size * 8, fps->frame_rate, 1000);
189+
vst->codecpar->bit_rate = av_rescale(dc1394->packet.size * 8, fps->frame_rate, 1000);
191190
*select_fps = fps;
192191
*select_fmt = fmt;
193192
out:

libavdevice/oss_dec.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ static int audio_read_header(AVFormatContext *s1)
6161
}
6262

6363
/* take real parameters */
64-
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
65-
st->codec->codec_id = s->codec_id;
66-
st->codec->sample_rate = s->sample_rate;
67-
st->codec->channels = s->channels;
64+
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
65+
st->codecpar->codec_id = s->codec_id;
66+
st->codecpar->sample_rate = s->sample_rate;
67+
st->codecpar->channels = s->channels;
6868

6969
avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
7070
return 0;

libavdevice/oss_enc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ static int audio_write_header(AVFormatContext *s1)
4747
int ret;
4848

4949
st = s1->streams[0];
50-
s->sample_rate = st->codec->sample_rate;
51-
s->channels = st->codec->channels;
50+
s->sample_rate = st->codecpar->sample_rate;
51+
s->channels = st->codecpar->channels;
5252
ret = ff_oss_audio_open(s1, 1, s1->filename);
5353
if (ret < 0) {
5454
return AVERROR(EIO);

0 commit comments

Comments
 (0)