MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ extract_regions()

void MayaFlux::IO::SoundFileReader::extract_regions ( const std::shared_ptr< FFmpegContext > &  ctx)
private

Extract region information from the file.

Definition at line 397 of file SoundFileReader.cpp.

398{
399 if (!ctx || !ctx->is_valid()) {
400 return;
401 }
402
403 std::lock_guard<std::mutex> lock(m_metadata_mutex);
404 m_cached_regions.clear();
405
406 for (unsigned int i = 0; i < ctx->format_context->nb_chapters; i++) {
407 AVChapter* chapter = ctx->format_context->chapters[i];
408
409 FileRegion region;
410 region.type = "chapter";
411
412 uint64_t start = av_rescale_q(chapter->start, chapter->time_base,
413 AVRational { 1, static_cast<int>(ctx->sample_rate) });
414 uint64_t end = av_rescale_q(chapter->end, chapter->time_base,
415 AVRational { 1, static_cast<int>(ctx->sample_rate) });
416
417 region.start_coordinates = { start };
418 region.end_coordinates = { end };
419
420 AVDictionaryEntry* entry = nullptr;
421 while ((entry = av_dict_get(chapter->metadata, "", entry, AV_DICT_IGNORE_SUFFIX))) {
422 if (strcmp(entry->key, "title") == 0) {
423 region.name = entry->value;
424 } else {
425 region.attributes[entry->key] = entry->value;
426 }
427 }
428
429 if (region.name.empty()) {
430 region.name = "Chapter " + std::to_string(i + 1);
431 }
432
433 m_cached_regions.push_back(region);
434 }
435
436 AVDictionaryEntry* tag = nullptr;
437 while ((tag = av_dict_get(ctx->format_context->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
438 std::string key = tag->key;
439 if (key.find("cue") != std::string::npos || key.find("CUE") != std::string::npos) {
440 FileRegion region;
441 region.type = "cue";
442 region.name = key;
443 region.attributes["description"] = tag->value;
444
445 try {
446 uint64_t position = std::stoull(tag->value);
447 region.start_coordinates = { position };
448 region.end_coordinates = { position };
449 } catch (...) {
450 region.start_coordinates = { 0 };
451 region.end_coordinates = { 0 };
452 region.attributes["value"] = tag->value;
453 }
454 m_cached_regions.push_back(region);
455 }
456
457 if (key.find("loop") != std::string::npos || key.find("LOOP") != std::string::npos) {
458 FileRegion region;
459 region.type = "loop";
460 region.name = key;
461 region.attributes["value"] = tag->value;
462 region.start_coordinates = { 0 };
463 region.end_coordinates = { 0 };
464 m_cached_regions.push_back(region);
465 }
466 }
467
468 /* tag = nullptr;
469 while ((tag = av_dict_get(ctx->format_context->streams[m_audio_stream_index]->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
470 std::string key = tag->key;
471
472 if (key.find("marker") != std::string::npos || key.find("MARKER") != std::string::npos) {
473 FileRegion region;
474 region.type = "marker";
475 region.name = key;
476 region.attributes["value"] = tag->value;
477 region.start_coordinates = { 0 };
478 region.end_coordinates = { 0 };
479 m_cached_regions.push_back(region);
480 }
481 } */
482}
std::mutex m_metadata_mutex
Mutex for thread-safe metadata access.
std::vector< FileRegion > m_cached_regions
Cached file regions (markers, loops, etc.).

References MayaFlux::IO::FileRegion::attributes, MayaFlux::IO::FileRegion::end_coordinates, m_cached_regions, m_metadata_mutex, MayaFlux::IO::FileRegion::name, MayaFlux::IO::FileRegion::start_coordinates, and MayaFlux::IO::FileRegion::type.

Referenced by open().

+ Here is the caller graph for this function: