mirror of
https://github.com/nestriness/warp.git
synced 2025-12-13 02:15:42 +02:00
fix: add a queryView
This commit is contained in:
105
src/media.rs
105
src/media.rs
@@ -6,7 +6,7 @@
|
||||
use anyhow::{self, Context};
|
||||
use gst::prelude::*;
|
||||
use gst::ClockTime;
|
||||
|
||||
use gst_app::glib;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use moq_transport::cache::{broadcast, fragment, segment, track};
|
||||
@@ -250,19 +250,85 @@ impl GST {
|
||||
let pipeline = gst::parse::launch(
|
||||
"videotestsrc num-buffers=99 ! x264enc ! mux. \
|
||||
audiotestsrc num-buffers=140 ! avenc_aac ! mux. \
|
||||
isomp4mux name=mux ! filesink location=test.mp4 name=sink \
|
||||
isomp4mux name=mux ! appsink name=sink \
|
||||
",
|
||||
).unwrap().downcast::<gst::Pipeline>().unwrap();
|
||||
)
|
||||
.unwrap()
|
||||
.downcast::<gst::Pipeline>()
|
||||
.unwrap();
|
||||
|
||||
//TODO: Create a sink that is "seekable", probably with a really good EOS https://github.com/sdroege/gst-plugin-rs/blob/80b58f3b45d2c3adee5684888937a3aa30e30cd7/mux/mp4/src/mp4mux/imp.rs#L1252
|
||||
|
||||
// let appsink = pipeline
|
||||
// .by_name("sink")
|
||||
// .unwrap()
|
||||
// .dynamic_cast::<gst_app::AppSink>()
|
||||
// .unwrap();
|
||||
let appsink = pipeline
|
||||
.by_name("sink")
|
||||
.unwrap()
|
||||
.dynamic_cast::<gst_app::AppSink>()
|
||||
.unwrap();
|
||||
|
||||
// appsink.set_buffer_list(true);
|
||||
appsink.set_buffer_list(true);
|
||||
|
||||
// Set the `emit-signals` property to `true` to receive signals
|
||||
appsink.set_property("emit-signals", &true);
|
||||
|
||||
// Set up a callback for the `new-sample` signal
|
||||
// appsink.connect_new_sample(move |sink| {
|
||||
// // Handle the new sample
|
||||
// let sample = sink.pull_sample().map_err(|_| gst::FlowError::Error)?;
|
||||
// let buffer = sample.buffer().ok_or_else(|| gst::FlowError::Error)?;
|
||||
// let _map = buffer.map_readable().map_err(|_| gst::FlowError::Error)?;
|
||||
|
||||
// // Perform any necessary operations on the buffer data
|
||||
|
||||
// // Return Ok to indicate successful handling of the new sample
|
||||
// Ok(gst::FlowSuccess::Ok)
|
||||
// });
|
||||
|
||||
// Set up a pad probe on the sink pad to intercept queries
|
||||
let sink_pad = appsink.static_pad("sink").unwrap();
|
||||
sink_pad.add_probe(gst::PadProbeType::QUERY_DOWNSTREAM, |pad, info| {
|
||||
if let Some(ref query) = info.query_mut() {
|
||||
//https://github.com/Kurento/gstreamer/blob/f2553fb153edeeecc2f4f74fca996c74dc8210df/plugins/elements/gstfilesink.c#L496C51-L496C69
|
||||
use gst::QueryViewMut;
|
||||
|
||||
match query.view_mut() {
|
||||
QueryViewMut::Seeking(q) => {
|
||||
// We don't support any seeking at all
|
||||
println!("Handling query {:?}", q);
|
||||
|
||||
let format = q.format();
|
||||
if format == gst::Format::Bytes || format == gst::Format::Default {
|
||||
q.set(
|
||||
true,
|
||||
gst::GenericFormattedValue::none_for_format(format),
|
||||
gst::GenericFormattedValue::none_for_format(format),
|
||||
);
|
||||
} else {
|
||||
q.set(
|
||||
false,
|
||||
gst::GenericFormattedValue::none_for_format(format),
|
||||
gst::GenericFormattedValue::none_for_format(format),
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
// if let gst::QueryView::Seeking(mut seeking) = query.view() {
|
||||
// println!("Handling query {:?}", query);
|
||||
|
||||
// if seeking.format() == gst::Format::Bytes || seeking.format() == gst::Format::Default {
|
||||
// seeking.to_owned().set(true, 0.bytes(), 1.bytes());
|
||||
// return gst::PadProbeReturn::Handled;
|
||||
// } else {
|
||||
// seeking.to_owned().set(false, 0.bytes(), 1.bytes());
|
||||
// return gst::PadProbeReturn::Handled;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
gst::PadProbeReturn::Pass
|
||||
});
|
||||
|
||||
// appsink.set_callbacks(
|
||||
// gst_app::AppSinkCallbacks::builder()
|
||||
@@ -277,6 +343,27 @@ impl GST {
|
||||
// // The muxer only outputs non-empty buffer lists
|
||||
// let mut buffer_list = sample.buffer_list_owned().expect("no buffer list");
|
||||
|
||||
// Ok(gst::FlowSuccess::Ok)
|
||||
// })
|
||||
// .query(move |sink, query| {
|
||||
// // Handle the seeking query
|
||||
// if let Some(seeking) = query.downcast_mut::<gst::query::Seeking>() {
|
||||
// if seeking.format() == gst::Format::Bytes {
|
||||
// // Set the seekable flag based on your custom sink's seekability
|
||||
// seeking.set_seekable(true); // Replace with your own logic to determine if the sink is seekable
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Handle other queries if needed
|
||||
// // ...
|
||||
|
||||
// // Call the default query handler for unhandled queries
|
||||
// sink.parent_query(query)
|
||||
// })
|
||||
// .build(),
|
||||
// );
|
||||
|
||||
// println!("buffer is empty {:?}", buffer_list.is_empty());
|
||||
// assert!(!buffer_list.is_empty());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user