1 /* vim: set sw=2: -*- Mode: C; tab-width: 2; indent-tabs-mode: t; c-basic-offset: 2; c-indent-level: 2 -*- */
2 /* GStreamer MythTV Plug-in
3 * Copyright (C) <2006> Rosfran Borges <rosfran.borges@indt.org.br>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library Lesser General
7 * Public License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more
20 #include "gstmythtvsrc.h"
21 #include "gmyth_file_transfer.h"
22 #include "gmyth_livetv.h"
24 #include <gmyth/gmyth_socket.h>
25 #include <gmyth/gmyth_tvchain.h>
30 GST_DEBUG_CATEGORY_STATIC (mythtvsrc_debug);
31 #define GST_CAT_DEFAULT mythtvsrc_debug
33 #define GST_GMYTHTV_ID_NUM 1
35 #define GMYTHTV_VERSION_DEFAULT 30
37 #define GMYTHTV_TRANSFER_MAX_WAITS 100
39 #define GMYTHTV_TRANSFER_MAX_BUFFER 1024*1024
43 #define MAX_READ_SIZE 12*1024
46 #define ENABLE_TIMING_POSITION 0
48 /* stablish a maximum iteration value to the IS_RECORDING message */
49 static guint wait_to_transfer = 0;
51 static const GstElementDetails gst_mythtv_src_details =
52 GST_ELEMENT_DETAILS ( "MythTV client source",
54 "Control and receive data as a client over the network via raw socket connections using the MythTV protocol",
55 "Rosfran Borges <rosfran.borges@indt.org.br>" );
57 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
60 GST_STATIC_CAPS ("video/x-nuv") );
61 //GST_STATIC_CAPS_ANY);
63 static GThread *update_size_task = NULL;
65 static GStaticMutex update_size_mutex = G_STATIC_MUTEX_INIT;
72 #ifndef GST_DISABLE_GST_DEBUG
78 PROP_GMYTHTV_LIVE_CHAINID
81 static void gst_mythtv_src_finalize (GObject * gobject);
83 static GstFlowReturn gst_mythtv_src_create (GstBaseSrc * psrc, guint64 offset,
84 guint size, GstBuffer ** outbuf);
85 //static GstFlowReturn gst_mythtv_src_create (GstPushSrc * psrc, GstBuffer ** outbuf);
86 static gboolean gst_mythtv_src_start (GstBaseSrc * bsrc);
87 static gboolean gst_mythtv_src_stop (GstBaseSrc * bsrc);
88 static gboolean gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size);
89 static gboolean gst_mythtv_src_is_seekable( GstBaseSrc *push_src );
90 //static gboolean gst_mythtv_new_segment ( GstBaseSrc * psrc );
92 static void gst_mythtv_src_set_property (GObject * object, guint prop_id,
93 const GValue * value, GParamSpec * pspec);
94 static void gst_mythtv_src_get_property (GObject * object, guint prop_id,
95 GValue * value, GParamSpec * pspec);
97 //static GstFlowReturn gst_mythtv_src_chain (GstPad * pad, GstBuffer * buf);
99 static void gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data);
101 static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event);
102 //static gboolean gst_mythtv_src_query ( GstPad * pad, GstQuery * query );
104 static gint do_read_request_response (GstMythtvSrc *src, guint64 offset,
105 guint size, GstBuffer **outbuf);
106 //static gboolean gst_mythtv_src_sink_activate_pull (GstPad * srcpad, gboolean active);
109 _urihandler_init (GType type)
111 static const GInterfaceInfo urihandler_info = {
112 gst_mythtv_src_uri_handler_init,
117 g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &urihandler_info);
119 GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0,
123 GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstBaseSrc,
124 GST_TYPE_BASE_SRC, _urihandler_init)
126 //GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstPushSrc,
127 // GST_TYPE_PUSH_SRC, _urihandler_init)
130 gst_mythtv_src_base_init (gpointer g_class)
132 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
134 gst_element_class_add_pad_template (element_class,
135 gst_static_pad_template_get (&srctemplate));
137 gst_element_class_set_details (element_class, &gst_mythtv_src_details);
141 gst_mythtv_src_class_init (GstMythtvSrcClass * klass)
143 GObjectClass *gobject_class;
144 //GstPushSrcClass *gstpushsrc_class;
145 GstBaseSrcClass *gstbasesrc_class;
147 gobject_class = (GObjectClass *) klass;
148 gstbasesrc_class = (GstBaseSrcClass *) klass;
149 //gstpushsrc_class = (GstPushSrcClass *) klass;
151 gobject_class->set_property = gst_mythtv_src_set_property;
152 gobject_class->get_property = gst_mythtv_src_get_property;
153 gobject_class->finalize = gst_mythtv_src_finalize;
155 g_object_class_install_property
156 (gobject_class, PROP_LOCATION,
157 g_param_spec_string ("location", "Location",
158 "The location. In the form:"
159 "\n\t\t\tmyth://a.com/file.nuv"
160 "\n\t\t\tmyth://a.com:23223/file.nuv "
161 "\n\t\t\ta.com/file.nuv - default scheme 'myth'",
162 "", G_PARAM_READWRITE));
164 g_object_class_install_property
165 (gobject_class, PROP_URI,
166 g_param_spec_string ("uri", "Uri",
167 "The location in form of a URI (deprecated; use location)",
168 "", G_PARAM_READWRITE));
170 g_object_class_install_property
171 (gobject_class, PROP_GMYTHTV_VERSION,
172 g_param_spec_int ("mythtv-version", "mythtv-version",
173 "Change Myth TV version",
174 26, 30, 26, G_PARAM_READWRITE));
176 g_object_class_install_property
177 (gobject_class, PROP_GMYTHTV_LIVEID,
178 g_param_spec_int ("mythtv-live-id", "mythtv-live-id",
179 "Change Myth TV version",
180 0, 200, GST_GMYTHTV_ID_NUM, G_PARAM_READWRITE));
182 g_object_class_install_property
183 (gobject_class, PROP_GMYTHTV_LIVE_CHAINID,
184 g_param_spec_string ("mythtv-live-chainid", "mythtv-live-chainid",
185 "Sets the Myth TV chain ID (from TV Chain)",
186 "", G_PARAM_READWRITE));
188 g_object_class_install_property
189 (gobject_class, PROP_GMYTHTV_LIVE,
190 g_param_spec_boolean ("mythtv-live", "mythtv-live",
191 "Enable MythTV Live TV content streaming",
192 FALSE, G_PARAM_READWRITE));
194 #ifndef GST_DISABLE_GST_DEBUG
195 g_object_class_install_property
196 (gobject_class, PROP_GMYTHTV_DBG,
197 g_param_spec_boolean ("mythtv-debug", "mythtv-debug",
198 "Enable MythTV debug messages",
199 FALSE, G_PARAM_READWRITE));
202 gstbasesrc_class->start = gst_mythtv_src_start;
203 gstbasesrc_class->stop = gst_mythtv_src_stop;
204 gstbasesrc_class->get_size = gst_mythtv_src_get_size;
205 gstbasesrc_class->is_seekable = gst_mythtv_src_is_seekable;
206 //gstpushsrc_class->newsegment = gst_mythtv_src_new_segment;
208 gstbasesrc_class->create = gst_mythtv_src_create;
210 GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0,
211 "MythTV Client Source");
215 gst_mythtv_src_init (GstMythtvSrc * this, GstMythtvSrcClass * g_class)
217 this->file_transfer = NULL;
219 this->unique_setup = FALSE;
221 this->mythtv_version = GMYTHTV_VERSION_DEFAULT;
223 this->bytes_read = 0;
225 this->content_size = -1;
226 this->read_offset = 0;
228 this->live_tv = FALSE;
230 this->user_agent = g_strdup ("mythtvsrc");
231 this->mythtv_caps = NULL;
233 gst_base_src_set_format( GST_BASE_SRC( this ), GST_FORMAT_BYTES );
235 gst_base_src_set_live ( GST_BASE_SRC( this ), TRUE );
237 //gst_pad_set_chain_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
238 // gst_mythtv_src_chain );
240 gst_pad_set_event_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
241 gst_mythtv_src_handle_event );
243 gst_pad_set_query_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
244 gst_mythtv_src_query );
246 //gst_pad_set_activatepull_function( GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
247 // gst_mythtv_src_sink_activate_pull );
252 gst_mythtv_src_finalize (GObject * gobject)
254 GstMythtvSrc *this = GST_MYTHTV_SRC (gobject);
256 g_free (this->user_agent);
258 if (this->mythtv_caps) {
259 gst_caps_unref (this->mythtv_caps);
260 this->mythtv_caps = NULL;
263 if (this->file_transfer) {
264 g_object_unref (this->file_transfer);
265 this->file_transfer = NULL;
268 if (this->uri_name) {
269 g_free (this->uri_name);
272 if (this->user_agent) {
273 g_free (this->user_agent);
276 G_OBJECT_CLASS (parent_class)->finalize (gobject);
280 do_read_request_response (GstMythtvSrc * src, guint64 offset, guint size, GstBuffer **outbuf)
283 guint sizetoread = size; //GST_BUFFER_SIZE (outbuf);
284 //GstBuffer *buffer = gst_buffer_new_and_alloc( size );
286 g_print( "Starting: [%s] Reading %d bytes...\n", __FUNCTION__, sizetoread );
288 /* Loop sending the Myth File Transfer request:
289 * Retry whilst authentication fails and we supply it. */
292 GST_OBJECT_LOCK(src);
294 while ( sizetoread > 0 ) {
296 len = gmyth_file_transfer_read( src->file_transfer,
297 GST_BUFFER_DATA( *outbuf ) + read, sizetoread, TRUE );
302 } else if ( len <= 0 ) {
304 if ( src->live_tv == FALSE ) {
306 } else if ( len == 0 ) {
307 src->update_prog_chain = TRUE;
309 } else if ( /*src->content_size >= src->read_offset &&
310 abs ( src->content_size - src->read_offset ) <= 1024 ) ||*/
311 ( src->content_size <= ( src->read_offset + size + GMYTHTV_TRANSFER_MAX_BUFFER ) ) )
313 #if ENABLE_TIMING_POSITION == 1
315 if (src->live_tv == TRUE) {
317 size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
318 if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
319 src->content_size = size_tmp;
320 else if ( size_tmp > 0 )
322 g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
323 __FUNCTION__, size_tmp );
326 gint64 new_offset = gmyth_file_transfer_get_file_position( src->file_transfer );
327 if ( new_offset > 0 ) {
328 if ( src->content_size < new_offset ) {
329 src->content_size = new_offset;
332 src->update_prog_chain = TRUE;
340 if ( read == sizetoread )
345 src->read_offset += read;
346 src->bytes_read += read;
348 g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
349 "OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read,
350 src->read_offset, src->content_size );
352 //GST_BUFFER_TIMESTAMP( buffer ) = GST_BUFFER_TIMESTAMP ( *outbuf );
353 GST_BUFFER_SIZE (*outbuf) = read; //GST_BUFFER_SIZE (buffer) = read;
354 GST_BUFFER_OFFSET (*outbuf) = offset; //GST_BUFFER_OFFSET (buffer) = offset;
355 GST_BUFFER_OFFSET_END (*outbuf) = offset + read;//GST_BUFFER_OFFSET_END (buffer) = offset + read;
356 //memcpy( GST_BUFFER_DATA( *outbuf ), GST_BUFFER_DATA( buffer ), read );
358 g_print( "Stopping: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\
359 "OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf),
360 GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) );
362 } else if ( !src->live_tv )
371 GST_OBJECT_UNLOCK(src);
377 gst_mythtv_src_create ( GstBaseSrc * psrc, guint64 offset, guint size, GstBuffer **outbuf)
380 GstFlowReturn ret = GST_FLOW_OK;
383 src = GST_MYTHTV_SRC (psrc);
384 /* The caller should know the number of bytes and not read beyond EOS. */
385 if (G_UNLIKELY (src->eos))
387 if ( G_UNLIKELY (src->update_prog_chain) )
388 goto change_progchain;
390 //GST_OBJECT_LOCK(src);
392 if (G_UNLIKELY (src->read_offset != offset)) {
393 gint64 new_offset = gmyth_file_transfer_seek(src->file_transfer, offset, SEEK_SET);
394 g_print( "[%s] SRC Offset = %lld, NEW actual backend SEEK Offset = %lld.\n",
395 __FUNCTION__, src->read_offset, new_offset );
396 if (G_UNLIKELY (new_offset < 0 ) )//|| new_offset != src->read_offset)) {
398 //GST_OBJECT_UNLOCK(src);
399 goto change_progchain;
402 src->read_offset = offset;
404 //GST_OBJECT_UNLOCK(src);
406 /* Create the buffer. */
407 ret = gst_pad_alloc_buffer (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
408 src->read_offset, size,
409 //src->icy_caps ? src->icy_caps :
410 GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), outbuf);
412 if (G_UNLIKELY (ret != GST_FLOW_OK))
415 //g_static_mutex_lock( &update_size_mutex );
416 read = do_read_request_response ( src, src->read_offset, size, outbuf );
417 //g_static_mutex_unlock( &update_size_mutex );
419 if (G_UNLIKELY (src->update_prog_chain) )
420 goto change_progchain;
422 if (G_UNLIKELY (read < 0) || *outbuf == NULL) {
423 //if ( src->live_tv )
430 if (G_UNLIKELY(src->eos))
438 const gchar *reason = gst_flow_get_name (ret);
440 GST_DEBUG_OBJECT (src, "DONE task, reason %s", reason);
445 const gchar *reason = gst_flow_get_name (ret);
447 GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
448 return GST_FLOW_UNEXPECTED;
453 GST_ELEMENT_ERROR (src, RESOURCE, READ,
454 (NULL), ("Could not read any bytes (%i, %s)", read,
456 return GST_FLOW_ERROR;
460 GST_ELEMENT_ERROR (src, RESOURCE, READ,
461 (NULL), ("Seek failed, go to the next program info... (%i, %s)", read,
463 // go to the next program chain
464 src->unique_setup = FALSE;
465 gst_mythtv_src_start( psrc );
473 update_size_func( void *mythtv_data )
477 g_return_if_fail( mythtv_data != NULL );
479 src = GST_MYTHTV_SRC ( mythtv_data );
481 g_static_mutex_lock( &update_size_mutex );
483 if ( src->do_start ) {
484 #if ENABLE_TIMING_POSITION == 1
486 if (src->live_tv == TRUE) {
489 size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
490 if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
491 src->content_size = size_tmp;
492 else if ( size_tmp > 0 )
494 g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
495 __FUNCTION__, size_tmp );
499 g_static_mutex_unlock( &update_size_mutex );
504 gst_mythtv_src_get_position ( GstMythtvSrc* src )
507 if ( src->do_start ) {
508 #if ENABLE_TIMING_POSITION == 1
510 if (src->live_tv == TRUE) {
513 size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
514 if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
515 src->content_size = size_tmp;
516 else if ( size_tmp > 0 )
518 g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
519 __FUNCTION__, size_tmp );
524 return src->content_size;
528 /* create a socket for connecting to remote server */
530 gst_mythtv_src_start ( GstBaseSrc * bsrc )
532 GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
534 GString *chain_id_local = NULL;
538 if (src->unique_setup == FALSE) {
539 src->unique_setup = TRUE;
544 GST_OBJECT_LOCK(src);
546 if ( src->live_tv ) {
547 src->spawn_livetv = gmyth_livetv_new( );
548 if ( gmyth_livetv_setup( src->spawn_livetv ) == FALSE ) {
552 /* set up the uri variable */
553 src->uri_name = g_strdup( src->spawn_livetv->proginfo->pathname->str );
554 chain_id_local = gmyth_tvchain_get_id( src->spawn_livetv->tvchain );
555 if ( chain_id_local != NULL ) {
556 src->live_chain_id = g_strdup( chain_id_local->str );
557 g_print( "\t[%s]\tLocal chain ID = %s.\n", __FUNCTION__, src->live_chain_id );
559 src->live_tv_id = src->spawn_livetv->remote_encoder->recorder_num;
560 g_print ( "[%s] LiveTV id = %d, URI path = %s.\n", __FUNCTION__, src->live_tv_id, src->uri_name );
563 src->file_transfer = gmyth_file_transfer_new( src->live_tv_id,
564 g_string_new( src->uri_name ), -1, src->mythtv_version );
566 if ( src->file_transfer == NULL ) {
567 GST_OBJECT_UNLOCK(src);
572 /* sets the Playback monitor connection */
573 ret = gmyth_file_transfer_playback_setup( &(src->file_transfer), src->live_tv );
575 if ( src->live_tv == TRUE && ret == TRUE ) {
576 /* loop finished, set the max tries variable to zero again... */
577 wait_to_transfer = 0;
579 while ( wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS && ( gmyth_file_transfer_is_recording( src->file_transfer ) == FALSE
580 /*|| ( gmyth_file_transfer_get_file_position( src->file_transfer ) < ( src->content_size + 327680 ) )*/ ) )
584 /* sets the FileTransfer instance connection (video/audio download) */
585 ret = gmyth_file_transfer_setup( &(src->file_transfer), src->live_tv );
587 if ( ret == FALSE ) {
588 GST_OBJECT_UNLOCK(src);
589 #ifndef GST_DISABLE_GST_DEBUG
590 if ( src->mythtv_msgs_dbg )
591 g_printerr( "MythTV FileTransfer request failed when setting up socket connection!\n" );
593 goto begin_req_failed;
596 src->content_size = src->file_transfer->filesize;
598 GST_OBJECT_UNLOCK(src);
599 if ( src->live_tv ) {
602 //update_size_task = g_thread_create( (GThreadFunc)update_size_func, src, FALSE, &error );
603 g_print( "[%s] Update Size task = %s\n", __FUNCTION__, update_size_task != NULL ? "OK !" : "ERROR!!!" );
606 src->do_start = TRUE;
614 if (src->spawn_livetv != NULL )
615 g_object_unref( src->spawn_livetv );
617 GST_ELEMENT_ERROR (src, LIBRARY, INIT,
618 (NULL), ("Could not initialize MythTV library (%i, %s)", ret, src->uri_name));
623 GST_ELEMENT_ERROR (src, LIBRARY, INIT,
624 (NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret, src->uri_name));
630 /* handles queries for location in the stream in the requested format */
632 gst_mythtv_src_query ( GstPad * pad, GstQuery * query )
635 GstMythtvSrc *mythtv;
639 mythtv = GST_GMYTHTV_SRC( GST_PAD_PARENT (pad) );
641 size = gst_mythtv_src_get_position (mythtv);
643 switch (GST_QUERY_TYPE (query)) {
645 case GST_QUERY_POSITION:
651 /* save requested format */
652 gst_query_parse_position (query, NULL, &cur);
654 /* query peer for current position in time */
655 g_print( "[%s] Actual size is %s than current size from sink. [ %lld, %lld ]\n", __FUNCTION__,
656 ( size > cur ) ? "greater" : "lower", size, cur );
657 gst_query_set_position (query, GST_FORMAT_BYTES, size);
664 case GST_QUERY_DURATION:
669 /* save requested format */
670 gst_query_parse_position (query, NULL, &cur);
672 /* query peer for current position in time */
673 g_print( "[%s] Actual size is %s than current size from sink. [ %lld, %lld ]\n", __FUNCTION__,
674 ( size * GST_SECOND > cur * GST_SECOND ) ? "greater" : "lower", size * GST_SECOND,
676 gst_query_set_position (query, GST_FORMAT_TIME, size * GST_SECOND );
678 if ( size * GST_SECOND < cur * GST_SECOND )
698 gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size)
700 GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
703 if (src->content_size <= 0) {
705 } else if ( abs ( src->content_size - src->read_offset ) <= GMYTHTV_TRANSFER_MAX_BUFFER ) {
706 //g_static_mutex_lock( &update_size_mutex );
707 GST_OBJECT_LOCK(src);
709 gint64 new_offset = gmyth_file_transfer_get_file_position( src->file_transfer );
710 if ( new_offset > 0 ) {
711 if ( src->content_size < new_offset ) {
712 src->content_size = new_offset;
715 src->update_prog_chain = TRUE;
716 src->content_size = 0;
719 #if ENABLE_TIMING_POSITION == 1
721 if (src->live_tv == TRUE) {
724 size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
725 if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
726 src->content_size = size_tmp;
727 else if ( size_tmp > 0 )
729 g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
730 __FUNCTION__, size_tmp );
733 GST_OBJECT_UNLOCK(src);
734 //g_static_mutex_unlock( &update_size_mutex );
738 *size = src->content_size;
739 g_print( "[%s] Content size = %llu\n", __FUNCTION__, src->content_size );
745 /* close the socket and associated resources
746 * used both to recover from errors and go to NULL state */
748 gst_mythtv_src_stop (GstBaseSrc * bsrc)
752 src = GST_MYTHTV_SRC (bsrc);
755 g_free (src->uri_name);
756 src->uri_name = NULL;
759 if (src->mythtv_caps) {
760 gst_caps_unref (src->mythtv_caps);
761 src->mythtv_caps = NULL;
770 gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event)
772 GstMythtvSrc *src = GST_MYTHTV_SRC (GST_PAD_PARENT (pad));
774 switch (GST_EVENT_TYPE (event)) {
776 case GST_EVENT_FLUSH_START:
780 case GST_EVENT_FLUSH_STOP:
781 src->do_start = TRUE;
783 gst_element_set_state (GST_ELEMENT(src), GST_STATE_NULL);
784 //gst_element_set_locked_state (GST_ELEMENT(src), TRUE);
788 g_print( "[%s] Got EOS event!!!\n", __FUNCTION__ );
789 guint64 cont_size = gst_mythtv_src_get_position (src);
790 if ( !src->live_tv ) {
791 if ( cont_size > src->content_size ) {
792 src->content_size = cont_size;
796 gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL );
797 gst_element_set_locked_state ( GST_ELEMENT (src), FALSE );
803 case GST_EVENT_NEWSEGMENT:
804 g_print( "[%s] Got NEWSEGMENT!!!\n", __FUNCTION__ );
809 g_print( "[%s] Got EVENT_SEEK!!!\n", __FUNCTION__ );
811 //gboolean update = TRUE;
813 GstSeekType cur_type, stop_type;
815 gint64 cur = 0, stop = 0;
816 gst_event_parse_seek ( event, &rate, &format,
817 &flags, &cur_type, &cur,
820 g_print( "[%s] Got EVENT_SEEK.\n", __FUNCTION__ );
821 if ( !( flags & GST_SEEK_FLAG_FLUSH ) ) {
822 g_print( "[%s] Could get the FLAG_FLUSH message.\n", __FUNCTION__ );
824 //gboolean ret = gst_event_parse_new_segment ( event,
825 // &update, &rate, &format, &start, &stop,
827 //GstFlowReturn flow_ret = gst_mythtv_src_create (GST_BASE_SRC( GST_PAD_PARENT( psrc ) ),
828 // cur, stop - cur + 1, GstBuffer)
832 return gst_pad_event_default (pad, event);
835 return gst_pad_event_default (pad, event);
839 gst_mythtv_src_is_seekable( GstBaseSrc *push_src )
845 gst_mythtv_src_set_property (GObject * object, guint prop_id,
846 const GValue * value, GParamSpec * pspec)
848 GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
850 GST_OBJECT_LOCK (mythtvsrc);
855 if (!g_value_get_string (value)) {
856 GST_WARNING ("location property cannot be NULL");
860 if (mythtvsrc->uri_name != NULL) {
861 g_free (mythtvsrc->uri_name);
862 mythtvsrc->uri_name = NULL;
864 mythtvsrc->uri_name = g_value_dup_string (value);
868 #ifndef GST_DISABLE_GST_DEBUG
869 case PROP_GMYTHTV_DBG:
871 mythtvsrc->mythtv_msgs_dbg = g_value_get_boolean (value);
875 case PROP_GMYTHTV_VERSION:
877 mythtvsrc->mythtv_version = g_value_get_int (value);
880 case PROP_GMYTHTV_LIVEID:
882 mythtvsrc->live_tv_id = g_value_get_int (value);
885 case PROP_GMYTHTV_LIVE:
887 mythtvsrc->live_tv = g_value_get_boolean (value);
890 case PROP_GMYTHTV_LIVE_CHAINID:
892 if (!g_value_get_string (value)) {
893 GST_WARNING ("MythTV Live chainid property cannot be NULL");
897 if (mythtvsrc->live_chain_id != NULL) {
898 g_free (mythtvsrc->live_chain_id);
899 mythtvsrc->live_chain_id = NULL;
901 mythtvsrc->live_chain_id = g_value_dup_string (value);
907 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
910 GST_OBJECT_UNLOCK (mythtvsrc);
916 gst_mythtv_src_get_property (GObject * object, guint prop_id,
917 GValue * value, GParamSpec * pspec)
919 GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
921 GST_OBJECT_LOCK (mythtvsrc);
926 gchar *str = g_strdup( "" );
928 if ( mythtvsrc->uri_name == NULL ) {
929 g_free (mythtvsrc->uri_name);
930 mythtvsrc->uri_name = NULL;
932 str = g_strdup( mythtvsrc->uri_name );
934 g_value_set_string ( value, str );
937 #ifndef GST_DISABLE_GST_DEBUG
938 case PROP_GMYTHTV_DBG:
939 g_value_set_boolean ( value, mythtvsrc->mythtv_msgs_dbg );
942 case PROP_GMYTHTV_VERSION:
944 g_value_set_int ( value, mythtvsrc->mythtv_version );
947 case PROP_GMYTHTV_LIVEID:
949 g_value_set_int ( value, mythtvsrc->live_tv_id );
952 case PROP_GMYTHTV_LIVE:
953 g_value_set_boolean ( value, mythtvsrc->live_tv );
955 case PROP_GMYTHTV_LIVE_CHAINID:
957 gchar *str = g_strdup( "" );
959 if ( mythtvsrc->live_chain_id == NULL ) {
960 g_free (mythtvsrc->live_chain_id);
961 mythtvsrc->live_chain_id = NULL;
963 str = g_strdup( mythtvsrc->live_chain_id );
965 g_value_set_string ( value, str );
969 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
972 GST_OBJECT_UNLOCK (mythtvsrc);
975 /* entry point to initialize the plug-in
976 * initialize the plug-in itself
977 * register the element factories and pad templates
978 * register the features
981 plugin_init (GstPlugin * plugin)
983 return gst_element_register (plugin, "mythtvsrc", GST_RANK_NONE,
984 GST_TYPE_MYTHTV_SRC);
987 /* this is the structure that gst-register looks for
988 * so keep the name plugin_desc, or you cannot get your plug-in registered */
989 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
993 plugin_init, VERSION, "LGPL", "GStreamer", "http://gstreamer.net/")
996 /*** GSTURIHANDLER INTERFACE *************************************************/
998 gst_mythtv_src_uri_get_type (void)
1004 gst_mythtv_src_uri_get_protocols (void)
1006 static gchar *protocols[] = { "myth", "myths", NULL };
1011 static const gchar *
1012 gst_mythtv_src_uri_get_uri (GstURIHandler * handler)
1014 GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
1016 return src->uri_name;
1020 gst_mythtv_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
1022 GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
1026 protocol = gst_uri_get_protocol (uri);
1027 if ((strcmp (protocol, "myth") != 0) && (strcmp (protocol, "myths") != 0)) {
1032 g_object_set (src, "location", uri, NULL);
1038 gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
1040 GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
1042 iface->get_type = gst_mythtv_src_uri_get_type;
1043 iface->get_protocols = gst_mythtv_src_uri_get_protocols;
1044 iface->get_uri = gst_mythtv_src_uri_get_uri;
1045 iface->set_uri = gst_mythtv_src_uri_set_uri;
1049 size_header_handler (void *userdata, const char *value)
1051 GstMythtvSrc *src = GST_MYTHTV_SRC (userdata);
1053 //src->content_size = g_ascii_strtoull (value, NULL, 10);
1055 GST_DEBUG_OBJECT (src, "content size = %lld bytes", src->content_size);