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

Function ds_open

tools/decode_simple.c:120–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

118}
119
120int ds_open(DecodeContext *dc, const char *url, int stream_idx)
121{
122 const AVCodec *codec;
123 int ret;
124
125 memset(dc, 0, sizeof(*dc));
126
127 dc->pkt = av_packet_alloc();
128 dc->frame = av_frame_alloc();
129 if (!dc->pkt || !dc->frame) {
130 ret = AVERROR(ENOMEM);
131 goto fail;
132 }
133
134 ret = avformat_open_input(&dc->demuxer, url, NULL, NULL);
135 if (ret < 0) {
136 fprintf(stderr, "Error opening input file: %d\n", ret);
137 return ret;
138 }
139
140 if (stream_idx < 0 || stream_idx >= dc->demuxer->nb_streams)
141 return AVERROR(EINVAL);
142
143 dc->stream = dc->demuxer->streams[stream_idx];
144
145 codec = avcodec_find_decoder(dc->stream->codecpar->codec_id);
146 if (!codec)
147 return AVERROR_DECODER_NOT_FOUND;
148
149 dc->decoder = avcodec_alloc_context3(codec);
150 if (!dc->decoder)
151 return AVERROR(ENOMEM);
152
153 ret = avcodec_parameters_to_context(dc->decoder, dc->stream->codecpar);
154 if (ret < 0)
155 goto fail;
156
157 return 0;
158
159fail:
160 ds_free(dc);
161 return ret;
162}

Callers 3

mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 7

av_packet_allocFunction · 0.85
av_frame_allocFunction · 0.85
avformat_open_inputFunction · 0.85
avcodec_find_decoderFunction · 0.85
avcodec_alloc_context3Function · 0.85
ds_freeFunction · 0.85

Tested by 2

mainFunction · 0.68
mainFunction · 0.68