Skip to content

Commit

Permalink
Revert "feat: Add support for overlapping captions situations"
Browse files Browse the repository at this point in the history
This reverts commit efcd53af572a36075ffbe124e1bfb1f764565449.
  • Loading branch information
IshanGrover2004 committed Feb 6, 2024
1 parent ca2b5e2 commit 97a2698
Showing 1 changed file with 10 additions and 39 deletions.
49 changes: 10 additions & 39 deletions src/rust/src/decoder/tv_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//! TV screen contains the captions to be displayed.
//! Captions are added to TV screen from a window when any of DSW, HDW, TGW, DLW or CR commands are received
use std::cmp::Ordering;
#[cfg(unix)]
use std::os::unix::prelude::IntoRawFd;
#[cfg(windows)]
Expand Down Expand Up @@ -387,42 +386,13 @@ impl dtvcc_tv_screen {
writer.write_to_file(b"Scenarist_SCC V1.0\n\n")?;
}

if writer.old_cc_time_end == 0 {
writer.old_cc_time_end = self.time_ms_show as i32;
}

let mut buf = String::new();
let mut time_show = ccx_boundary_time::get_time(self.time_ms_show);
let time_end = ccx_boundary_time::get_time(self.time_ms_hide);

// Caption overlapping situation
match writer.old_cc_time_end.cmp(&(time_show.time_in_ms as i32)) {
Ordering::Greater => {
// Correct the frame delay
time_show.time_in_ms -= 1000 / 29.97 as i64;
buf.push_str(&(get_scc_time_str(time_show) + "\t942c 942c ").to_owned());
time_show.time_in_ms += 1000 / 29.97 as i64;
// Clear the buffer and start pop on caption
buf.push_str("94ae 94ae 9420 9420");
}
Ordering::Less => {
// Clear the screen for new caption
let time_to_display = ccx_boundary_time::get_time(writer.old_cc_time_end as i64);
buf.push_str(&(get_scc_time_str(time_to_display) + "\t942c 942c \n\n").to_owned());
// Correct the frame delay
time_show.time_in_ms -= 1000 / 29.97 as i64;
// Clear the buffer and start pop on caption in new time
buf.push_str(&(get_scc_time_str(time_show) + "\t94ae 94ae 9420 9420").to_owned());
time_show.time_in_ms += 1000 / 29.97 as i64;
}
Ordering::Equal => {
time_show.time_in_ms -= 1000 / 29.97 as i64;
buf.push_str(
&(get_scc_time_str(time_show) + "\t942c 942c 94ae 94ae 9420 9420").to_owned(),
);
time_show.time_in_ms += 1000 / 29.97 as i64;
}
}
let time_show = get_scc_time_str(self.time_ms_show);
let time_end = get_scc_time_str(self.time_ms_hide);
buf.push_str(&time_show);

// Clear buffer (94ae 94ae), start pop-on caption (9420 9420), move cursor to row-15, column-1(9470)
buf.push_str("\t94ae 94ae 9420 9420 9470 ");

for row_index in 0..CCX_DTVCC_SCREENGRID_ROWS as usize {
if !self.is_row_empty(row_index) {
Expand All @@ -440,7 +410,7 @@ impl dtvcc_tv_screen {
}
// add 0x80 padding and form byte pair if the last byte pair is not form
if bytes_written % 2 == 1 {
buf.push_str("80 ");
buf.push_str("80");
} else {
buf.push(' ');
}
Expand All @@ -449,8 +419,9 @@ impl dtvcc_tv_screen {
// Display caption (942f 942f)
buf.push_str("942f 942f \n\n");
writer.write_to_file(buf.as_bytes())?;

writer.old_cc_time_end = time_end.time_in_ms as i32;
// Clear caption (942c 942c)
buf = format!("{}\t942c 942c \n\n", time_end);
writer.write_to_file(buf.as_bytes())?;
Ok(())
}

Expand Down

0 comments on commit 97a2698

Please sign in to comment.