Skip to content

Commit ee94b1a

Browse files
committed
ffplay: convert to codecpar
Tested-by: Michael Niedermayer <[email protected]> Signed-off-by: Marton Balint <[email protected]>
1 parent af5419f commit ee94b1a

File tree

1 file changed

+34
-22
lines changed

1 file changed

+34
-22
lines changed

ffplay.c

+34-22
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ static int decoder_decode_frame(Decoder *d, AVFrame *frame, AVSubtitle *sub) {
641641

642642
static void decoder_destroy(Decoder *d) {
643643
av_packet_unref(&d->pkt);
644+
avcodec_free_context(&d->avctx);
644645
}
645646

646647
static void frame_queue_unref_item(Frame *vp)
@@ -1139,13 +1140,13 @@ static void video_audio_display(VideoState *s)
11391140
static void stream_component_close(VideoState *is, int stream_index)
11401141
{
11411142
AVFormatContext *ic = is->ic;
1142-
AVCodecContext *avctx;
1143+
AVCodecParameters *codecpar;
11431144

11441145
if (stream_index < 0 || stream_index >= ic->nb_streams)
11451146
return;
1146-
avctx = ic->streams[stream_index]->codec;
1147+
codecpar = ic->streams[stream_index]->codecpar;
11471148

1148-
switch (avctx->codec_type) {
1149+
switch (codecpar->codec_type) {
11491150
case AVMEDIA_TYPE_AUDIO:
11501151
decoder_abort(&is->auddec, &is->sampq);
11511152
SDL_CloseAudio();
@@ -1175,8 +1176,7 @@ static void stream_component_close(VideoState *is, int stream_index)
11751176
}
11761177

11771178
ic->streams[stream_index]->discard = AVDISCARD_ALL;
1178-
avcodec_close(avctx);
1179-
switch (avctx->codec_type) {
1179+
switch (codecpar->codec_type) {
11801180
case AVMEDIA_TYPE_AUDIO:
11811181
is->audio_st = NULL;
11821182
is->audio_stream = -1;
@@ -1652,8 +1652,8 @@ static void video_refresh(void *opaque, double *remaining_time)
16521652
aqsize / 1024,
16531653
vqsize / 1024,
16541654
sqsize,
1655-
is->video_st ? is->video_st->codec->pts_correction_num_faulty_dts : 0,
1656-
is->video_st ? is->video_st->codec->pts_correction_num_faulty_pts : 0);
1655+
is->video_st ? is->viddec.avctx->pts_correction_num_faulty_dts : 0,
1656+
is->video_st ? is->viddec.avctx->pts_correction_num_faulty_pts : 0);
16571657
fflush(stdout);
16581658
last_time = cur_time;
16591659
}
@@ -1905,7 +1905,7 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c
19051905
char buffersrc_args[256];
19061906
int ret;
19071907
AVFilterContext *filt_src = NULL, *filt_out = NULL, *last_filter = NULL;
1908-
AVCodecContext *codec = is->video_st->codec;
1908+
AVCodecParameters *codecpar = is->video_st->codecpar;
19091909
AVRational fr = av_guess_frame_rate(is->ic, is->video_st, NULL);
19101910
AVDictionaryEntry *e = NULL;
19111911

@@ -1924,7 +1924,7 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c
19241924
"video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
19251925
frame->width, frame->height, frame->format,
19261926
is->video_st->time_base.num, is->video_st->time_base.den,
1927-
codec->sample_aspect_ratio.num, FFMAX(codec->sample_aspect_ratio.den, 1));
1927+
codecpar->sample_aspect_ratio.num, FFMAX(codecpar->sample_aspect_ratio.den, 1));
19281928
if (fr.num && fr.den)
19291929
av_strlcatf(buffersrc_args, sizeof(buffersrc_args), ":frame_rate=%d/%d", fr.num, fr.den);
19301930

@@ -2651,7 +2651,7 @@ static int stream_component_open(VideoState *is, int stream_index)
26512651
AVCodecContext *avctx;
26522652
AVCodec *codec;
26532653
const char *forced_codec_name = NULL;
2654-
AVDictionary *opts;
2654+
AVDictionary *opts = NULL;
26552655
AVDictionaryEntry *t = NULL;
26562656
int sample_rate, nb_channels;
26572657
int64_t channel_layout;
@@ -2660,7 +2660,15 @@ static int stream_component_open(VideoState *is, int stream_index)
26602660

