MCPcopy Create free account
hub / github.com/audacity/audacity / Open

Method Open

modules/import-export/mod-flac/ImportFLAC.cpp:288–328  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

286
287
288std::unique_ptr<ImportFileHandle> FLACImportPlugin::Open(
289 const FilePath &filename, AudacityProject*)
290{
291 // First check if it really is a FLAC file
292
293 int cnt;
294 wxFile binaryFile;
295 if (!binaryFile.Open(filename)) {
296 return nullptr; // File not found
297 }
298
299 // FIXME: TRAP_ERR wxFILE ops in FLAC Import could fail.
300 // Seek() return value is not examined, for example.
301#ifdef USE_LIBID3TAG
302 // Skip any ID3 tags that might be present
303 id3_byte_t query[ID3_TAG_QUERYSIZE];
304 cnt = binaryFile.Read(query, sizeof(query));
305 cnt = id3_tag_query(query, cnt);
306 binaryFile.Seek(cnt);
307#endif
308
309 char buf[5];
310 cnt = binaryFile.Read(buf, 4);
311 binaryFile.Close();
312
313 if (cnt == wxInvalidOffset || strncmp(buf, FLAC_HEADER, 4) != 0) {
314 // File is not a FLAC file
315 return nullptr;
316 }
317
318 // Open the file for import
319 auto handle = std::make_unique<FLACImportFileHandle>(filename);
320
321 bool success = handle->Init();
322 if (!success) {
323 return nullptr;
324 }
325
326 // This std::move is needed to "upcast" the pointer type
327 return std::move(handle);
328}
329
330static Importer::RegisteredImportPlugin registered{ "FLAC",
331 std::make_unique< FLACImportPlugin >()

Callers 2

ExportFLAC.cppFile · 0.45
InitMethod · 0.45

Calls 5

moveFunction · 0.85
ReadMethod · 0.45
SeekMethod · 0.45
CloseMethod · 0.45
InitMethod · 0.45

Tested by

no test coverage detected