| 568 | } |
| 569 | |
| 570 | void 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, |
nothing calls this directly
no test coverage detected