Audacity  2.2.2
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
AliasBlockFile Class Reference

A BlockFile that refers to data in an existing file. More...

#include <BlockFile.h>

Inheritance diagram for AliasBlockFile:
BlockFile PCMAliasBlockFile LegacyAliasBlockFile ODPCMAliasBlockFile

Public Member Functions

 AliasBlockFile (wxFileNameWrapper &&baseFileName, wxFileNameWrapper &&aliasedFileName, sampleCount aliasStart, size_t aliasLen, int aliasChannel)
 Constructs an AliasBlockFile. More...
 
 AliasBlockFile (wxFileNameWrapper &&existingSummaryFileName, wxFileNameWrapper &&aliasedFileName, sampleCount aliasStart, size_t aliasLen, int aliasChannel, float min, float max, float RMS)
 
virtual ~AliasBlockFile ()
 
DiskByteCount GetSpaceUsage () const override
 
void SilenceAliasLog () const
 as SilentLog (which would affect Summary data access), but More...
 
const wxFileName & GetAliasedFileName () const
 
void ChangeAliasedFileName (wxFileNameWrapper &&newAliasedFile)
 
bool IsAlias () const override
 Returns TRUE if this block references another disk file. More...
 
- Public Member Functions inherited from BlockFile
 BlockFile (wxFileNameWrapper &&fileName, size_t samples)
 Construct a BlockFile. More...
 
virtual ~BlockFile ()
 
virtual size_t ReadData (samplePtr data, sampleFormat format, size_t start, size_t len, bool mayThrow=true) const =0
 
virtual bool GetNeedWriteCacheToDisk ()
 
virtual void WriteCacheToDisk ()
 
virtual bool GetNeedFillCache ()
 
virtual void FillCache ()
 
virtual void SaveXML (XMLWriter &xmlFile)=0
 Stores a representation of this file in XML. More...
 
virtual GetFileNameResult GetFileName () const
 
virtual void SetFileName (wxFileNameWrapper &&name)
 sets the file name the summary info will be saved in. threadsafe. More...
 
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 MinMaxRMS GetMinMaxRMS (size_t start, size_t len, bool mayThrow=true) const
 Gets extreme values for the specified region. More...
 
virtual MinMaxRMS GetMinMaxRMS (bool mayThrow=true) const
 Gets extreme values for the entire block. More...
 
virtual bool Read256 (float *buffer, size_t start, size_t len)
 Returns the 256 byte summary data block. More...
 
virtual bool Read64K (float *buffer, size_t start, size_t len)
 Returns the 64K summary data block. More...
 
virtual bool IsSummaryAvailable () const
 Returns TRUE if this block's complete summary has been computed and is ready (for OD) More...
 
virtual bool IsDataAvailable () const
 Returns TRUE if this block's complete data is ready to be accessed by Read() More...
 
virtual bool IsSummaryBeingComputed ()
 Returns TRUE if the summary has not yet been written, but is actively being computed and written to disk. More...
 
virtual BlockFilePtr Copy (wxFileNameWrapper &&newFileName)=0
 Create a NEW BlockFile identical to this, using the given filename. More...
 
