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

◆ decode_thread_func()

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

Definition at line 517 of file VideoFileReader.cpp.

518{
519 auto vc = m_container_ref.lock();
520 if (!vc) {
522 "VideoFileReader: decode thread — container expired");
523 m_decode_active.store(false);
524 return;
525 }
526
527 const uint64_t total = vc->get_total_source_frames();
528 const uint32_t ring_cap = vc->get_ring_capacity();
529 const uint32_t threshold = (m_refill_threshold > 0)
531 : ring_cap / 4;
532
533 while (!m_decode_stop.load()) {
534 uint64_t head = m_decode_head.load();
535 const uint64_t read_pos = vc->get_read_position()[0];
536
537 if (head >= total)
538 break;
539
540 const uint64_t buffered = (head > read_pos) ? (head - read_pos) : 0;
541
542 if (buffered >= static_cast<uint64_t>(ring_cap)) {
543 std::unique_lock lock(m_decode_mutex);
544 m_decode_cv.wait_for(lock, std::chrono::milliseconds(50), [&] {
545 if (m_decode_stop.load())
546 return true;
547 const uint64_t h = m_decode_head.load(std::memory_order_acquire);
548 const uint64_t rp = vc->get_read_position()[0];
549 const uint64_t ahead = (h > rp) ? (h - rp) : 0;
550 return ahead <= static_cast<uint64_t>(ring_cap - threshold);
551 });
552 continue;
553 }
554
555 const uint64_t want = static_cast<uint64_t>(ring_cap) - buffered;
556 const uint64_t capped = std::min(want, total - head);
557 const uint64_t batch = std::min(capped,
558 static_cast<uint64_t>(m_decode_batch_size));
559
560 uint64_t decoded = decode_batch(*vc, batch);
561
562 if (decoded == 0)
563 break;
564 }
565
566 m_decode_active.store(false);
567}
#define MF_WARN(comp, ctx,...)
uint32_t h
Definition InkPress.cpp:28
float threshold
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, h, 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, MF_WARN, and threshold.

Referenced by start_decode_thread().

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