Insert SCTE35 whenever we want

This commit is contained in:
Rafael Caricio 2022-04-15 00:56:48 +02:00
parent 4e37ce96ff
commit d8e9295b91
Signed by: rafaelcaricio
GPG key ID: 3C86DBCE8E93C947

View file

@ -1,9 +1,9 @@
use gst::prelude::*;
use log::info;
use std::fs::File; use std::fs::File;
use std::io::Write; use std::io::Write;
use std::process; use std::process;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use gst::prelude::*;
use log::info;
use std::time::Duration; use std::time::Duration;
fn send_splice<C>(element: &gst::Element, gst_sit: C) fn send_splice<C>(element: &gst::Element, gst_sit: C)
@ -25,15 +25,14 @@ fn send_splice_in(element: &gst::Element, event_id: u32, time: gst::ClockTime) {
}) })
} }
fn send_splice_out( fn send_splice_out(element: &gst::Element, event_id: u32, time: gst::ClockTime) {
element: &gst::Element, info!(
event_id: u32, "Sending Splice Out event: {} @ {}",
time: gst::ClockTime, event_id,
duration: gst::ClockTime, time.display()
) { );
info!("Sending Splice Out event: {} @ {} for {}", event_id, time.display(), duration.display());
send_splice(element, || unsafe { send_splice(element, || unsafe {
gst_mpegts::gst_mpegts_scte_splice_out_new(event_id, time.nseconds(), duration.nseconds()) gst_mpegts::gst_mpegts_scte_splice_out_new(event_id, time.nseconds(), 0)
}) })
} }
@ -75,20 +74,15 @@ fn main() -> eyre::Result<()> {
let now = pipeline.current_running_time().unwrap(); let now = pipeline.current_running_time().unwrap();
// How much ahead should the ad be inserted, we say 5 seconds in the future // How much ahead should the ad be inserted, we say 5 seconds in the future
let ahead = gst::ClockTime::from_seconds(5); let ahead = gst::ClockTime::from_seconds(0);
// next event id // next event id
let event_id = { let event_id = {
let mut ad_event_counter = ad_event_counter.lock().unwrap(); let mut ad_event_counter = ad_event_counter.lock().unwrap();
*ad_event_counter += 1; *ad_event_counter += 1;
*ad_event_counter *ad_event_counter
}; };
send_splice_out( send_splice_out(&muxer, event_id, now + ahead);
&muxer,
event_id,
now + ahead,
gst::ClockTime::from_seconds(10), // Just an indicative, but the Splice In is the actual decision
);
// Now we add a timed call for the duration of the ad from now to indicate via // Now we add a timed call for the duration of the ad from now to indicate via
// splice in that the stream can go back to normal programming. // splice in that the stream can go back to normal programming.
@ -98,7 +92,7 @@ fn main() -> eyre::Result<()> {
move || { move || {
if let Some(muxer) = muxer_weak.upgrade() { if let Some(muxer) = muxer_weak.upgrade() {
// next event id // next event id
let event_id = { let event_id = {
let mut ad_event_counter = ad_event_counter.lock().unwrap(); let mut ad_event_counter = ad_event_counter.lock().unwrap();
*ad_event_counter += 1; *ad_event_counter += 1;
*ad_event_counter *ad_event_counter
@ -110,14 +104,12 @@ fn main() -> eyre::Result<()> {
glib::Continue(false) glib::Continue(false)
} }
}); });
} }
// Run this again next time... // Run this again next time...
glib::Continue(true) glib::Continue(true)
} }
}); });
let context = glib::MainContext::default(); let context = glib::MainContext::default();
let main_loop = glib::MainLoop::new(Some(&context), false); let main_loop = glib::MainLoop::new(Some(&context), false);
@ -154,7 +146,6 @@ fn main() -> eyre::Result<()> {
move || { move || {
if let Some(pipeline) = pipeline_weak.upgrade() { if let Some(pipeline) = pipeline_weak.upgrade() {
pipeline.call_async(|itself| { pipeline.call_async(|itself| {
let dot_graph = itself let dot_graph = itself
.debug_to_dot_data(gst::DebugGraphDetails::all()) .debug_to_dot_data(gst::DebugGraphDetails::all())
.to_string(); .to_string();