Audacity  2.2.0
ODDecodeBlockFile Class Referencefinal

An AliasBlockFile that references uncompressed data in an existing file. More...

#include <ODDecodeBlockFile.h>

Inheritance diagram for ODDecodeBlockFile:
SimpleBlockFile BlockFile

Public Member Functions

 ODDecodeBlockFile (wxFileNameWrapper &&baseFileName, wxFileNameWrapper &&audioFileName, sampleCount aliasStart, size_t aliasLen, int aliasChannel, unsigned int decodeType)
 Create a disk file and write summary and sample data to it. More...
 
 ODDecodeBlockFile (wxFileNameWrapper &&existingFile, wxFileNameWrapper &&audioFileName, sampleCount aliasStart, size_t aliasLen, int aliasChannel, unsigned int decodeType, float min, float max, float rms, bool dataAvailable)
 Create the memory structure to refer to the given block file. More...
 
virtual ~ODDecodeBlockFile ()
 
bool IsSummaryAvailable () const override
 Returns TRUE if this block's complete summary has been computed and is ready (for OD) More...
 
bool IsDataAvailable () const override
 Returns TRUE if this block's complete data is ready to be accessed by Read() More...
 
bool IsSummaryBeingComputed () override
 Returns TRUE if the summary has not yet been written, but is actively being computed and written to disk. More...
 
DiskByteCount GetSpaceUsage () const override
 
MinMaxRMS GetMinMaxRMS (size_t start, size_t len, bool mayThrow) const override
 Gets extreme values for the specified region. More...
 
MinMaxRMS GetMinMaxRMS (bool mayThrow) const override
 Gets extreme values for the entire block. More...
 
bool Read256 (float *buffer, size_t start, size_t len) override
 Returns the 256 byte summary data block. More...
 
bool Read64K (float *buffer, size_t start, size_t len) override
 Returns the 64K summary data block. More...
 
BlockFilePtr Copy (wxFileNameWrapper &&fileName) override
 Makes NEW ODDecodeBlockFile or SimpleBlockFile depending on summary availability. More...
 
void SaveXML (XMLWriter &xmlFile) override
 Saves as xml ODDecodeBlockFile or SimpleBlockFile depending on summary availability. More...
 
void Recover (void) override
 Writes the summary file if summary data is available. More...
 
int DoWriteBlockFile ()
 
int WriteODDecodeBlockFile ()
 
void SetStart (sampleCount startSample)
 Sets the value that indicates where the first sample in this block corresponds to the global sequence/clip. Only for display use. More...
 
sampleCount GetStart () const
 Gets the value that indicates where the first sample in this block corresponds to the global sequence/clip. Only for display use. More...
 
sampleCount GetGlobalStart () const
 
sampleCount GetGlobalEnd () const
 
size_t ReadData (samplePtr data, sampleFormat format, size_t start, size_t len, bool mayThrow) const override
 Reads the specified data from the aliased file using libsndfile. More...
 
bool ReadSummary (ArrayOf< char > &data) override
 Read the summary into a buffer. More...
 
unsigned int GetDecodeType () const
 Returns the type of audiofile this blockfile is loaded from. More...
 
void SetClipOffset (sampleCount numSamples)
 sets the amount of samples the clip associated with this blockfile is offset in the wavetrack (non effecting) More...
 
sampleCount GetClipOffset () const
 Gets the number of samples the clip associated with this blockfile is offset by. More...
 
void SetODFileDecoder (ODFileDecoder *decoder)
 set the decoder, More...
 
const wxFileName & GetAudioFileName ()
 
void SetFileName (wxFileNameWrapper &&name) override
 sets the file name the summary info will be saved in. threadsafe. More...
 
GetFileNameResult GetFileName () const override
 sets the file name the summary info will be saved in. threadsafe. More...
 
void LockRead () const override
 Prevents a read on other threads of the encoded audio file. More...
 
void UnlockRead () const override
 Allows reading of encoded file on other threads. More...
 
const wxFileName & GetEncodedAudioFilename ()
 
void ChangeAudioFile (wxFileNameWrapper &&newAudioFile)
 
- Public Member Functions inherited from SimpleBlockFile
 SimpleBlockFile (wxFileNameWrapper &&baseFileName, samplePtr sampleData, size_t sampleLen, sampleFormat format, bool allowDeferredWrite=false, bool bypassCache=false)
 Create a disk file and write summary and sample data to it. More...
 
 SimpleBlockFile (wxFileNameWrapper &&existingFile, size_t len, float min, float max, float rms)
 Create the memory structure to refer to the given block file. More...
 
