507{
509 if (!vc) {
511 "VideoFileReader: decode thread — container expired");
513 return;
514 }
515
516 const uint64_t total = vc->get_total_source_frames();
517 const uint32_t ring_cap = vc->get_ring_capacity();
520 : ring_cap / 4;
521
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)) {
533 m_decode_cv.wait_for(lock, std::chrono::milliseconds(50), [&] {
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,
548
550
551 if (decoded == 0)
552 break;
553 }
554
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.
uint32_t m_decode_batch_size
std::atomic< bool > m_decode_stop
std::weak_ptr< Kakshya::VideoFileContainer > m_container_ref
std::atomic< bool > m_decode_active
uint32_t m_refill_threshold
std::atomic< uint64_t > m_decode_head
std::mutex m_decode_mutex
@ FileIO
Filesystem I/O operations.
@ IO
Networking, file handling, streaming.