Audacity  3.0.3
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Attributes | List of all members
ODPCMAliasBlockFile Class Referencefinal

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

#include <ODPCMAliasBlockFile.h>

Inheritance diagram for ODPCMAliasBlockFile:
[legend]
Collaboration diagram for ODPCMAliasBlockFile:
[legend]

Public Member Functions

 ODPCMAliasBlockFile (wxFileNameWrapper &&baseFileName, wxFileNameWrapper &&aliasedFileName, sampleCount aliasStart, size_t aliasLen, int aliasChannel)
 Constructs a PCMAliasBlockFile, writing the summary to disk. More...
 
 ODPCMAliasBlockFile (wxFileNameWrapper &&existingSummaryFileName, wxFileNameWrapper &&aliasedFileName, sampleCount aliasStart, size_t aliasLen, int aliasChannel, float min, float max, float rms, bool summaryAvailable)
 summaryAvailable should be true if the file has been written already. More...
 
virtual ~ODPCMAliasBlockFile ()
 
bool IsSummaryAvailable () const override
 
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 ODPCMAliasBlockFile or PCMAliasBlockFile depending on summary availability. More...
 
void SaveXML (XMLWriter &xmlFile) override
 Saves as xml ODPCMAliasBlockFile or PCMAliasBlockFile depending on summary availability. More...
 
void Recover (void) override
 Writes the summary file if summary data is available. More...
 
void DoWriteSummary ()
 A public interface to WriteSummary. More...
 
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...
 
void Lock () override
 Locks the blockfile only if it has a file that exists. More...
 
void Unlock () override
 Unlocks the blockfile only if it has a file that exists. 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...
 
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...
 
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 CloseLock () override
 
void LockRead () const override
 Prevents a read on other threads. More...
 
void UnlockRead () const override
 Allows reading on other threads. More...
 
- Public Member Functions inherited from PCMAliasBlockFile
 PCMAliasBlockFile (wxFileNameWrapper &&baseFileName, wxFileNameWrapper &&aliasedFileName, sampleCount aliasStart, size_t aliasLen, int aliasChannel)
 Constructs a PCMAliasBlockFile, writing the summary to disk. More...
 
 PCMAliasBlockFile (wxFileNameWrapper &&fileName, wxFileNameWrapper &&aliasedFileName, sampleCount aliasStart, size_t aliasLen, int aliasChannel, bool writeSummary)
 Constructs a PCMAliasBlockFile with the option of not writing to disk. More...
 
 PCMAliasBlockFile (wxFileNameWrapper &&existingSummaryFileName, wxFileNameWrapper &&aliasedFileName, sampleCount aliasStart, size_t aliasLen, int aliasChannel, float min, float max, float rms)
 
virtual ~PCMAliasBlockFile ()
 
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...
 
void SaveXML (XMLWriter &xmlFile) override
 
BlockFilePtr Copy (wxFileNameWrapper &&fileName) override
 
void Recover () override
 

Static Public Member Functions

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

Protected Member Functions

void WriteSummary () override
 Write the summary to disk, using the derived ReadData() to get the data. More...
 
void * CalcSummary (samplePtr buffer, size_t len, sampleFormat format, ArrayOf< char > &cleanup) override
 

Private Attributes

ODLock mWriteSummaryMutex
 
ODLock mFileNameMutex
 
ODLock mAliasedFileNameMutex
 Also need to protect the aliased file name. More...
 
ODLock mReadDataMutex
 
ODLock mSummaryAvailableMutex
 
bool mSummaryAvailable
 
bool mSummaryBeingComputed
 
bool mHasBeenSaved
 
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...
 

Detailed Description

An AliasBlockFile that references uncompressed data in an existing file.

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

Load On-Demand implementation of the AliasBlockFile for PCM files.

to load large files more quickly, we skip computing the summary data and put ODPCMAliasBlockFiles in the sequence as place holders. A background thread loads and computes the summary data into these classes. ODPCMAliasBlockFiles unlike all other BlockFiles are not immutable (for the most part,) because when NEW summary data is computed for an existing ODPCMAliasBlockFile we save the buffer then and write the Summary File.

All BlockFile methods that treat the summary data as a buffer that exists in its BlockFile are implemented here to behave when the data is not available yet.

Some of these methods have been overridden only because they used the unsafe wxLog calls in the base class.

Definition at line 42 of file ODPCMAliasBlockFile.h.

Constructor & Destructor Documentation

◆ ODPCMAliasBlockFile() [1/2]

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

Constructs a PCMAliasBlockFile, writing the summary to disk.

Definition at line 44 of file ODPCMAliasBlockFile.cpp.

49 : PCMAliasBlockFile { std::move(fileName), std::move(aliasedFileName),
50  aliasStart, aliasLen, aliasChannel, false }
51 {
53 }

