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

Method WriteData

modules/import-export/mod-ffmpeg/ImportFFmpeg.cpp:570–667  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

568}
569
570void FFmpegImportFileHandle::WriteData(StreamContext *sc, const AVPacketWrapper* packet)
571{
572 // Find the stream in mStreamContexts array
573 auto streamIt = std::find_if(
574 mStreamContexts.begin(),
575 mStreamContexts.end(),
576 [&](StreamContext& context) { return sc == &context; }
577 );
578
579 // Stream is not found. This should not really happen
580 if (streamIt == mStreamContexts.end())
581 {
582 //VS: Shouldn't this mean import failure?
583 return;
584 }
585 auto stream = mStreams[std::distance(mStreamContexts.begin(), streamIt)];
586
587 const auto nChannels = std::min(sc->CodecContext->GetChannels(), sc->InitialChannels);
588
589 // Write audio into WaveTracks
590 if (sc->SampleFormat == int16Sample)
591 {
592 auto data = sc->CodecContext->DecodeAudioPacketInt16(packet);
593 const auto channelsCount = sc->CodecContext->GetChannels();
594 const auto samplesPerChannel = data.size() / channelsCount;
595
596 unsigned chn = 0;
597 ImportUtils::ForEachChannel(*stream, [&](auto& channel)
598 {
599 if(chn >= nChannels)
600 return;
601
602 channel.AppendBuffer(
603 reinterpret_cast<samplePtr>(data.data() + chn),
604 sc->SampleFormat,
605 samplesPerChannel,
606 sc->CodecContext->GetChannels(),
607 sc->SampleFormat
608 );
609 ++chn;
610 });
611 }
612 else if (sc->SampleFormat == floatSample)
613 {
614 auto data = sc->CodecContext->DecodeAudioPacketFloat(packet);
615 const auto channelsCount = sc->CodecContext->GetChannels();
616 const auto samplesPerChannel = data.size() / channelsCount;
617
618 auto channelIndex = 0;
619 ImportUtils::ForEachChannel(*stream, [&](auto& channel)
620 {
621 if(channelIndex >= nChannels)
622 return;
623
624 channel.AppendBuffer(
625 reinterpret_cast<samplePtr>(data.data() + channelIndex),
626 sc->SampleFormat,
627 samplesPerChannel,

Callers

nothing calls this directly

Calls 10

GetChannelsMethod · 0.80
AppendBufferMethod · 0.80
GetStreamMethod · 0.80
GetDurationMethod · 0.80
minFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45
GetWrappedValueMethod · 0.45

Tested by

no test coverage detected