From cd847a89ceb4035dcdde28a6a75ef725212efe1d Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Tue, 19 May 2020 03:34:49 +1000 Subject: [PATCH] decoder: removed old unused code Minor cleanup. --- app/codec/decoder.cpp | 119 ------------------------------------------ app/codec/decoder.h | 2 - 2 files changed, 121 deletions(-) diff --git a/app/codec/decoder.cpp b/app/codec/decoder.cpp index 6c7ed066c..a487e03e1 100644 --- a/app/codec/decoder.cpp +++ b/app/codec/decoder.cpp @@ -161,125 +161,6 @@ DecoderPtr Decoder::CreateFromID(const QString &id) return nullptr; } -/*void Decoder::Conform(const AudioRenderingParams ¶ms, const QAtomicInt* cancelled) -{ - if (stream()->type() != Stream::kAudio) { - // Nothing to be done - return; - } - - // Get indexed WAV file - WaveInput input(GetIndexFilename()); - - // FIXME: No handling if input failed to open/is corrupt - if (input.open()) { - // If the parameters are equal, nothing to be done - // FIXME: Technically we only need to conform if the SAMPLE RATE is not equal. Format and channel layout conversion - // could be done on the fly so we could perhaps conform less often at some point. - if (input.params() == params) { - input.close(); - return; - } - - // Otherwise, let's start converting the format - QMutexLocker locker(stream()->index_process_lock()); - - // Generate destination filename for this conversion to see if it exists - QString conformed_fn = GetConformedFilename(params); - - if (QFileInfo::exists(conformed_fn)) { - // We must have already conformed this format - std::static_pointer_cast(stream())->append_conformed_version(params); - input.close(); - return; - } - - // Set up resampler - SwrContext* resampler = swr_alloc_set_opts(nullptr, - static_cast(params.channel_layout()), - FFmpegCommon::GetFFmpegSampleFormat(params.format()), - params.sample_rate(), - static_cast(input.params().channel_layout()), - FFmpegCommon::GetFFmpegSampleFormat(input.params().format()), - input.params().sample_rate(), - 0, - nullptr); - - swr_init(resampler); - - WaveOutput conformed_output(conformed_fn, params); - if (!conformed_output.open()) { - qWarning() << "Failed to open conformed output:" << conformed_fn; - input.close(); - return; - } - - // Convert one second of audio at a time - int input_buffer_sz = input.params().time_to_bytes(1); - - int read_count = 0; - - while (!input.at_end()) { - if (cancelled && *cancelled) { - break; - } - - // Read up to one second of audio from WAV file - QByteArray read_samples = input.read(input_buffer_sz); - - // Determine how many samples this is - int in_sample_count = input.params().bytes_to_samples(read_samples.size()); - - ConformInternal(resampler, &conformed_output, read_samples.data(), in_sample_count); - - read_count += read_samples.size(); - emit IndexProgress(qRound(100.0 * static_cast(read_count) / static_cast(input.data_length()))); - } - - // Flush resampler - ConformInternal(resampler, &conformed_output, nullptr, 0); - - // Clean up - swr_free(&resampler); - conformed_output.close(); - input.close(); - - // If we cancelled, the conform didn't finish so remove it - if (cancelled && *cancelled) { - QFile(conformed_fn).remove(); - } else { - std::static_pointer_cast(stream())->append_conformed_version(params); - } - } else { - qWarning() << "Failed to conform file:" << stream()->footage()->filename(); - } -}*/ - -void Decoder::ConformInternal(SwrContext* resampler, WaveOutput* output, const char* in_data, int in_sample_count) -{ - // Determine how many samples the output will be - int out_sample_count = swr_get_out_samples(resampler, in_sample_count); - - // Allocate array for the amount of samples we'll need - QByteArray out_samples; - out_samples.resize(output->params().samples_to_bytes(out_sample_count)); - - char* out_data = out_samples.data(); - - // Convert samples - int convert_count = swr_convert(resampler, - reinterpret_cast(&out_data), - out_sample_count, - reinterpret_cast(&in_data), - in_sample_count); - - if (convert_count != out_sample_count) { - out_samples.resize(output->params().samples_to_bytes(convert_count)); - } - - output->write(out_samples); -} - QString Decoder::GetConformedFilename(const AudioRenderingParams ¶ms) { QString index_fn = GetIndexFilename(); diff --git a/app/codec/decoder.h b/app/codec/decoder.h index 31b183f88..b18a84603 100644 --- a/app/codec/decoder.h +++ b/app/codec/decoder.h @@ -265,8 +265,6 @@ protected: QMutex mutex_; private: - void ConformInternal(SwrContext *resampler, WaveOutput *output, const char *in_data, int in_sample_count); - StreamPtr stream_; };