MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / try_decode_frame

Function try_decode_frame

libavformat/demux.c:2138–2238  ·  view source on GitHub ↗

returns 1 or 0 if or if not decoded data was returned, or a negative error */

Source from the content-addressed store, hash-verified

2136
2137/* returns 1 or 0 if or if not decoded data was returned, or a negative error */
2138static int try_decode_frame(AVFormatContext *s, AVStream *st,
2139 const AVPacket *pkt, AVDictionary **options)
2140{
2141 FFStream *const sti = ffstream(st);
2142 AVCodecContext *const avctx = sti->avctx;
2143 const AVCodec *codec;
2144 int got_picture = 1, ret = 0;
2145 AVFrame *frame = av_frame_alloc();
2146 AVSubtitle subtitle;
2147 int do_skip_frame = 0;
2148 enum AVDiscard skip_frame;
2149 int pkt_to_send = pkt->size > 0;
2150
2151 if (!frame)
2152 return AVERROR(ENOMEM);
2153
2154 if (!avcodec_is_open(avctx) &&
2155 sti->info->found_decoder <= 0 &&
2156 (st->codecpar->codec_id != -sti->info->found_decoder || !st->codecpar->codec_id)) {
2157 AVDictionary *thread_opt = NULL;
2158
2159 codec = find_probe_decoder(s, st, st->codecpar->codec_id);
2160
2161 if (!codec) {
2162 sti->info->found_decoder = -st->codecpar->codec_id;
2163 ret = -1;
2164 goto fail;
2165 }
2166
2167 /* Force thread count to 1 since the H.264 decoder will not extract
2168 * SPS and PPS to extradata during multi-threaded decoding. */
2169 av_dict_set(options ? options : &thread_opt, "threads", "1", 0);
2170 /* Force lowres to 0. The decoder might reduce the video size by the
2171 * lowres factor, and we don't want that propagated to the stream's
2172 * codecpar */
2173 av_dict_set(options ? options : &thread_opt, "lowres", "0", 0);
2174 if (s->codec_whitelist)
2175 av_dict_set(options ? options : &thread_opt, "codec_whitelist", s->codec_whitelist, 0);
2176 ret = avcodec_open2(avctx, codec, options ? options : &thread_opt);
2177 if (!options)
2178 av_dict_free(&thread_opt);
2179 if (ret < 0) {
2180 sti->info->found_decoder = -avctx->codec_id;
2181 goto fail;
2182 }
2183 sti->info->found_decoder = 1;
2184 } else if (!sti->info->found_decoder)
2185 sti->info->found_decoder = 1;
2186
2187 if (sti->info->found_decoder < 0) {
2188 ret = -1;
2189 goto fail;
2190 }
2191
2192 if (avpriv_codec_get_cap_skip_frame_fill_param(avctx->codec)) {
2193 do_skip_frame = 1;
2194 skip_frame = avctx->skip_frame;
2195 avctx->skip_frame = AVDISCARD_ALL;

Callers 1

Calls 15

ffstreamFunction · 0.85
av_frame_allocFunction · 0.85
avcodec_is_openFunction · 0.85
find_probe_decoderFunction · 0.85
av_dict_setFunction · 0.85
avcodec_open2Function · 0.85
av_dict_freeFunction · 0.85
has_codec_parametersFunction · 0.85
avcodec_send_packetFunction · 0.85
avcodec_receive_frameFunction · 0.85

Tested by

no test coverage detected