From a2279bc253386d9fa78d8f1129edba832cf5274d Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Thu, 12 Dec 2024 17:15:02 +1100 Subject: [PATCH] cea708mux: make sure to empty the stored pending codes Fixes some captions being truncated if multiple of the same service is received in the same input buffer. Part-of: --- video/closedcaption/src/cea708mux/imp.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/video/closedcaption/src/cea708mux/imp.rs b/video/closedcaption/src/cea708mux/imp.rs index 78491fe6..92469b20 100644 --- a/video/closedcaption/src/cea708mux/imp.rs +++ b/video/closedcaption/src/cea708mux/imp.rs @@ -324,6 +324,22 @@ impl AggregatorImpl for Cea708Mux { } } } + for (service_no, pending_codes) in pad_state.pending_services.iter_mut() { + let new_service = services + .entry(*service_no) + .or_insert_with_key(|&n| Service::new(n)); + + while let Some(code) = pending_codes.pop_front() { + match new_service.push_code(&code) { + Ok(_) => (), + Err(cea708_types::WriterError::WouldOverflow(_)) => { + pending_codes.push_front(code); + break; + } + Err(cea708_types::WriterError::ReadOnly) => unreachable!(), + } + } + } } _ => (), }