◆ ODPCMAliasBlockFile() [2/2]

ODPCMAliasBlockFile::ODPCMAliasBlockFile ( wxFileNameWrapper &&  existingSummaryFileName,
wxFileNameWrapper &&  aliasedFileName,
sampleCount  aliasStart,
size_t  aliasLen,
int  aliasChannel,
float  min,
float  max,
float  rms,
bool  summaryAvailable 
)

summaryAvailable should be true if the file has been written already.

Definition at line 56 of file ODPCMAliasBlockFile.cpp.

62 : PCMAliasBlockFile(std::move(existingSummaryFileName), std::move(aliasedFileName),
63  aliasStart, aliasLen,
64  aliasChannel, min, max, rms)
65 {
66  mSummaryAvailable=summaryAvailable;
68  }

References mHasBeenSaved, mSummaryAvailable, and mSummaryBeingComputed.

◆ ~ODPCMAliasBlockFile()

ODPCMAliasBlockFile::~ODPCMAliasBlockFile ( )
virtual

Definition at line 70 of file ODPCMAliasBlockFile.cpp.

71 {
72 }

Member Function Documentation

◆ BuildFromXML()

BlockFilePtr ODPCMAliasBlockFile::BuildFromXML ( DirManager &  dm,
const wxChar **  attrs 
)
static

Reconstructs from XML a ODPCMAliasBlockFile and reschedules it for OD loading.

Constructs a ODPCMAliasBlockFile from the xml output of WriteXML. Does not schedule the ODPCMAliasBlockFile for OD loading. Client code must do this.

Definition at line 272 of file ODPCMAliasBlockFile.cpp.

273 {
274  wxFileNameWrapper summaryFileName;
275  wxFileNameWrapper aliasFileName;
276  sampleCount aliasStart = 0;
277  size_t aliasLen = 0;
278  int aliasChannel=0;
279  long nValue;
280  long long nnValue;
281 
282  while(*attrs)
283  {
284  const wxChar *attr = *attrs++;
285  const wxChar *value = *attrs++;
286  if (!value)
287  break;
288 
289  const wxString strValue = value;
290  if (!wxStricmp(attr, wxT("summaryfile")) &&
291  // Can't use XMLValueChecker::IsGoodFileName here, but do part of its test.
293  (strValue.length() + 1 + dm.GetProjectDataDir().length() <= PLATFORM_MAX_PATH))
294  {
295  if (!dm.AssignFile(summaryFileName, strValue, false))
296  // Make sure summaryFileName is back to uninitialized state so we can detect problem later.
297  summaryFileName.Clear();
298  }
299  else if( !wxStricmp(attr, wxT("aliasfile")) )
300  {
301  if (XMLValueChecker::IsGoodPathName(strValue))
302  aliasFileName.Assign(strValue);
303  else if (XMLValueChecker::IsGoodFileName(strValue, dm.GetProjectDataDir()))
304  // Allow fallback of looking for the file name, located in the data directory.
305  aliasFileName.Assign(dm.GetProjectDataDir(), strValue);
306  else if (XMLValueChecker::IsGoodPathString(strValue))
307  // If the aliased file is missing, we failed XMLValueChecker::IsGoodPathName()
308  // and XMLValueChecker::IsGoodFileName, because both do existence tests,
309  // but we want to keep the reference to the missing file because it's a good path string.
310  aliasFileName.Assign(strValue);
311  }
312  else if ( !wxStricmp(attr, wxT("aliasstart")) )
313  {
314  if (XMLValueChecker::IsGoodInt64(strValue) &&
315  strValue.ToLongLong(&nnValue) && (nnValue >= 0))
316  aliasStart = nnValue;
317  }
318  else if (XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue))
319  { // integer parameters
320  if (!wxStricmp(attr, wxT("aliaslen")) && (nValue >= 0))
321  aliasLen = nValue;
322  else if (!wxStricmp(attr, wxT("aliaschannel")) && XMLValueChecker::IsValidChannel(aliasChannel))
323  aliasChannel = nValue;
324  }
325  }
326 
327  return make_blockfile<ODPCMAliasBlockFile>
328  (std::move(summaryFileName), std::move(aliasFileName),
329  aliasStart, aliasLen, aliasChannel, 0, 0, 0, false);
330 }

References XMLValueChecker::IsGoodFileName(), XMLValueChecker::IsGoodFileString(), XMLValueChecker::IsGoodInt(), XMLValueChecker::IsGoodInt64(), XMLValueChecker::IsGoodPathName(), XMLValueChecker::IsGoodPathString(), anonymous_namespace{WaveTrack.cpp}::IsValidChannel(), and PLATFORM_MAX_PATH.

