MCPcopy Create free account
hub / github.com/audacity/audacity / EncodeAudioFrame

Method EncodeAudioFrame

modules/import-export/mod-ffmpeg/ExportFFmpeg.cpp:1549–1587  ·  view source on GitHub ↗

All paths in this that fail must report their error to the user.

Source from the content-addressed store, hash-verified

1547
1548// All paths in this that fail must report their error to the user.
1549bool 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
1589FFmpegExportProcessor::FFmpegExportProcessor(std::shared_ptr<FFmpegFunctions> ffmpeg, int subformat )
1590 : mFFmpeg(std::move(ffmpeg))

Callers 1

ProcessMethod · 0.80

Calls 6

GetChannelsMethod · 0.80
GetAvailableMethod · 0.80
CreateAVPacketWrapperMethod · 0.80
WriteMethod · 0.45
ReadMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected