| 296 | } |
| 297 | |
| 298 | void cFFmpegSource::readAndSendPacketToDecoder() |
| 299 | { |
| 300 | readFrame: |
| 301 | AVPacket avPacket; |
| 302 | av_init_packet(&avPacket); |
| 303 | avPacket.data = NULL; |
| 304 | avPacket.size = 0; |
| 305 | |
| 306 | int ret = av_read_frame(avFormatContext, &avPacket); |
| 307 | if (ret >= 0) { |
| 308 | // discard any packets that do not belong to the audio stream we are interested in |
| 309 | if (avPacket.stream_index != audioStreamIndex) { |
| 310 | av_packet_unref(&avPacket); |
| 311 | goto readFrame; |
| 312 | } |
| 313 | // send packet to decoder |
| 314 | if ((ret = avcodec_send_packet(avCodecContext, &avPacket)) < 0) { |
| 315 | COMP_ERR("Error sending packet to decoder. %s",avGetErrorString(ret)); |
| 316 | } |
| 317 | av_packet_unref(&avPacket); |
| 318 | } else if (ret == AVERROR_EOF) { |
| 319 | // reached end-of-input, send a flush packet to flush decoder |
| 320 | if ((ret = avcodec_send_packet(avCodecContext, NULL)) < 0) { |
| 321 | COMP_ERR("Error flushing decoder. %s",avGetErrorString(ret)); |
| 322 | } |
| 323 | } else { |
| 324 | COMP_ERR("Error reading frame. %s",avGetErrorString(ret)); |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | // Receives decoded data from the decoder |
| 329 | // Return value: -1 eof, 0 error, > 0 num samples read |
nothing calls this directly
no test coverage detected