Here is the call graph for this function:

◆ CalcSummary()

void * ODPCMAliasBlockFile::CalcSummary ( samplePtr  buffer,
size_t  len,
sampleFormat  format,
ArrayOf< char > &  cleanup 
)
overrideprotected

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.

Definition at line 450 of file ODPCMAliasBlockFile.cpp.

452 {
453  cleanup.reinit(mSummaryInfo.totalSummaryBytes);
454  char* localFullSummary = cleanup.get();
455 
456  memcpy(localFullSummary, aheaderTag, aheaderTagLen);
457 
458  float *summary64K = (float *)(localFullSummary + mSummaryInfo.offset64K);
459  float *summary256 = (float *)(localFullSummary + mSummaryInfo.offset256);
460 
461  Floats floats;
462  float *fbuffer;
463 
464  //mchinen: think we can hack this - don't allocate and copy if we don't need to.,
465  if(format==floatSample)
466  {
467  fbuffer = (float*)buffer;
468  }
469  else
470  {
471  floats.reinit(len);
472  fbuffer = floats.get();
473  CopySamples(buffer, format,
474  (samplePtr)fbuffer, floatSample, len);
475  }
476 
477  BlockFile::CalcSummaryFromBuffer(fbuffer, len, summary256, summary64K);
478 
479  return localFullSummary;
480 }

References aheaderTag, aheaderTagLen, CopySamples(), floatSample, format, and ArrayOf< X >::reinit().

Referenced by WriteSummary().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CloseLock()

void ODPCMAliasBlockFile::CloseLock ( )
override

Definition at line 104 of file ODPCMAliasBlockFile.cpp.

105 {
106  if(mHasBeenSaved)
107  PCMAliasBlockFile::Lock();
108 }

References mHasBeenSaved.

◆ Copy()

BlockFilePtr ODPCMAliasBlockFile::Copy ( wxFileNameWrapper &&  newFileName)
override

Makes NEW ODPCMAliasBlockFile or PCMAliasBlockFile depending on summary availability.

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

Parameters
newFileNameThe filename to copy the summary data to.

Definition at line 201 of file ODPCMAliasBlockFile.cpp.

