diff -r a102805611e7 -r 3cf3c6019e3b gst-gmyth/mythsrc/gstmythtvsrc.c --- a/gst-gmyth/mythsrc/gstmythtvsrc.c Thu May 31 16:02:53 2007 +0100 +++ b/gst-gmyth/mythsrc/gstmythtvsrc.c Thu Jun 14 18:21:08 2007 +0100 @@ -84,7 +84,7 @@ #include #include -GST_DEBUG_CATEGORY_STATIC (mythtvsrc_debug); +GST_DEBUG_CATEGORY_STATIC(mythtvsrc_debug); #define GST_CAT_DEFAULT mythtvsrc_debug #define GST_GMYTHTV_ID_NUM 1 @@ -108,17 +108,17 @@ #define INTERNAL_BUFFER_SIZE (90*1024) static const GstElementDetails gst_mythtv_src_details = -GST_ELEMENT_DETAILS ("MythTV client source", - "Source/Network", - "Control and receive data as a client over the network " - "via raw socket connections using the MythTV protocol", - "Rosfran Borges "); +GST_ELEMENT_DETAILS("MythTV client source", + "Source/Network", + "Control and receive data as a client over the network " + "via raw socket connections using the MythTV protocol", + "Rosfran Borges "); -static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS_ANY ); - /* GST_STATIC_CAPS ("video/x-nuv")); */ +static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS_ANY); + /* GST_STATIC_CAPS ("video/x-nuv")); */ enum { @@ -136,71 +136,73 @@ PROP_GMYTHTV_MAX_TRY }; -static void gst_mythtv_src_clear (GstMythtvSrc *mythtv_src); +static void gst_mythtv_src_clear(GstMythtvSrc * mythtv_src); -static void gst_mythtv_src_finalize (GObject * gobject); +static void gst_mythtv_src_finalize(GObject * gobject); -static GstFlowReturn gst_mythtv_src_create (GstPushSrc * psrc, - GstBuffer ** outbuf); +static GstFlowReturn gst_mythtv_src_create(GstPushSrc * psrc, + GstBuffer ** outbuf); -static gboolean gst_mythtv_src_start (GstBaseSrc * bsrc); -static gboolean gst_mythtv_src_stop (GstBaseSrc * bsrc); -static gboolean gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size); -static gboolean gst_mythtv_src_is_seekable (GstBaseSrc * push_src); +static gboolean gst_mythtv_src_start(GstBaseSrc * bsrc); +static gboolean gst_mythtv_src_stop(GstBaseSrc * bsrc); +static gboolean gst_mythtv_src_get_size(GstBaseSrc * bsrc, guint64 * size); +static gboolean gst_mythtv_src_is_seekable(GstBaseSrc * push_src); -static gboolean gst_mythtv_src_do_seek (GstBaseSrc * base, - GstSegment * segment); +static gboolean gst_mythtv_src_do_seek(GstBaseSrc * base, + GstSegment * segment); static GstStateChangeReturn -gst_mythtv_src_change_state (GstElement * element, GstStateChange transition); +gst_mythtv_src_change_state(GstElement * element, GstStateChange transition); -static void gst_mythtv_src_set_property (GObject * object, guint prop_id, - const GValue * value, GParamSpec * pspec); -static void gst_mythtv_src_get_property (GObject * object, guint prop_id, - GValue * value, GParamSpec * pspec); +static void gst_mythtv_src_set_property(GObject * object, guint prop_id, + const GValue * value, + GParamSpec * pspec); +static void gst_mythtv_src_get_property(GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); -static void gst_mythtv_src_uri_handler_init (gpointer g_iface, - gpointer iface_data); +static void gst_mythtv_src_uri_handler_init(gpointer g_iface, + gpointer iface_data); -static gboolean gst_mythtv_src_handle_query (GstPad * pad, GstQuery * query); +static gboolean gst_mythtv_src_handle_query(GstPad * pad, GstQuery * query); -static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event); +static gboolean gst_mythtv_src_handle_event(GstPad * pad, GstEvent * event); -static GMythFileReadResult do_read_request_response (GstMythtvSrc * src, guint size, - GByteArray * data_ptr); +static GMythFileReadResult do_read_request_response(GstMythtvSrc * src, + guint size, + GByteArray * data_ptr); static void -_urihandler_init (GType type) +_urihandler_init(GType type) { static const GInterfaceInfo urihandler_info = { - gst_mythtv_src_uri_handler_init, - NULL, - NULL + gst_mythtv_src_uri_handler_init, + NULL, + NULL }; - g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &urihandler_info); + g_type_add_interface_static(type, GST_TYPE_URI_HANDLER, &urihandler_info); - GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0, "MythTV src"); + GST_DEBUG_CATEGORY_INIT(mythtvsrc_debug, "mythtvsrc", 0, "MythTV src"); } -GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstPushSrc, - GST_TYPE_PUSH_SRC, _urihandler_init) +GST_BOILERPLATE_FULL(GstMythtvSrc, gst_mythtv_src, GstPushSrc, + GST_TYPE_PUSH_SRC, _urihandler_init) + static void gst_mythtv_src_base_init(gpointer g_class) +{ + GstElementClass *element_class = GST_ELEMENT_CLASS(g_class); - static void gst_mythtv_src_base_init (gpointer g_class) -{ - GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); + gst_element_class_add_pad_template(element_class, + gst_static_pad_template_get + (&srctemplate)); - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&srctemplate)); - - gst_element_class_set_details (element_class, &gst_mythtv_src_details); + gst_element_class_set_details(element_class, &gst_mythtv_src_details); element_class->change_state = gst_mythtv_src_change_state; } static void -gst_mythtv_src_class_init (GstMythtvSrcClass * klass) +gst_mythtv_src_class_init(GstMythtvSrcClass * klass) { GObjectClass *gobject_class; GstPushSrcClass *gstpushsrc_class; @@ -215,60 +217,64 @@ gobject_class->finalize = gst_mythtv_src_finalize; g_object_class_install_property - (gobject_class, PROP_LOCATION, - g_param_spec_string ("location", "Location", - "The location. In the form:" - "\n\t\t\tmyth://a.com/file.nuv" - "\n\t\t\tmyth://a.com:23223/file.nuv " - "\n\t\t\ta.com/file.nuv - default scheme 'myth'", - "", G_PARAM_READWRITE)); + (gobject_class, PROP_LOCATION, + g_param_spec_string("location", "Location", + "The location. In the form:" + "\n\t\t\tmyth://a.com/file.nuv" + "\n\t\t\tmyth://a.com:23223/file.nuv " + "\n\t\t\ta.com/file.nuv - default scheme 'myth'", + "", G_PARAM_READWRITE)); g_object_class_install_property - (gobject_class, PROP_GMYTHTV_VERSION, - g_param_spec_int ("mythtv-version", "mythtv-version", - "Change MythTV version", 26, 30, 26, G_PARAM_READWRITE)); + (gobject_class, PROP_GMYTHTV_VERSION, + g_param_spec_int("mythtv-version", "mythtv-version", + "Change MythTV version", 26, 30, 26, + G_PARAM_READWRITE)); g_object_class_install_property - (gobject_class, PROP_GMYTHTV_LIVEID, - g_param_spec_int ("mythtv-live-id", "mythtv-live-id", - "Change MythTV version", - 0, 200, GST_GMYTHTV_ID_NUM, G_PARAM_READWRITE)); + (gobject_class, PROP_GMYTHTV_LIVEID, + g_param_spec_int("mythtv-live-id", "mythtv-live-id", + "Change MythTV version", + 0, 200, GST_GMYTHTV_ID_NUM, G_PARAM_READWRITE)); g_object_class_install_property - (gobject_class, PROP_GMYTHTV_LIVE_CHAINID, - g_param_spec_string ("mythtv-live-chainid", "mythtv-live-chainid", - "Sets the MythTV chain ID (from TV Chain)", "", G_PARAM_READWRITE)); + (gobject_class, PROP_GMYTHTV_LIVE_CHAINID, + g_param_spec_string("mythtv-live-chainid", "mythtv-live-chainid", + "Sets the MythTV chain ID (from TV Chain)", "", + G_PARAM_READWRITE)); g_object_class_install_property - (gobject_class, PROP_GMYTHTV_LIVE, - g_param_spec_boolean ("mythtv-live", "mythtv-live", - "Enable MythTV Live TV content streaming", FALSE, G_PARAM_READWRITE)); + (gobject_class, PROP_GMYTHTV_LIVE, + g_param_spec_boolean("mythtv-live", "mythtv-live", + "Enable MythTV Live TV content streaming", FALSE, + G_PARAM_READWRITE)); g_object_class_install_property - (gobject_class, PROP_GMYTHTV_ENABLE_TIMING_POSITION, - g_param_spec_boolean ("mythtv-enable-timing-position", - "mythtv-enable-timing-position", - "Enable MythTV Live TV content size continuous updating", FALSE, - G_PARAM_READWRITE)); + (gobject_class, PROP_GMYTHTV_ENABLE_TIMING_POSITION, + g_param_spec_boolean("mythtv-enable-timing-position", + "mythtv-enable-timing-position", + "Enable MythTV Live TV content size continuous updating", + FALSE, G_PARAM_READWRITE)); g_object_class_install_property - (gobject_class, PROP_GMYTHTV_CHANNEL_NUM, - g_param_spec_string ("mythtv-channel", "mythtv-channel", - "Change MythTV channel number", - "", G_PARAM_READWRITE)); + (gobject_class, PROP_GMYTHTV_CHANNEL_NUM, + g_param_spec_string("mythtv-channel", "mythtv-channel", + "Change MythTV channel number", + "", G_PARAM_READWRITE)); g_object_class_install_property - (gobject_class, PROP_GMYTHTV_MAX_TRY, - g_param_spec_int ("max-try", "max-try", - "Set the max try for get MythTV free recorder", - 0, G_MAXINT, 10, G_PARAM_READWRITE)); + (gobject_class, PROP_GMYTHTV_MAX_TRY, + g_param_spec_int("max-try", "max-try", + "Set the max try for get MythTV free recorder", + 0, G_MAXINT, 10, G_PARAM_READWRITE)); #ifndef GST_DISABLE_GST_DEBUG g_object_class_install_property - (gobject_class, PROP_GMYTHTV_DBG, - g_param_spec_boolean ("mythtv-debug", "mythtv-debug", - "Enable MythTV debug messages", FALSE, G_PARAM_READWRITE)); + (gobject_class, PROP_GMYTHTV_DBG, + g_param_spec_boolean("mythtv-debug", "mythtv-debug", + "Enable MythTV debug messages", FALSE, + G_PARAM_READWRITE)); #endif gstbasesrc_class->start = gst_mythtv_src_start; @@ -279,12 +285,12 @@ gstbasesrc_class->do_seek = gst_mythtv_src_do_seek; gstpushsrc_class->create = gst_mythtv_src_create; - GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0, - "MythTV Client Source"); + GST_DEBUG_CATEGORY_INIT(mythtvsrc_debug, "mythtvsrc", 0, + "MythTV Client Source"); } static void -gst_mythtv_src_init (GstMythtvSrc * this, GstMythtvSrcClass * g_class) +gst_mythtv_src_init(GstMythtvSrc * this, GstMythtvSrcClass * g_class) { this->file = NULL; @@ -308,7 +314,7 @@ this->enable_timing_position = FALSE; this->update_prog_chain = FALSE; - this->user_agent = g_strdup ("mythtvsrc"); + this->user_agent = g_strdup("mythtvsrc"); this->update_prog_chain = FALSE; this->channel_name = NULL; @@ -319,114 +325,132 @@ this->wait_to_transfer = 0; - gst_base_src_set_format (GST_BASE_SRC (this), GST_FORMAT_BYTES); + gst_base_src_set_format(GST_BASE_SRC(this), GST_FORMAT_BYTES); - gst_pad_set_event_function (GST_BASE_SRC_PAD (GST_BASE_SRC (this)), - gst_mythtv_src_handle_event); - gst_pad_set_query_function (GST_BASE_SRC_PAD (GST_BASE_SRC (this)), - gst_mythtv_src_handle_query); + gst_pad_set_event_function(GST_BASE_SRC_PAD(GST_BASE_SRC(this)), + gst_mythtv_src_handle_event); + gst_pad_set_query_function(GST_BASE_SRC_PAD(GST_BASE_SRC(this)), + gst_mythtv_src_handle_query); } static void -gst_mythtv_src_clear (GstMythtvSrc *mythtv_src) +gst_mythtv_src_clear(GstMythtvSrc * mythtv_src) { mythtv_src->unique_setup = FALSE; - if (mythtv_src->spawn_livetv) { - g_object_unref (mythtv_src->spawn_livetv); - mythtv_src->spawn_livetv = NULL; - } + if (mythtv_src->spawn_livetv) + { + g_object_unref(mythtv_src->spawn_livetv); + mythtv_src->spawn_livetv = NULL; + } - if (mythtv_src->file) { - g_object_unref (mythtv_src->file); - mythtv_src->file = NULL; - } + if (mythtv_src->file) + { + g_object_unref(mythtv_src->file); + mythtv_src->file = NULL; + } - if (mythtv_src->backend_info) { - g_object_unref (mythtv_src->backend_info); - mythtv_src->backend_info = NULL; - } + if (mythtv_src->backend_info) + { + g_object_unref(mythtv_src->backend_info); + mythtv_src->backend_info = NULL; + } - if (mythtv_src->bytes_queue) { - g_byte_array_free (mythtv_src->bytes_queue, TRUE); - mythtv_src->bytes_queue = NULL; - } + if (mythtv_src->bytes_queue) + { + g_byte_array_free(mythtv_src->bytes_queue, TRUE); + mythtv_src->bytes_queue = NULL; + } } static void -gst_mythtv_src_finalize (GObject * gobject) +gst_mythtv_src_finalize(GObject * gobject) { - GstMythtvSrc *this = GST_MYTHTV_SRC (gobject); + GstMythtvSrc *this = GST_MYTHTV_SRC(gobject); - gst_mythtv_src_clear (this); + gst_mythtv_src_clear(this); - if (this->uri_name) { - g_free (this->uri_name); - this->uri_name = NULL; - } + if (this->uri_name) + { + g_free(this->uri_name); + this->uri_name = NULL; + } - if (this->user_agent) { - g_free (this->user_agent); - this->user_agent = NULL; - } + if (this->user_agent) + { + g_free(this->user_agent); + this->user_agent = NULL; + } - G_OBJECT_CLASS (parent_class)->finalize (gobject); + G_OBJECT_CLASS(parent_class)->finalize(gobject); } static GMythFileReadResult -do_read_request_response (GstMythtvSrc * src, guint size, GByteArray *data_ptr) +do_read_request_response(GstMythtvSrc * src, guint size, + GByteArray * data_ptr) { gint read = 0; guint sizetoread = size; gint max_iters = GMYTHTV_TRANSFER_MAX_RESENDS; GMythFileReadResult result; - GST_LOG_OBJECT (src, "Starting: Reading %d bytes...", sizetoread); + GST_LOG_OBJECT(src, "Starting: Reading %d bytes...", sizetoread); - /* Loop sending the Myth File Transfer request: - * Retry whilst authentication fails and we supply it. */ + /* Loop sending the Myth File Transfer request: + * Retry whilst authentication fails and we supply it. */ - while (sizetoread == size && --max_iters > 0) { - /* if ( gmyth_backend_info_is_local_file(src->backend_info) ) */ - if ( IS_GMYTH_FILE_LOCAL(src->file) ) - result = gmyth_file_local_read ( GMYTH_FILE_LOCAL(src->file), - data_ptr, sizetoread, src->live_tv); - else if ( IS_GMYTH_FILE_TRANSFER(src->file) ) - result = gmyth_file_transfer_read ( GMYTH_FILE_TRANSFER(src->file), - data_ptr, sizetoread, src->live_tv ); + while (sizetoread == size && --max_iters > 0) + { + /* if ( gmyth_backend_info_is_local_file(src->backend_info) ) */ + if (IS_GMYTH_FILE_LOCAL(src->file)) + result = gmyth_file_local_read(GMYTH_FILE_LOCAL(src->file), + data_ptr, sizetoread, src->live_tv); + else if (IS_GMYTH_FILE_TRANSFER(src->file)) + result = gmyth_file_transfer_read(GMYTH_FILE_TRANSFER(src->file), + data_ptr, sizetoread, src->live_tv); - if (data_ptr->len > 0) { - read += data_ptr->len; - sizetoread -= data_ptr->len; - } else if (data_ptr->len <= 0) { - if (src->live_tv == FALSE) { - result = GMYTH_FILE_READ_EOF; - goto eos; - } else { - if (result == GMYTH_FILE_READ_ERROR) { /* -314 */ - GST_INFO_OBJECT (src, "[LiveTV] FileTransfer READ_ERROR!"); - goto done; - } else if (result == GMYTH_FILE_READ_NEXT_PROG_CHAIN) { /* -315 */ - GST_INFO_OBJECT (src, - "[LiveTV] FileTransfer - Go to athe next program chain!"); - src->update_prog_chain = TRUE; - continue; - } - goto done; - } + if (data_ptr->len > 0) + { + read += data_ptr->len; + sizetoread -= data_ptr->len; + } + else if (data_ptr->len <= 0) + { + if (src->live_tv == FALSE) + { + result = GMYTH_FILE_READ_EOF; + goto eos; + } + else + { + if (result == GMYTH_FILE_READ_ERROR) + { /* -314 */ + GST_INFO_OBJECT(src, "[LiveTV] FileTransfer READ_ERROR!"); + goto done; + } + else if (result == GMYTH_FILE_READ_NEXT_PROG_CHAIN) + { /* -315 */ + GST_INFO_OBJECT(src, + "[LiveTV] FileTransfer - Go to athe next program chain!"); + src->update_prog_chain = TRUE; + continue; + } + goto done; + } - } /* else if (data_ptr->len == 0) - goto done;*/ + } /* else if (data_ptr->len == 0) + goto done; */ - if (read == sizetoread) - goto done; - } + if (read == sizetoread) + goto done; + } - if ((read < 0 && !src->live_tv) || max_iters == 0) { - result = GMYTH_FILE_READ_EOF; - goto eos; - } + if ((read < 0 && !src->live_tv) || max_iters == 0) + { + result = GMYTH_FILE_READ_EOF; + goto eos; + } goto done; @@ -438,471 +462,532 @@ } static GstFlowReturn -gst_mythtv_src_create (GstPushSrc * psrc, GstBuffer ** outbuf) +gst_mythtv_src_create(GstPushSrc * psrc, GstBuffer ** outbuf) { GstMythtvSrc *src; GstFlowReturn ret = GST_FLOW_OK; guint buffer_size_inter = 0; - src = GST_MYTHTV_SRC (psrc); + src = GST_MYTHTV_SRC(psrc); - /* The caller should know the number of bytes and not read beyond EOS. */ - if (G_UNLIKELY (src->eos)) - goto eos; - GST_DEBUG_OBJECT (src, "offset = %" G_GUINT64_FORMAT ", size = %d...", - src->read_offset, MAX_READ_SIZE); + /* The caller should know the number of bytes and not read beyond EOS. */ + if (G_UNLIKELY(src->eos)) + goto eos; + GST_DEBUG_OBJECT(src, "offset = %" G_GUINT64_FORMAT ", size = %d...", + src->read_offset, MAX_READ_SIZE); - GST_DEBUG_OBJECT (src, "Create: buffer_remain: %d, buffer_size = %d.", - (gint) src->buffer_remain, src->bytes_queue->len); + GST_DEBUG_OBJECT(src, "Create: buffer_remain: %d, buffer_size = %d.", + (gint) src->buffer_remain, src->bytes_queue->len); program_chain_changed: - /* just get from the byte array, no network effort... */ - if ((src->buffer_remain = src->bytes_queue->len) < MAX_READ_SIZE) { - GByteArray *buffer; - GMythFileReadResult result = GMYTH_FILE_READ_OK; - - buffer = NULL; - buffer_size_inter = (INTERNAL_BUFFER_SIZE - src->buffer_remain); + /* just get from the byte array, no network effort... */ + if ((src->buffer_remain = src->bytes_queue->len) < MAX_READ_SIZE) + { + GByteArray *buffer; + GMythFileReadResult result = GMYTH_FILE_READ_OK; - if (buffer_size_inter > REQUEST_MAX_SIZE) - buffer_size_inter = REQUEST_MAX_SIZE; + buffer = NULL; + buffer_size_inter = (INTERNAL_BUFFER_SIZE - src->buffer_remain); - buffer = g_byte_array_new (); + if (buffer_size_inter > REQUEST_MAX_SIZE) + buffer_size_inter = REQUEST_MAX_SIZE; - result = do_read_request_response (src, buffer_size_inter, buffer); + buffer = g_byte_array_new(); - /* got the next program info? */ - if (G_UNLIKELY (src->update_prog_chain) || (result == GMYTH_FILE_READ_NEXT_PROG_CHAIN)) { - GST_DEBUG_OBJECT (src, "Update PROGRAM CHAIN!!! buffer_size = %d.", - src->bytes_queue->len); - gst_pad_push_event (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)), - gst_event_new_custom(GST_EVENT_CUSTOM_DOWNSTREAM, NULL)); + result = do_read_request_response(src, buffer_size_inter, buffer); + + /* got the next program info? */ + if (G_UNLIKELY(src->update_prog_chain) + || (result == GMYTH_FILE_READ_NEXT_PROG_CHAIN)) + { + GST_DEBUG_OBJECT(src, "Update PROGRAM CHAIN!!! buffer_size = %d.", + src->bytes_queue->len); + gst_pad_push_event(GST_BASE_SRC_PAD(GST_BASE_SRC(psrc)), + gst_event_new_custom(GST_EVENT_CUSTOM_DOWNSTREAM, + NULL)); /* gst_pad_push_event (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)), gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_BYTES, 0, -1, 0)); */ - src->update_prog_chain = FALSE; - src->eos = FALSE; + src->update_prog_chain = FALSE; + src->eos = FALSE; - if (result == GMYTH_FILE_READ_NEXT_PROG_CHAIN) { - /* - if (buffer != NULL) { - g_byte_array_free (buffer, TRUE); - buffer = NULL; - } - goto program_chain_changed; */ - } else if (result == GMYTH_FILE_READ_OK) { - /* remove wasteful, NUV file header data */ - /* buffer = g_byte_array_remove_range( buffer, 0, 512 ); */ - /* TODO: need to send a new segment event to NUVDemux? */ - //gst_pad_push_event (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)), - // gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_BYTES, 0, -1, 0)); + if (result == GMYTH_FILE_READ_NEXT_PROG_CHAIN) + { + /* + if (buffer != NULL) { + g_byte_array_free (buffer, TRUE); + buffer = NULL; + } + goto program_chain_changed; */ + } + else if (result == GMYTH_FILE_READ_OK) + { + /* remove wasteful, NUV file header data */ + /* buffer = g_byte_array_remove_range( buffer, 0, 512 ); */ + /* TODO: need to send a new segment event to NUVDemux? */ + //gst_pad_push_event (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)), + // gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_BYTES, 0, -1, 0)); - /* goto change_progchain; */ - } + /* goto change_progchain; */ + } - } /* */ + } /* */ - if (G_UNLIKELY (buffer->len < 0)) { - - if (buffer != NULL) { - g_byte_array_free (buffer, TRUE); - buffer = NULL; - } - - if (src->live_tv || ( result == GMYTH_FILE_READ_NEXT_PROG_CHAIN )) - goto change_progchain; - else - goto read_error; - } else if (G_UNLIKELY (buffer->len == 0)) { - - if (buffer != NULL) { - g_byte_array_free (buffer, TRUE); - buffer = NULL; - } - - if (!src->live_tv) - goto done; - else - goto program_chain_changed; - } + if (G_UNLIKELY(buffer->len < 0)) + { - src->bytes_queue = - g_byte_array_append (src->bytes_queue, buffer->data, buffer->len); - if (buffer->len > buffer_size_inter) - GST_WARNING_OBJECT (src, - "INCREASED buffer size! Backend sent more than we ask him... (%d)", - abs (buffer->len - buffer_size_inter)); + if (buffer != NULL) + { + g_byte_array_free(buffer, TRUE); + buffer = NULL; + } - src->buffer_remain += buffer->len; + if (src->live_tv || (result == GMYTH_FILE_READ_NEXT_PROG_CHAIN)) + goto change_progchain; + else + goto read_error; + } + else if (G_UNLIKELY(buffer->len == 0)) + { - if (buffer != NULL) { - g_byte_array_free (buffer, TRUE); - buffer = NULL; - } + if (buffer != NULL) + { + g_byte_array_free(buffer, TRUE); + buffer = NULL; + } - /* - GST_DEBUG_OBJECT (src, - "BYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, " - "OFFSET = %llu, CONTENT SIZE = %llu.", read, - src->bytes_read, src->read_offset, src->content_size); - */ - } + if (!src->live_tv) + goto done; + else + goto program_chain_changed; + } + + src->bytes_queue = + g_byte_array_append(src->bytes_queue, buffer->data, buffer->len); + if (buffer->len > buffer_size_inter) + GST_WARNING_OBJECT(src, + "INCREASED buffer size! Backend sent more than we ask him... (%d)", + abs(buffer->len - buffer_size_inter)); + + src->buffer_remain += buffer->len; + + if (buffer != NULL) + { + g_byte_array_free(buffer, TRUE); + buffer = NULL; + } + + /* + GST_DEBUG_OBJECT (src, + "BYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, " + "OFFSET = %llu, CONTENT SIZE = %llu.", read, + src->bytes_read, src->read_offset, src->content_size); + */ + } guint buffer_size = - (src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE; + (src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE; - *outbuf = gst_buffer_new (); + *outbuf = gst_buffer_new(); - /* - GST_DEBUG_OBJECT (src, "read from network? %s!, buffer_remain = %d", - (buffer_size_inter == - 0) ? "NO, got from buffer" : "YES, go see the backend's log file", - src->buffer_remain); - */ + /* + GST_DEBUG_OBJECT (src, "read from network? %s!, buffer_remain = %d", + (buffer_size_inter == + 0) ? "NO, got from buffer" : "YES, go see the backend's log file", + src->buffer_remain); + */ - GST_BUFFER_SIZE (*outbuf) = buffer_size; - GST_BUFFER_MALLOCDATA (*outbuf) = g_malloc0 (GST_BUFFER_SIZE (*outbuf)); - GST_BUFFER_DATA (*outbuf) = GST_BUFFER_MALLOCDATA (*outbuf); - g_memmove (GST_BUFFER_DATA ((*outbuf)), src->bytes_queue->data, - GST_BUFFER_SIZE (*outbuf)); - GST_BUFFER_OFFSET (*outbuf) = src->read_offset; - GST_BUFFER_OFFSET_END (*outbuf) = - src->read_offset + GST_BUFFER_SIZE (*outbuf); + GST_BUFFER_SIZE(*outbuf) = buffer_size; + GST_BUFFER_MALLOCDATA(*outbuf) = g_malloc0(GST_BUFFER_SIZE(*outbuf)); + GST_BUFFER_DATA(*outbuf) = GST_BUFFER_MALLOCDATA(*outbuf); + g_memmove(GST_BUFFER_DATA((*outbuf)), src->bytes_queue->data, + GST_BUFFER_SIZE(*outbuf)); + GST_BUFFER_OFFSET(*outbuf) = src->read_offset; + GST_BUFFER_OFFSET_END(*outbuf) = + src->read_offset + GST_BUFFER_SIZE(*outbuf); - src->buffer_remain -= GST_BUFFER_SIZE (*outbuf); + src->buffer_remain -= GST_BUFFER_SIZE(*outbuf); - src->read_offset += GST_BUFFER_SIZE (*outbuf); - src->bytes_read += GST_BUFFER_SIZE (*outbuf); - //GST_DEBUG_OBJECT (src, "Buffer output with size: %d", - // GST_BUFFER_SIZE (*outbuf)); + src->read_offset += GST_BUFFER_SIZE(*outbuf); + src->bytes_read += GST_BUFFER_SIZE(*outbuf); + //GST_DEBUG_OBJECT (src, "Buffer output with size: %d", + // GST_BUFFER_SIZE (*outbuf)); - /* flushs the newly buffer got from byte array */ + /* flushs the newly buffer got from byte array */ src->bytes_queue = - g_byte_array_remove_range (src->bytes_queue, 0, buffer_size); + g_byte_array_remove_range(src->bytes_queue, 0, buffer_size); - if ( G_UNLIKELY (src->eos) || ( !src->live_tv - && ( src->bytes_read >= src->content_size ) ) ) - goto eos; + if (G_UNLIKELY(src->eos) || (!src->live_tv + && (src->bytes_read >= src->content_size))) + goto eos; done: { - const gchar *reason = gst_flow_get_name (ret); - return ret; + const gchar *reason = gst_flow_get_name(ret); + return ret; } eos: { - const gchar *reason = gst_flow_get_name (ret); + const gchar *reason = gst_flow_get_name(ret); - GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason); - return GST_FLOW_UNEXPECTED; + GST_DEBUG_OBJECT(src, "pausing task, reason %s", reason); + return GST_FLOW_UNEXPECTED; } - /* ERRORS */ + /* ERRORS */ read_error: { - GST_ELEMENT_ERROR (src, RESOURCE, READ, - (NULL), ("Could not read any bytes (%i, %s)", read, src->uri_name)); - return GST_FLOW_ERROR; + GST_ELEMENT_ERROR(src, RESOURCE, READ, + (NULL), ("Could not read any bytes (%i, %s)", read, + src->uri_name)); + return GST_FLOW_ERROR; } change_progchain: { - GST_ELEMENT_ERROR (src, RESOURCE, READ, - (NULL), ("Seek failed, go to the next program info... (%i, %s)", read, - src->uri_name)); + GST_ELEMENT_ERROR(src, RESOURCE, READ, + (NULL), + ("Seek failed, go to the next program info... (%i, %s)", + read, src->uri_name)); /* TODO: need to send a new segment event to NUVDemux? */ - gst_pad_push_event (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)), - gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0)); + gst_pad_push_event(GST_BASE_SRC_PAD(GST_BASE_SRC(psrc)), + gst_event_new_new_segment(TRUE, 1.0, GST_FORMAT_TIME, + 0, -1, 0)); - goto program_chain_changed; + goto program_chain_changed; } } gint64 -gst_mythtv_src_get_position (GstMythtvSrc * src) +gst_mythtv_src_get_position(GstMythtvSrc * src) { gint64 size_tmp = 0; guint max_tries = 2; - if (src->live_tv == TRUE && (abs (src->content_size - src->bytes_read) < - GMYTHTV_TRANSFER_MAX_BUFFER)) { + if (src->live_tv == TRUE && (abs(src->content_size - src->bytes_read) < + GMYTHTV_TRANSFER_MAX_BUFFER)) + { - get_file_pos: - g_usleep (10); - size_tmp = gmyth_recorder_get_file_position (src->spawn_livetv->recorder); - if (size_tmp > (src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER)) - src->content_size = size_tmp; - else if (size_tmp > 0 && --max_tries > 0) - goto get_file_pos; - GST_LOG_OBJECT (src, "GET_POSITION: file_position = %lld", size_tmp); - /* sets the last content size amount before it can be updated */ - src->prev_content_size = src->content_size; - } + get_file_pos: + g_usleep(10); + size_tmp = + gmyth_recorder_get_file_position(src->spawn_livetv->recorder); + if (size_tmp > (src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER)) + src->content_size = size_tmp; + else if (size_tmp > 0 && --max_tries > 0) + goto get_file_pos; + GST_LOG_OBJECT(src, "GET_POSITION: file_position = %lld", size_tmp); + /* sets the last content size amount before it can be updated */ + src->prev_content_size = src->content_size; + } return src->content_size; } static gboolean -gst_mythtv_src_do_seek (GstBaseSrc * base, GstSegment * segment) +gst_mythtv_src_do_seek(GstBaseSrc * base, GstSegment * segment) { - GstMythtvSrc *src = GST_MYTHTV_SRC (base); + GstMythtvSrc *src = GST_MYTHTV_SRC(base); gint64 new_offset = -1; gint64 actual_seek = segment->start; gboolean ret = TRUE; - GST_LOG_OBJECT (src, "seek, segment: %" GST_SEGMENT_FORMAT, segment); + GST_LOG_OBJECT(src, "seek, segment: %" GST_SEGMENT_FORMAT, segment); - if (segment->format == GST_FORMAT_TIME) { - goto done; - } - GST_LOG_OBJECT (src, - "Trying to seek at the value (actual_seek = %lld, read_offset = %lld)", - actual_seek, src->read_offset); - /* verify if it needs to seek */ - if (src->read_offset != actual_seek) { - - /* if ( gmyth_backend_info_is_local_file(src->backend_info) ) */ - if ( IS_GMYTH_FILE_LOCAL(src->file) ) - new_offset = - gmyth_file_local_seek ( GMYTH_FILE_LOCAL(src->file), segment->start, G_SEEK_SET); - else if ( IS_GMYTH_FILE_TRANSFER(src->file) ) - new_offset = - gmyth_file_transfer_seek ( GMYTH_FILE_TRANSFER(src->file), segment->start, SEEK_SET); + if (segment->format == GST_FORMAT_TIME) + { + goto done; + } + GST_LOG_OBJECT(src, + "Trying to seek at the value (actual_seek = %lld, read_offset = %lld)", + actual_seek, src->read_offset); + /* verify if it needs to seek */ + if (src->read_offset != actual_seek) + { - GST_LOG_OBJECT (src, - "Segment offset start = %lld, SRC Offset = %lld, NEW actual backend SEEK Offset = %lld.", - segment->start, src->read_offset, new_offset); - if (G_UNLIKELY (new_offset < 0)) { - ret = FALSE; - if (!src->live_tv) - goto eos; - } + /* if ( gmyth_backend_info_is_local_file(src->backend_info) ) */ + if (IS_GMYTH_FILE_LOCAL(src->file)) + new_offset = + gmyth_file_local_seek(GMYTH_FILE_LOCAL(src->file), segment->start, + G_SEEK_SET); + else if (IS_GMYTH_FILE_TRANSFER(src->file)) + new_offset = + gmyth_file_transfer_seek(GMYTH_FILE_TRANSFER(src->file), + segment->start, SEEK_SET); - src->read_offset = new_offset; + GST_LOG_OBJECT(src, + "Segment offset start = %lld, SRC Offset = %lld, NEW actual backend SEEK Offset = %lld.", + segment->start, src->read_offset, new_offset); + if (G_UNLIKELY(new_offset < 0)) + { + ret = FALSE; + if (!src->live_tv) + goto eos; + } - if (ret == FALSE) { - GST_INFO_OBJECT (src, "Failed to set the SEEK on segment!"); - } + src->read_offset = new_offset; - } + if (ret == FALSE) + { + GST_INFO_OBJECT(src, "Failed to set the SEEK on segment!"); + } + + } done: return ret; eos: { - GST_DEBUG_OBJECT (src, "EOS found on seeking!!!"); - return FALSE; + GST_DEBUG_OBJECT(src, "EOS found on seeking!!!"); + return FALSE; } } /* create a socket for connecting to remote server */ static gboolean -gst_mythtv_src_start (GstBaseSrc * bsrc) +gst_mythtv_src_start(GstBaseSrc * bsrc) { - GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc); + GstMythtvSrc *src = GST_MYTHTV_SRC(bsrc); - GString *chain_id_local = NULL; + GString *chain_id_local = NULL; GMythURI *gmyth_uri = NULL; gboolean ret = TRUE; GstMessage *msg; - if (src->unique_setup == FALSE) { - src->unique_setup = TRUE; - } else { - goto done; - } - - gmyth_uri = gmyth_uri_new_with_value (src->uri_name); - src->backend_info = gmyth_backend_info_new_with_uri (src->uri_name); - src->live_tv = gmyth_uri_is_livetv( gmyth_uri ); - /* testing UPnP... */ - /* gmyth_backend_info_set_hostname( src->backend_info, NULL ); */ - if ( src->live_tv ) { - src->spawn_livetv = gmyth_livetv_new (src->backend_info); - - gchar* ch = gmyth_uri_get_channel_name( gmyth_uri ); - if ( ch != NULL ) - src->channel_name = ch; - - if (src->channel_name != NULL) { - gboolean result; - result = gmyth_livetv_channel_name_setup (src->spawn_livetv, src->channel_name); - if (result == FALSE) { - GST_INFO_OBJECT (src, "LiveTV setup felt down on error"); - ret = FALSE; - goto init_failed; - } + if (src->unique_setup == FALSE) + { + src->unique_setup = TRUE; + } + else + { + goto done; + } - } else { - if (gmyth_livetv_setup (src->spawn_livetv) == FALSE) { - GST_INFO_OBJECT (src, "LiveTV setup felt down on error"); - ret = FALSE; - goto init_failed; - } - } + gmyth_uri = gmyth_uri_new_with_value(src->uri_name); + src->backend_info = gmyth_backend_info_new_with_uri(src->uri_name); + src->live_tv = gmyth_uri_is_livetv(gmyth_uri); + /* testing UPnP... */ + /* gmyth_backend_info_set_hostname( src->backend_info, NULL ); */ + if (src->live_tv) + { + src->spawn_livetv = gmyth_livetv_new(src->backend_info); - /* testing change channel... */ - /* gmyth_recorder_change_channel( src->spawn_livetv->recorder, CHANNEL_DIRECTION_UP ); */ + gchar *ch = gmyth_uri_get_channel_name(gmyth_uri); + if (ch != NULL) + src->channel_name = ch; - src->file = GMYTH_FILE( gmyth_livetv_create_file_transfer (src->spawn_livetv) ); + if (src->channel_name != NULL) + { + gboolean result; + result = + gmyth_livetv_channel_name_setup(src->spawn_livetv, + src->channel_name); + if (result == FALSE) + { + GST_INFO_OBJECT(src, "LiveTV setup felt down on error"); + ret = FALSE; + goto init_failed; + } - if (NULL == src->file) { - GST_INFO_OBJECT (src, "[LiveTV] FileTransfer equals to NULL"); - ret = FALSE; - goto init_failed; - } - - /* Check if the file is local to this specific client renderer */ - if ( gmyth_uri_is_local_file(gmyth_uri) ) - ret = gmyth_file_local_open( GMYTH_FILE_LOCAL(src->file) ); - else - ret = gmyth_file_transfer_open( GMYTH_FILE_TRANSFER(src->file), src->spawn_livetv->uri != NULL ? - gmyth_uri_get_path(src->spawn_livetv->uri) : - src->spawn_livetv->proginfo->pathname->str ); - - /* sets the mythtvsrc "location" property */ - g_object_set (src, "location", gmyth_file_get_uri (src->file), NULL); + } + else + { + if (gmyth_livetv_setup(src->spawn_livetv) == FALSE) + { + GST_INFO_OBJECT(src, "LiveTV setup felt down on error"); + ret = FALSE; + goto init_failed; + } + } - if ( !ret ) + /* testing change channel... */ + /* gmyth_recorder_change_channel( src->spawn_livetv->recorder, CHANNEL_DIRECTION_UP ); */ + + src->file = + GMYTH_FILE(gmyth_livetv_create_file_transfer(src->spawn_livetv)); + + if (NULL == src->file) { - GST_INFO_OBJECT (src, "Error: couldn't open the FileTransfer from LiveTV source!" ); - g_object_unref( src->file ); - src->file = NULL; - goto init_failed; + GST_INFO_OBJECT(src, "[LiveTV] FileTransfer equals to NULL"); + ret = FALSE; + goto init_failed; } - } else { - - /* Check if the file is local to this specific client renderer, and tries to open - * a local connection - */ - if ( gmyth_uri_is_local_file(gmyth_uri) ) - { - src->file = GMYTH_FILE(gmyth_file_local_new(src->backend_info)); - ret = gmyth_file_local_open ( GMYTH_FILE_LOCAL( src->file ) ); - } else { - src->file = GMYTH_FILE(gmyth_file_transfer_new(src->backend_info)); - ret = gmyth_file_transfer_open ( GMYTH_FILE_TRANSFER(src->file), src->uri_name ); - } - } /* if (else) - recorded FileTransfer */ + /* Check if the file is local to this specific client renderer */ + if (gmyth_uri_is_local_file(gmyth_uri)) + ret = gmyth_file_local_open(GMYTH_FILE_LOCAL(src->file)); + else + ret = + gmyth_file_transfer_open(GMYTH_FILE_TRANSFER(src->file), + src->spawn_livetv->uri != + NULL ? gmyth_uri_get_path(src-> + spawn_livetv-> + uri) : src-> + spawn_livetv->proginfo->pathname->str); - if (NULL == src->file) { - GST_INFO_OBJECT (src, "FileTransfer is NULL"); - goto init_failed; - } - /*GST_INFO_OBJECT( src, "uri = %s", src->spawn_livetv->file); */ + /* sets the mythtvsrc "location" property */ + g_object_set(src, "location", gmyth_file_get_uri(src->file), NULL); - if (ret == FALSE) { + if (!ret) + { + GST_INFO_OBJECT(src, + "Error: couldn't open the FileTransfer from LiveTV source!"); + g_object_unref(src->file); + src->file = NULL; + goto init_failed; + } + } + else + { + + /* Check if the file is local to this specific client renderer, and tries to open + * a local connection + */ + if (gmyth_uri_is_local_file(gmyth_uri)) + { + src->file = GMYTH_FILE(gmyth_file_local_new(src->backend_info)); + ret = gmyth_file_local_open(GMYTH_FILE_LOCAL(src->file)); + } + else + { + src->file = GMYTH_FILE(gmyth_file_transfer_new(src->backend_info)); + ret = + gmyth_file_transfer_open(GMYTH_FILE_TRANSFER(src->file), + src->uri_name); + } + + } /* if (else) - recorded FileTransfer */ + + if (NULL == src->file) + { + GST_INFO_OBJECT(src, "FileTransfer is NULL"); + goto init_failed; + } + /*GST_INFO_OBJECT( src, "uri = %s", src->spawn_livetv->file); */ + + if (ret == FALSE) + { #ifndef GST_DISABLE_GST_DEBUG - if (src->mythtv_msgs_dbg) - GST_INFO_OBJECT (src, - "MythTV FileTransfer request failed when setting up socket connection!"); + if (src->mythtv_msgs_dbg) + GST_INFO_OBJECT(src, + "MythTV FileTransfer request failed when setting up socket connection!"); #endif - goto begin_req_failed; - } + goto begin_req_failed; + } - GST_INFO_OBJECT (src, - "MythTV FileTransfer filesize = %lld, content_size = %lld!", - gmyth_file_get_filesize( src->file ), src->content_size); + GST_INFO_OBJECT(src, + "MythTV FileTransfer filesize = %lld, content_size = %lld!", + gmyth_file_get_filesize(src->file), src->content_size); - src->content_size = gmyth_file_get_filesize (src->file); + src->content_size = gmyth_file_get_filesize(src->file); - msg = gst_message_new_duration (GST_OBJECT (src), GST_FORMAT_BYTES, src->content_size); - gst_element_post_message (GST_ELEMENT (src), msg); + msg = + gst_message_new_duration(GST_OBJECT(src), GST_FORMAT_BYTES, + src->content_size); + gst_element_post_message(GST_ELEMENT(src), msg); src->do_start = FALSE; - /* this is used for the buffer cache */ - src->bytes_queue = g_byte_array_sized_new (INTERNAL_BUFFER_SIZE); + /* this is used for the buffer cache */ + src->bytes_queue = g_byte_array_sized_new(INTERNAL_BUFFER_SIZE); src->buffer_remain = 0; - - gst_pad_push_event (GST_BASE_SRC_PAD (GST_BASE_SRC (src)), - gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, - src->content_size, 0)); + + gst_pad_push_event(GST_BASE_SRC_PAD(GST_BASE_SRC(src)), + gst_event_new_new_segment(TRUE, 1.0, GST_FORMAT_TIME, 0, + src->content_size, 0)); done: - if (gmyth_uri != NULL) + if (gmyth_uri != NULL) { - g_object_unref (gmyth_uri); - gmyth_uri = NULL; + g_object_unref(gmyth_uri); + gmyth_uri = NULL; } - if (chain_id_local != NULL) { - g_string_free (chain_id_local, TRUE); - chain_id_local = NULL; - } - - return TRUE; - - /* ERRORS */ -init_failed: - if (gmyth_uri != NULL) + if (chain_id_local != NULL) { - g_object_unref (gmyth_uri); - gmyth_uri = NULL; + g_string_free(chain_id_local, TRUE); + chain_id_local = NULL; } - if (src->spawn_livetv != NULL) { - g_object_unref (src->spawn_livetv); - src->spawn_livetv = NULL; - } - - GST_ELEMENT_ERROR (src, LIBRARY, INIT, - (NULL), ("Could not initialize MythTV library (%i, %s)", ret, - src->uri_name)); + return TRUE; - - gst_mythtv_src_clear (src); - - return FALSE; -begin_req_failed: - if (gmyth_uri != NULL) + /* ERRORS */ +init_failed: + if (gmyth_uri != NULL) { - g_object_unref (gmyth_uri); - gmyth_uri = NULL; + g_object_unref(gmyth_uri); + gmyth_uri = NULL; } - GST_ELEMENT_ERROR (src, LIBRARY, INIT, - (NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret, - src->uri_name)); - return FALSE; + if (src->spawn_livetv != NULL) + { + g_object_unref(src->spawn_livetv); + src->spawn_livetv = NULL; + } + + GST_ELEMENT_ERROR(src, LIBRARY, INIT, + (NULL), ("Could not initialize MythTV library (%i, %s)", + ret, src->uri_name)); + + + gst_mythtv_src_clear(src); + + return FALSE; +begin_req_failed: + if (gmyth_uri != NULL) + { + g_object_unref(gmyth_uri); + gmyth_uri = NULL; + } + + GST_ELEMENT_ERROR(src, LIBRARY, INIT, + (NULL), + ("Could not begin request sent to MythTV server (%i, %s)", + ret, src->uri_name)); + return FALSE; } static gboolean -gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size) +gst_mythtv_src_get_size(GstBaseSrc * bsrc, guint64 * size) { - GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc); + GstMythtvSrc *src = GST_MYTHTV_SRC(bsrc); gboolean ret = TRUE; - GST_LOG_OBJECT (src, "Differs from previous content size: %d (max.: %d)", - abs (src->content_size - src->prev_content_size), - GMYTHTV_TRANSFER_MAX_BUFFER); + GST_LOG_OBJECT(src, "Differs from previous content size: %d (max.: %d)", + abs(src->content_size - src->prev_content_size), + GMYTHTV_TRANSFER_MAX_BUFFER); - if (src->live_tv) { - ret = FALSE; - } else if (src->live_tv && src->enable_timing_position - && (abs (src->content_size - src->bytes_read) < - GMYTHTV_TRANSFER_MAX_BUFFER)) { + if (src->live_tv) + { + ret = FALSE; + } + else if (src->live_tv && src->enable_timing_position + && (abs(src->content_size - src->bytes_read) < + GMYTHTV_TRANSFER_MAX_BUFFER)) + { - gint64 new_offset = - gmyth_recorder_get_file_position (src->spawn_livetv->recorder); - if (new_offset > 0 && new_offset > src->content_size) { - src->content_size = new_offset; - } else if (new_offset < src->content_size) { - src->update_prog_chain = TRUE; - } + gint64 new_offset = + gmyth_recorder_get_file_position(src->spawn_livetv->recorder); + if (new_offset > 0 && new_offset > src->content_size) + { + src->content_size = new_offset; + } + else if (new_offset < src->content_size) + { + src->update_prog_chain = TRUE; + } - } + } *size = src->content_size; - GST_LOG_OBJECT (src, "Content size = %lld", src->content_size); + GST_LOG_OBJECT(src, "Content size = %lld", src->content_size); return ret; @@ -911,312 +996,328 @@ /* close the socket and associated resources * used both to recover from errors and go to NULL state */ static gboolean -gst_mythtv_src_stop (GstBaseSrc * bsrc) +gst_mythtv_src_stop(GstBaseSrc * bsrc) { - GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc); - - gst_mythtv_src_clear (src); + GstMythtvSrc *src = GST_MYTHTV_SRC(bsrc); - /* src->eos = FALSE; */ + gst_mythtv_src_clear(src); + + /* src->eos = FALSE; */ return TRUE; } static gboolean -gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event) +gst_mythtv_src_handle_event(GstPad * pad, GstEvent * event) { - GstMythtvSrc *src = GST_MYTHTV_SRC (GST_PAD_PARENT (pad)); + GstMythtvSrc *src = GST_MYTHTV_SRC(GST_PAD_PARENT(pad)); gint64 cont_size = 0; gboolean ret = FALSE; - switch (GST_EVENT_TYPE (event)) { - case GST_EVENT_EOS: - GST_WARNING_OBJECT (src, "Got EOS event"); + switch (GST_EVENT_TYPE(event)) + { + case GST_EVENT_EOS: + GST_WARNING_OBJECT(src, "Got EOS event"); - if (src->live_tv) { - cont_size = gst_mythtv_src_get_position (src); - if (cont_size > src->content_size) { - src->content_size = cont_size; - src->eos = FALSE; - } else { - src->eos = TRUE; - gst_element_set_state (GST_ELEMENT (src), GST_STATE_NULL); - gst_element_set_locked_state (GST_ELEMENT (src), FALSE); - } - } - break; - default: - ret = gst_pad_event_default (pad, event); - } + if (src->live_tv) + { + cont_size = gst_mythtv_src_get_position(src); + if (cont_size > src->content_size) + { + src->content_size = cont_size; + src->eos = FALSE; + } + else + { + src->eos = TRUE; + gst_element_set_state(GST_ELEMENT(src), GST_STATE_NULL); + gst_element_set_locked_state(GST_ELEMENT(src), FALSE); + } + } + break; + default: + ret = gst_pad_event_default(pad, event); + } return ret; } static gboolean -gst_mythtv_src_is_seekable (GstBaseSrc * push_src) +gst_mythtv_src_is_seekable(GstBaseSrc * push_src) { return TRUE; } static gboolean -gst_mythtv_src_handle_query (GstPad * pad, GstQuery * query) +gst_mythtv_src_handle_query(GstPad * pad, GstQuery * query) { gboolean res = FALSE; - GstMythtvSrc *myth = GST_MYTHTV_SRC (gst_pad_get_parent (pad)); + GstMythtvSrc *myth = GST_MYTHTV_SRC(gst_pad_get_parent(pad)); GstFormat formt; - switch (GST_QUERY_TYPE (query)) { - case GST_QUERY_POSITION: - { - gst_query_parse_position (query, &formt, NULL); - if (formt == GST_FORMAT_BYTES) { - gst_query_set_position (query, formt, myth->read_offset); - GST_DEBUG_OBJECT (myth, "POS %" G_GINT64_FORMAT, myth->read_offset); - res = TRUE; - } else if (formt == GST_FORMAT_TIME) { - res = gst_pad_query_default (pad, query); - } - break; - } - case GST_QUERY_DURATION: - { - gst_query_parse_duration (query, &formt, NULL); - if (formt == GST_FORMAT_BYTES) { - gint64 size = myth->content_size; - gst_query_set_duration (query, GST_FORMAT_BYTES, 10); - GST_DEBUG_OBJECT (myth, "SIZE %" G_GINT64_FORMAT, size); - res = TRUE; - } else if (formt == GST_FORMAT_TIME) { - res = gst_pad_query_default (pad, query); - } - break; - } - default: - { - res = gst_pad_query_default (pad, query); - break; - } - } + switch (GST_QUERY_TYPE(query)) + { + case GST_QUERY_POSITION: + { + gst_query_parse_position(query, &formt, NULL); + if (formt == GST_FORMAT_BYTES) + { + gst_query_set_position(query, formt, myth->read_offset); + GST_DEBUG_OBJECT(myth, "POS %" G_GINT64_FORMAT, + myth->read_offset); + res = TRUE; + } + else if (formt == GST_FORMAT_TIME) + { + res = gst_pad_query_default(pad, query); + } + break; + } + case GST_QUERY_DURATION: + { + gst_query_parse_duration(query, &formt, NULL); + if (formt == GST_FORMAT_BYTES) + { + gint64 size = myth->content_size; + gst_query_set_duration(query, GST_FORMAT_BYTES, 10); + GST_DEBUG_OBJECT(myth, "SIZE %" G_GINT64_FORMAT, size); + res = TRUE; + } + else if (formt == GST_FORMAT_TIME) + { + res = gst_pad_query_default(pad, query); + } + break; + } + default: + { + res = gst_pad_query_default(pad, query); + break; + } + } - gst_object_unref (myth); + gst_object_unref(myth); return res; } static GstStateChangeReturn -gst_mythtv_src_change_state (GstElement * element, GstStateChange transition) +gst_mythtv_src_change_state(GstElement * element, GstStateChange transition) { GstStateChangeReturn ret = GST_STATE_CHANGE_FAILURE; - GstMythtvSrc *src = GST_MYTHTV_SRC (element); + GstMythtvSrc *src = GST_MYTHTV_SRC(element); - g_debug ("MYTHSRC: state_changed"); + switch (transition) + { + case GST_STATE_CHANGE_NULL_TO_READY: + break; + case GST_STATE_CHANGE_READY_TO_PAUSED: + case GST_STATE_CHANGE_PAUSED_TO_PLAYING: + if (src->live_tv) + { + if (!gmyth_recorder_send_frontend_ready_command(src->spawn_livetv-> + recorder)) + GST_WARNING_OBJECT(src, + "Couldn't send the FRONTEND_READY message to the backend!"); + else + GST_DEBUG_OBJECT(src, "FRONTEND_READY was sent to the backend"); + } + break; + default: + break; + } - switch (transition) { - case GST_STATE_CHANGE_NULL_TO_READY: - break; - case GST_STATE_CHANGE_READY_TO_PAUSED: - case GST_STATE_CHANGE_PAUSED_TO_PLAYING: - if (src->live_tv) { - if (!gmyth_recorder_send_frontend_ready_command (src->spawn_livetv-> - recorder)) - GST_WARNING_OBJECT (src, - "Couldn't send the FRONTEND_READY message to the backend!"); - else - GST_DEBUG_OBJECT (src, "FRONTEND_READY was sent to the backend"); - } - break; - default: - break; - } + ret = GST_ELEMENT_CLASS(parent_class)->change_state(element, transition); + if (ret == GST_STATE_CHANGE_FAILURE) + return ret; - g_debug ("MYTHSRC: state_changed 1"); - ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); - if (ret == GST_STATE_CHANGE_FAILURE) - return ret; + switch (transition) + { + case GST_STATE_CHANGE_READY_TO_NULL: + gst_mythtv_src_clear(src); + break; + case GST_STATE_CHANGE_PLAYING_TO_PAUSED: + case GST_STATE_CHANGE_PAUSED_TO_READY: + break; + default: + break; + } - - g_debug ("MYTHSRC: state_changed2"); - - switch (transition) { - case GST_STATE_CHANGE_READY_TO_NULL: - gst_mythtv_src_clear (src); - break; - case GST_STATE_CHANGE_PLAYING_TO_PAUSED: - case GST_STATE_CHANGE_PAUSED_TO_READY: - break; - default: - break; - } - - g_debug ("MYTHSRC: state_changed: DONE"); return ret; } static void -gst_mythtv_src_set_property (GObject * object, guint prop_id, - const GValue * value, GParamSpec * pspec) +gst_mythtv_src_set_property(GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) { - GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object); + GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC(object); - GST_OBJECT_LOCK (mythtvsrc); - switch (prop_id) { - case PROP_LOCATION: - { - if (!g_value_get_string (value)) { - GST_WARNING ("location property cannot be NULL"); - break; - } + GST_OBJECT_LOCK(mythtvsrc); + switch (prop_id) + { + case PROP_LOCATION: + { + if (!g_value_get_string(value)) + { + GST_WARNING("location property cannot be NULL"); + break; + } - if (mythtvsrc->uri_name != NULL) { - g_free (mythtvsrc->uri_name); - mythtvsrc->uri_name = NULL; - } - mythtvsrc->uri_name = g_value_dup_string (value); + if (mythtvsrc->uri_name != NULL) + { + g_free(mythtvsrc->uri_name); + mythtvsrc->uri_name = NULL; + } + mythtvsrc->uri_name = g_value_dup_string(value); - break; - } + break; + } #ifndef GST_DISABLE_GST_DEBUG - case PROP_GMYTHTV_DBG: - { - mythtvsrc->mythtv_msgs_dbg = g_value_get_boolean (value); - break; - } + case PROP_GMYTHTV_DBG: + { + mythtvsrc->mythtv_msgs_dbg = g_value_get_boolean(value); + break; + } #endif - case PROP_GMYTHTV_VERSION: - { - mythtvsrc->mythtv_version = g_value_get_int (value); - break; - } - case PROP_GMYTHTV_LIVEID: - { - mythtvsrc->live_tv_id = g_value_get_int (value); - break; - } - case PROP_GMYTHTV_LIVE: - { - mythtvsrc->live_tv = g_value_get_boolean (value); - break; - } - case PROP_GMYTHTV_ENABLE_TIMING_POSITION: - { - mythtvsrc->enable_timing_position = g_value_get_boolean (value); - break; - } - case PROP_GMYTHTV_LIVE_CHAINID: - { - if (!g_value_get_string (value)) { - GST_WARNING ("MythTV Live chainid property cannot be NULL"); - break; - } + case PROP_GMYTHTV_VERSION: + { + mythtvsrc->mythtv_version = g_value_get_int(value); + break; + } + case PROP_GMYTHTV_LIVEID: + { + mythtvsrc->live_tv_id = g_value_get_int(value); + break; + } + case PROP_GMYTHTV_LIVE: + { + mythtvsrc->live_tv = g_value_get_boolean(value); + break; + } + case PROP_GMYTHTV_ENABLE_TIMING_POSITION: + { + mythtvsrc->enable_timing_position = g_value_get_boolean(value); + break; + } + case PROP_GMYTHTV_LIVE_CHAINID: + { + if (!g_value_get_string(value)) + { + GST_WARNING("MythTV Live chainid property cannot be NULL"); + break; + } - if (mythtvsrc->live_chain_id != NULL) { - g_free (mythtvsrc->live_chain_id); - mythtvsrc->live_chain_id = NULL; - } - mythtvsrc->live_chain_id = g_value_dup_string (value); - break; - } - case PROP_GMYTHTV_CHANNEL_NUM: - { - mythtvsrc->channel_name = g_value_dup_string (value); - break; - } - case PROP_GMYTHTV_MAX_TRY: - { - mythtvsrc->max_try = g_value_get_int (value); - break; - } - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + if (mythtvsrc->live_chain_id != NULL) + { + g_free(mythtvsrc->live_chain_id); + mythtvsrc->live_chain_id = NULL; + } + mythtvsrc->live_chain_id = g_value_dup_string(value); + break; + } + case PROP_GMYTHTV_CHANNEL_NUM: + { + mythtvsrc->channel_name = g_value_dup_string(value); + break; + } + case PROP_GMYTHTV_MAX_TRY: + { + mythtvsrc->max_try = g_value_get_int(value); + break; + } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } - GST_OBJECT_UNLOCK (mythtvsrc); + GST_OBJECT_UNLOCK(mythtvsrc); } static void -gst_mythtv_src_get_property (GObject * object, guint prop_id, - GValue * value, GParamSpec * pspec) +gst_mythtv_src_get_property(GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec) { - GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object); + GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC(object); - GST_OBJECT_LOCK (mythtvsrc); - switch (prop_id) { - case PROP_LOCATION: - { - g_value_set_string (value, mythtvsrc->uri_name); - break; - } + GST_OBJECT_LOCK(mythtvsrc); + switch (prop_id) + { + case PROP_LOCATION: + { + g_value_set_string(value, mythtvsrc->uri_name); + break; + } #ifndef GST_DISABLE_GST_DEBUG - case PROP_GMYTHTV_DBG: - g_value_set_boolean (value, mythtvsrc->mythtv_msgs_dbg); - break; + case PROP_GMYTHTV_DBG: + g_value_set_boolean(value, mythtvsrc->mythtv_msgs_dbg); + break; #endif - case PROP_GMYTHTV_VERSION: - { - g_value_set_int (value, mythtvsrc->mythtv_version); - break; - } - case PROP_GMYTHTV_LIVEID: - { - g_value_set_int (value, mythtvsrc->live_tv_id); - break; - } - case PROP_GMYTHTV_LIVE: - g_value_set_boolean (value, mythtvsrc->live_tv); - break; - case PROP_GMYTHTV_ENABLE_TIMING_POSITION: - g_value_set_boolean (value, mythtvsrc->enable_timing_position); - break; - case PROP_GMYTHTV_LIVE_CHAINID: - { - g_value_set_string (value, mythtvsrc->live_chain_id); - break; - } - case PROP_GMYTHTV_CHANNEL_NUM: - { - g_value_set_string (value, mythtvsrc->channel_name); - break; - } - case PROP_GMYTHTV_MAX_TRY: - { - g_value_set_int (value, mythtvsrc->max_try); - break; - } + case PROP_GMYTHTV_VERSION: + { + g_value_set_int(value, mythtvsrc->mythtv_version); + break; + } + case PROP_GMYTHTV_LIVEID: + { + g_value_set_int(value, mythtvsrc->live_tv_id); + break; + } + case PROP_GMYTHTV_LIVE: + g_value_set_boolean(value, mythtvsrc->live_tv); + break; + case PROP_GMYTHTV_ENABLE_TIMING_POSITION: + g_value_set_boolean(value, mythtvsrc->enable_timing_position); + break; + case PROP_GMYTHTV_LIVE_CHAINID: + { + g_value_set_string(value, mythtvsrc->live_chain_id); + break; + } + case PROP_GMYTHTV_CHANNEL_NUM: + { + g_value_set_string(value, mythtvsrc->channel_name); + break; + } + case PROP_GMYTHTV_MAX_TRY: + { + g_value_set_int(value, mythtvsrc->max_try); + break; + } - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } - GST_OBJECT_UNLOCK (mythtvsrc); + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } + GST_OBJECT_UNLOCK(mythtvsrc); } static gboolean -plugin_init (GstPlugin * plugin) +plugin_init(GstPlugin * plugin) { - return gst_element_register (plugin, "mythtvsrc", GST_RANK_NONE, - GST_TYPE_MYTHTV_SRC); + return gst_element_register(plugin, "mythtvsrc", GST_RANK_NONE, + GST_TYPE_MYTHTV_SRC); } -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "mythtv", - "lib MythTV src", - plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN); +GST_PLUGIN_DEFINE(GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "mythtv", + "lib MythTV src", + plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, + GST_PACKAGE_ORIGIN); /*** GSTURIHANDLER INTERFACE *************************************************/ static guint -gst_mythtv_src_uri_get_type (void) +gst_mythtv_src_uri_get_type(void) { return GST_URI_SRC; } static gchar ** -gst_mythtv_src_uri_get_protocols (void) +gst_mythtv_src_uri_get_protocols(void) { static gchar *protocols[] = { "myth", "myths", NULL }; @@ -1224,33 +1325,34 @@ } static const gchar * -gst_mythtv_src_uri_get_uri (GstURIHandler * handler) +gst_mythtv_src_uri_get_uri(GstURIHandler * handler) { - GstMythtvSrc *src = GST_MYTHTV_SRC (handler); + GstMythtvSrc *src = GST_MYTHTV_SRC(handler); return src->uri_name; } static gboolean -gst_mythtv_src_uri_set_uri (GstURIHandler * handler, const gchar * uri) +gst_mythtv_src_uri_set_uri(GstURIHandler * handler, const gchar * uri) { - GstMythtvSrc *src = GST_MYTHTV_SRC (handler); + GstMythtvSrc *src = GST_MYTHTV_SRC(handler); gchar *protocol; - protocol = gst_uri_get_protocol (uri); - if ((strcmp (protocol, "myth") != 0) && (strcmp (protocol, "myths") != 0)) { - g_free (protocol); - return FALSE; - } - g_free (protocol); - g_object_set (src, "location", uri, NULL); + protocol = gst_uri_get_protocol(uri); + if ((strcmp(protocol, "myth") != 0) && (strcmp(protocol, "myths") != 0)) + { + g_free(protocol); + return FALSE; + } + g_free(protocol); + g_object_set(src, "location", uri, NULL); return TRUE; } static void -gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data) +gst_mythtv_src_uri_handler_init(gpointer g_iface, gpointer iface_data) { GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface; @@ -1261,9 +1363,9 @@ } void -size_header_handler (void *userdata, const char *value) +size_header_handler(void *userdata, const char *value) { - GstMythtvSrc *src = GST_MYTHTV_SRC (userdata); + GstMythtvSrc *src = GST_MYTHTV_SRC(userdata); - GST_DEBUG_OBJECT (src, "content size = %lld bytes", src->content_size); + GST_DEBUG_OBJECT(src, "content size = %lld bytes", src->content_size); }