26612661
if (stream_index < 0 || stream_index >= ic->nb_streams)
26622662
return -1;
2663-
avctx = ic->streams[stream_index]->codec;
2663+
2664+
avctx = avcodec_alloc_context3(NULL);
2665+
if (!avctx)
2666+
return AVERROR(ENOMEM);
2667+
2668+
ret = avcodec_parameters_to_context(avctx, ic->streams[stream_index]->codecpar);
2669+
if (ret < 0)
2670+
goto fail;
2671+
av_codec_set_pkt_timebase(avctx, ic->streams[stream_index]->time_base);
26642672

26652673
codec = avcodec_find_decoder(avctx->codec_id);
26662674

@@ -2676,7 +2684,8 @@ static int stream_component_open(VideoState *is, int stream_index)
26762684
"No codec could be found with name '%s'\n", forced_codec_name);
26772685
else av_log(NULL, AV_LOG_WARNING,
26782686
"No codec could be found with id %d\n", avctx->codec_id);
2679-
return -1;
2687+
ret = AVERROR(EINVAL);
2688+
goto fail;
26802689
}
26812690

26822691
avctx->codec_id = codec->id;
@@ -2762,7 +2771,7 @@ static int stream_component_open(VideoState *is, int stream_index)
27622771
is->auddec.start_pts_tb = is->audio_st->time_base;
27632772
}
27642773
if ((ret = decoder_start(&is->auddec, audio_thread, is)) < 0)
2765-
goto fail;
2774+
goto out;
27662775
SDL_PauseAudio(0);
27672776
break;
27682777
case AVMEDIA_TYPE_VIDEO:
@@ -2774,7 +2783,7 @@ static int stream_component_open(VideoState *is, int stream_index)
27742783

27752784
decoder_init(&is->viddec, avctx, &is->videoq, is->continue_read_thread);
27762785
if ((ret = decoder_start(&is->viddec, video_thread, is)) < 0)
2777-
goto fail;
2786+
goto out;
27782787
is->queue_attachments_req = 1;
27792788
break;
27802789
case AVMEDIA_TYPE_SUBTITLE:
@@ -2783,13 +2792,16 @@ static int stream_component_open(VideoState *is, int stream_index)
27832792

27842793
decoder_init(&is->subdec, avctx, &is->subtitleq, is->continue_read_thread);
27852794
if ((ret = decoder_start(&is->subdec, subtitle_thread, is)) < 0)
2786-
goto fail;
2795+
goto out;
27872796
break;
27882797
default:
27892798
break;
27902799
}
2800+
goto out;
27912801

27922802
fail:
2803+
avcodec_free_context(&avctx);
2804+
out:
27932805
av_dict_free(&opts);
27942806

27952807
return ret;
@@ -2928,7 +2940,7 @@ static int read_thread(void *arg)
29282940

29292941
for (i = 0; i < ic->nb_streams; i++) {
29302942
AVStream *st = ic->streams[i];
2931-
enum AVMediaType type = st->codec->codec_type;
2943+
enum AVMediaType type = st->codecpar->codec_type;
29322944
st->discard = AVDISCARD_ALL;
29332945
if (wanted_stream_spec[type] && st_index[type] == -1)
29342946
if (avformat_match_stream_specifier(ic, st, wanted_stream_spec[type]) > 0)
@@ -2963,10 +2975,10 @@ static int read_thread(void *arg)
29632975
is->show_mode = show_mode;
29642976
if (st_index[AVMEDIA_TYPE_VIDEO] >= 0) {
29652977
AVStream *st = ic->streams[st_index[AVMEDIA_TYPE_VIDEO]];
2966-
AVCodecContext *avctx = st->codec;
2978+
AVCodecParameters *codecpar = st->codecpar;
29672979
AVRational sar = av_guess_sample_aspect_ratio(ic, st, NULL);
2968-
if (avctx->width)
2969-
set_default_window_size(avctx->width, avctx->height, sar);
2980+
if (codecpar->width)
2981+
set_default_window_size(codecpar->width, codecpar->height, sar);
29702982
}
29712983

29722984
/* open the streams */
@@ -3240,12 +3252,12 @@ static void stream_cycle_channel(VideoState *is, int codec_type)
32403252
if (stream_index == start_index)
32413253
return;
32423254
st = is->ic->streams[p ? p->stream_index[stream_index] : stream_index];
3243-
if (st->codec->codec_type == codec_type) {
3255+
if (st->codecpar->codec_type == codec_type) {
32443256
/* check that parameters are OK */
32453257
switch (codec_type) {
32463258
case AVMEDIA_TYPE_AUDIO:
3247-
if (st->codec->sample_rate != 0 &&
3248-
st->codec->channels != 0)
3259+
if (st->codecpar->sample_rate != 0 &&
3260+
st->codecpar->channels != 0)
32493261
goto the_end;
32503262
break;
32513263
case AVMEDIA_TYPE_VIDEO:

0 commit comments

Comments
 (0)