202 {
203  BlockFilePtr newBlockFile;
204 
205  //mAliasedFile can change so we lock readdatamutex, which is responsible for it.
206  auto locker = LockForRead();
207  //If the file has been written AND it has been saved, we create a PCM alias blockfile because for
208  //all intents and purposes, it is the same.
209  //However, if it hasn't been saved yet, we shouldn't create one because the default behavior of the
210  //PCMAliasBlockFile is to lock on exit, and this will cause orphaned blockfiles..
212  {
213  newBlockFile = make_blockfile<PCMAliasBlockFile>
214  (std::move(newFileName), wxFileNameWrapper{mAliasedFileName},
215  mAliasStart, mLen, mAliasChannel, mMin, mMax, mRMS);
216 
217  }
218  else
219  {
220  //Summary File might exist in this case, but it might not.
221  newBlockFile = make_blockfile<ODPCMAliasBlockFile>
222  (std::move(newFileName), wxFileNameWrapper{mAliasedFileName},
223  mAliasStart, mLen, mAliasChannel, mMin, mMax, mRMS,
225  //The client code will need to schedule this blockfile for OD summarizing if it is going to a NEW track.
226  }
227 
228  return newBlockFile;
229 }

References IsSummaryAvailable(), and mHasBeenSaved.

Here is the call graph for this function:

◆ DoWriteSummary()

void ODPCMAliasBlockFile::DoWriteSummary ( )

A public interface to WriteSummary.

Calls write summary, and makes sure it is only done once in a thread-safe fashion.

Definition at line 352 of file ODPCMAliasBlockFile.cpp.

353 {
354  ODLocker locker { &mWriteSummaryMutex };
355  if(!IsSummaryAvailable())
356  WriteSummary();
357 }

References IsSummaryAvailable(), mWriteSummaryMutex, and WriteSummary().

Here is the call graph for this function:

◆ GetClipOffset()

sampleCount ODPCMAliasBlockFile::GetClipOffset ( ) const
inline

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

Definition at line 104 of file ODPCMAliasBlockFile.h.

104 {return mClipOffset;}

References mClipOffset.

Referenced by ODComputeSummaryTask::Update().

Here is the caller graph for this function:

◆ GetFileName()

auto ODPCMAliasBlockFile::GetFileName ( ) const
override

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

Definition at line 368 of file ODPCMAliasBlockFile.cpp.

369 {
370  return { mFileName, ODLocker{ &mFileNameMutex } };
371 }

References mFileNameMutex.

◆ GetGlobalEnd()

sampleCount ODPCMAliasBlockFile::GetGlobalEnd ( ) const
inline

Definition at line 110 of file ODPCMAliasBlockFile.h.

110 {return mClipOffset+mStart+GetLength();}

References mClipOffset, and mStart.

Referenced by ODComputeSummaryTask::OrderBlockFiles().

Here is the caller graph for this function:

◆ GetGlobalStart()

sampleCount ODPCMAliasBlockFile::GetGlobalStart ( ) const
inline

Definition at line 107 of file ODPCMAliasBlockFile.h.

107 {return mClipOffset+mStart;}

References mClipOffset, and mStart.

Referenced by ODComputeSummaryTask::OrderBlockFiles().

Here is the caller graph for this function:

◆ GetMinMaxRMS() [1/2]

auto ODPCMAliasBlockFile::GetMinMaxRMS ( bool  mayThrow) const
override

Gets extreme values for the entire block.

Definition at line 144 of file ODPCMAliasBlockFile.cpp.

145 {
146  if(IsSummaryAvailable())
147  {
148  return PCMAliasBlockFile::GetMinMaxRMS(mayThrow);
149  }
150  else
151  {
152  if (mayThrow)
153  throw NotYetAvailableException{ GetAliasedFileName() };
154 
155  //fake values. These values are used usually for normalization and amplifying, so we want
156  //the max to be maximal and the min to be minimal
157  return {
158  -JUST_BELOW_MAX_AUDIO,
159  JUST_BELOW_MAX_AUDIO,
160  0.707f //sin with amp of 1 rms
161  };
162  }
163 }

◆ GetMinMaxRMS() [2/2]

auto ODPCMAliasBlockFile::GetMinMaxRMS ( size_t  start,
size_t  len,
bool  mayThrow 
) const
override

Gets extreme values for the specified region.

Definition at line 121 of file ODPCMAliasBlockFile.cpp.

123 {
124  if(IsSummaryAvailable())
125  {
126  return PCMAliasBlockFile::GetMinMaxRMS(start, len, mayThrow);
127  }
128  else
129  {
130  if (mayThrow)
131  throw NotYetAvailableException{ GetAliasedFileName() };
132 
133  //fake values. These values are used usually for normalization and amplifying, so we want
134  //the max to be maximal and the min to be minimal
135  return {
136  -JUST_BELOW_MAX_AUDIO,
137  JUST_BELOW_MAX_AUDIO,
138  0.707f //sin with amp of 1 rms
139  };
140  }
141 }

◆ GetSpaceUsage()

auto ODPCMAliasBlockFile::GetSpaceUsage ( ) const
override

Definition at line 77 of file ODPCMAliasBlockFile.cpp.

78 {
79  if(IsSummaryAvailable())
80  {
81  DiskByteCount ret;
82  mFileNameMutex.Lock();
83  wxFFile summaryFile(mFileName.GetFullPath());
84  ret= summaryFile.Length();
85  mFileNameMutex.Unlock();
86  return ret;
87  }
88  else
89  {
90  return 0;
91  }
92 }

References IsSummaryAvailable(), and mFileNameMutex.

Here is the call graph for this function:

◆ GetStart()

sampleCount ODPCMAliasBlockFile::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.

Definition at line 92 of file ODPCMAliasBlockFile.h.

92 {return mStart;}

References mStart.

Referenced by ODComputeSummaryTask::Update().

Here is the caller graph for this function:

◆ IsSummaryAvailable()

bool ODPCMAliasBlockFile::IsSummaryAvailable ( ) const
override

Definition at line 342 of file ODPCMAliasBlockFile.cpp.

343 {
344  bool retval;
345  mSummaryAvailableMutex.Lock();
346  retval= mSummaryAvailable;
347  mSummaryAvailableMutex.Unlock();
348  return retval;
349 }

References mSummaryAvailable, and mSummaryAvailableMutex.

Referenced by Copy(), DoWriteSummary(), GetSpaceUsage(), Lock(), Read256(), Read64K(), Recover(), SaveXML(), and Unlock().

Here is the caller graph for this function:

◆ IsSummaryBeingComputed()

bool ODPCMAliasBlockFile::IsSummaryBeingComputed ( )
inlineoverride

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

Definition at line 59 of file ODPCMAliasBlockFile.h.

59 { return mSummaryBeingComputed; }

References mSummaryBeingComputed.

◆ Lock()

void ODPCMAliasBlockFile::Lock ( )
override

Locks the blockfile only if it has a file that exists.

Locks the blockfile only if it has a file that exists. This needs to be done so that the unsaved ODPCMAliasBlockfiles are deleted upon exit

Definition at line 96 of file ODPCMAliasBlockFile.cpp.

97 {
99  PCMAliasBlockFile::Lock();
100 }

References IsSummaryAvailable(), and mHasBeenSaved.

Here is the call graph for this function:

◆ LockRead()

void ODPCMAliasBlockFile::LockRead ( ) const
override

Prevents a read on other threads.

Definition at line 551 of file ODPCMAliasBlockFile.cpp.

552 {
553  mReadDataMutex.Lock();
554 }

References mReadDataMutex.

◆ Read256()

bool ODPCMAliasBlockFile::Read256 ( float *  buffer,
size_t  start,
size_t  len 
)
override

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.

Definition at line 167 of file ODPCMAliasBlockFile.cpp.

168 {
169  if(IsSummaryAvailable())
170  {
171  return PCMAliasBlockFile::Read256(buffer,start,len);
172  }
173  else
174  {
175  //return nothing.
176  ClearSamples((samplePtr)buffer, floatSample, 0, len);
177  return false;
178  }
179 }

References ClearSamples(), floatSample, and IsSummaryAvailable().

Here is the call graph for this function:

◆ Read64K()

bool ODPCMAliasBlockFile::Read64K ( float *  buffer,
size_t  start,
size_t  len 
)
override

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.

Definition at line 183 of file ODPCMAliasBlockFile.cpp.

184 {
185  if(IsSummaryAvailable())
186  {
187  return PCMAliasBlockFile::Read64K(buffer,start,len);
188  }
189  else
190  {
191  //return nothing - it hasn't been calculated yet
192  ClearSamples((samplePtr)buffer, floatSample, 0, len);
193  return false;
194  }
195 }

References ClearSamples(), floatSample, and IsSummaryAvailable().

Here is the call graph for this function:

◆ ReadData()

size_t ODPCMAliasBlockFile::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.

Reads the specified data from the aliased file, using libsndfile, and converts it to the given sample format. Copied from PCMAliasBlockFIle but wxLog calls taken out for thread safety

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

Definition at line 493 of file ODPCMAliasBlockFile.cpp.

495 {
496 
497  auto locker = LockForRead();
498 
499  if(!mAliasedFileName.IsOk()){ // intentionally silenced
500  memset(data,0,SAMPLE_SIZE(format)*len);
501  return len;
502  }
503 
504  return CommonReadData( mayThrow,
505  mAliasedFileName, mSilentAliasLog, this, mAliasStart, mAliasChannel,
506  data, format, start, len);
507 }

References format, and SAMPLE_SIZE.

Referenced by WriteSummary().

Here is the caller graph for this function:

◆ ReadSummary()

bool ODPCMAliasBlockFile::ReadSummary ( ArrayOf< char > &  data)
override

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.

Definition at line 515 of file ODPCMAliasBlockFile.cpp.

516 {
517  data.reinit( mSummaryInfo.totalSummaryBytes );
518 
519  ODLocker locker{ &mFileNameMutex };
520  wxFFile summaryFile(mFileName.GetFullPath(), wxT("rb"));
521 
522  if( !summaryFile.IsOpened() ) {
523 
524  // NEW model; we need to return valid data
525  memset(data.get(), 0, mSummaryInfo.totalSummaryBytes);
526 
527  // we silence the logging for this operation in this object
528  // after first occurrence of error; it's already reported and
529  // spewing at the user will complicate the user's ability to
530  // deal
531  mSilentLog = TRUE;
532 
533  return false;
534  }
535  else
536  mSilentLog = FALSE; // worked properly, any future error is NEW
537 
538  auto read = summaryFile.Read(data.get(), mSummaryInfo.totalSummaryBytes);
539 
540  if (read != mSummaryInfo.totalSummaryBytes) {
541  memset(data.get(), 0, mSummaryInfo.totalSummaryBytes);
542  return false;
543  }
544 
545  FixSummary(data.get());
546 
547  return true;
548 }

References mFileNameMutex, and ArrayOf< X >::reinit().

Here is the call graph for this function:

◆ Recover()

void ODPCMAliasBlockFile::Recover ( void  )
override

Writes the summary file if summary data is available.

Definition at line 334 of file ODPCMAliasBlockFile.cpp.

335 {
336  if(IsSummaryAvailable())
337  {
338  WriteSummary();
339  }
340 }

References IsSummaryAvailable(), and WriteSummary().

Here is the call graph for this function:

◆ SaveXML()

void ODPCMAliasBlockFile::SaveXML ( XMLWriter xmlFile)
override

Saves as xml ODPCMAliasBlockFile or PCMAliasBlockFile depending on summary availability.

Writes the xml as a PCMAliasBlockFile 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 exist, 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

Definition at line 236 of file ODPCMAliasBlockFile.cpp.

238 {
239  //we lock this so that mAliasedFileName doesn't change.
240  auto locker = LockForRead();
241  if(IsSummaryAvailable())
242  {
244  mHasBeenSaved = true;
245  }
246  else
247  {
248  xmlFile.StartTag(wxT("odpcmaliasblockfile"));
249 
250  //unlock to prevent deadlock and resume lock after.
251  {
252  auto suspension = locker.Suspend();
253  ODLocker locker2 { &mFileNameMutex };
254  xmlFile.WriteAttr(wxT("summaryfile"), mFileName.GetFullName());
255  }
256 
257  xmlFile.WriteAttr(wxT("aliasfile"), mAliasedFileName.GetFullPath());
258  xmlFile.WriteAttr(wxT("aliasstart"),
259  mAliasStart.as_long_long());
260  xmlFile.WriteAttr(wxT("aliaslen"), mLen);
261  xmlFile.WriteAttr(wxT("aliaschannel"), mAliasChannel);
262 
263  xmlFile.EndTag(wxT("odpcmaliasblockfile"));
264  }
265 }

References XMLWriter::EndTag(), IsSummaryAvailable(), mFileNameMutex, mHasBeenSaved, PCMAliasBlockFile::SaveXML(), XMLWriter::StartTag(), and XMLWriter::WriteAttr().

Here is the call graph for this function:

◆ SetClipOffset()

void ODPCMAliasBlockFile::SetClipOffset ( sampleCount  numSamples)
inline

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

Definition at line 101 of file ODPCMAliasBlockFile.h.

101 {mClipOffset= numSamples;}

References mClipOffset.

◆ SetFileName()

void ODPCMAliasBlockFile::SetFileName ( wxFileNameWrapper &&  name)
override

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

Definition at line 360 of file ODPCMAliasBlockFile.cpp.

361 {
362  mFileNameMutex.Lock();
363  mFileName = std::move(name);
364  mFileNameMutex.Unlock();
365 }

References mFileNameMutex, and name.

◆ SetStart()

void ODPCMAliasBlockFile::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.

Definition at line 89 of file ODPCMAliasBlockFile.h.

89 {mStart = startSample;}

References mStart.

◆ Unlock()

void ODPCMAliasBlockFile::Unlock ( )
override

Unlocks the blockfile only if it has a file that exists.

unlocks the blockfile only if it has a file that exists. This needs to be done so that the unsaved ODPCMAliasBlockfiles are deleted upon exit

Definition at line 113 of file ODPCMAliasBlockFile.cpp.

114 {
115  if(IsSummaryAvailable() && IsLocked())
116  PCMAliasBlockFile::Unlock();
117 }

References IsSummaryAvailable().

Here is the call graph for this function:

◆ UnlockRead()

void ODPCMAliasBlockFile::UnlockRead ( ) const
override

Allows reading on other threads.

Definition at line 556 of file ODPCMAliasBlockFile.cpp.

557 {
558  mReadDataMutex.Unlock();
559 }

References mReadDataMutex.

◆ WriteSummary()

void ODPCMAliasBlockFile::WriteSummary ( )
overrideprotected

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

Definition at line 374 of file ODPCMAliasBlockFile.cpp.

375 {
376  // To build the summary data, call ReadData (implemented by the
377  // derived classes) to get the sample data
378  // Call this first, so that in case of exceptions from ReadData, there is
379  // no NEW output file
380  SampleBuffer sampleData(mLen, floatSample);
381  this->ReadData(sampleData.ptr(), floatSample, 0, mLen, true);
382 
383  ArrayOf< char > fileNameChar;
384  FILE *summaryFile{};
385  {
386  //the mFileName path may change, for example, when the project is saved.
387  //(it moves from /tmp/ to wherever it is saved to.
388  ODLocker locker { &mFileNameMutex };
389 
390  //wxFFile is not thread-safe - if any error occurs in opening the file,
391  // it posts a wxlog message which WILL crash
392  // Audacity because it goes into the wx GUI.
393  // For this reason I left the wxFFile method commented out. (mchinen)
394  // wxFFile summaryFile(mFileName.GetFullPath(), wxT("wb"));
395 
396  // ...and we use fopen instead.
397  wxString sFullPath = mFileName.GetFullPath();
398  fileNameChar.reinit( strlen(sFullPath.mb_str(wxConvFile)) + 1 );
399  strcpy(fileNameChar.get(), sFullPath.mb_str(wxConvFile));
400  summaryFile = fopen(fileNameChar.get(), "wb");
401  }
402 
403  // JKC ANSWER-ME: Whay is IsOpened() commented out?
404  if (!summaryFile){//.IsOpened() ){
405 
406  // Never silence the Log w.r.t write errors; they always count
407  //however, this is going to be called from a non-main thread,
408  //and wxLog calls are not thread safe.
409  wxPrintf("Unable to write summary data to file: %s", fileNameChar.get());
410 
411  throw FileException{
412  FileException::Cause::Open, wxFileName{ fileNameChar.get() } };
413  }
414 
415  ArrayOf<char> cleanup;
416  void *summaryData = CalcSummary(sampleData.ptr(), mLen,
417  floatSample, cleanup);
418 
419  //summaryFile.Write(summaryData, mSummaryInfo.totalSummaryBytes);
420  fwrite(summaryData, 1, mSummaryInfo.totalSummaryBytes, summaryFile);
421  fclose(summaryFile);
422 
423 
424  // wxPrintf("write successful. filename: %s\n", fileNameChar);
425 
426  mSummaryAvailableMutex.Lock();
427  mSummaryAvailable=true;
428  mSummaryAvailableMutex.Unlock();
429 }

References CalcSummary(), floatSample, mFileNameMutex, mSummaryAvailable, mSummaryAvailableMutex, FileException::Open, SampleBuffer::ptr(), ReadData(), and ArrayOf< X >::reinit().

Referenced by DoWriteSummary(), and Recover().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mAliasedFileNameMutex

ODLock ODPCMAliasBlockFile::mAliasedFileNameMutex
private

Also need to protect the aliased file name.

Definition at line 149 of file ODPCMAliasBlockFile.h.

◆ mClipOffset

sampleCount ODPCMAliasBlockFile::mClipOffset
private

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

Definition at line 163 of file ODPCMAliasBlockFile.h.

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

◆ mFileNameMutex

ODLock ODPCMAliasBlockFile::mFileNameMutex
mutableprivate

◆ mHasBeenSaved

bool ODPCMAliasBlockFile::mHasBeenSaved
private

Definition at line 157 of file ODPCMAliasBlockFile.h.

Referenced by CloseLock(), Copy(), Lock(), ODPCMAliasBlockFile(), and SaveXML().

◆ mReadDataMutex

ODLock ODPCMAliasBlockFile::mReadDataMutex
mutableprivate

Definition at line 152 of file ODPCMAliasBlockFile.h.

Referenced by LockRead(), and UnlockRead().

◆ mStart

sampleCount ODPCMAliasBlockFile::mStart
private

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

Definition at line 160 of file ODPCMAliasBlockFile.h.

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

◆ mSummaryAvailable

bool ODPCMAliasBlockFile::mSummaryAvailable
private

Definition at line 155 of file ODPCMAliasBlockFile.h.

Referenced by IsSummaryAvailable(), ODPCMAliasBlockFile(), and WriteSummary().

◆ mSummaryAvailableMutex

ODLock ODPCMAliasBlockFile::mSummaryAvailableMutex
mutableprivate

Definition at line 154 of file ODPCMAliasBlockFile.h.

Referenced by IsSummaryAvailable(), and WriteSummary().

◆ mSummaryBeingComputed

bool ODPCMAliasBlockFile::mSummaryBeingComputed
private

Definition at line 156 of file ODPCMAliasBlockFile.h.

Referenced by IsSummaryBeingComputed(), and ODPCMAliasBlockFile().

◆ mWriteSummaryMutex

ODLock ODPCMAliasBlockFile::mWriteSummaryMutex
private

Definition at line 143 of file ODPCMAliasBlockFile.h.

Referenced by DoWriteSummary().


The documentation for this class was generated from the following files:
XMLWriter::EndTag
virtual void EndTag(const wxString &name)
Definition: XMLWriter.cpp:99
ClearSamples
void ClearSamples(samplePtr dst, sampleFormat format, size_t start, size_t len)
Definition: SampleFormat.cpp:77
aheaderTag
char aheaderTag[aheaderTagLen+1]
Definition: ODPCMAliasBlockFile.cpp:41
ODPCMAliasBlockFile::mReadDataMutex
ODLock mReadDataMutex
Definition: ODPCMAliasBlockFile.h:152
ODPCMAliasBlockFile::mStart
sampleCount mStart
for reporting after task is complete. Only for display use.
Definition: ODPCMAliasBlockFile.h:160
aheaderTagLen
const int aheaderTagLen
Definition: ODPCMAliasBlockFile.cpp:40
wxFileNameWrapper
Definition: wxFileNameWrapper.h:21
XMLValueChecker::IsGoodInt
static bool IsGoodInt(const wxString &strInt)
Check that the supplied string can be converted to a long (32bit) integer.
Definition: XMLTagHandler.cpp:157
XMLValueChecker::IsGoodPathName
static bool IsGoodPathName(const FilePath &strPathName)
Definition: XMLTagHandler.cpp:98
NotYetAvailableException
Definition: NotYetAvailableException.h:17
ODPCMAliasBlockFile::ReadData
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.
Definition: ODPCMAliasBlockFile.cpp:493
ODPCMAliasBlockFile::IsSummaryAvailable
bool IsSummaryAvailable() const override
Definition: ODPCMAliasBlockFile.cpp:342
PCMAliasBlockFile
An AliasBlockFile that references uncompressed data in an existing file.
Definition: PCMAliasBlockFile.h:20
ArrayOf::reinit
void reinit(Integral count, bool initialize=false)
Definition: MemoryX.h:57
FileException
Thrown for failure of file or database operations in deeply nested places.
Definition: FileException.h:19
ODPCMAliasBlockFile::mSummaryBeingComputed
bool mSummaryBeingComputed
Definition: ODPCMAliasBlockFile.h:156
XMLValueChecker::IsGoodInt64
static bool IsGoodInt64(const wxString &strInt)
Check that the supplied string can be converted to a 64bit integer.
Definition: XMLTagHandler.cpp:163
SAMPLE_SIZE
#define SAMPLE_SIZE(SampleFormat)
Definition: SampleFormat.h:44
ODPCMAliasBlockFile::mHasBeenSaved
bool mHasBeenSaved
Definition: ODPCMAliasBlockFile.h:157
ODPCMAliasBlockFile::mFileNameMutex
ODLock mFileNameMutex
Definition: ODPCMAliasBlockFile.h:146
floatSample
@ floatSample
Definition: SampleFormat.h:34
ODPCMAliasBlockFile::mSummaryAvailableMutex
ODLock mSummaryAvailableMutex
Definition: ODPCMAliasBlockFile.h:154
PCMAliasBlockFile::SaveXML
void SaveXML(XMLWriter &xmlFile) override
Definition: PCMAliasBlockFile.cpp:97
CopySamples
void CopySamples(constSamplePtr src, sampleFormat srcFormat, samplePtr dst, sampleFormat dstFormat, size_t len, DitherType ditherType, unsigned int srcStride, unsigned int dstStride)
Copy samples from any format to any other format; apply dithering only if narrowing the format.
Definition: SampleFormat.cpp:111
name
const TranslatableString name
Definition: Distortion.cpp:98
XMLValueChecker::IsGoodFileName
static bool IsGoodFileName(const FilePath &strFileName, const FilePath &strDirName={})
Definition: XMLTagHandler.cpp:58
FileException::Cause::Open
@ Open
ODPCMAliasBlockFile::CalcSummary
void * CalcSummary(samplePtr buffer, size_t len, sampleFormat format, ArrayOf< char > &cleanup) override
Definition: ODPCMAliasBlockFile.cpp:450
format
int format
Definition: ExportPCM.cpp:56
PCMAliasBlockFile::PCMAliasBlockFile
PCMAliasBlockFile(wxFileNameWrapper &&baseFileName, wxFileNameWrapper &&aliasedFileName, sampleCount aliasStart, size_t aliasLen, int aliasChannel)
Constructs a PCMAliasBlockFile, writing the summary to disk.
Definition: PCMAliasBlockFile.cpp:25
ODLocker
Definition: ODTaskThread.h:120
XMLValueChecker::IsGoodFileString
static bool IsGoodFileString(const FilePath &str)
Definition: XMLTagHandler.cpp:70
SampleBuffer
Definition: SampleFormat.h:69
samplePtr
char * samplePtr
Definition: SampleFormat.h:49
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
anonymous_namespace{WaveTrack.cpp}::IsValidChannel
bool IsValidChannel(const int nValue)
Definition: WaveTrack.cpp:1706
sampleCount
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:18
ODPCMAliasBlockFile::mSummaryAvailable
bool mSummaryAvailable
Definition: ODPCMAliasBlockFile.h:155
XMLWriter::WriteAttr
void WriteAttr(const wxString &name, const Identifier &value)
Definition: XMLWriter.h:34
PLATFORM_MAX_PATH
#define PLATFORM_MAX_PATH
Definition: FileNames.h:22
XMLValueChecker::IsGoodPathString
static bool IsGoodPathString(const FilePath &str)
Definition: XMLTagHandler.cpp:105
ODPCMAliasBlockFile::mWriteSummaryMutex
ODLock mWriteSummaryMutex
Definition: ODPCMAliasBlockFile.h:143
ODPCMAliasBlockFile::WriteSummary
void WriteSummary() override
Write the summary to disk, using the derived ReadData() to get the data.
Definition: ODPCMAliasBlockFile.cpp:374
ArrayOf< float >
XMLWriter::StartTag
virtual void StartTag(const wxString &name)
Definition: XMLWriter.cpp:76
ODPCMAliasBlockFile::mClipOffset
sampleCount mClipOffset
the ODTask needs to know where this blockfile lies in the track, so for convenience,...
Definition: ODPCMAliasBlockFile.h:163