| 449 | } |
| 450 | |
| 451 | void FFmpegImportFileHandle::Import( |
| 452 | ImportProgressListener& progressListener, WaveTrackFactory* trackFactory, |
| 453 | TrackHolders& outTracks, Tags* tags, |
| 454 | std::optional<LibFileFormats::AcidizerTags>&) |
| 455 | { |
| 456 | outTracks.clear(); |
| 457 | mCancelled = false; |
| 458 | mStopped = false; |
| 459 | |
| 460 | //! This may break the correspondence with mStreamInfo |
| 461 | mStreamContexts.erase (std::remove_if (mStreamContexts.begin (), mStreamContexts.end (), [](const StreamContext& ctx) { |
| 462 | return !ctx.Use; |
| 463 | }), mStreamContexts.end()); |
| 464 | |
| 465 | for(unsigned s = 0; s < mStreamContexts.size(); ++s) |
| 466 | { |
| 467 | const StreamContext& sc = mStreamContexts[s]; |
| 468 | |
| 469 | const auto format = ImportUtils::ChooseFormat(sc.SampleFormat); |
| 470 | auto tracks = trackFactory->CreateMany(sc.InitialChannels, format, sc.CodecContext->GetSampleRate()); |
| 471 | |
| 472 | |
| 473 | // Handles the start_time by creating silence. This may or may not be correct. |
| 474 | // There is a possibility that we should ignore first N milliseconds of audio instead. I do not know. |
| 475 | /// TODO: Nag FFmpeg devs about start_time until they finally say WHAT is this and HOW to handle it. |
| 476 | |
| 477 | int64_t stream_delay = 0; |
| 478 | |
| 479 | const int64_t streamStartTime = |
| 480 | mAVFormatContext->GetStream(sc.StreamIndex)->GetStartTime(); |
| 481 | |
| 482 | if (streamStartTime != int64_t(AUDACITY_AV_NOPTS_VALUE) && streamStartTime > 0) |
| 483 | { |
| 484 | stream_delay = streamStartTime; |
| 485 | |
| 486 | wxLogDebug( |
| 487 | wxT("Stream %d start_time = %lld, that would be %f milliseconds."), |
| 488 | s, (long long)streamStartTime, double(streamStartTime) / 1000); |
| 489 | } |
| 490 | if (stream_delay > 0) |
| 491 | { |
| 492 | for (auto track : *tracks) |
| 493 | { |
| 494 | track->InsertSilence(0, double(stream_delay) / AUDACITY_AV_TIME_BASE); |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | mStreams.push_back(tracks); |
| 499 | } |
| 500 | |
| 501 | // This is the heart of the importing process |
| 502 | |
| 503 | // Read frames. |
| 504 | for (std::unique_ptr<AVPacketWrapper> packet; |
| 505 | (packet = mAVFormatContext->ReadNextPacket()) != nullptr && |
| 506 | !mCancelled && !mStopped;) |
| 507 | { |
| 508 | // Find a matching StreamContext |
nothing calls this directly
no test coverage detected