virtual void Recover ()=0
 if the on-disk state disappeared, either recover it (if it was More...
 
void SilenceLog () const
 if we've detected an on-disk problem, the user opted to More...
 
virtual void CloseLock ()
 
ReadLock LockForRead () const
 

Protected Member Functions

virtual void WriteSummary ()
 Write the summary to disk, using the derived ReadData() to get the data. More...
 
bool ReadSummary (ArrayOf< char > &data) override
 Read the summary into a buffer. More...
 
- Protected Member Functions inherited from BlockFile
virtual void LockRead () const
 Prevents a read on other threads. The basic blockfile runs on only one thread, so does nothing. More...
 
virtual void UnlockRead () const
 Allows reading on other threads. More...
 
virtual void * CalcSummary (samplePtr buffer, size_t len, sampleFormat format, ArrayOf< char > &cleanup)
 
void CalcSummaryFromBuffer (const float *fbuffer, size_t len, float *summary256, float *summary64K)
 
virtual void FixSummary (void *data)
 

Protected Attributes

wxFileNameWrapper mAliasedFileName
 
sampleCount mAliasStart
 
const int mAliasChannel
 
bool mSilentAliasLog
 
- 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 = std::unique_ptr< const BlockFile, ReadUnlocker >
 
- 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

A BlockFile that refers to data in an existing file.

An AliasBlockFile references an existing disk file for its storage instead of copying the data. It still writes a file to disk, but only stores summary data in it.

This is a common base class for all alias block files. It handles reading and writing summary data, leaving very little for derived classes to need to implement.

Definition at line 251 of file BlockFile.h.

Constructor & Destructor Documentation

AliasBlockFile::AliasBlockFile ( wxFileNameWrapper &&  baseFileName,
wxFileNameWrapper &&  aliasedFileName,
sampleCount  aliasStart,
size_t  aliasLen,
int  aliasChannel 
)

Constructs an AliasBlockFile.

Constructs an AliasBlockFile based on the given information about the aliased file.

Note that derived classes /must/ call AliasBlockFile::WriteSummary() in their constructors for the summary file to be correctly written to disk.

Parameters
baseFileNameThe name of the summary file to be written, but without an extension. This constructor will add the appropriate extension before passing it to BlockFile::BlockFile
aliasedFileNameThe name of the file where the audio data for this block actually exists.
aliasStartThe offset in the aliased file where this block's data begins
aliasLenThe length of this block's data in the aliased file.
aliasChannelThe channel where this block's data is located in the aliased file

Definition at line 640 of file BlockFile.cpp.

References mAliasChannel, mAliasedFileName, mAliasStart, and mSilentAliasLog.

643  :
644  BlockFile {
645  (baseFileName.SetExt(wxT("auf")), std::move(baseFileName)),
646  aliasLen
647  },
648  mAliasedFileName(std::move(aliasedFileName)),
649  mAliasStart(aliasStart),
650  mAliasChannel(aliasChannel)
651 {
652  mSilentAliasLog=FALSE;
653 }
const int mAliasChannel
Definition: BlockFile.h:291
A BlockFile is a chunk of immutable audio data.
Definition: BlockFile.h:56
wxFileNameWrapper mAliasedFileName
Definition: BlockFile.h:289
bool mSilentAliasLog
Definition: BlockFile.h:292
sampleCount mAliasStart
Definition: BlockFile.h:290
AliasBlockFile::AliasBlockFile ( wxFileNameWrapper &&  existingSummaryFileName,
wxFileNameWrapper &&  aliasedFileName,
sampleCount  aliasStart,
size_t  aliasLen,
int  aliasChannel,
float  min,
float  max,
float  RMS 
)

Definition at line 655 of file BlockFile.cpp.

660  :
661  BlockFile{ std::move(existingSummaryFileName), aliasLen },
662  mAliasedFileName(std::move(aliasedFileName)),
663  mAliasStart(aliasStart),
664  mAliasChannel(aliasChannel)
665 {
666  mMin = min;
667  mMax = max;
668  mRMS = rms;
669  mSilentAliasLog=FALSE;
670 }
const int mAliasChannel
Definition: BlockFile.h:291
A BlockFile is a chunk of immutable audio data.
Definition: BlockFile.h:56
float mMin
Definition: BlockFile.h:238
wxFileNameWrapper mAliasedFileName
Definition: BlockFile.h:289
float mRMS
Definition: BlockFile.h:238
int min(int a, int b)
bool mSilentAliasLog
Definition: BlockFile.h:292
sampleCount mAliasStart
Definition: BlockFile.h:290
float mMax
Definition: BlockFile.h:238
AliasBlockFile::~AliasBlockFile ( )
virtual

Definition at line 707 of file BlockFile.cpp.

708 {
709 }

Member Function Documentation

void AliasBlockFile::ChangeAliasedFileName ( wxFileNameWrapper &&  newAliasedFile)

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().

Definition at line 757 of file BlockFile.cpp.

References mAliasedFileName.

758 {
759  mAliasedFileName = std::move(newAliasedFile);
760 }
wxFileNameWrapper mAliasedFileName
Definition: BlockFile.h:289
const wxFileName& AliasBlockFile::GetAliasedFileName ( ) const
inline

Definition at line 278 of file BlockFile.h.

References mAliasedFileName.

Referenced by FindDependencies(), AudacityApp::MarkAliasedFilesMissingWarning(), and RemoveDependencies().

278 { return mAliasedFileName; }
wxFileNameWrapper mAliasedFileName
Definition: BlockFile.h:289
auto AliasBlockFile::GetSpaceUsage ( ) const
overridevirtual

Implements BlockFile.

Definition at line 762 of file BlockFile.cpp.

References BlockFile::mFileName.

763 {
764  wxFFile summaryFile(mFileName.GetFullPath());
765  return summaryFile.Length();
766 }
wxFileNameWrapper mFileName
Definition: BlockFile.h:235
bool AliasBlockFile::IsAlias ( ) const
inlineoverridevirtual

Returns TRUE if this block references another disk file.

Reimplemented from BlockFile.

Definition at line 280 of file BlockFile.h.

280 { return true; }
bool AliasBlockFile::ReadSummary ( ArrayOf< char > &  data)
overrideprotectedvirtual

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.

Definition at line 717 of file BlockFile.cpp.

References Maybe< X >::create(), BlockFile::FixSummary(), BlockFile::mFileName, BlockFile::mSilentLog, BlockFile::mSummaryInfo, ArrayOf< X >::reinit(), and SummaryInfo::totalSummaryBytes.

718 {
720  wxFFile summaryFile(mFileName.GetFullPath(), wxT("rb"));
721 
722  {
723  Maybe<wxLogNull> silence{};
724  if (mSilentLog)
725  silence.create();
726 
727  if (!summaryFile.IsOpened()){
728 
729  // NEW model; we need to return valid data
730  memset(data.get(), 0, mSummaryInfo.totalSummaryBytes);
731 
732  // we silence the logging for this operation in this object
733  // after first occurrence of error; it's already reported and
734  // spewing at the user will complicate the user's ability to
735  // deal
736  mSilentLog = TRUE;
737  return false;
738 
739  }
740  else mSilentLog = FALSE; // worked properly, any future error is NEW
741  }
742 
743  auto read = summaryFile.Read(data.get(), mSummaryInfo.totalSummaryBytes);
744  if (read != mSummaryInfo.totalSummaryBytes) {
745  memset(data.get(), 0, mSummaryInfo.totalSummaryBytes);
746  return false;
747  }
748 
749  FixSummary(data.get());
750 
751  return true;
752 }
wxFileNameWrapper mFileName
Definition: BlockFile.h:235
void reinit(Integral count, bool initialize=false)
Definition: MemoryX.h:117
bool mSilentLog
Definition: BlockFile.h:239
Definition: MemoryX.h:204
SummaryInfo mSummaryInfo
Definition: BlockFile.h:237
size_t totalSummaryBytes
Definition: BlockFile.h:41
virtual void FixSummary(void *data)
Definition: BlockFile.cpp:331
void create(Args &&...args)
Definition: MemoryX.h:251
void AliasBlockFile::SilenceAliasLog ( ) const
inline

as SilentLog (which would affect Summary data access), but

Definition at line 273 of file BlockFile.h.

References mSilentAliasLog.

273 { mSilentAliasLog = TRUE; }
bool mSilentAliasLog
Definition: BlockFile.h:292
void AliasBlockFile::WriteSummary ( )
protectedvirtual

Write the summary to disk, using the derived ReadData() to get the data.

Write the summary to disk. Derived classes must call this method from their constructors for the summary to be correctly written. It uses the derived class's ReadData() to retrieve the data to summarize.

Reimplemented in ODPCMAliasBlockFile.

Definition at line 675 of file BlockFile.cpp.

References BlockFile::CalcSummary(), floatSample, BlockFile::mFileName, BlockFile::mLen, BlockFile::mSummaryInfo, SampleBuffer::ptr(), BlockFile::ReadData(), and SummaryInfo::totalSummaryBytes.

Referenced by LegacyAliasBlockFile::Recover(), and PCMAliasBlockFile::Recover().

676 {
677  // To build the summary data, call ReadData (implemented by the
678  // derived classes) to get the sample data
679  // Call this first, so that in case of exceptions from ReadData, there is
680  // no NEW output file
681  SampleBuffer sampleData(mLen, floatSample);
682  this->ReadData(sampleData.ptr(), floatSample, 0, mLen);
683 
684  // Now checked carefully in the DirManager
685  //wxASSERT( !wxFileExists(FILENAME(mFileName.GetFullPath())));
686 
687  // I would much rather have this code as part of the constructor, but
688  // I can't call virtual functions from the constructor. So we just
689  // need to ensure that every derived class calls this in *its* constructor
690  wxFFile summaryFile(mFileName.GetFullPath(), wxT("wb"));
691 
692  if( !summaryFile.IsOpened() ){
693  // Never silence the Log w.r.t write errors; they always count
694  // as NEW errors
695  wxLogError(wxT("Unable to write summary data to file %s"),
696  mFileName.GetFullPath());
697  // If we can't write, there's nothing to do.
698  return;
699  }
700 
701  ArrayOf<char> cleanup;
702  void *summaryData = BlockFile::CalcSummary(sampleData.ptr(), mLen,
703  floatSample, cleanup);
704  summaryFile.Write(summaryData, mSummaryInfo.totalSummaryBytes);
705 }
wxFileNameWrapper mFileName
Definition: BlockFile.h:235
SummaryInfo mSummaryInfo
Definition: BlockFile.h:237
size_t totalSummaryBytes
Definition: BlockFile.h:41
size_t mLen
Definition: BlockFile.h:236
virtual void * CalcSummary(samplePtr buffer, size_t len, sampleFormat format, ArrayOf< char > &cleanup)
Definition: BlockFile.cpp:181
virtual size_t ReadData(samplePtr data, sampleFormat format, size_t start, size_t len, bool mayThrow=true) const =0

Member Data Documentation

const int AliasBlockFile::mAliasChannel
protected
wxFileNameWrapper AliasBlockFile::mAliasedFileName
protected
sampleCount AliasBlockFile::mAliasStart
protected
bool AliasBlockFile::mSilentAliasLog
mutableprotected

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