Map do_seek()

To be used in the HTTP source at some point
This commit is contained in:
Sebastian Dröge 2016-05-14 17:57:25 +03:00
parent 0f177d8de7
commit fdab33f01b
2 changed files with 34 additions and 9 deletions

View file

@ -16,14 +16,15 @@ static GHashTable *sources;
/* Declarations for Rust code */ /* Declarations for Rust code */
extern gboolean sources_register (void *plugin); extern gboolean sources_register (void *plugin);
extern void source_drop (void * filesrc); extern void source_drop (void * source);
extern GstFlowReturn source_fill (void * filesrc, uint64_t offset, void * data, size_t * data_len); extern GstFlowReturn source_fill (void * source, uint64_t offset, void * data, size_t * data_len);
extern gboolean source_set_uri (void * filesrc, const char *uri); extern gboolean source_do_seek (void * source, uint64_t start, uint64_t stop);
extern char * source_get_uri (void * filesrc); extern gboolean source_set_uri (void * source, const char *uri);
extern uint64_t source_get_size (void * filesrc); extern char * source_get_uri (void * source);
extern gboolean source_is_seekable (void * filesrc); extern uint64_t source_get_size (void * source);
extern gboolean source_start (void * filesrc); extern gboolean source_is_seekable (void * source);
extern gboolean source_stop (void * filesrc); extern gboolean source_start (void * source);
extern gboolean source_stop (void * source);
GST_DEBUG_CATEGORY_STATIC (gst_rs_src_debug); GST_DEBUG_CATEGORY_STATIC (gst_rs_src_debug);
#define GST_CAT_DEFAULT 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 gboolean gst_rs_src_get_size (GstBaseSrc * src, guint64 * size);
static GstFlowReturn gst_rs_src_fill (GstBaseSrc * src, guint64 offset, static GstFlowReturn gst_rs_src_fill (GstBaseSrc * src, guint64 offset,
guint length, GstBuffer * buf); guint length, GstBuffer * buf);
static gboolean gst_rs_src_do_seek (GstBaseSrc * src, GstSegment * segment);
static GObjectClass *parent_class; 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->is_seekable = GST_DEBUG_FUNCPTR (gst_rs_src_is_seekable);
gstbasesrc_class->get_size = GST_DEBUG_FUNCPTR (gst_rs_src_get_size); gstbasesrc_class->get_size = GST_DEBUG_FUNCPTR (gst_rs_src_get_size);
gstbasesrc_class->fill = GST_DEBUG_FUNCPTR (gst_rs_src_fill); gstbasesrc_class->fill = GST_DEBUG_FUNCPTR (gst_rs_src_fill);
gstbasesrc_class->do_seek = GST_DEBUG_FUNCPTR (gst_rs_src_do_seek);
} }
static void static void
@ -197,7 +200,6 @@ gst_rs_src_start (GstBaseSrc * basesrc)
return source_start (src->instance); return source_start (src->instance);
} }
/* unmap and close the rs */
static gboolean static gboolean
gst_rs_src_stop (GstBaseSrc * basesrc) gst_rs_src_stop (GstBaseSrc * basesrc)
{ {
@ -206,6 +208,19 @@ gst_rs_src_stop (GstBaseSrc * basesrc)
return source_stop (src->instance); 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 static GstURIType
gst_rs_src_uri_get_type (GType type) gst_rs_src_uri_get_type (GType type)
{ {

View file

@ -13,6 +13,9 @@ pub trait Source {
fn start(&mut self) -> bool; fn start(&mut self) -> bool;
fn stop(&mut self) -> bool; fn stop(&mut self) -> bool;
fn fill(&mut self, offset: u64, data: &mut [u8]) -> Result<usize, GstFlowReturn>; fn fill(&mut self, offset: u64, data: &mut [u8]) -> Result<usize, GstFlowReturn>;
fn do_seek(&mut self, start: u64, stop: u64) -> bool {
return true;
}
} }
#[no_mangle] #[no_mangle]
@ -87,3 +90,10 @@ pub extern "C" fn source_is_seekable(ptr: *mut Box<Source>) -> GBoolean {
GBoolean::from_bool(source.is_seekable()) GBoolean::from_bool(source.is_seekable())
} }
#[no_mangle]
pub extern "C" fn source_do_seek(ptr: *mut Box<Source>, start: u64, stop: u64) -> GBoolean {
let source: &mut Box<Source> = unsafe { &mut *ptr };
GBoolean::from_bool(source.do_seek(start, stop))
}