Audacity 3.2.0
Public Member Functions | Private Attributes | Friends | List of all members
FLACImportFileHandle Class Referencefinal

An ImportFileHandle for FLAC data. More...

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

Public Member Functions

 FLACImportFileHandle (const FilePath &name)
 
 ~FLACImportFileHandle ()
 
bool Init ()
 
TranslatableString GetFileDescription () override
 
ByteCount GetFileUncompressedBytes () override
 
void Import (ImportProgressListener &progressListener, WaveTrackFactory *trackFactory, TrackHolders &outTracks, Tags *tags, std::optional< LibFileFormats::AcidizerTags > &outAcidTags) override
 
wxInt32 GetStreamCount () override
 
const TranslatableStringsGetStreamInfo () override
 
void SetStreamUsage (wxInt32 WXUNUSED(StreamID), bool WXUNUSED(Use)) override
 
- Public Member Functions inherited from ImportFileHandleEx
 ImportFileHandleEx (const FilePath &filename)
 
FilePath GetFilename () const override
 
void Cancel () override
 
void Stop () override
 
- Public Member Functions inherited from ImportFileHandle
virtual ~ImportFileHandle ()
 
virtual FilePath GetFilename () const =0
 
virtual TranslatableString GetErrorMessage () const
 
virtual TranslatableString GetFileDescription ()=0
 
virtual ByteCount GetFileUncompressedBytes ()=0
 
virtual wxInt32 GetStreamCount ()=0
 
virtual const TranslatableStringsGetStreamInfo ()=0
 
virtual void SetStreamUsage (wxInt32 StreamID, bool Use)=0
 
virtual void Import (ImportProgressListener &progressListener, WaveTrackFactory *trackFactory, TrackHolders &outTracks, Tags *tags, std::optional< LibFileFormats::AcidizerTags > &acidTags)=0
 
virtual void Cancel ()=0
 
virtual void Stop ()=0
 

Private Attributes

sampleFormat mFormat
 
std::unique_ptr< MyFLACFilemFile
 
wxFFile mHandle
 
unsigned long mSampleRate
 
unsigned long mNumChannels
 
unsigned long mBitsPerSample
 
FLAC__uint64 mNumSamples
 
FLAC__uint64 mSamplesDone
 
bool mStreamInfoDone
 
WaveTrack::Holder mTrack
 

Friends

class MyFLACFile
 

Additional Inherited Members

- Public Types inherited from ImportFileHandle
using ByteCount = unsigned long long
 
- Protected Member Functions inherited from ImportFileHandleEx
void BeginImport ()
 
bool IsCancelled () const noexcept
 
bool IsStopped () const noexcept
 

Detailed Description

An ImportFileHandle for FLAC data.

Definition at line 115 of file ImportFLAC.cpp.

Constructor & Destructor Documentation

◆ FLACImportFileHandle()

FLACImportFileHandle::FLACImportFileHandle ( const FilePath name)

Definition at line 321 of file ImportFLAC.cpp.

323 mSamplesDone(0),
324 mStreamInfoDone(false)
325{
326 // Initialize mFormat as narrowest
328 mFile = std::make_unique<MyFLACFile>(this);
329}
@ narrowestSampleFormat
Two synonyms for previous values that might change if more values were added.
wxString name
Definition: TagsEditor.cpp:166
FLAC__uint64 mSamplesDone
Definition: ImportFLAC.cpp:150
std::unique_ptr< MyFLACFile > mFile
Definition: ImportFLAC.cpp:144
sampleFormat mFormat
Definition: ImportFLAC.cpp:143
ImportFileHandleEx(const FilePath &filename)

References mFile, mFormat, and narrowestSampleFormat.

◆ ~FLACImportFileHandle()

FLACImportFileHandle::~FLACImportFileHandle ( )

Definition at line 468 of file ImportFLAC.cpp.

469{
470 mFile->finish();
471}

References mFile.

Member Function Documentation

◆ GetFileDescription()

TranslatableString FLACImportFileHandle::GetFileDescription ( )
overridevirtual

Implements ImportFileHandle.

Definition at line 383 of file ImportFLAC.cpp.

384{
385 return DESC;
386}
#define DESC
Definition: ImportFLAC.cpp:36

References DESC.

◆ GetFileUncompressedBytes()

auto FLACImportFileHandle::GetFileUncompressedBytes ( )
overridevirtual

Implements ImportFileHandle.

Definition at line 389 of file ImportFLAC.cpp.

390{
391 // TODO: Get Uncompressed byte count.
392 return 0;
393}

◆ GetStreamCount()

