mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-07 15:22:34 +02:00
ODDecode task checks blockfile error, making no progress if so...
... also replace explicit mutex locking with RAII and atomics. This is a part of the big project that handles failure to write block files, as from disk exhaustion. ODDecodeBlockFile::WriteODDecodeBlockFile is the one place calling WriteSimpleBlockFile but not (as in SimpleBlockFile constructor) throwing an exception. It is called only when attempting to recover files at open time, or in worker threads in an EXPERIMENTAL code branch.
This commit is contained in:
parent
a399d4e23a
commit
5de19dc952
@ -47,7 +47,6 @@ ODDecodeBlockFile::ODDecodeBlockFile(wxFileNameWrapper &&baseFileName, wxFileNam
|
||||
mAliasChannel(aliasChannel)
|
||||
{
|
||||
mDecoder = NULL;
|
||||
mDataAvailable=false;
|
||||
mAudioFileName = std::move(audioFileName);
|
||||
mFormat = int16Sample;
|
||||
}
|
||||
@ -59,11 +58,11 @@ ODDecodeBlockFile::ODDecodeBlockFile(wxFileNameWrapper &&existingFile, wxFileNam
|
||||
SimpleBlockFile{ std::move(existingFile), aliasLen, min, max, rms },
|
||||
|
||||
mType(decodeType),
|
||||
mDataAvailable( dataAvailable ),
|
||||
mAliasStart(aliasStart),
|
||||
mAliasChannel(aliasChannel)
|
||||
{
|
||||
mDecoder = NULL;
|
||||
mDataAvailable=dataAvailable;
|
||||
mAudioFileName = std::move(audioFileName);
|
||||
mFormat = int16Sample;
|
||||
}
|
||||
@ -304,11 +303,7 @@ bool ODDecodeBlockFile::IsSummaryAvailable() const
|
||||
|
||||
bool ODDecodeBlockFile::IsDataAvailable() const
|
||||
{
|
||||
bool retval;
|
||||
mDataAvailableMutex.Lock();
|
||||
retval= mDataAvailable;
|
||||
mDataAvailableMutex.Unlock();
|
||||
return retval;
|
||||
return mDataAvailable;
|
||||
}
|
||||
|
||||
/// Write the summary to disk, using the derived ReadData() to get the data
|
||||
@ -321,43 +316,38 @@ int ODDecodeBlockFile::WriteODDecodeBlockFile()
|
||||
// derived classes) to get the sample data
|
||||
SampleBuffer sampleData;// = NewSamples(mLen, floatSample);
|
||||
int ret;
|
||||
//use the decoder here.
|
||||
mDecoderMutex.Lock();
|
||||
|
||||
if(!mDecoder)
|
||||
{
|
||||
mDecoderMutex.Unlock();
|
||||
return -1;
|
||||
//use the decoder here.
|
||||
ODLocker locker{ &mDecoderMutex };
|
||||
|
||||
if(!mDecoder)
|
||||
return -1;
|
||||
|
||||
//sampleData and mFormat are set by the decoder.
|
||||
ret = mDecoder->Decode(sampleData, mFormat, mAliasStart, mLen, mAliasChannel);
|
||||
|
||||
if(ret < 0) {
|
||||
printf("ODDecodeBlockFile Decode failure\n");
|
||||
return ret; //failure
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//sampleData and mFormat are set by the decoder.
|
||||
ret = mDecoder->Decode(sampleData, mFormat, mAliasStart, mLen, mAliasChannel);
|
||||
|
||||
mDecoderMutex.Unlock();
|
||||
if(ret < 0) {
|
||||
printf("ODDecodeBlockFile Decode failure\n");
|
||||
return ret; //failure
|
||||
{
|
||||
//the summary is also calculated here.
|
||||
ODLocker locker{ &mFileNameMutex };
|
||||
//TODO: we may need to write a version of WriteSimpleBlockFile that uses threadsafe FILE vs wxFile
|
||||
bool bSuccess =
|
||||
WriteSimpleBlockFile(
|
||||
sampleData.ptr(),
|
||||
mLen,
|
||||
mFormat,
|
||||
NULL);
|
||||
if ( !bSuccess )
|
||||
return -1;
|
||||
}
|
||||
|
||||
//the summary is also calculated here.
|
||||
mFileNameMutex.Lock();
|
||||
//TODO: we may need to write a version of WriteSimpleBlockFile that uses threadsafe FILE vs wxFile
|
||||
bool bSuccess =
|
||||
WriteSimpleBlockFile(
|
||||
sampleData.ptr(),
|
||||
mLen,
|
||||
mFormat,
|
||||
NULL);
|
||||
wxASSERT(bSuccess); // TODO: Handle failure here by alert to user and undo partial op.
|
||||
wxUnusedVar(bSuccess);
|
||||
|
||||
mFileNameMutex.Unlock();
|
||||
|
||||
|
||||
mDataAvailableMutex.Lock();
|
||||
mDataAvailable=true;
|
||||
mDataAvailableMutex.Unlock();
|
||||
wxAtomicInc( mDataAvailable );
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ Also, see ODPCMAliasBlockFile for a similar file.
|
||||
#include "../ondemand/ODTaskThread.h"
|
||||
#include "../DirManager.h"
|
||||
#include "../ondemand/ODDecodeTask.h"
|
||||
#include <wx/atomic.h>
|
||||
#include <wx/thread.h>
|
||||
|
||||
/// An AliasBlockFile that references uncompressed data in an existing file
|
||||
@ -166,8 +167,7 @@ class ODDecodeBlockFile final : public SimpleBlockFile
|
||||
///The original file the audio came from.
|
||||
wxFileNameWrapper mAudioFileName;
|
||||
|
||||
mutable ODLock mDataAvailableMutex;
|
||||
bool mDataAvailable;
|
||||
wxAtomicInt mDataAvailable{ 0 };
|
||||
bool mDataBeingComputed;
|
||||
|
||||
ODFileDecoder* mDecoder;
|
||||
|
Loading…
x
Reference in New Issue
Block a user