| 256 | } |
| 257 | |
| 258 | void cFFmpegSource::openAVCodecContext(int *streamIndex, AVCodecContext **avCodecContext, AVFormatContext *avFormatContext) |
| 259 | { |
| 260 | int ret; |
| 261 | |
| 262 | // find audio stream and get decoder for it |
| 263 | AVCodec *decoder; |
| 264 | if ((ret = av_find_best_stream(avFormatContext, AVMEDIA_TYPE_AUDIO, -1, -1, &decoder, 0)) < 0) { |
| 265 | COMP_ERR("Could not find an audio stream in the input file. %s",avGetErrorString(ret)); |
| 266 | } |
| 267 | |
| 268 | *streamIndex = ret; |
| 269 | AVStream *stream = avFormatContext->streams[*streamIndex]; |
| 270 | |
| 271 | // set discard flag for all other streams so the demuxer may skip them |
| 272 | // some demuxers ignore this flag so we still need to skip packets manually in readAndSendPacketToDecoder() |
| 273 | for (int i = 0; i < avFormatContext->nb_streams; i++) { |
| 274 | if (i != *streamIndex) { |
| 275 | avFormatContext->streams[i]->discard = AVDISCARD_ALL; |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | *avCodecContext = avcodec_alloc_context3(decoder); |
| 280 | if (!*avCodecContext) { |
| 281 | COMP_ERR("Could not allocate audio codec context"); |
| 282 | } |
| 283 | |
| 284 | // copy codec parameters from input stream to output codec context |
| 285 | if ((ret = avcodec_parameters_to_context(*avCodecContext, stream->codecpar)) < 0) { |
| 286 | COMP_ERR("Could not copy audio codec parameters to decoder context. %s",avGetErrorString(ret)); |
| 287 | } |
| 288 | |
| 289 | // initialize the decoder with reference counting |
| 290 | AVDictionary *options = NULL; |
| 291 | av_dict_set(&options, "refcounted_frames", "1", 0); |
| 292 | |
| 293 | if ((ret = avcodec_open2(*avCodecContext, decoder, &options)) < 0) { |
| 294 | COMP_ERR("Could not open audio codec. %s",avGetErrorString(ret)); |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | void cFFmpegSource::readAndSendPacketToDecoder() |
| 299 | { |
nothing calls this directly
no test coverage detected