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

◆ decode_thread_func()

void MayaFlux::IO::VideoFileReader::decode_thread_func ( )
private

Definition at line 506 of file VideoFileReader.cpp.

507{
508 auto vc = m_container_ref.lock();
509 if (!vc) {
511 "VideoFileReader: decode thread — container expired");
512 m_decode_active.store(false);
513 return;
514 }
515
516 const uint64_t total = vc->get_total_source_frames();
517 const uint32_t ring_cap = vc->get_ring_capacity();
518 const uint32_t threshold = (m_refill_threshold > 0)
520 : ring_cap / 4;
521
522 while (!m_decode_stop.load()) {
523 uint64_t head = m_decode_head.load();
524 const uint64_t read_pos = vc->get_read_position()[0];
525
526 if (head >= total)
527 break;
528
529 const uint64_t buffered = (head > read_pos) ? (head - read_pos) : 0;
530
531 if (buffered >= static_cast<uint64_t>(ring_cap)) {
532 std::unique_lock lock(m_decode_mutex);
533 m_decode_cv.wait_for(lock, std::chrono::milliseconds(50), [&] {
534 if (m_decode_stop.load())
535 return true;
536 const uint64_t h = m_decode_head.load(std::memory_order_acquire);
537 const uint64_t rp = vc->get_read_position()[0];
538 const uint64_t ahead = (h > rp) ? (h - rp) : 0;
539 return ahead <= static_cast<uint64_t>(ring_cap - threshold);
540 });
541 continue;
542 }
543
544 const uint64_t want = static_cast<uint64_t>(ring_cap) - buffered;
545 const uint64_t capped = std::min(want, total - head);
546 const uint64_t batch = std::min(capped,
547 static_cast<uint64_t>(m_decode_batch_size));
548
549 uint64_t decoded = decode_batch(*vc, batch);
550
551 if (decoded == 0)
552 break;
553 }
554
555 m_decode_active.store(false);
556}
#define MF_WARN(comp, ctx,...)
std::condition_variable m_decode_cv
uint64_t decode_batch(Kakshya::VideoFileContainer &vc, uint64_t batch_size)
Decode up to batch_size frames starting at m_decode_head.
std::weak_ptr< Kakshya::VideoFileContainer > m_container_ref
std::atomic< bool > m_decode_active
std::atomic< uint64_t > m_decode_head
@ FileIO
Filesystem I/O operations.
@ IO
Networking, file handling, streaming.

References decode_batch(), MayaFlux::Journal::FileIO, MayaFlux::Journal::IO, m_container_ref, m_decode_active, m_decode_batch_size, m_decode_cv, m_decode_head, m_decode_mutex, m_decode_stop, m_refill_threshold, and MF_WARN.

Referenced by start_decode_thread().

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