wxInt32 FLACImportFileHandle::GetStreamCount ( )
inlineoverridevirtual

Implements ImportFileHandle.

Definition at line 131 of file ImportFLAC.cpp.

131{ return 1; }

◆ GetStreamInfo()

const TranslatableStrings & FLACImportFileHandle::GetStreamInfo ( )
inlineoverridevirtual

Implements ImportFileHandle.

Definition at line 133 of file ImportFLAC.cpp.

134 {
135 static TranslatableStrings empty;
136 return empty;
137 }
std::vector< TranslatableString > TranslatableStrings

◆ Import()

void FLACImportFileHandle::Import ( ImportProgressListener progressListener,
WaveTrackFactory trackFactory,
TrackHolders outTracks,
Tags tags,
std::optional< LibFileFormats::AcidizerTags > &  outAcidTags 
)
overridevirtual

Implements ImportFileHandle.

Definition at line 395 of file ImportFLAC.cpp.

399{
400 BeginImport();
401
402 outTracks.clear();
403
404 auto cleanup = finally([&]{ mFile->mImportProgressListener = nullptr; });
405
406 wxASSERT(mStreamInfoDone);
407
409
410 mFile->mImportProgressListener = &progressListener;
411
412 // TODO: Vigilant Sentry: Variable res unused after assignment (error code DA1)
413 // Should check the result.
414 #ifdef LEGACY_FLAC
415 bool res = (mFile->process_until_end_of_file() != 0);
416 #else
417 bool res = (mFile->process_until_end_of_stream() != 0);
418 #endif
419
420 if(IsCancelled())
421 {
423 return;
424 }
425
427
428 wxString comment;
429 wxString description;
430
431 size_t cnt = mFile->mComments.size();
432 if (cnt > 0) {
433 tags->Clear();
434 for (size_t c = 0; c < cnt; c++) {
435 wxString name = mFile->mComments[c].BeforeFirst(wxT('='));
436 wxString value = mFile->mComments[c].AfterFirst(wxT('='));
437 wxString upper = name.Upper();
438 if (upper == wxT("DATE") && !tags->HasTag(TAG_YEAR)) {
439 long val;
440 if (value.length() == 4 && value.ToLong(&val)) {
441 name = TAG_YEAR;
442 }
443 }
444 else if (upper == wxT("COMMENT") || upper == wxT("COMMENTS")) {
445 comment = value;
446 continue;
447 }
448 else if (upper == wxT("DESCRIPTION")) {
449 description = value;
450 continue;
451 }
452 tags->SetTag(name, value);
453 }
454
455 if (comment.empty()) {
456 comment = description;
457 }
458 if (!comment.empty()) {
459 tags->SetTag(TAG_COMMENTS, comment);
460 }
461 }
462
463 progressListener.OnImportResult(IsStopped()
466}
wxT("CloseDown"))
#define TAG_COMMENTS
Definition: Tags.h:64
#define TAG_YEAR
Definition: Tags.h:62
WaveTrack::Holder mTrack
Definition: ImportFLAC.cpp:152
unsigned long mNumChannels
Definition: ImportFLAC.cpp:147
unsigned long mSampleRate
Definition: ImportFLAC.cpp:146
bool IsStopped() const noexcept
bool IsCancelled() const noexcept
virtual void OnImportResult(ImportResult result)=0
Used to report on import result for file handle passed as argument to OnImportFileOpened.
static std::shared_ptr< WaveTrack > NewWaveTrack(WaveTrackFactory &trackFactory, unsigned nChannels, sampleFormat effectiveFormat, double rate)
Definition: ImportUtils.cpp:35
static void FinalizeImport(TrackHolders &outTracks, const std::vector< std::shared_ptr< WaveTrack > > &importedStreams)
Flushes the given channels and moves them to outTracks.
Definition: ImportUtils.cpp:49
void Clear()
Definition: Tags.cpp:293
bool HasTag(const wxString &name) const
Definition: Tags.cpp:397
void SetTag(const wxString &name, const wxString &value, const bool bSpecialTag=false)
Definition: Tags.cpp:431

References ImportFileHandleEx::BeginImport(), ImportProgressListener::Cancelled, Tags::Clear(), ImportUtils::FinalizeImport(), Tags::HasTag(), ImportFileHandleEx::IsCancelled(), ImportFileHandleEx::IsStopped(), mFile, mFormat, mNumChannels, mSampleRate, mStreamInfoDone, mTrack, name, ImportUtils::NewWaveTrack(), ImportProgressListener::OnImportResult(), Tags::SetTag(), ImportProgressListener::Stopped, ImportProgressListener::Success, TAG_COMMENTS, TAG_YEAR, and wxT().

