open a given stream. Return 0 if OK */
| 2686 | |
| 2687 | /* open a given stream. Return 0 if OK */ |
| 2688 | static int stream_component_open(VideoState *is, int stream_index) |
| 2689 | { |
| 2690 | AVFormatContext *ic = is->ic; |
| 2691 | AVCodecContext *avctx; |
| 2692 | const AVCodec *codec; |
| 2693 | const char *forced_codec_name = NULL; |
| 2694 | AVDictionary *opts = NULL; |
| 2695 | int sample_rate; |
| 2696 | AVChannelLayout ch_layout = { 0 }; |
| 2697 | int ret = 0; |
| 2698 | int stream_lowres = lowres; |
| 2699 | |
| 2700 | if (stream_index < 0 || stream_index >= ic->nb_streams) |
| 2701 | return -1; |
| 2702 | |
| 2703 | avctx = avcodec_alloc_context3(NULL); |
| 2704 | if (!avctx) |
| 2705 | return AVERROR(ENOMEM); |
| 2706 | |
| 2707 | ret = avcodec_parameters_to_context(avctx, ic->streams[stream_index]->codecpar); |
| 2708 | if (ret < 0) |
| 2709 | goto fail; |
| 2710 | avctx->pkt_timebase = ic->streams[stream_index]->time_base; |
| 2711 | |
| 2712 | codec = avcodec_find_decoder(avctx->codec_id); |
| 2713 | |
| 2714 | switch(avctx->codec_type){ |
| 2715 | case AVMEDIA_TYPE_AUDIO : is->last_audio_stream = stream_index; forced_codec_name = audio_codec_name; break; |
| 2716 | case AVMEDIA_TYPE_SUBTITLE: is->last_subtitle_stream = stream_index; forced_codec_name = subtitle_codec_name; break; |
| 2717 | case AVMEDIA_TYPE_VIDEO : is->last_video_stream = stream_index; forced_codec_name = video_codec_name; break; |
| 2718 | } |
| 2719 | if (forced_codec_name) |
| 2720 | codec = avcodec_find_decoder_by_name(forced_codec_name); |
| 2721 | if (!codec) { |
| 2722 | if (forced_codec_name) av_log(NULL, AV_LOG_WARNING, |
| 2723 | "No codec could be found with name '%s'\n", forced_codec_name); |
| 2724 | else av_log(NULL, AV_LOG_WARNING, |
| 2725 | "No decoder could be found for codec %s\n", avcodec_get_name(avctx->codec_id)); |
| 2726 | ret = AVERROR(EINVAL); |
| 2727 | goto fail; |
| 2728 | } |
| 2729 | |
| 2730 | avctx->codec_id = codec->id; |
| 2731 | if (stream_lowres > codec->max_lowres) { |
| 2732 | av_log(avctx, AV_LOG_WARNING, "The maximum value for lowres supported by the decoder is %d\n", |
| 2733 | codec->max_lowres); |
| 2734 | stream_lowres = codec->max_lowres; |
| 2735 | } |
| 2736 | avctx->lowres = stream_lowres; |
| 2737 | |
| 2738 | if (fast) |
| 2739 | avctx->flags2 |= AV_CODEC_FLAG2_FAST; |
| 2740 | |
| 2741 | ret = filter_codec_opts(codec_opts, avctx->codec_id, ic, |
| 2742 | ic->streams[stream_index], codec, &opts, NULL); |
| 2743 | if (ret < 0) |
| 2744 | goto fail; |
| 2745 |
no test coverage detected