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/gmyth_file_transfer.h>
22 #include <gmyth/gmyth_livetv.h>
24 #include <gmyth/gmyth_socket.h>
25 #include <gmyth/gmyth_tvchain.h>
27 #include <gmyth/gmyth_context.h>
32 GST_DEBUG_CATEGORY_STATIC (mythtvsrc_debug);
33 #define GST_CAT_DEFAULT mythtvsrc_debug
35 #define GST_GMYTHTV_ID_NUM 1
37 #define GST_GMYTHTV_CHANNEL_NUM 1000
39 #define GMYTHTV_VERSION_DEFAULT 30
41 #define GMYTHTV_TRANSFER_MAX_WAITS 100
43 #define GMYTHTV_TRANSFER_MAX_BUFFER 128*1024
47 #define MAX_READ_SIZE 4*1024
50 #define GST_FLOW_ERROR_NO_DATA -101
52 #define INTERNAL_BUFFER_SIZE 64*1024
54 /* stablish a maximum iteration value to the IS_RECORDING message */
55 static guint wait_to_transfer = 0;
57 static const GstElementDetails gst_mythtv_src_details =
58 GST_ELEMENT_DETAILS ( "MythTV client source",
60 "Control and receive data as a client over the network via raw socket connections using the MythTV protocol",
61 "Rosfran Borges <rosfran.borges@indt.org.br>" );
63 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ( "src",
66 GST_STATIC_CAPS ("video/x-nuv") );
73 #ifndef GST_DISABLE_GST_DEBUG
79 PROP_GMYTHTV_LIVE_CHAINID,
80 PROP_GMYTHTV_ENABLE_TIMING_POSITION,
81 PROP_GMYTHTV_CHANNEL_NUM
84 static void gst_mythtv_src_finalize (GObject * gobject);
86 static GstFlowReturn gst_mythtv_src_create (GstBaseSrc * psrc, guint64 offset,
87 guint size, GstBuffer ** outbuf);
89 //static GstFlowReturn gst_mythtv_src_create ( GstPushSrc* psrc, GstBuffer** outbuf );
91 static gboolean gst_mythtv_src_start (GstBaseSrc * bsrc);
92 static gboolean gst_mythtv_src_stop (GstBaseSrc * bsrc);
93 static gboolean gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size);
94 static gboolean gst_mythtv_src_is_seekable( GstBaseSrc *push_src );
96 //static void gst_mythtv_src_get_times (GstBaseSrc * src, GstBuffer * buffer,
97 // GstClockTime * start, GstClockTime * end);
99 //static gboolean gst_mythtv_src_do_seek( GstBaseSrc *base, GstSegment *segment );
101 static gboolean gst_mythtv_src_next_program_chain ( GstMythtvSrc *src );
103 static GstStateChangeReturn
104 gst_mythtv_src_change_state (GstElement * element, GstStateChange transition);
106 static void gst_mythtv_src_set_property (GObject * object, guint prop_id,
107 const GValue * value, GParamSpec * pspec);
108 static void gst_mythtv_src_get_property (GObject * object, guint prop_id,
109 GValue * value, GParamSpec * pspec);
111 static void gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data);
113 static gboolean gst_mythtv_src_handle_query (GstPad * pad, GstQuery * query);
115 static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event);
117 static gint do_read_request_response (GstMythtvSrc * src, guint64 offset,
118 guint size, guint8 **data_ptr);
120 GStaticRecMutex th_mutex = G_STATIC_REC_MUTEX_INIT;
123 _urihandler_init (GType type)
125 static const GInterfaceInfo urihandler_info = {
126 gst_mythtv_src_uri_handler_init,
131 g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &urihandler_info);
133 GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0,
137 //GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstBaseSrc,
138 // GST_TYPE_BASE_SRC, _urihandler_init)
140 GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstBaseSrc,
141 GST_TYPE_BASE_SRC, _urihandler_init)
144 gst_mythtv_src_base_init (gpointer g_class)
146 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
148 gst_element_class_add_pad_template (element_class,
149 gst_static_pad_template_get (&srctemplate));
151 gst_element_class_set_details (element_class, &gst_mythtv_src_details);
153 element_class->change_state = gst_mythtv_src_change_state;
158 gst_mythtv_src_class_init (GstMythtvSrcClass * klass)
160 GObjectClass *gobject_class;
161 //GstPushSrcClass *gstpushsrc_class;
162 GstBaseSrcClass *gstbasesrc_class;
164 gobject_class = (GObjectClass *) klass;
165 gstbasesrc_class = (GstBaseSrcClass *) klass;
166 //gstpushsrc_class = (GstPushSrcClass *) klass;
168 gobject_class->set_property = gst_mythtv_src_set_property;
169 gobject_class->get_property = gst_mythtv_src_get_property;
170 gobject_class->finalize = gst_mythtv_src_finalize;
172 g_object_class_install_property
173 (gobject_class, PROP_LOCATION,
174 g_param_spec_string ("location", "Location",
175 "The location. In the form:"
176 "\n\t\t\tmyth://a.com/file.nuv"
177 "\n\t\t\tmyth://a.com:23223/file.nuv "
178 "\n\t\t\ta.com/file.nuv - default scheme 'myth'",
179 "", G_PARAM_READWRITE));
181 g_object_class_install_property
182 (gobject_class, PROP_URI,
183 g_param_spec_string ("uri", "Uri",
184 "The location in form of a URI (deprecated; use location)",
185 "", G_PARAM_READWRITE));
187 g_object_class_install_property
188 (gobject_class, PROP_GMYTHTV_VERSION,
189 g_param_spec_int ("mythtv-version", "mythtv-version",
190 "Change MythTV version",
191 26, 30, 26, G_PARAM_READWRITE));
193 g_object_class_install_property
194 (gobject_class, PROP_GMYTHTV_LIVEID,
195 g_param_spec_int ("mythtv-live-id", "mythtv-live-id",
196 "Change MythTV version",
197 0, 200, GST_GMYTHTV_ID_NUM, G_PARAM_READWRITE));
199 g_object_class_install_property
200 (gobject_class, PROP_GMYTHTV_LIVE_CHAINID,
201 g_param_spec_string ("mythtv-live-chainid", "mythtv-live-chainid",
202 "Sets the MythTV chain ID (from TV Chain)",
203 "", G_PARAM_READWRITE));
205 g_object_class_install_property
206 (gobject_class, PROP_GMYTHTV_LIVE,
207 g_param_spec_boolean ("mythtv-live", "mythtv-live",
208 "Enable MythTV Live TV content streaming",
209 FALSE, G_PARAM_READWRITE));
211 g_object_class_install_property
212 (gobject_class, PROP_GMYTHTV_ENABLE_TIMING_POSITION,
213 g_param_spec_boolean ("mythtv-enable-timing-position", "mythtv-enable-timing-position",
214 "Enable MythTV Live TV content size continuous updating",
215 FALSE, G_PARAM_READWRITE));
217 g_object_class_install_property
218 (gobject_class, PROP_GMYTHTV_CHANNEL_NUM,
219 g_param_spec_int ("mythtv-channel", "mythtv-channel",
220 "Change MythTV channel number",
221 0, 99999, GST_GMYTHTV_CHANNEL_NUM, G_PARAM_READWRITE));
223 #ifndef GST_DISABLE_GST_DEBUG
224 g_object_class_install_property
225 (gobject_class, PROP_GMYTHTV_DBG,
226 g_param_spec_boolean ("mythtv-debug", "mythtv-debug",
227 "Enable MythTV debug messages",
228 FALSE, G_PARAM_READWRITE));
231 gstbasesrc_class->start = gst_mythtv_src_start;
232 gstbasesrc_class->stop = gst_mythtv_src_stop;
233 gstbasesrc_class->get_size = gst_mythtv_src_get_size;
234 gstbasesrc_class->is_seekable = gst_mythtv_src_is_seekable;
236 //gstbasesrc_class->get_times = gst_mythtv_src_get_times;
238 //gstbasesrc_class->do_seek = gst_mythtv_src_do_seek;
239 gstbasesrc_class->create = gst_mythtv_src_create;
241 GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0,
242 "MythTV Client Source");
246 gst_mythtv_src_init (GstMythtvSrc * this, GstMythtvSrcClass * g_class)
248 this->file_transfer = NULL;
250 this->unique_setup = FALSE;
252 this->mythtv_version = GMYTHTV_VERSION_DEFAULT;
254 this->state = GST_MYTHTV_SRC_FILE_TRANSFER;
256 this->bytes_read = 0;
258 this->prev_content_size = 0;
260 this->content_size = 0;
261 this->read_offset = 0;
263 this->content_size_last = 0;
265 this->live_tv = FALSE;
267 this->enable_timing_position = FALSE;
268 this->update_prog_chain = FALSE;
270 this->user_agent = g_strdup ("mythtvsrc");
271 this->mythtv_caps = NULL;
272 this->update_prog_chain = FALSE;
274 this->channel_num = 0;
278 this->bytes_queue = NULL;
280 //this->th_read_ahead = NULL;
282 this->th_mutex = NULL;
284 //this->srcpad = gst_pad_new_from_static_template (&srctemplate, "src");
285 //gst_element_add_pad (GST_ELEMENT (this), this->srcpad);
287 gst_base_src_set_format( GST_BASE_SRC( this ), GST_FORMAT_BYTES );
289 //gst_base_src_set_live ( GST_BASE_SRC( this ), TRUE );
291 gst_pad_set_event_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
292 gst_mythtv_src_handle_event );
293 gst_pad_set_query_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
294 gst_mythtv_src_handle_query );
299 gst_mythtv_src_finalize (GObject * gobject)
301 GstMythtvSrc *this = GST_MYTHTV_SRC (gobject);
303 if ( this->th_read_ahead != NULL ) {
304 gst_task_stop( this->th_read_ahead );
305 this->th_read_ahead = NULL;
308 if (this->mythtv_caps) {
309 gst_caps_unref (this->mythtv_caps);
310 this->mythtv_caps = NULL;
313 if (this->file_transfer) {
314 g_object_unref (this->file_transfer);
315 this->file_transfer = NULL;
318 if (this->spawn_livetv) {
319 g_object_unref (this->spawn_livetv);
320 this->spawn_livetv = NULL;
323 if (this->uri_name) {
324 g_free (this->uri_name);
327 if (this->user_agent) {
328 g_free (this->user_agent);
331 G_OBJECT_CLASS (parent_class)->finalize (gobject);
335 do_read_request_response (GstMythtvSrc * src, guint64 offset, guint size, guint8 **data_ptr)
338 guint sizetoread = size;
340 g_print( "Starting: [%s] Reading %d bytes...\n", __FUNCTION__, sizetoread );
342 /* Loop sending the Myth File Transfer request:
343 * Retry whilst authentication fails and we supply it. */
346 //while ( sizetoread > 0 ) {
348 len = gmyth_file_transfer_read( src->file_transfer,
349 *data_ptr + offset + read, sizetoread, TRUE );
359 if ( src->live_tv == FALSE )
365 if ( len == GMYTHTV_FILE_TRANSFER_READ_ERROR ) { /* -314 */
366 src->update_prog_chain = TRUE;
368 } /*if ( abs( src->content_size - src->bytes_read ) < GMYTHTV_TRANSFER_MAX_BUFFER ) {
369 src->update_prog_chain = TRUE;
370 if ( src->enable_timing_position ) {
373 size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
374 if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
375 src->content_size = size_tmp;
376 else if ( size_tmp > 0 )
378 g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
379 __FUNCTION__, size_tmp );
387 if ( read == sizetoread )
391 if ( read < 0 && !src->live_tv )
406 gst_mythtv_src_create ( GstPushSrc* psrc, GstBuffer** outbuf )
409 GstFlowReturn ret = GST_FLOW_OK;
411 gint adapter_size = 0;
412 guint max_adapter_rep = 1;
414 src = GST_MYTHTV_SRC ( psrc );
416 /* The caller should know the number of bytes and not read beyond EOS. */
417 if (G_UNLIKELY (src->eos))
419 if ( G_UNLIKELY (src->update_prog_chain) )
420 goto change_progchain;
422 //g_static_rec_mutex_lock( &th_mutex );
423 g_print ( "[%s] %d - Adapter size = (%d)...\n", __FUNCTION__, max_adapter_rep, adapter_size );
425 /* just get from the adapter, no network effort... */
427 guint size = (src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE;
429 g_print ( "[%s]\t\tCreate: buffer_remain: %d\n", __FUNCTION__,
430 (gint) src->buffer_remain);
432 /* Create the buffer. */
433 ret = gst_pad_alloc_buffer ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
434 src->read_offset /*GST_BUFFER_OFFSET_NONE*/, size,
435 GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), outbuf );
437 if (G_UNLIKELY (ret != GST_FLOW_OK)) {
439 goto change_progchain;
444 if ( ( src->buffer_remain = gst_adapter_available_fast( src->adapter ) ) < MAX_READ_SIZE ) {
446 ret = gst_pad_alloc_buffer ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
447 src->read_offset /*GST_BUFFER_OFFSET_NONE*/, INTERNAL_BUFFER_SIZE - src->buffer_remain,
448 GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), &buffer );
450 read = do_read_request_response( src, 0, INTERNAL_BUFFER_SIZE - src->buffer_remain, &(GST_BUFFER_DATA(buffer)) );
452 if (G_UNLIKELY (read < 0)) {
454 goto change_progchain;
459 if ( G_UNLIKELY (src->update_prog_chain) )
460 goto change_progchain;
462 gst_adapter_push( src->adapter, buffer );
464 src->buffer_remain = src->buffer_remain + read;
466 g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
467 "OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read,
468 src->read_offset, src->content_size );
473 now = gst_element_get_base_time( GST_ELEMENT( src ) );
477 size = ( src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE;
479 buffer = gst_adapter_take_buffer( src->adapter, size );
481 g_print( "[%s] read = %d, buffer_remain = %d\n", __FUNCTION__, read, src->buffer_remain );
483 GST_BUFFER_SIZE (*outbuf) = size;
484 GST_BUFFER_MALLOCDATA( *outbuf ) = g_malloc0( GST_BUFFER_SIZE (*outbuf) );
485 GST_BUFFER_DATA( *outbuf ) = GST_BUFFER_MALLOCDATA( *outbuf );
486 g_memmove( GST_BUFFER_DATA( (*outbuf) ), GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(*outbuf) );
487 //GST_BUFFER_TIMESTAMP( *outbuf ) = now;
488 GST_BUFFER_OFFSET (*outbuf) = src->read_offset;
489 GST_BUFFER_OFFSET_END (*outbuf) = src->read_offset + GST_BUFFER_SIZE (*outbuf);
491 src->buffer_remain -= GST_BUFFER_SIZE (*outbuf);
493 src->read_offset += GST_BUFFER_SIZE (*outbuf);
494 src->bytes_read += GST_BUFFER_SIZE (*outbuf);
495 g_print ( "[%s]\t\tBuffer output with size: %d\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf) );
497 //gst_adapter_flush( src->adapter, size );
498 gst_buffer_unref( buffer );
500 g_print( "Got buffer: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\
501 "OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf),
502 GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) );
504 /* just get from the adapter, no network effort... */
511 const gchar *reason = gst_flow_get_name (ret);
513 GST_DEBUG_OBJECT (src, "DONE task, reason %s", reason);
518 const gchar *reason = gst_flow_get_name (ret);
520 GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
521 return GST_FLOW_UNEXPECTED;
526 GST_ELEMENT_ERROR (src, RESOURCE, READ,
527 (NULL), ("Could not read any bytes (%i, %s)", read,
529 return GST_FLOW_ERROR;
533 GST_ELEMENT_ERROR (src, RESOURCE, READ,
534 (NULL), ("Seek failed, go to the next program info... (%i, %s)", read,
537 gst_pad_push_event ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
538 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0 ) );
539 // go to the next program chain
540 src->unique_setup = FALSE;
541 src->update_prog_chain = TRUE;
543 gst_mythtv_src_next_program_chain( src );
545 return GST_FLOW_ERROR_NO_DATA;
552 gst_mythtv_src_create ( GstBaseSrc * psrc, guint64 offset, guint size, GstBuffer **outbuf )
555 GstFlowReturn ret = GST_FLOW_OK;
557 gint adapter_size = 0;
558 guint max_adapter_rep = 1;
560 src = GST_MYTHTV_SRC ( psrc );
562 /* The caller should know the number of bytes and not read beyond EOS. */
563 if (G_UNLIKELY (src->eos))
565 if ( G_UNLIKELY (src->update_prog_chain) )
566 goto change_progchain;
568 //g_static_rec_mutex_lock( &th_mutex );
569 g_print ( "[%s] %d - Adapter size = (%d), offset = %llu, size = %d...\n", __FUNCTION__,
570 max_adapter_rep, adapter_size, offset, size );
572 /* just get from the adapter, no network effort... */
573 //GstBuffer *buffer = NULL;
575 g_print ( "[%s]\t\tCreate: buffer_remain: %d\n", __FUNCTION__,
576 (gint) src->buffer_remain);
578 if ( ( src->buffer_remain = src->bytes_queue->len ) < MAX_READ_SIZE ) {
579 guint8 *buffer = g_malloc0( INTERNAL_BUFFER_SIZE - src->buffer_remain );
581 read = do_read_request_response( src, 0, INTERNAL_BUFFER_SIZE - src->buffer_remain, &(buffer) );
583 if (G_UNLIKELY (read < 0)) {
585 goto change_progchain;
590 if ( G_UNLIKELY (src->update_prog_chain) )
591 goto change_progchain;
593 src->bytes_queue = g_byte_array_append( src->bytes_queue, buffer, read );
595 src->buffer_remain = src->buffer_remain + read;
597 g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
598 "OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read,
599 src->read_offset, src->content_size );
603 guint buffer_size = ( src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE;
605 /* Create the buffer. */
606 ret = gst_pad_alloc_buffer ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
608 GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), outbuf );
610 if (G_UNLIKELY (ret != GST_FLOW_OK)) {
612 goto change_progchain;
617 guint8 *buf = g_memdup( src->bytes_queue->data, buffer_size );
619 g_print( "[%s] read = %d, buffer_remain = %d\n", __FUNCTION__, read, src->buffer_remain );
620 //src->read_offset = offset;
622 GST_BUFFER_SIZE (*outbuf) = buffer_size;
623 GST_BUFFER_MALLOCDATA( *outbuf ) = g_malloc0( GST_BUFFER_SIZE (*outbuf) );
624 GST_BUFFER_DATA( *outbuf ) = GST_BUFFER_MALLOCDATA( *outbuf );
625 g_memmove( GST_BUFFER_DATA( (*outbuf) ), buf, GST_BUFFER_SIZE(*outbuf) );
626 GST_BUFFER_OFFSET (*outbuf) = offset;
627 GST_BUFFER_OFFSET_END (*outbuf) = offset + GST_BUFFER_SIZE (*outbuf);
629 src->buffer_remain -= GST_BUFFER_SIZE (*outbuf);
631 src->read_offset += GST_BUFFER_SIZE (*outbuf);
632 src->bytes_read += GST_BUFFER_SIZE (*outbuf);
633 g_print ( "[%s]\t\tBuffer output with size: %d\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf) );
635 src->bytes_queue = g_byte_array_remove_range( src->bytes_queue, 0, buffer_size );
637 g_print( "Got buffer: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\
638 "OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf),
639 GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) );
641 /* just get from the adapter, no network effort... */
647 const gchar *reason = gst_flow_get_name (ret);
649 GST_DEBUG_OBJECT (src, "DONE task, reason %s", reason);
654 const gchar *reason = gst_flow_get_name (ret);
656 GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
657 return GST_FLOW_UNEXPECTED;
662 GST_ELEMENT_ERROR (src, RESOURCE, READ,
663 (NULL), ("Could not read any bytes (%i, %s)", read,
665 return GST_FLOW_ERROR;
669 GST_ELEMENT_ERROR (src, RESOURCE, READ,
670 (NULL), ("Seek failed, go to the next program info... (%i, %s)", read,
673 gst_pad_push_event ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
674 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0 ) );
675 // go to the next program chain
676 src->unique_setup = FALSE;
677 src->update_prog_chain = TRUE;
679 gst_mythtv_src_next_program_chain( src );
681 return GST_FLOW_ERROR_NO_DATA;
687 gst_mythtv_src_get_position ( GstMythtvSrc* src )
692 if (src->live_tv == TRUE && ( abs( src->content_size - src->bytes_read ) <
693 GMYTHTV_TRANSFER_MAX_BUFFER ) ) {
697 size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
698 if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
699 src->content_size = size_tmp;
700 else if ( size_tmp > 0 && --max_tries > 0 )
702 g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
703 __FUNCTION__, size_tmp );
704 /* sets the last content size amount before it can be updated */
705 src->prev_content_size = src->content_size;
708 return src->content_size;
714 gst_mythtv_src_do_seek( GstBaseSrc *base, GstSegment *segment )
716 GstMythtvSrc *src = GST_MYTHTV_SRC( base );
717 gint64 new_offset = -1;
718 gint64 actual_seek = segment->start;
721 g_print( "[%s]DO Seek called! (start = %lld, stop = %lld)\n", __FUNCTION__, segment->start, segment->stop );
723 if ( segment->format == GST_FORMAT_TIME )
726 //actual_seek = ( ( segment->start / 1000 ) * 28 ) * 4000;
728 g_print( "[%s]Trying to seek at the value (actual_seek = %lld, read_offset = %lld)\n", __FUNCTION__, actual_seek, src->read_offset );
729 /* verify if it needs to seek */
730 if ( src->read_offset != actual_seek )
733 new_offset = gmyth_file_transfer_seek( src->file_transfer, segment->start, SEEK_SET );
735 g_print( "[%s] Segment offset start = %lld, SRC Offset = %lld, NEW actual backend SEEK Offset = %lld.\n",
736 __FUNCTION__, segment->start, src->read_offset, new_offset );
737 if ( G_UNLIKELY (new_offset < 0 ) )
741 goto change_progchain;
746 src->read_offset = new_offset;
748 if ( ret == FALSE ) {
749 g_print( "[%s] Failed to set the SEEK on segment!\n", __FUNCTION__ );
754 g_static_rec_mutex_lock( &th_mutex );
756 GST_TASK_SIGNAL( src->th_read_ahead );
758 g_static_rec_mutex_unlock( &th_mutex );
766 GST_DEBUG_OBJECT (src, "EOS found on seeking!!!");
767 //gst_object_unref( src );
772 GST_ELEMENT_ERROR (src, RESOURCE, READ,
773 (NULL), ("Seek failed, go to the next program info... (%i, %s)", read,
776 gst_pad_push_event ( GST_BASE_SRC_PAD (base),
777 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0 ) );
778 /* go to the next program chain */
779 src->unique_setup = FALSE;
780 src->update_prog_chain = TRUE;
782 gst_mythtv_src_next_program_chain( src );
792 gst_mythtv_src_read_ahead ( void *data ) {
794 GstMythtvSrc *src = NULL;
796 GstBuffer *outbuf = NULL;
802 src = GST_MYTHTV_SRC( data );
804 //GST_PAD_STREAM_TRYLOCK( GST_BASE_SRC_PAD (GST_BASE_SRC (src)) );
807 GST_TASK_WAIT( src->th_read_ahead );
811 outbuf = gst_buffer_new_and_alloc( size );
813 read = do_read_request_response ( src, src->adapter_offset, size, &data );
816 src->read_offset += read;
817 src->bytes_read += read;
820 g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
821 "OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read,
822 src->read_offset, src->content_size );
824 GST_BUFFER_SIZE (outbuf) = read;
825 GST_BUFFER_MALLOCDATA( outbuf ) = g_malloc0( GST_BUFFER_SIZE (outbuf) );
826 GST_BUFFER_DATA( outbuf ) = GST_BUFFER_MALLOCDATA( outbuf );
827 g_memmove( GST_BUFFER_DATA( outbuf ), data, read );
828 GST_BUFFER_OFFSET (outbuf) = src->adapter_offset;
829 GST_BUFFER_OFFSET_END (outbuf) = src->adapter_offset + read;
830 g_print( "Got buffer: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\
831 "OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (outbuf),
832 GST_BUFFER_OFFSET (outbuf), GST_BUFFER_OFFSET_END (outbuf) );
836 gst_adapter_push( src->adapter, outbuf );
838 GST_TASK_SIGNAL( src->th_read_ahead );
840 } while ( read < size );
842 //GST_PAD_STREAM_UNLOCK( GST_BASE_SRC_PAD (GST_BASE_SRC (src)) );
848 /* create a socket for connecting to remote server */
850 gst_mythtv_src_start ( GstBaseSrc * bsrc )
852 GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
854 GString *chain_id_local = NULL;
858 if ( G_UNLIKELY (src->update_prog_chain) )
859 goto change_progchain;
861 if (src->unique_setup == FALSE) {
862 src->unique_setup = TRUE;
867 if ( src->live_tv ) {
868 gmyth_context_initialize();
869 src->spawn_livetv = gmyth_livetv_new( );
870 if ( gmyth_livetv_setup( src->spawn_livetv ) == FALSE ) {
875 /* set up the uri variable */
876 src->uri_name = g_strdup( src->spawn_livetv->proginfo->pathname->str );
877 chain_id_local = gmyth_tvchain_get_id( src->spawn_livetv->tvchain );
878 if ( chain_id_local != NULL ) {
879 src->live_chain_id = g_strdup( chain_id_local->str );
880 g_print( "\t[%s]\tLocal chain ID = %s.\n", __FUNCTION__, src->live_chain_id );
882 src->live_tv_id = src->spawn_livetv->recorder->recorder_num;
883 g_print ( "[%s] LiveTV id = %d, URI path = %s.\n", __FUNCTION__, src->live_tv_id, src->uri_name );
886 src->file_transfer = gmyth_file_transfer_new( src->live_tv_id,
887 g_string_new( src->uri_name ), -1, src->mythtv_version );
889 if ( src->file_transfer == NULL ) {
893 /* sets the Playback monitor connection */
894 ret = gmyth_file_transfer_playback_setup( &(src->file_transfer), src->live_tv );
896 if ( src->live_tv == TRUE && ret == TRUE ) {
897 /* loop finished, set the max tries variable to zero again... */
898 wait_to_transfer = 0;
900 while ( wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS &&
901 ( gmyth_file_transfer_is_recording( src->file_transfer ) == FALSE
902 /*|| ( gmyth_file_transfer_get_file_position( src->file_transfer ) < ( src->content_size + 327680 ) )*/ ) )
908 /* sets the FileTransfer instance connection (video/audio download) */
909 ret = gmyth_file_transfer_setup( &(src->file_transfer), src->live_tv );
911 if ( ret == FALSE ) {
912 #ifndef GST_DISABLE_GST_DEBUG
913 if ( src->mythtv_msgs_dbg )
914 g_printerr( "MythTV FileTransfer request failed when setting up socket connection!\n" );
916 goto begin_req_failed;
919 src->content_size = src->file_transfer->filesize;
921 src->do_start = FALSE;
923 //if ( src->live_tv ) {
924 src->bytes_queue = g_byte_array_new();
925 //src->th_read_ahead = gst_task_create( (GstTaskFunction)gst_mythtv_src_read_ahead, src );
926 //gst_task_set_lock( src->th_read_ahead, &th_mutex );
927 //gst_task_start( src->th_read_ahead );
929 src->buffer_remain = 0;
938 if (src->spawn_livetv != NULL )
939 g_object_unref( src->spawn_livetv );
941 GST_ELEMENT_ERROR (src, LIBRARY, INIT,
942 (NULL), ("Could not initialize MythTV library (%i, %s)", ret, src->uri_name));
947 GST_ELEMENT_ERROR (src, LIBRARY, INIT,
948 (NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret, src->uri_name));
953 GST_ELEMENT_ERROR (src, RESOURCE, READ,
954 (NULL), ("Seek failed, go to the next program info... (%s)",
957 gst_pad_push_event ( GST_BASE_SRC_PAD (GST_BASE_SRC (src)),
958 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0 ) );
960 // go to the next program chain
961 src->unique_setup = FALSE;
962 src->update_prog_chain = TRUE;
964 gst_mythtv_src_next_program_chain( src );
972 gst_mythtv_src_get_times (GstBaseSrc * src, GstBuffer * buffer,
973 GstClockTime * start, GstClockTime * end)
980 /* create a new socket for connecting to the next program chain */
982 gst_mythtv_src_next_program_chain ( GstMythtvSrc *src )
984 GString *chain_id_local = NULL;
991 if (src->unique_setup == FALSE) {
992 src->unique_setup = TRUE;
997 GST_PAD_STREAM_LOCK( GST_BASE_SRC_PAD (GST_BASE_SRC (src)) );
999 if (src->file_transfer) {
1000 g_object_unref (src->file_transfer);
1001 src->file_transfer = NULL;
1004 if (src->uri_name) {
1005 g_free (src->uri_name);
1008 if ( src->live_tv ) {
1009 if ( gmyth_livetv_next_program_chain( src->spawn_livetv ) == FALSE ) {
1010 g_print( "\n\n[%s]\t\tFailed to go to the next program chain!!!\n\n", __FUNCTION__ );
1014 /* set up the uri variable */
1015 src->uri_name = g_strdup( src->spawn_livetv->proginfo->pathname->str );
1016 chain_id_local = gmyth_tvchain_get_id( src->spawn_livetv->tvchain );
1017 if ( chain_id_local != NULL ) {
1018 src->live_chain_id = g_strdup( chain_id_local->str );
1019 g_print( "\t[%s]\tLocal chain ID = %s.\n", __FUNCTION__, src->live_chain_id );
1021 src->live_tv_id = src->spawn_livetv->recorder->recorder_num;
1022 g_print ( "[%s] LiveTV id = %d, URI path = %s.\n", __FUNCTION__, src->live_tv_id, src->uri_name );
1025 src->file_transfer = gmyth_file_transfer_new( src->live_tv_id,
1026 g_string_new( src->uri_name ), -1, src->mythtv_version );
1028 if ( src->file_transfer == NULL ) {
1032 /* sets the Playback monitor connection */
1033 ret = gmyth_file_transfer_playback_setup( &(src->file_transfer), src->live_tv );
1035 if ( src->live_tv == TRUE && ret == TRUE ) {
1036 /* loop finished, set the max tries variable to zero again... */
1037 wait_to_transfer = 0;
1041 while ( wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS &&
1042 ( gmyth_file_transfer_is_recording( src->file_transfer ) == FALSE ) )
1046 /* sets the FileTransfer instance connection (video/audio download) */
1047 ret = gmyth_file_transfer_setup( &(src->file_transfer), src->live_tv );
1049 if ( ret == FALSE ) {
1050 #ifndef GST_DISABLE_GST_DEBUG
1051 if ( src->mythtv_msgs_dbg )
1052 g_printerr( "MythTV FileTransfer request failed when setting up socket connection!\n" );
1054 goto begin_req_failed;
1056 src->content_size_last = src->content_size;
1059 if ( src->content_size < src->file_transfer->filesize ) {
1060 src->content_size = src->file_transfer->filesize;
1062 //gint64 pos = gst_mythtv_src_get_position(src);
1063 //if ( pos > src->file_transfer->filesize )
1064 // src->content_size = pos;
1069 src->content_size = src->file_transfer->filesize;
1070 if ( src->live_tv ) {
1071 wait_to_transfer = 0;
1072 while ( wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS && src->content_size < GMYTHTV_TRANSFER_MAX_BUFFER )
1073 src->content_size = gst_mythtv_src_get_position( src );
1076 src->read_offset = 0;
1079 src->update_prog_chain = FALSE;
1081 GST_PAD_STREAM_UNLOCK( GST_BASE_SRC_PAD (GST_BASE_SRC (src)) );
1088 if (src->spawn_livetv != NULL )
1089 g_object_unref( src->spawn_livetv );
1091 GST_ELEMENT_ERROR (src, LIBRARY, INIT,
1092 (NULL), ("Could not initialize MythTV library (%i, %s)", ret, src->uri_name));
1097 GST_ELEMENT_ERROR (src, LIBRARY, INIT,
1098 (NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret, src->uri_name));
1105 gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size)
1107 GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
1108 gboolean ret = TRUE;
1109 g_print( "[%s] Differs from previous content size: %d (max.: %d)\n", __FUNCTION__,
1110 abs( src->content_size - src->prev_content_size ), GMYTHTV_TRANSFER_MAX_BUFFER );
1113 //src->content_size = (guint64)-1;
1115 else if (src->content_size == -1) {
1117 } else if ( src->live_tv && ( abs( src->content_size - src->bytes_read ) <
1118 GMYTHTV_TRANSFER_MAX_BUFFER ) ) {
1119 //g_static_mutex_lock( &update_size_mutex );
1120 //GST_OBJECT_LOCK(src);
1122 gint64 new_offset = gmyth_file_transfer_get_file_position( src->file_transfer );
1123 if ( new_offset > 0 && new_offset > src->content_size ) {
1124 src->content_size = new_offset;
1125 } else if ( new_offset < src->content_size ) {
1126 src->update_prog_chain = TRUE;
1129 if ( src->enable_timing_position ) {
1130 gint64 size_tmp = 0;
1131 if (src->live_tv == TRUE) {
1134 size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
1135 if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
1136 src->content_size = size_tmp;
1137 else if ( size_tmp > 0 )
1139 g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
1140 __FUNCTION__, size_tmp );
1144 src->prev_content_size = src->content_size;
1146 //GST_OBJECT_UNLOCK(src);
1147 //g_static_mutex_unlock( &update_size_mutex );
1150 *size = src->content_size;
1151 g_print( "[%s] Content size = %lld\n", __FUNCTION__, src->content_size );
1157 /* close the socket and associated resources
1158 * used both to recover from errors and go to NULL state */
1160 gst_mythtv_src_stop (GstBaseSrc * bsrc)
1164 src = GST_MYTHTV_SRC (bsrc);
1166 if (src->uri_name) {
1167 g_free (src->uri_name);
1168 src->uri_name = NULL;
1171 if (src->mythtv_caps) {
1172 gst_caps_unref (src->mythtv_caps);
1173 src->mythtv_caps = NULL;
1182 gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event)
1184 GstMythtvSrc *src = GST_MYTHTV_SRC (GST_PAD_PARENT (pad));
1185 gint64 cont_size = 0;
1186 gboolean ret = FALSE;
1188 switch (GST_EVENT_TYPE (event)) {
1190 case GST_EVENT_FLUSH_START:
1192 g_print( "\n\n\n[%s]\t\tGot FLUSH_START event!!!\n\n\n", __FUNCTION__ );
1193 cont_size = gst_mythtv_src_get_position (src);
1194 if ( !src->live_tv ) {
1195 if ( cont_size > src->content_size ) {
1196 src->content_size = cont_size;
1200 gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL );
1201 gst_element_set_locked_state ( GST_ELEMENT (src), FALSE );
1204 if ( cont_size <= 0 ) {
1205 src->update_prog_chain = TRUE;
1207 src->unique_setup = FALSE;
1208 src->do_start = TRUE;
1212 case GST_EVENT_FLUSH_STOP:
1213 src->do_start = TRUE;
1215 gst_element_set_state (GST_ELEMENT(src), GST_STATE_NULL);
1216 //gst_element_set_locked_state (GST_ELEMENT(src), TRUE);
1220 g_print( "[%s] Got EOS event!!!\n", __FUNCTION__ );
1222 if ( src->live_tv ) {
1223 cont_size = gst_mythtv_src_get_position (src);
1224 if ( cont_size > src->content_size ) {
1225 src->content_size = cont_size;
1229 gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL );
1230 gst_element_set_locked_state ( GST_ELEMENT (src), FALSE );
1236 case GST_EVENT_NEWSEGMENT:
1237 g_print( "[%s] Got NEWSEGMENT!!!\n", __FUNCTION__ );
1238 ret = gst_pad_event_default (pad, event);
1240 case GST_EVENT_SEEK:
1242 gst_event_ref( event );
1245 //gboolean update = TRUE;
1247 GstSeekType cur_type, stop_type;
1249 gint64 cur = 0, stop = 0;
1250 gst_event_parse_seek ( event, &rate, &format,
1251 &flags, &cur_type, &cur,
1252 &stop_type, &stop );
1254 g_print( "[%s] Got EVENT_SEEK (pos = %lld)!!!\n", __FUNCTION__, cur );
1255 if ( !( flags & GST_SEEK_FLAG_FLUSH ) ) {
1256 g_print( "[%s] Could get the FLAG_FLUSH message.\n", __FUNCTION__ );
1258 if ( format == GST_FORMAT_TIME && ( ret = gst_pad_event_default (pad, event) ) == FALSE ) {
1259 gst_event_unref( event );
1266 ret = gst_pad_event_default (pad, event);
1273 gst_mythtv_src_is_seekable( GstBaseSrc *push_src )
1279 gst_mythtv_src_handle_query (GstPad * pad, GstQuery * query)
1281 gboolean res = FALSE;
1282 GstMythtvSrc *myth = GST_MYTHTV_SRC (gst_pad_get_parent (pad));
1284 switch (GST_QUERY_TYPE (query)) {
1285 case GST_QUERY_POSITION:
1286 gst_query_set_position (query, GST_FORMAT_BYTES,
1287 myth->read_offset );
1289 GST_DEBUG_OBJECT (myth, "POS %d", myth->read_offset);
1291 case GST_QUERY_DURATION:
1293 if (myth->duration != 0) {
1297 fps = nuv->h->i_fpsn / nuv->h->i_fpsd;
1298 total = gst_util_uint64_scale_int (GST_SECOND, nuv->h->i_video_blocks, fps);
1300 //gst_query_set_duration (query, GST_FORMAT_TIME, myth->content_size);
1301 GST_DEBUG_OBJECT (myth, "DURATION %d", myth->content_size);
1309 gst_object_unref (myth);
1314 static GstStateChangeReturn
1315 gst_mythtv_src_change_state (GstElement * element, GstStateChange transition)
1317 GstStateChangeReturn ret = GST_STATE_CHANGE_FAILURE;//GST_STATE_CHANGE_NO_PREROLL;
1318 GstMythtvSrc *src = GST_MYTHTV_SRC (element);
1320 switch (transition) {
1321 case GST_STATE_CHANGE_NULL_TO_READY:
1322 //src->do_start = TRUE;
1323 //src->unique_setup = FALSE;
1325 case GST_STATE_CHANGE_READY_TO_PAUSED:
1326 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1333 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1334 if (ret == GST_STATE_CHANGE_FAILURE)
1337 switch (transition) {
1338 case GST_STATE_CHANGE_READY_TO_NULL:
1339 g_print( "[%s] READY to NULL called!\n", __FUNCTION__ );
1341 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1342 g_print( "[%s] PLAYING to PAUSED called!\n", __FUNCTION__ );
1343 case GST_STATE_CHANGE_PAUSED_TO_READY:
1344 g_print( "[%s] PAUSED to READY called!\n", __FUNCTION__ );
1346 if ( src->live_tv && src->update_prog_chain ) {
1350 gst_pad_push_event ( GST_BASE_SRC_PAD (GST_BASE_SRC (src)),
1351 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0 ) );
1353 src->read_offset = 0;
1354 src->bytes_read = 0;
1355 src->unique_setup = FALSE;
1356 gst_mythtv_src_next_program_chain( src );
1369 gst_mythtv_src_set_property (GObject * object, guint prop_id,
1370 const GValue * value, GParamSpec * pspec)
1372 GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
1374 GST_OBJECT_LOCK (mythtvsrc);
1379 if (!g_value_get_string (value)) {
1380 GST_WARNING ("location property cannot be NULL");
1384 if (mythtvsrc->uri_name != NULL) {
1385 g_free (mythtvsrc->uri_name);
1386 mythtvsrc->uri_name = NULL;
1388 mythtvsrc->uri_name = g_value_dup_string (value);
1392 #ifndef GST_DISABLE_GST_DEBUG
1393 case PROP_GMYTHTV_DBG:
1395 mythtvsrc->mythtv_msgs_dbg = g_value_get_boolean (value);
1399 case PROP_GMYTHTV_VERSION:
1401 mythtvsrc->mythtv_version = g_value_get_int (value);
1404 case PROP_GMYTHTV_LIVEID:
1406 mythtvsrc->live_tv_id = g_value_get_int (value);
1409 case PROP_GMYTHTV_LIVE:
1411 mythtvsrc->live_tv = g_value_get_boolean (value);
1414 case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
1416 mythtvsrc->enable_timing_position = g_value_get_boolean (value);
1419 case PROP_GMYTHTV_LIVE_CHAINID:
1421 if (!g_value_get_string (value)) {
1422 GST_WARNING ("MythTV Live chainid property cannot be NULL");
1426 if (mythtvsrc->live_chain_id != NULL) {
1427 g_free (mythtvsrc->live_chain_id);
1428 mythtvsrc->live_chain_id = NULL;
1430 mythtvsrc->live_chain_id = g_value_dup_string (value);
1433 case PROP_GMYTHTV_CHANNEL_NUM:
1435 mythtvsrc->channel_num = g_value_get_int (value);
1439 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1442 GST_OBJECT_UNLOCK (mythtvsrc);
1448 gst_mythtv_src_get_property (GObject * object, guint prop_id,
1449 GValue * value, GParamSpec * pspec)
1451 GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
1453 GST_OBJECT_LOCK (mythtvsrc);
1458 gchar *str = g_strdup( "" );
1460 if ( mythtvsrc->uri_name == NULL ) {
1461 g_free (mythtvsrc->uri_name);
1462 mythtvsrc->uri_name = NULL;
1464 str = g_strdup( mythtvsrc->uri_name );
1466 g_value_set_string ( value, str );
1469 #ifndef GST_DISABLE_GST_DEBUG
1470 case PROP_GMYTHTV_DBG:
1471 g_value_set_boolean ( value, mythtvsrc->mythtv_msgs_dbg );
1474 case PROP_GMYTHTV_VERSION:
1476 g_value_set_int ( value, mythtvsrc->mythtv_version );
1479 case PROP_GMYTHTV_LIVEID:
1481 g_value_set_int ( value, mythtvsrc->live_tv_id );
1484 case PROP_GMYTHTV_LIVE:
1485 g_value_set_boolean ( value, mythtvsrc->live_tv );
1487 case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
1488 g_value_set_boolean ( value, mythtvsrc->enable_timing_position );
1490 case PROP_GMYTHTV_LIVE_CHAINID:
1492 gchar *str = g_strdup( "" );
1494 if ( mythtvsrc->live_chain_id == NULL ) {
1495 g_free (mythtvsrc->live_chain_id);
1496 mythtvsrc->live_chain_id = NULL;
1498 str = g_strdup( mythtvsrc->live_chain_id );
1500 g_value_set_string ( value, str );
1503 case PROP_GMYTHTV_CHANNEL_NUM:
1505 g_value_set_int ( value, mythtvsrc->channel_num );
1509 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1512 GST_OBJECT_UNLOCK (mythtvsrc);
1515 /* entry point to initialize the plug-in
1516 * initialize the plug-in itself
1517 * register the element factories and pad templates
1518 * register the features
1521 plugin_init (GstPlugin * plugin)
1523 return gst_element_register (plugin, "mythtvsrc", GST_RANK_NONE,
1524 GST_TYPE_MYTHTV_SRC);
1527 /* this is the structure that gst-register looks for
1528 * so keep the name plugin_desc, or you cannot get your plug-in registered */
1529 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
1533 plugin_init, VERSION, "LGPL", "GStreamer", "http://gstreamer.net/")
1536 /*** GSTURIHANDLER INTERFACE *************************************************/
1538 gst_mythtv_src_uri_get_type (void)
1544 gst_mythtv_src_uri_get_protocols (void)
1546 static gchar *protocols[] = { "myth", "myths", NULL };
1551 static const gchar *
1552 gst_mythtv_src_uri_get_uri (GstURIHandler * handler)
1554 GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
1556 return src->uri_name;
1560 gst_mythtv_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
1562 GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
1566 protocol = gst_uri_get_protocol (uri);
1567 if ((strcmp (protocol, "myth") != 0) && (strcmp (protocol, "myths") != 0)) {
1572 g_object_set (src, "location", uri, NULL);
1578 gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
1580 GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
1582 iface->get_type = gst_mythtv_src_uri_get_type;
1583 iface->get_protocols = gst_mythtv_src_uri_get_protocols;
1584 iface->get_uri = gst_mythtv_src_uri_get_uri;
1585 iface->set_uri = gst_mythtv_src_uri_set_uri;
1589 size_header_handler (void *userdata, const char *value)
1591 GstMythtvSrc *src = GST_MYTHTV_SRC (userdata);
1593 //src->content_size = g_ascii_strtoull (value, NULL, 10);
1595 GST_DEBUG_OBJECT (src, "content size = %lld bytes", src->content_size);