Here is the call graph for this function:

◆ Init()

bool FLACImportFileHandle::Init ( )

Definition at line 331 of file ImportFLAC.cpp.

332{
333#ifdef LEGACY_FLAC
334 bool success = mFile->set_filename(OSINPUT(mFilename));
335 if (!success) {
336 return false;
337 }
338 mFile->set_metadata_respond(FLAC__METADATA_TYPE_STREAMINFO);
339 mFile->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT);
340 FLAC::Decoder::File::State state = mFile->init();
341 if (state != FLAC__FILE_DECODER_OK) {
342 return false;
343 }
344#else
345 if (!mHandle.Open(GetFilename(), wxT("rb"))) {
346 return false;
347 }
348
349 // Even though there is an init() method that takes a filename, use the one that
350 // takes a file handle because wxWidgets can open a file with a Unicode name and
351 // libflac can't (under Windows).
352 //
353 // Responsibility for closing the file is passed to libflac.
354 // (it happens when mFile->finish() is called)
355 bool result = mFile->init(mHandle.fp())?true:false;
356 mHandle.Detach();
357
358 if (result != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
359 return false;
360 }
361#endif
362 mFile->process_until_end_of_metadata();
363
364#ifdef LEGACY_FLAC
365 state = mFile->get_state();
366 if (state != FLAC__FILE_DECODER_OK) {
367 return false;
368 }
369#else
370 // not necessary to check state, error callback will catch errors, but here's how:
371 if (mFile->get_state() > FLAC__STREAM_DECODER_READ_FRAME) {
372 return false;
373 }
374#endif
375
376 if (!mFile->is_valid() || mFile->get_was_error()) {
377 // This probably is not a FLAC file at all
378 return false;
379 }
380 return true;
381}
#define OSINPUT(X)
FilePath GetFilename() const override

References ImportFileHandleEx::GetFilename(), mFile, ImportFileHandleEx::mFilename, mHandle, OSINPUT, and wxT().

Here is the call graph for this function:

◆ SetStreamUsage()

void FLACImportFileHandle::SetStreamUsage ( wxInt32   WXUNUSEDStreamID,
bool   WXUNUSEDUse 
)
inlineoverride

Definition at line 139 of file ImportFLAC.cpp.

140 {}

Friends And Related Function Documentation

◆ MyFLACFile

friend class MyFLACFile
friend

Definition at line 117 of file ImportFLAC.cpp.

Member Data Documentation

◆ mBitsPerSample

unsigned long FLACImportFileHandle::mBitsPerSample
private

Definition at line 148 of file ImportFLAC.cpp.

Referenced by MyFLACFile::metadata_callback().

◆ mFile

std::unique_ptr<MyFLACFile> FLACImportFileHandle::mFile
private

Definition at line 144 of file ImportFLAC.cpp.

Referenced by FLACImportFileHandle(), Import(), Init(), and ~FLACImportFileHandle().

◆ mFormat

sampleFormat FLACImportFileHandle::mFormat
private

Definition at line 143 of file ImportFLAC.cpp.

Referenced by FLACImportFileHandle(), Import(), and MyFLACFile::metadata_callback().

◆ mHandle

wxFFile FLACImportFileHandle::mHandle
private

Definition at line 145 of file ImportFLAC.cpp.

Referenced by Init().

◆ mNumChannels

unsigned long FLACImportFileHandle::mNumChannels
private

Definition at line 147 of file ImportFLAC.cpp.

Referenced by Import(), and MyFLACFile::metadata_callback().

◆ mNumSamples

FLAC__uint64 FLACImportFileHandle::mNumSamples
private

Definition at line 149 of file ImportFLAC.cpp.

Referenced by MyFLACFile::metadata_callback(), and MyFLACFile::write_callback().

◆ mSampleRate

unsigned long FLACImportFileHandle::mSampleRate
private

Definition at line 146 of file ImportFLAC.cpp.

Referenced by Import(), and MyFLACFile::metadata_callback().

◆ mSamplesDone

FLAC__uint64 FLACImportFileHandle::mSamplesDone
private

Definition at line 150 of file ImportFLAC.cpp.

Referenced by MyFLACFile::write_callback().

◆ mStreamInfoDone

bool FLACImportFileHandle::mStreamInfoDone
private

Definition at line 151 of file ImportFLAC.cpp.

Referenced by Import(), and MyFLACFile::metadata_callback().

◆ mTrack

WaveTrack::Holder FLACImportFileHandle::mTrack
private

Definition at line 152 of file ImportFLAC.cpp.

Referenced by Import(), and MyFLACFile::write_callback().


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