Extract region information from the file.
398{
399 if (!ctx || !ctx->is_valid()) {
400 return;
401 }
402
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
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 }
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 };
465 }
466 }
467
468
469
470
471
472
473
474
475
476
477
478
479
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.).