@@ -641,6 +641,7 @@ static int decoder_decode_frame(Decoder *d, AVFrame *frame, AVSubtitle *sub) {
641
641
642
642
static void decoder_destroy (Decoder * d ) {
643
643
av_packet_unref (& d -> pkt );
644
+ avcodec_free_context (& d -> avctx );
644
645
}
645
646
646
647
static void frame_queue_unref_item (Frame * vp )
@@ -1139,13 +1140,13 @@ static void video_audio_display(VideoState *s)
1139
1140
static void stream_component_close (VideoState * is , int stream_index )
1140
1141
{
1141
1142
AVFormatContext * ic = is -> ic ;
1142
- AVCodecContext * avctx ;
1143
+ AVCodecParameters * codecpar ;
1143
1144
1144
1145
if (stream_index < 0 || stream_index >= ic -> nb_streams )
1145
1146
return ;
1146
- avctx = ic -> streams [stream_index ]-> codec ;
1147
+ codecpar = ic -> streams [stream_index ]-> codecpar ;
1147
1148
1148
- switch (avctx -> codec_type ) {
1149
+ switch (codecpar -> codec_type ) {
1149
1150
case AVMEDIA_TYPE_AUDIO :
1150
1151
decoder_abort (& is -> auddec , & is -> sampq );
1151
1152
SDL_CloseAudio ();
@@ -1175,8 +1176,7 @@ static void stream_component_close(VideoState *is, int stream_index)
1175
1176
}
1176
1177
1177
1178
ic -> streams [stream_index ]-> discard = AVDISCARD_ALL ;
1178
- avcodec_close (avctx );
1179
- switch (avctx -> codec_type ) {
1179
+ switch (codecpar -> codec_type ) {
1180
1180
case AVMEDIA_TYPE_AUDIO :
1181
1181
is -> audio_st = NULL ;
1182
1182
is -> audio_stream = -1 ;
@@ -1652,8 +1652,8 @@ static void video_refresh(void *opaque, double *remaining_time)
1652
1652
aqsize / 1024 ,
1653
1653
vqsize / 1024 ,
1654
1654
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 );
1657
1657
fflush (stdout );
1658
1658
last_time = cur_time ;
1659
1659
}
@@ -1905,7 +1905,7 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c
1905
1905
char buffersrc_args [256 ];
1906
1906
int ret ;
1907
1907
AVFilterContext * filt_src = NULL , * filt_out = NULL , * last_filter = NULL ;
1908
- AVCodecContext * codec = is -> video_st -> codec ;
1908
+ AVCodecParameters * codecpar = is -> video_st -> codecpar ;
1909
1909
AVRational fr = av_guess_frame_rate (is -> ic , is -> video_st , NULL );
1910
1910
AVDictionaryEntry * e = NULL ;
1911
1911
@@ -1924,7 +1924,7 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c
1924
1924
"video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d" ,
1925
1925
frame -> width , frame -> height , frame -> format ,
1926
1926
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 ));
1928
1928
if (fr .num && fr .den )
1929
1929
av_strlcatf (buffersrc_args , sizeof (buffersrc_args ), ":frame_rate=%d/%d" , fr .num , fr .den );
1930
1930
@@ -2651,7 +2651,7 @@ static int stream_component_open(VideoState *is, int stream_index)
2651
2651
AVCodecContext * avctx ;
2652
2652
AVCodec * codec ;
2653
2653
const char * forced_codec_name = NULL ;
2654
- AVDictionary * opts ;
2654
+ AVDictionary * opts = NULL ;
2655
2655
AVDictionaryEntry * t = NULL ;
2656
2656
int sample_rate , nb_channels ;
2657
2657
int64_t channel_layout ;
@@ -2660,7 +2660,15 @@ static int stream_component_open(VideoState *is, int stream_index)
2660
2660
2661
2661
if (stream_index < 0 || stream_index >= ic -> nb_streams )
2662
2662
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 );
2664
2672
2665
2673
codec = avcodec_find_decoder (avctx -> codec_id );
2666
2674
@@ -2676,7 +2684,8 @@ static int stream_component_open(VideoState *is, int stream_index)
2676
2684
"No codec could be found with name '%s'\n" , forced_codec_name );
2677
2685
else av_log (NULL , AV_LOG_WARNING ,
2678
2686
"No codec could be found with id %d\n" , avctx -> codec_id );
2679
- return -1 ;
2687
+ ret = AVERROR (EINVAL );
2688
+ goto fail ;
2680
2689
}
2681
2690
2682
2691
avctx -> codec_id = codec -> id ;
@@ -2762,7 +2771,7 @@ static int stream_component_open(VideoState *is, int stream_index)
2762
2771
is -> auddec .start_pts_tb = is -> audio_st -> time_base ;
2763
2772
}
2764
2773
if ((ret = decoder_start (& is -> auddec , audio_thread , is )) < 0 )
2765
- goto fail ;
2774
+ goto out ;
2766
2775
SDL_PauseAudio (0 );
2767
2776
break ;
2768
2777
case AVMEDIA_TYPE_VIDEO :
@@ -2774,7 +2783,7 @@ static int stream_component_open(VideoState *is, int stream_index)
2774
2783
2775
2784
decoder_init (& is -> viddec , avctx , & is -> videoq , is -> continue_read_thread );
2776
2785
if ((ret = decoder_start (& is -> viddec , video_thread , is )) < 0 )
2777
- goto fail ;
2786
+ goto out ;
2778
2787
is -> queue_attachments_req = 1 ;
2779
2788
break ;
2780
2789
case AVMEDIA_TYPE_SUBTITLE :
@@ -2783,13 +2792,16 @@ static int stream_component_open(VideoState *is, int stream_index)
2783
2792
2784
2793
decoder_init (& is -> subdec , avctx , & is -> subtitleq , is -> continue_read_thread );
2785
2794
if ((ret = decoder_start (& is -> subdec , subtitle_thread , is )) < 0 )
2786
- goto fail ;
2795
+ goto out ;
2787
2796
break ;
2788
2797
default :
2789
2798
break ;
2790
2799
}
2800
+ goto out ;
2791
2801
2792
2802
fail :
2803
+ avcodec_free_context (& avctx );
2804
+ out :
2793
2805
av_dict_free (& opts );
2794
2806
2795
2807
return ret ;
@@ -2928,7 +2940,7 @@ static int read_thread(void *arg)
2928
2940
2929
2941
for (i = 0 ; i < ic -> nb_streams ; i ++ ) {
2930
2942
AVStream * st = ic -> streams [i ];
2931
- enum AVMediaType type = st -> codec -> codec_type ;
2943
+ enum AVMediaType type = st -> codecpar -> codec_type ;
2932
2944
st -> discard = AVDISCARD_ALL ;
2933
2945
if (wanted_stream_spec [type ] && st_index [type ] == -1 )
2934
2946
if (avformat_match_stream_specifier (ic , st , wanted_stream_spec [type ]) > 0 )
@@ -2963,10 +2975,10 @@ static int read_thread(void *arg)
2963
2975
is -> show_mode = show_mode ;
2964
2976
if (st_index [AVMEDIA_TYPE_VIDEO ] >= 0 ) {
2965
2977
AVStream * st = ic -> streams [st_index [AVMEDIA_TYPE_VIDEO ]];
2966
- AVCodecContext * avctx = st -> codec ;
2978
+ AVCodecParameters * codecpar = st -> codecpar ;
2967
2979
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 );
2970
2982
}
2971
2983
2972
2984
/* open the streams */
@@ -3240,12 +3252,12 @@ static void stream_cycle_channel(VideoState *is, int codec_type)
3240
3252
if (stream_index == start_index )
3241
3253
return ;
3242
3254
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 ) {
3244
3256
/* check that parameters are OK */
3245
3257
switch (codec_type ) {
3246
3258
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 )
3249
3261
goto the_end ;
3250
3262
break ;
3251
3263
case AVMEDIA_TYPE_VIDEO :
0 commit comments