From 3dd37349fc27eb21e2c121a2b6bc13f558b694f2 Mon Sep 17 00:00:00 2001 From: mchinen Date: Fri, 1 Jun 2012 06:11:15 +0000 Subject: [PATCH] add on demand preference to library pane --- src/import/ImportFFmpeg.cpp | 92 ++++++++++++++++++------------------- src/prefs/LibraryPrefs.cpp | 5 ++ 2 files changed, 51 insertions(+), 46 deletions(-) diff --git a/src/import/ImportFFmpeg.cpp b/src/import/ImportFFmpeg.cpp index 927d69998..47fd29af9 100644 --- a/src/import/ImportFFmpeg.cpp +++ b/src/import/ImportFFmpeg.cpp @@ -554,63 +554,61 @@ int FFmpegImportFileHandle::Import(TrackFactory *trackFactory, int res = eProgressSuccess; #ifdef EXPERIMENTAL_OD_FFMPEG - mUsingOD = true; //TODO: for now just use it - later use a prefs + mUsingOD = false; + gPrefs->Read(wxT("/Library/FFmpegOnDemand"), &mUsingOD); //at this point we know the file is good and that we have to load the number of channels in mScs[s]->m_stream->codec->channels; //so for OD loading we create the tracks and releasee the modal lock after starting the ODTask. - std::vector tasks; - //append blockfiles to each stream and add an individual ODDecodeTask for each one. - for (int s = 0; s < mNumStreams; s++) - { - ODDecodeFFmpegTask* odTask=new ODDecodeFFmpegTask(mScs,mNumStreams,mChannels,mFormatContext, s); - ODFileDecoder* odDecoder = (ODFileDecoder*)odTask->CreateFileDecoder(mFilename); + if (mUsingOD) { + std::vector tasks; + //append blockfiles to each stream and add an individual ODDecodeTask for each one. + for (int s = 0; s < mNumStreams; s++) { + ODDecodeFFmpegTask* odTask=new ODDecodeFFmpegTask(mScs,mNumStreams,mChannels,mFormatContext, s); + ODFileDecoder* odDecoder = odTask->CreateFileDecoder(mFilename); - //each stream has different duration. We need to know it if seeking is to be allowed. - sampleCount sampleDuration = 0; - if (mScs[s]->m_stream->duration > 0) - sampleDuration = ((sampleCount)mScs[s]->m_stream->duration * mScs[s]->m_stream->time_base.num) *mScs[s]->m_stream->codec->sample_rate / mScs[s]->m_stream->time_base.den; - else - sampleDuration = ((sampleCount)mFormatContext->duration *mScs[s]->m_stream->codec->sample_rate) / AV_TIME_BASE; + //each stream has different duration. We need to know it if seeking is to be allowed. + sampleCount sampleDuration = 0; + if (mScs[s]->m_stream->duration > 0) + sampleDuration = ((sampleCount)mScs[s]->m_stream->duration * mScs[s]->m_stream->time_base.num) *mScs[s]->m_stream->codec->sample_rate / mScs[s]->m_stream->time_base.den; + else + sampleDuration = ((sampleCount)mFormatContext->duration *mScs[s]->m_stream->codec->sample_rate) / AV_TIME_BASE; -// printf(" OD duration samples %qi, sr %d, secs %d\n",sampleDuration, (int)mScs[s]->m_stream->codec->sample_rate,(int)sampleDuration/mScs[s]->m_stream->codec->sample_rate); + // printf(" OD duration samples %qi, sr %d, secs %d\n",sampleDuration, (int)mScs[s]->m_stream->codec->sample_rate,(int)sampleDuration/mScs[s]->m_stream->codec->sample_rate); - //for each wavetrack within the stream add coded blockfiles - for (int c = 0; c < mScs[s]->m_stream->codec->channels; c++) - { - WaveTrack *t = mChannels[s][c]; - odTask->AddWaveTrack(t); + //for each wavetrack within the stream add coded blockfiles + for (int c = 0; c < mScs[s]->m_stream->codec->channels; c++) { + WaveTrack *t = mChannels[s][c]; + odTask->AddWaveTrack(t); - sampleCount maxBlockSize = t->GetMaxBlockSize(); - //use the maximum blockfile size to divide the sections (about 11secs per blockfile at 44.1khz) - for (sampleCount i = 0; i < sampleDuration; i += maxBlockSize) - { - sampleCount blockLen = maxBlockSize; - if (i + blockLen > sampleDuration) - blockLen = sampleDuration - i; + sampleCount maxBlockSize = t->GetMaxBlockSize(); + //use the maximum blockfile size to divide the sections (about 11secs per blockfile at 44.1khz) + for (sampleCount i = 0; i < sampleDuration; i += maxBlockSize) { + sampleCount blockLen = maxBlockSize; + if (i + blockLen > sampleDuration) + blockLen = sampleDuration - i; - t->AppendCoded(mFilename, i, blockLen, c,ODTask::eODFFMPEG); + t->AppendCoded(mFilename, i, blockLen, c,ODTask::eODFFMPEG); - // This only works well for single streams since we assume - // each stream is of the same duration and channels - res = mProgress->Update(i+sampleDuration*c+ sampleDuration*mScs[s]->m_stream->codec->channels*s, - sampleDuration*mScs[s]->m_stream->codec->channels*mNumStreams); - if (res != eProgressSuccess) - break; + // This only works well for single streams since we assume + // each stream is of the same duration and channels + res = mProgress->Update(i+sampleDuration*c+ sampleDuration*mScs[s]->m_stream->codec->channels*s, + sampleDuration*mScs[s]->m_stream->codec->channels*mNumStreams); + if (res != eProgressSuccess) + break; + } } + tasks.push_back(odTask); } - tasks.push_back(odTask); - } - //Now we add the tasks and let them run, or delete them if the user cancelled - for(int i=0; i < (int)tasks.size(); i++) - { - if(res==eProgressSuccess) - ODManager::Instance()->AddNewTask(tasks[i]); - else - { - delete tasks[i]; + //Now we add the tasks and let them run, or delete them if the user cancelled + for(int i=0; i < (int)tasks.size(); i++) { + if(res==eProgressSuccess) + ODManager::Instance()->AddNewTask(tasks[i]); + else + { + delete tasks[i]; + } } - } -#else //ifndef EXPERIMENTAL_OD_FFMPEG - + } else { +#endif streamContext *sc = NULL; // Read next frame. @@ -656,6 +654,8 @@ int FFmpegImportFileHandle::Import(TrackFactory *trackFactory, } } } +#ifdef EXPERIMENTAL_OD_FFMPEG + } // else -- !mUsingOD == true #endif //EXPERIMENTAL_OD_FFMPEG // Something bad happened - destroy everything! diff --git a/src/prefs/LibraryPrefs.cpp b/src/prefs/LibraryPrefs.cpp index 786b2b49a..26caa1f50 100644 --- a/src/prefs/LibraryPrefs.cpp +++ b/src/prefs/LibraryPrefs.cpp @@ -135,6 +135,11 @@ void LibraryPrefs::PopulateOrExchange(ShuttleGui & S) #endif } S.EndTwoColumn(); +#ifdef EXPERIMENTAL_OD_FFMPEG + S.TieCheckBox(_("Allow &background on-demand loading"), + wxT("/Library/FFmpegOnDemand"), + false); +#endif } S.EndStatic(); }