virtual ~SimpleBlockFile ()
 
bool ReadSummary (ArrayOf< char > &data) override
 Read the summary section of the disk file. More...
 
size_t ReadData (samplePtr data, sampleFormat format, size_t start, size_t len, bool mayThrow) const override
 Read the data section of the disk file. More...
 
BlockFilePtr Copy (wxFileNameWrapper &&newFileName) override
 Create a NEW block file identical to this one. More...
 
void SaveXML (XMLWriter &xmlFile) override
 Write an XML representation of this file. More...
 
DiskByteCount GetSpaceUsage () const override
 
void Recover () override
 if the on-disk state disappeared, either recover it (if it was More...
 
bool GetNeedWriteCacheToDisk () override
 
void WriteCacheToDisk () override
 
bool GetNeedFillCache () override
 
void FillCache () override
 
- Public Member Functions inherited from BlockFile
 BlockFile (wxFileNameWrapper &&fileName, size_t samples)
 Construct a BlockFile. More...
 
virtual ~BlockFile ()
 
size_t GetLength () const
 
void SetLength (size_t newLen)
 
virtual void Lock ()
 Locks this BlockFile, to prevent it from being moved. More...
 
virtual void Unlock ()
 Unlock this BlockFile, allowing it to be moved. More...
 
virtual bool IsLocked ()
 Returns TRUE if this BlockFile is locked. More...
 
virtual bool IsAlias () const
 Returns TRUE if this block references another disk file. More...
 
void SilenceLog () const
 if we've detected an on-disk problem, the user opted to More...
 
virtual void CloseLock ()
 
ReadLock LockForRead () const
 

Static Public Member Functions

static BlockFilePtr BuildFromXML (DirManager &dm, const wxChar **attrs)
 Reconstructs from XML a ODDecodeBlockFile and reschedules it for OD loading. More...
 
- Static Public Member Functions inherited from SimpleBlockFile
static BlockFilePtr BuildFromXML (DirManager &dm, const wxChar **attrs)
 static More...
 

Protected Member Functions

void * CalcSummary (samplePtr buffer, size_t len, sampleFormat format, ArrayOf< char > &cleanup) override
 
- Protected Member Functions inherited from SimpleBlockFile
bool WriteSimpleBlockFile (samplePtr sampleData, size_t sampleLen, sampleFormat format, void *summaryData)
 
void ReadIntoCache ()
 
- Protected Member Functions inherited from BlockFile
void CalcSummaryFromBuffer (const float *fbuffer, size_t len, float *summary256, float *summary64K)
 
virtual void FixSummary (void *data)
 

Protected Attributes

unsigned int mType
 
ODLock mFileNameMutex
 
wxFileNameWrapper mAudioFileName
 The original file the audio came from. More...
 
wxAtomicInt mDataAvailable { 0 }
 
bool mDataBeingComputed
 
ODFileDecodermDecoder
 
ODLock mDecoderMutex
 
ODLock mReadDataMutex
 For accessing the audio file that will be decoded. Used by dir manager;. More...
 
sampleCount mStart
 for reporting after task is complete. Only for display use. More...
 
sampleCount mClipOffset
 the ODTask needs to know where this blockfile lies in the track, so for convenience, we have this here. More...
 
sampleFormat mFormat
 
sampleCount mAliasStart
 
const int mAliasChannel
 
- Protected Attributes inherited from SimpleBlockFile
SimpleBlockFileCache mCache
 
- Protected Attributes inherited from BlockFile
wxFileNameWrapper mFileName
 
size_t mLen
 
SummaryInfo mSummaryInfo
 
float mMin
 
float mMax
 
float mRMS
 
bool mSilentLog
 

Additional Inherited Members

- Public Types inherited from BlockFile
using DiskByteCount = unsigned long long
 
- Static Public Attributes inherited from BlockFile
static unsigned long gBlockFileDestructionCount { 0 }
 
- Protected Types inherited from BlockFile
using ReadLockBase = movable_ptr_with_deleter< const BlockFile, ReadUnlocker >
 
- Static Protected Member Functions inherited from SimpleBlockFile
static bool GetCache ()
 
- Static Protected Member Functions inherited from BlockFile
static size_t CommonReadData (bool mayThrow, const wxFileName &fileName, bool &mSilentLog, const AliasBlockFile *pAliasFile, sampleCount origin, unsigned channel, samplePtr data, sampleFormat format, size_t start, size_t len, const sampleFormat *pLegacyFormat=nullptr, size_t legacyLen=0)
 

Detailed Description

An AliasBlockFile that references uncompressed data in an existing file.

ODDecodeBlockFile is a special type of SimpleBlockFile that does not necessarily have summary OR audio data available The summary and audio is eventually computed and written to a file in a background thread.

ODDecodeBlockFile is a special type of SimpleBlockFile that does not necessarily have summary OR audio data available The summary is eventually computed and written to a file in a background thread. See ODPCMAliasBlockFile for a similar class.

Load On-Demand implementation of the SimpleBlockFile for audio files that need to be decoded (mp3,flac,etc..).

Also, see ODPCMAliasBlockFile for a similar file.

Constructor & Destructor Documentation

ODDecodeBlockFile::ODDecodeBlockFile ( wxFileNameWrapper &&  baseFileName,
wxFileNameWrapper &&  audioFileName,
sampleCount  aliasStart,
size_t  aliasLen,
int  aliasChannel,
unsigned int  decodeType 
)

Create a disk file and write summary and sample data to it.

ODDecodeBlockFile::ODDecodeBlockFile ( wxFileNameWrapper &&  existingFile,
wxFileNameWrapper &&  audioFileName,
sampleCount  aliasStart,
size_t  aliasLen,
int  aliasChannel,
unsigned int  decodeType,
float  min,
float  max,
float  rms,
bool  dataAvailable 
)

Create the memory structure to refer to the given block file.

References min().

ODDecodeBlockFile::~ODDecodeBlockFile ( )
virtual

Member Function Documentation

BlockFilePtr ODDecodeBlockFile::BuildFromXML ( DirManager dm,
const wxChar **  attrs 
)
static
void * ODDecodeBlockFile::CalcSummary ( samplePtr  buffer,
size_t  len,
sampleFormat  format,
ArrayOf< char > &  cleanup 
)
overrideprotectedvirtual

A thread-safe version of CalcSummary. BlockFile::CalcSummary uses a static summary array across the class, which we can't use. Get a buffer containing a summary block describing this sample data. This must be called by derived classes when they are constructed, to allow them to construct their summary data, after which they should write that data to their disk file.

This method also has the side effect of setting the mMin, mMax, and mRMS members of this class.

Unlike BlockFile's implementation You SHOULD DELETE the returned buffer. this is protected so it shouldn't be hard to deal with - just override all BlockFile methods that use this method.

Parameters
bufferA buffer containing the sample data to be analyzed
lenThe length of the sample data
formatThe format of the sample data.

Reimplemented from BlockFile.

References bheaderTag, bheaderTagLen, BlockFile::CalcSummaryFromBuffer(), CopySamples(), BlockFile::mSummaryInfo, SummaryInfo::offset256, SummaryInfo::offset64K, ArrayOf< X >::reinit(), and SummaryInfo::totalSummaryBytes.

void ODDecodeBlockFile::ChangeAudioFile ( wxFileNameWrapper &&  newAudioFile)

Modify this block to point at a different file. This is generally looked down on, but it is necessary in one case: see DirManager::EnsureSafeFilename().

References mAudioFileName.

Referenced by DirManager::EnsureSafeFilename().

BlockFilePtr ODDecodeBlockFile::Copy ( wxFileNameWrapper &&  newFileName)
overridevirtual

Makes NEW ODDecodeBlockFile or SimpleBlockFile depending on summary availability.

returns true before decoding is complete, because it is linked to the encoded file until then. returns false afterwards.

If the summary has been computed, Construct a NEW SimpleBlockFile based on this one. otherwise construct an ODDecodeBlockFile that still needs to be computed.

Parameters
newFileNameThe filename to copy the summary data to.

Implements BlockFile.

References SimpleBlockFile::Copy(), IsSummaryAvailable(), BlockFile::LockForRead(), mAliasChannel, mAliasStart, mAudioFileName, BlockFile::mLen, BlockFile::mMax, BlockFile::mMin, BlockFile::mRMS, and mType.

int ODDecodeBlockFile::DoWriteBlockFile ( )
inline
const wxFileName& ODDecodeBlockFile::GetAudioFileName ( )
inline
sampleCount ODDecodeBlockFile::GetClipOffset ( ) const
inline

Gets the number of samples the clip associated with this blockfile is offset by.

References mClipOffset.

unsigned int ODDecodeBlockFile::GetDecodeType ( ) const
inline

Returns the type of audiofile this blockfile is loaded from.

References mType.

Referenced by ODDecodeTask::GetOrCreateMatchingFileDecoder().

const wxFileName& ODDecodeBlockFile::GetEncodedAudioFilename ( )
inline

Get the name of the file where the audio data for this block is stored.

References mAudioFileName.

auto ODDecodeBlockFile::GetFileName ( ) const
overridevirtual

sets the file name the summary info will be saved in. threadsafe.

Reimplemented from BlockFile.

References BlockFile::mFileName, and mFileNameMutex.

sampleCount ODDecodeBlockFile::GetGlobalEnd ( ) const
inline
sampleCount ODDecodeBlockFile::GetGlobalStart ( ) const
inline

References mClipOffset, and mStart.

auto ODDecodeBlockFile::GetMinMaxRMS ( size_t  start,
size_t  len,
bool  mayThrow 
) const
overridevirtual

Gets extreme values for the specified region.

Reimplemented from BlockFile.

References BlockFile::GetMinMaxRMS().

auto ODDecodeBlockFile::GetMinMaxRMS ( bool  mayThrow) const
overridevirtual

Gets extreme values for the entire block.

Reimplemented from BlockFile.

References BlockFile::GetMinMaxRMS().

auto ODDecodeBlockFile::GetSpaceUsage ( ) const
overridevirtual

Implements BlockFile.

References IsSummaryAvailable(), and BlockFile::mFileName.

sampleCount ODDecodeBlockFile::GetStart ( ) const
inline

Gets the value that indicates where the first sample in this block corresponds to the global sequence/clip. Only for display use.

References mStart.

bool ODDecodeBlockFile::IsDataAvailable ( ) const
overridevirtual

Returns TRUE if this block's complete data is ready to be accessed by Read()

Reimplemented from BlockFile.

References mDataAvailable.

Referenced by IsSummaryAvailable().

bool ODDecodeBlockFile::IsSummaryAvailable ( ) const
overridevirtual

Returns TRUE if this block's complete summary has been computed and is ready (for OD)

Reimplemented from BlockFile.

References IsDataAvailable().

Referenced by Copy(), GetSpaceUsage(), Read256(), Read64K(), ReadData(), ReadSummary(), Recover(), and SaveXML().

bool ODDecodeBlockFile::IsSummaryBeingComputed ( )
inlineoverridevirtual

Returns TRUE if the summary has not yet been written, but is actively being computed and written to disk.

Reimplemented from BlockFile.

void ODDecodeBlockFile::LockRead ( ) const
overridevirtual

Prevents a read on other threads of the encoded audio file.

Prevents a read on other threads.

Reimplemented from BlockFile.

References mReadDataMutex.

bool ODDecodeBlockFile::Read256 ( float *  buffer,
size_t  start,
size_t  len 
)
overridevirtual

Returns the 256 byte summary data block.

Returns the 256 byte summary data block Fill with zeroes and return false if data are unavailable for any reason.

Reimplemented from BlockFile.

References ClearSamples(), IsSummaryAvailable(), and BlockFile::Read256().

bool ODDecodeBlockFile::Read64K ( float *  buffer,
size_t  start,
size_t  len 
)
overridevirtual

Returns the 64K summary data block.

Returns the 64K summary data block Fill with zeroes and return false if data are unavailable for any reason.

Reimplemented from BlockFile.

References ClearSamples(), IsSummaryAvailable(), and BlockFile::Read64K().

size_t ODDecodeBlockFile::ReadData ( samplePtr  data,
sampleFormat  format,
size_t  start,
size_t  len,
bool  mayThrow 
) const
overridevirtual

Reads the specified data from the aliased file using libsndfile.

Reads the specified data from the aliased file, using libsndfile, and converts it to the given sample format.

Parameters
dataThe buffer to read the sample data into.
formatThe format to convert the data into
startThe offset within the block to begin reading
lenThe number of samples to read

Implements BlockFile.

References ClearSamples(), IsSummaryAvailable(), BlockFile::LockForRead(), mAudioFileName, and SimpleBlockFile::ReadData().

bool ODDecodeBlockFile::ReadSummary ( ArrayOf< char > &  data)
overridevirtual

Read the summary into a buffer.

Read the summary of this alias block from disk. Since the audio data is elsewhere, this consists of reading the entire summary file. Fill with zeroes and return false if data are unavailable for any reason.

Parameters
*dataThe buffer where the summary data will be stored. It must be at least mSummaryInfo.totalSummaryBytes long.

Implements BlockFile.

References IsSummaryAvailable(), BlockFile::mSummaryInfo, SimpleBlockFile::ReadSummary(), ArrayOf< X >::reinit(), and SummaryInfo::totalSummaryBytes.

void ODDecodeBlockFile::Recover ( void  )
overridevirtual

Writes the summary file if summary data is available.

Implements BlockFile.

References IsSummaryAvailable(), and WriteODDecodeBlockFile().

void ODDecodeBlockFile::SaveXML ( XMLWriter xmlFile)
overridevirtual

Saves as xml ODDecodeBlockFile or SimpleBlockFile depending on summary availability.

Writes the xml as a SimpleBlockFile if we can (if we have a summary file) Otherwise writes XML as a subset of attributes with 'odpcmaliasblockfile as the start tag. Most notably, the summaryfile attribute refers to a file that does not yet, so when the project file is read back in and this object reconstructed, it needs to avoid trying to open it as well as schedule itself for OD loading

Implements BlockFile.

References XMLWriter::EndTag(), IsSummaryAvailable(), BlockFile::LockForRead(), mAliasChannel, mAliasStart, mAudioFileName, BlockFile::mFileName, mFileNameMutex, BlockFile::mLen, mType, SimpleBlockFile::SaveXML(), XMLWriter::StartTag(), and XMLWriter::WriteAttr().

void ODDecodeBlockFile::SetClipOffset ( sampleCount  numSamples)
inline

sets the amount of samples the clip associated with this blockfile is offset in the wavetrack (non effecting)

References mClipOffset.

void ODDecodeBlockFile::SetFileName ( wxFileNameWrapper &&  name)
overridevirtual

sets the file name the summary info will be saved in. threadsafe.

Reimplemented from BlockFile.

References BlockFile::mFileName, mFileNameMutex, and name.

void ODDecodeBlockFile::SetODFileDecoder ( ODFileDecoder decoder)

set the decoder,

References mDecoder, and mDecoderMutex.

void ODDecodeBlockFile::SetStart ( sampleCount  startSample)
inline

Sets the value that indicates where the first sample in this block corresponds to the global sequence/clip. Only for display use.

References mStart.

void ODDecodeBlockFile::UnlockRead ( ) const
overridevirtual

Allows reading of encoded file on other threads.

Reimplemented from BlockFile.

References mReadDataMutex.

int ODDecodeBlockFile::WriteODDecodeBlockFile ( )

Write the summary to disk, using the derived ReadData() to get the data Here, the decoder ODTask associated with this file must fetch the samples with the ODDecodeTask::Decode() method.

References ODFileDecoder::Decode(), mAliasChannel, mAliasStart, mDataAvailable, mDecoder, mDecoderMutex, mFileNameMutex, mFormat, BlockFile::mLen, SampleBuffer::ptr(), and SimpleBlockFile::WriteSimpleBlockFile().

Referenced by DoWriteBlockFile(), and Recover().

Member Data Documentation

const int ODDecodeBlockFile::mAliasChannel
protected
sampleCount ODDecodeBlockFile::mAliasStart
protected
wxFileNameWrapper ODDecodeBlockFile::mAudioFileName
protected

The original file the audio came from.

Referenced by ChangeAudioFile(), Copy(), GetAudioFileName(), GetEncodedAudioFilename(), ReadData(), and SaveXML().

sampleCount ODDecodeBlockFile::mClipOffset
protected

the ODTask needs to know where this blockfile lies in the track, so for convenience, we have this here.

Referenced by GetClipOffset(), GetGlobalEnd(), GetGlobalStart(), and SetClipOffset().

wxAtomicInt ODDecodeBlockFile::mDataAvailable { 0 }
protected
bool ODDecodeBlockFile::mDataBeingComputed
protected
ODFileDecoder* ODDecodeBlockFile::mDecoder
protected
ODLock ODDecodeBlockFile::mDecoderMutex
protected
ODLock ODDecodeBlockFile::mFileNameMutex
mutableprotected

This lock is for the filename (string) of the blockfile that contains summary/audio data after decoding

Referenced by GetFileName(), SaveXML(), SetFileName(), and WriteODDecodeBlockFile().

sampleFormat ODDecodeBlockFile::mFormat
protected

Referenced by WriteODDecodeBlockFile().

ODLock ODDecodeBlockFile::mReadDataMutex
mutableprotected

For accessing the audio file that will be decoded. Used by dir manager;.

Referenced by LockRead(), and UnlockRead().

sampleCount ODDecodeBlockFile::mStart
protected

for reporting after task is complete. Only for display use.

Referenced by GetGlobalEnd(), GetGlobalStart(), GetStart(), and SetStart().

unsigned int ODDecodeBlockFile::mType
protected

Referenced by Copy(), GetDecodeType(), and SaveXML().


The documentation for this class was generated from the following files: