1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-27 15:53:49 +01:00

add on demand preference to library pane

This commit is contained in:
mchinen
2012-06-01 06:11:15 +00:00
parent 816b58bc08
commit 3dd37349fc
2 changed files with 51 additions and 46 deletions

View File

@@ -554,63 +554,61 @@ int FFmpegImportFileHandle::Import(TrackFactory *trackFactory,
int res = eProgressSuccess; int res = eProgressSuccess;
#ifdef EXPERIMENTAL_OD_FFMPEG #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; //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. //so for OD loading we create the tracks and releasee the modal lock after starting the ODTask.
std::vector<ODDecodeFFmpegTask*> tasks; if (mUsingOD) {
//append blockfiles to each stream and add an individual ODDecodeTask for each one. std::vector<ODDecodeFFmpegTask*> tasks;
for (int s = 0; s < mNumStreams; s++) //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); ODDecodeFFmpegTask* odTask=new ODDecodeFFmpegTask(mScs,mNumStreams,mChannels,mFormatContext, s);
ODFileDecoder* odDecoder = (ODFileDecoder*)odTask->CreateFileDecoder(mFilename); ODFileDecoder* odDecoder = odTask->CreateFileDecoder(mFilename);
//each stream has different duration. We need to know it if seeking is to be allowed. //each stream has different duration. We need to know it if seeking is to be allowed.
sampleCount sampleDuration = 0; sampleCount sampleDuration = 0;
if (mScs[s]->m_stream->duration > 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; 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 else
sampleDuration = ((sampleCount)mFormatContext->duration *mScs[s]->m_stream->codec->sample_rate) / AV_TIME_BASE; 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 each wavetrack within the stream add coded blockfiles
for (int c = 0; c < mScs[s]->m_stream->codec->channels; c++) for (int c = 0; c < mScs[s]->m_stream->codec->channels; c++) {
{ WaveTrack *t = mChannels[s][c];
WaveTrack *t = mChannels[s][c]; odTask->AddWaveTrack(t);
odTask->AddWaveTrack(t);
sampleCount maxBlockSize = t->GetMaxBlockSize(); sampleCount maxBlockSize = t->GetMaxBlockSize();
//use the maximum blockfile size to divide the sections (about 11secs per blockfile at 44.1khz) //use the maximum blockfile size to divide the sections (about 11secs per blockfile at 44.1khz)
for (sampleCount i = 0; i < sampleDuration; i += maxBlockSize) for (sampleCount i = 0; i < sampleDuration; i += maxBlockSize) {
{ sampleCount blockLen = maxBlockSize;
sampleCount blockLen = maxBlockSize; if (i + blockLen > sampleDuration)
if (i + blockLen > sampleDuration) blockLen = sampleDuration - i;
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 // This only works well for single streams since we assume
// each stream is of the same duration and channels // each stream is of the same duration and channels
res = mProgress->Update(i+sampleDuration*c+ sampleDuration*mScs[s]->m_stream->codec->channels*s, res = mProgress->Update(i+sampleDuration*c+ sampleDuration*mScs[s]->m_stream->codec->channels*s,
sampleDuration*mScs[s]->m_stream->codec->channels*mNumStreams); sampleDuration*mScs[s]->m_stream->codec->channels*mNumStreams);
if (res != eProgressSuccess) if (res != eProgressSuccess)
break; 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++) {
//Now we add the tasks and let them run, or delete them if the user cancelled if(res==eProgressSuccess)
for(int i=0; i < (int)tasks.size(); i++) ODManager::Instance()->AddNewTask(tasks[i]);
{ else
if(res==eProgressSuccess) {
ODManager::Instance()->AddNewTask(tasks[i]); delete tasks[i];
else }
{
delete tasks[i];
} }
} } else {
#else //ifndef EXPERIMENTAL_OD_FFMPEG #endif
streamContext *sc = NULL; streamContext *sc = NULL;
// Read next frame. // Read next frame.
@@ -656,6 +654,8 @@ int FFmpegImportFileHandle::Import(TrackFactory *trackFactory,
} }
} }
} }
#ifdef EXPERIMENTAL_OD_FFMPEG
} // else -- !mUsingOD == true
#endif //EXPERIMENTAL_OD_FFMPEG #endif //EXPERIMENTAL_OD_FFMPEG
// Something bad happened - destroy everything! // Something bad happened - destroy everything!

View File

@@ -135,6 +135,11 @@ void LibraryPrefs::PopulateOrExchange(ShuttleGui & S)
#endif #endif
} }
S.EndTwoColumn(); S.EndTwoColumn();
#ifdef EXPERIMENTAL_OD_FFMPEG
S.TieCheckBox(_("Allow &background on-demand loading"),
wxT("/Library/FFmpegOnDemand"),
false);
#endif
} }
S.EndStatic(); S.EndStatic();
} }