All paths in this that fail must report their error to the user.
| 1547 | |
| 1548 | // All paths in this that fail must report their error to the user. |
| 1549 | bool FFmpegExporter::EncodeAudioFrame(int16_t *pFrame, size_t numSamples) |
| 1550 | { |
| 1551 | const auto frameSize = numSamples * sizeof(int16_t) * mChannels; |
| 1552 | int nBytesToWrite = 0; |
| 1553 | uint8_t *pRawSamples = nullptr; |
| 1554 | int nAudioFrameSizeOut = mDefaultFrameSize * mEncAudioCodecCtx->GetChannels() * sizeof(int16_t); |
| 1555 | int ret; |
| 1556 | |
| 1557 | nBytesToWrite = frameSize; |
| 1558 | pRawSamples = (uint8_t*)pFrame; |
| 1559 | |
| 1560 | // Put the raw audio samples into the FIFO. |
| 1561 | ret = mEncAudioFifo->Write(pRawSamples, nBytesToWrite); |
| 1562 | |
| 1563 | if (ret != nBytesToWrite) { |
| 1564 | throw ExportErrorException("FFmpeg:913"); |
| 1565 | } |
| 1566 | |
| 1567 | if (nAudioFrameSizeOut > mEncAudioFifoOutBufSize) { |
| 1568 | throw ExportException(_("FFmpeg : ERROR - nAudioFrameSizeOut too large.")); |
| 1569 | } |
| 1570 | |
| 1571 | // Read raw audio samples out of the FIFO in nAudioFrameSizeOut byte-sized groups to encode. |
| 1572 | while (mEncAudioFifo->GetAvailable() >= nAudioFrameSizeOut) |
| 1573 | { |
| 1574 | mEncAudioFifo->Read( |
| 1575 | mEncAudioFifoOutBuf.data(), nAudioFrameSizeOut); |
| 1576 | |
| 1577 | std::unique_ptr<AVPacketWrapper> pkt = mFFmpeg->CreateAVPacketWrapper(); |
| 1578 | |
| 1579 | ret = EncodeAudio(*pkt, // out |
| 1580 | mEncAudioFifoOutBuf.data(), // in |
| 1581 | mDefaultFrameSize); |
| 1582 | |
| 1583 | if (ret < 0) |
| 1584 | return false; |
| 1585 | } |
| 1586 | return true; |
| 1587 | } |
| 1588 | |
| 1589 | FFmpegExportProcessor::FFmpegExportProcessor(std::shared_ptr<FFmpegFunctions> ffmpeg, int subformat ) |
| 1590 | : mFFmpeg(std::move(ffmpeg)) |
no test coverage detected