You've already forked FFmpeg
							
							
				mirror of
				https://github.com/FFmpeg/FFmpeg.git
				synced 2025-10-30 23:18:11 +02:00 
			
		
		
		
	ffplay: convert to codecpar
Tested-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Marton Balint <cus@passwd.hu>
This commit is contained in:
		
							
								
								
									
										56
									
								
								ffplay.c
									
									
									
									
									
								
							
							
						
						
									
										56
									
								
								ffplay.c
									
									
									
									
									
								
							| @@ -641,6 +641,7 @@ static int decoder_decode_frame(Decoder *d, AVFrame *frame, AVSubtitle *sub) { | ||||
|  | ||||
| static void decoder_destroy(Decoder *d) { | ||||
|     av_packet_unref(&d->pkt); | ||||
|     avcodec_free_context(&d->avctx); | ||||
| } | ||||
|  | ||||
| static void frame_queue_unref_item(Frame *vp) | ||||
| @@ -1139,13 +1140,13 @@ static void video_audio_display(VideoState *s) | ||||
| static void stream_component_close(VideoState *is, int stream_index) | ||||
| { | ||||
|     AVFormatContext *ic = is->ic; | ||||
|     AVCodecContext *avctx; | ||||
|     AVCodecParameters *codecpar; | ||||
|  | ||||
|     if (stream_index < 0 || stream_index >= ic->nb_streams) | ||||
|         return; | ||||
|     avctx = ic->streams[stream_index]->codec; | ||||
|     codecpar = ic->streams[stream_index]->codecpar; | ||||
|  | ||||
|     switch (avctx->codec_type) { | ||||
|     switch (codecpar->codec_type) { | ||||
|     case AVMEDIA_TYPE_AUDIO: | ||||
|         decoder_abort(&is->auddec, &is->sampq); | ||||
|         SDL_CloseAudio(); | ||||
| @@ -1175,8 +1176,7 @@ static void stream_component_close(VideoState *is, int stream_index) | ||||
|     } | ||||
|  | ||||
|     ic->streams[stream_index]->discard = AVDISCARD_ALL; | ||||
|     avcodec_close(avctx); | ||||
|     switch (avctx->codec_type) { | ||||
|     switch (codecpar->codec_type) { | ||||
|     case AVMEDIA_TYPE_AUDIO: | ||||
|         is->audio_st = NULL; | ||||
|         is->audio_stream = -1; | ||||
| @@ -1652,8 +1652,8 @@ display: | ||||
|                    aqsize / 1024, | ||||
|                    vqsize / 1024, | ||||
|                    sqsize, | ||||
|                    is->video_st ? is->video_st->codec->pts_correction_num_faulty_dts : 0, | ||||
|                    is->video_st ? is->video_st->codec->pts_correction_num_faulty_pts : 0); | ||||
|                    is->video_st ? is->viddec.avctx->pts_correction_num_faulty_dts : 0, | ||||
|                    is->video_st ? is->viddec.avctx->pts_correction_num_faulty_pts : 0); | ||||
|             fflush(stdout); | ||||
|             last_time = cur_time; | ||||
|         } | ||||
| @@ -1905,7 +1905,7 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c | ||||
|     char buffersrc_args[256]; | ||||
|     int ret; | ||||
|     AVFilterContext *filt_src = NULL, *filt_out = NULL, *last_filter = NULL; | ||||
|     AVCodecContext *codec = is->video_st->codec; | ||||
|     AVCodecParameters *codecpar = is->video_st->codecpar; | ||||
|     AVRational fr = av_guess_frame_rate(is->ic, is->video_st, NULL); | ||||
|     AVDictionaryEntry *e = NULL; | ||||
|  | ||||
| @@ -1924,7 +1924,7 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c | ||||
|              "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d", | ||||
|              frame->width, frame->height, frame->format, | ||||
|              is->video_st->time_base.num, is->video_st->time_base.den, | ||||
|              codec->sample_aspect_ratio.num, FFMAX(codec->sample_aspect_ratio.den, 1)); | ||||
|              codecpar->sample_aspect_ratio.num, FFMAX(codecpar->sample_aspect_ratio.den, 1)); | ||||
|     if (fr.num && fr.den) | ||||
|         av_strlcatf(buffersrc_args, sizeof(buffersrc_args), ":frame_rate=%d/%d", fr.num, fr.den); | ||||
|  | ||||
| @@ -2651,7 +2651,7 @@ static int stream_component_open(VideoState *is, int stream_index) | ||||
|     AVCodecContext *avctx; | ||||
|     AVCodec *codec; | ||||
|     const char *forced_codec_name = NULL; | ||||
|     AVDictionary *opts; | ||||
|     AVDictionary *opts = NULL; | ||||
|     AVDictionaryEntry *t = NULL; | ||||
|     int sample_rate, nb_channels; | ||||
|     int64_t channel_layout; | ||||
| @@ -2660,7 +2660,15 @@ static int stream_component_open(VideoState *is, int stream_index) | ||||
|  | ||||
|     if (stream_index < 0 || stream_index >= ic->nb_streams) | ||||
|         return -1; | ||||
|     avctx = ic->streams[stream_index]->codec; | ||||
|  | ||||
|     avctx = avcodec_alloc_context3(NULL); | ||||
|     if (!avctx) | ||||
|         return AVERROR(ENOMEM); | ||||
|  | ||||
|     ret = avcodec_parameters_to_context(avctx, ic->streams[stream_index]->codecpar); | ||||
|     if (ret < 0) | ||||
|         goto fail; | ||||
|     av_codec_set_pkt_timebase(avctx, ic->streams[stream_index]->time_base); | ||||
|  | ||||
|     codec = avcodec_find_decoder(avctx->codec_id); | ||||
|  | ||||
| @@ -2676,7 +2684,8 @@ static int stream_component_open(VideoState *is, int stream_index) | ||||
|                                       "No codec could be found with name '%s'\n", forced_codec_name); | ||||
|         else                   av_log(NULL, AV_LOG_WARNING, | ||||
|                                       "No codec could be found with id %d\n", avctx->codec_id); | ||||
|         return -1; | ||||
|         ret = AVERROR(EINVAL); | ||||
|         goto fail; | ||||
|     } | ||||
|  | ||||
|     avctx->codec_id = codec->id; | ||||
| @@ -2762,7 +2771,7 @@ static int stream_component_open(VideoState *is, int stream_index) | ||||
|             is->auddec.start_pts_tb = is->audio_st->time_base; | ||||
|         } | ||||
|         if ((ret = decoder_start(&is->auddec, audio_thread, is)) < 0) | ||||
|             goto fail; | ||||
|             goto out; | ||||
|         SDL_PauseAudio(0); | ||||
|         break; | ||||
|     case AVMEDIA_TYPE_VIDEO: | ||||
| @@ -2774,7 +2783,7 @@ static int stream_component_open(VideoState *is, int stream_index) | ||||
|  | ||||
|         decoder_init(&is->viddec, avctx, &is->videoq, is->continue_read_thread); | ||||
|         if ((ret = decoder_start(&is->viddec, video_thread, is)) < 0) | ||||
|             goto fail; | ||||
|             goto out; | ||||
|         is->queue_attachments_req = 1; | ||||
|         break; | ||||
|     case AVMEDIA_TYPE_SUBTITLE: | ||||
| @@ -2783,13 +2792,16 @@ static int stream_component_open(VideoState *is, int stream_index) | ||||
|  | ||||
|         decoder_init(&is->subdec, avctx, &is->subtitleq, is->continue_read_thread); | ||||
|         if ((ret = decoder_start(&is->subdec, subtitle_thread, is)) < 0) | ||||
|             goto fail; | ||||
|             goto out; | ||||
|         break; | ||||
|     default: | ||||
|         break; | ||||
|     } | ||||
|     goto out; | ||||
|  | ||||
| fail: | ||||
|     avcodec_free_context(&avctx); | ||||
| out: | ||||
|     av_dict_free(&opts); | ||||
|  | ||||
|     return ret; | ||||
| @@ -2928,7 +2940,7 @@ static int read_thread(void *arg) | ||||
|  | ||||
|     for (i = 0; i < ic->nb_streams; i++) { | ||||
|         AVStream *st = ic->streams[i]; | ||||
|         enum AVMediaType type = st->codec->codec_type; | ||||
|         enum AVMediaType type = st->codecpar->codec_type; | ||||
|         st->discard = AVDISCARD_ALL; | ||||
|         if (wanted_stream_spec[type] && st_index[type] == -1) | ||||
|             if (avformat_match_stream_specifier(ic, st, wanted_stream_spec[type]) > 0) | ||||
| @@ -2963,10 +2975,10 @@ static int read_thread(void *arg) | ||||
|     is->show_mode = show_mode; | ||||
|     if (st_index[AVMEDIA_TYPE_VIDEO] >= 0) { | ||||
|         AVStream *st = ic->streams[st_index[AVMEDIA_TYPE_VIDEO]]; | ||||
|         AVCodecContext *avctx = st->codec; | ||||
|         AVCodecParameters *codecpar = st->codecpar; | ||||
|         AVRational sar = av_guess_sample_aspect_ratio(ic, st, NULL); | ||||
|         if (avctx->width) | ||||
|             set_default_window_size(avctx->width, avctx->height, sar); | ||||
|         if (codecpar->width) | ||||
|             set_default_window_size(codecpar->width, codecpar->height, sar); | ||||
|     } | ||||
|  | ||||
|     /* open the streams */ | ||||
| @@ -3240,12 +3252,12 @@ static void stream_cycle_channel(VideoState *is, int codec_type) | ||||
|         if (stream_index == start_index) | ||||
|             return; | ||||
|         st = is->ic->streams[p ? p->stream_index[stream_index] : stream_index]; | ||||
|         if (st->codec->codec_type == codec_type) { | ||||
|         if (st->codecpar->codec_type == codec_type) { | ||||
|             /* check that parameters are OK */ | ||||
|             switch (codec_type) { | ||||
|             case AVMEDIA_TYPE_AUDIO: | ||||
|                 if (st->codec->sample_rate != 0 && | ||||
|                     st->codec->channels != 0) | ||||
|                 if (st->codecpar->sample_rate != 0 && | ||||
|                     st->codecpar->channels != 0) | ||||
|                     goto the_end; | ||||
|                 break; | ||||
|             case AVMEDIA_TYPE_VIDEO: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user