From fdab33f01b6b97146aad5ed4414b0960e30f0379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sat, 14 May 2016 17:57:25 +0300 Subject: [PATCH] Map do_seek() To be used in the HTTP source at some point --- src/rssource.c | 33 ++++++++++++++++++++++++--------- src/rssource.rs | 10 ++++++++++ 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/rssource.c b/src/rssource.c index 0f9cdf0e..bbc63aa1 100644 --- a/src/rssource.c +++ b/src/rssource.c @@ -16,14 +16,15 @@ static GHashTable *sources; /* Declarations for Rust code */ extern gboolean sources_register (void *plugin); -extern void source_drop (void * filesrc); -extern GstFlowReturn source_fill (void * filesrc, uint64_t offset, void * data, size_t * data_len); -extern gboolean source_set_uri (void * filesrc, const char *uri); -extern char * source_get_uri (void * filesrc); -extern uint64_t source_get_size (void * filesrc); -extern gboolean source_is_seekable (void * filesrc); -extern gboolean source_start (void * filesrc); -extern gboolean source_stop (void * filesrc); +extern void source_drop (void * source); +extern GstFlowReturn source_fill (void * source, uint64_t offset, void * data, size_t * data_len); +extern gboolean source_do_seek (void * source, uint64_t start, uint64_t stop); +extern gboolean source_set_uri (void * source, const char *uri); +extern char * source_get_uri (void * source); +extern uint64_t source_get_size (void * source); +extern gboolean source_is_seekable (void * source); +extern gboolean source_start (void * source); +extern gboolean source_stop (void * source); GST_DEBUG_CATEGORY_STATIC (gst_rs_src_debug); #define GST_CAT_DEFAULT gst_rs_src_debug @@ -56,6 +57,7 @@ static gboolean gst_rs_src_is_seekable (GstBaseSrc * src); static gboolean gst_rs_src_get_size (GstBaseSrc * src, guint64 * size); static GstFlowReturn gst_rs_src_fill (GstBaseSrc * src, guint64 offset, guint length, GstBuffer * buf); +static gboolean gst_rs_src_do_seek (GstBaseSrc * src, GstSegment * segment); static GObjectClass *parent_class; @@ -95,6 +97,7 @@ gst_rs_src_class_init (GstRsSrcClass * klass) gstbasesrc_class->is_seekable = GST_DEBUG_FUNCPTR (gst_rs_src_is_seekable); gstbasesrc_class->get_size = GST_DEBUG_FUNCPTR (gst_rs_src_get_size); gstbasesrc_class->fill = GST_DEBUG_FUNCPTR (gst_rs_src_fill); + gstbasesrc_class->do_seek = GST_DEBUG_FUNCPTR (gst_rs_src_do_seek); } static void @@ -197,7 +200,6 @@ gst_rs_src_start (GstBaseSrc * basesrc) return source_start (src->instance); } -/* unmap and close the rs */ static gboolean gst_rs_src_stop (GstBaseSrc * basesrc) { @@ -206,6 +208,19 @@ gst_rs_src_stop (GstBaseSrc * basesrc) return source_stop (src->instance); } +static gboolean +gst_rs_src_do_seek (GstBaseSrc * basesrc, GstSegment * segment) +{ + GstRsSrc *src = GST_RS_SRC (basesrc); + gboolean ret; + + ret = source_do_seek (src->instance, segment->start, segment->stop); + if (!ret) + return FALSE; + + return GST_BASE_SRC_CLASS (parent_class)->do_seek (basesrc, segment); +} + static GstURIType gst_rs_src_uri_get_type (GType type) { diff --git a/src/rssource.rs b/src/rssource.rs index c6aa6f2e..1aac363e 100644 --- a/src/rssource.rs +++ b/src/rssource.rs @@ -13,6 +13,9 @@ pub trait Source { fn start(&mut self) -> bool; fn stop(&mut self) -> bool; fn fill(&mut self, offset: u64, data: &mut [u8]) -> Result; + fn do_seek(&mut self, start: u64, stop: u64) -> bool { + return true; + } } #[no_mangle] @@ -87,3 +90,10 @@ pub extern "C" fn source_is_seekable(ptr: *mut Box) -> GBoolean { GBoolean::from_bool(source.is_seekable()) } +#[no_mangle] +pub extern "C" fn source_do_seek(ptr: *mut Box, start: u64, stop: u64) -> GBoolean { + let source: &mut Box = unsafe { &mut *ptr }; + + GBoolean::from_bool(source.do_seek(start, stop)) +} +