# HG changeset patch # User rosfran # Date 1169229958 0 # Node ID 5a224299ab370d353d30621c403e74e1c70e4a2f # Parent a24bacc8d75275d2572b804832b3869f017f517f [svn r280] Some fixes to the TV chain creation, and gmyth_uri query parsing (set channel). diff -r a24bacc8d752 -r 5a224299ab37 gmyth/src/gmyth_backendinfo.c --- a/gmyth/src/gmyth_backendinfo.c Fri Jan 19 13:09:21 2007 +0000 +++ b/gmyth/src/gmyth_backendinfo.c Fri Jan 19 18:05:58 2007 +0000 @@ -143,7 +143,6 @@ if ( NULL == hostname || strlen(hostname) <= 0 ) { gmyth_debug ( "Error trying to set a hostname equals to NULL." ); - return NULL; } else { backend_info->hostname = g_strdup (hostname); } @@ -181,7 +180,6 @@ if ( port <= 0 ) { gmyth_debug ( "Error trying to set a hostname equals to NULL (it doesn't using UPnP)." ); - return NULL; } else { backend_info->port = port; } diff -r a24bacc8d752 -r 5a224299ab37 gmyth/src/gmyth_livetv.c --- a/gmyth/src/gmyth_livetv.c Fri Jan 19 13:09:21 2007 +0000 +++ b/gmyth/src/gmyth_livetv.c Fri Jan 19 18:05:58 2007 +0000 @@ -266,7 +266,28 @@ res = FALSE; goto error; } + + // Init remote encoder. Opens its control socket. + res = gmyth_recorder_setup(livetv->recorder); + if ( !res ) { + g_warning ("[%s] Fail while setting remote encoder\n", __FUNCTION__); + res = FALSE; + goto error; + } + + if ( channel != -1 ) + { + gint ch = channel; + //if ( gmyth_recorder_check_channel( livetv->recorder, ch ) ) + //{ + if ( gmyth_recorder_set_channel( livetv->recorder, ch ) ) + { + g_print( "[%s] Channel changed!!! [%d].\n", __FUNCTION__, ch ); + } + //} + } + // Creates livetv chain handler livetv->tvchain = GMYTH_TVCHAIN ( g_object_new(GMYTH_TVCHAIN_TYPE, NULL) ); gmyth_tvchain_initialize ( livetv->tvchain, livetv->backend_info ); @@ -276,27 +297,13 @@ goto error; } - // Init remote encoder. Opens its control socket. - res = gmyth_recorder_setup(livetv->recorder); - if ( !res ) { - g_warning ("[%s] Fail while setting remote encoder\n", __FUNCTION__); + // Reload all TV chain from Mysql database. + gmyth_tvchain_reload_all (livetv->tvchain); + + if ( livetv->tvchain == NULL ) { res = FALSE; goto error; } - - if ( channel != -1 ) { - gint ch = channel; - gint ch_idx = 0; - for ( ; ch_idx < 5; ch_idx++ ) { - if ( gmyth_recorder_check_channel( livetv->recorder, ch ) ) { - if ( gmyth_recorder_set_channel( livetv->recorder, ch ) ) { - g_print( "[%s] Channel changed!!! [%d].\n", __FUNCTION__, ch ); - break; - } - } - ++ch; - } - } // Spawn live tv. Uses the socket to send mythprotocol data to start livetv in the backend (remotelly) res = gmyth_recorder_spawntv ( livetv->recorder, @@ -307,14 +314,6 @@ goto error; } - // Reload all TV chain from Mysql database. - gmyth_tvchain_reload_all (livetv->tvchain); - - if ( livetv->tvchain == NULL ) { - res = FALSE; - goto error; - } - // Get program info from database using chanid and starttime livetv->proginfo = gmyth_tvchain_get_program_at (livetv->tvchain, tvchain_curr_index++ ); if ( livetv->proginfo == NULL ) { diff -r a24bacc8d752 -r 5a224299ab37 gmyth/src/gmyth_tvchain.c --- a/gmyth/src/gmyth_tvchain.c Fri Jan 19 13:09:21 2007 +0000 +++ b/gmyth/src/gmyth_tvchain.c Fri Jan 19 18:05:58 2007 +0000 @@ -226,7 +226,7 @@ entry->inputname = g_string_new (msql_row[8]); //m_maxpos = query.value(4).toInt() + 1; - g_print( "[%s] Reading TV chain entry: [%s, %s, %s]\n", __FUNCTION__, entry->chanid->str, + g_print( "[%s] Reading TV chain entry (channel %d): [%s, %s, %s]\n", __FUNCTION__, entry->channum, entry->chanid->str, (gchar*)msql_row[1], (gchar*)msql_row[2] ); /* add this to get the actual start timestamp of the last recording */ diff -r a24bacc8d752 -r 5a224299ab37 gmyth/src/gmyth_uri.c --- a/gmyth/src/gmyth_uri.c Fri Jan 19 13:09:21 2007 +0000 +++ b/gmyth/src/gmyth_uri.c Fri Jan 19 18:05:58 2007 +0000 @@ -215,6 +215,7 @@ gint atIdx; gint colonIdx; gint shashIdx; + gint eIdx; gchar *host; gint eblacketIdx; gint hostLen; @@ -273,8 +274,8 @@ /**** port ****/ portStr = g_string_new_len (hostStr->str+colonIdx+1, hostLen-colonIdx-1); uri->port = (gint)g_ascii_strtoull( portStr->str, NULL, 10 ); - g_string_free (portStr, TRUE); - g_string_free (hostStr, TRUE); + g_string_free (portStr, FALSE); + g_string_free (hostStr, FALSE); } else { const gchar* protocol = gmyth_uri_get_protocol(uri); @@ -306,22 +307,24 @@ /* First set path simply to the rest of URI */ uri->path = g_string_new_len (value+currIdx, uriLen-currIdx ); } - + + gmyth_debug( "uri value: %s", value ); + uri->query = g_string_new ( g_strstr_len( value, strlen(value), GMYTH_URI_E_DELIM ) ); + + eIdx = gmyth_strstr( value+currIdx, GMYTH_URI_E_DELIM ); + + if ( 0 < eIdx ) { + uri->query = g_string_new ( g_strstr_len( value, strlen(value), GMYTH_URI_E_DELIM ) ); + gmyth_debug( "query = %s", uri->query->str ); + } + /**** Path (Query/Fragment) ****/ sharpIdx = gmyth_strstr(value+currIdx, GMYTH_URI_SHARP_DELIM); if (0 < sharpIdx) { uri->path = g_string_append_len( uri->path, value+currIdx, sharpIdx); uri->fragment = g_string_new_len (value+currIdx+sharpIdx+1, uriLen-(currIdx+sharpIdx+1)); - } - - questionIdx = gmyth_strstr( value+currIdx, GMYTH_URI_QUESTION_DELIM ); - if ( 0 < questionIdx ) { - uri->path = g_string_append_len (uri->path, value+currIdx, questionIdx ); - queryLen = uriLen-(currIdx+questionIdx+1); - if ( 0 < sharpIdx ) - queryLen -= uriLen - (currIdx+sharpIdx+1); - uri->query = g_string_new_len (value+currIdx+questionIdx+1, queryLen ); - } + } + gmyth_debug( "[%s] GMythURI: host = %s, port = %d, path = %s, query = %s, fragment = %s, "\ "user = %s, password = %s.\n", __FUNCTION__, gmyth_uri_print_field( uri->host ), uri->port, gmyth_uri_print_field( uri->path ), gmyth_uri_print_field( uri->query ), gmyth_uri_print_field( uri->fragment ), @@ -336,3 +339,44 @@ gmyth_uri_get_port( uri1 ) == gmyth_uri_get_port( uri2 ) ); } +gboolean +gmyth_uri_is_livetv( GMythURI* uri ) +{ + + g_return_val_if_fail( uri != NULL && uri->uri != NULL && uri->uri->str != NULL, FALSE ); + + return ( g_strstr_len( uri->uri->str, strlen( uri->uri->str ), "/?" ) != NULL ); + +} + +gint +gmyth_uri_get_channel_num( GMythURI* uri ) +{ + gint channel = -1; + + g_return_val_if_fail( uri != NULL && uri->uri != NULL && uri->uri->str != NULL, FALSE ); + + gchar *channel_query = g_strstr_len( gmyth_uri_get_query( uri ), strlen( gmyth_uri_get_query( uri ) ), "channel" ); + + if ( channel_query != NULL ) + { + gmyth_debug( "Channel is in the following URI segment: %s", channel_query ); + + gchar **chan_key_value = g_strsplit( gmyth_uri_get_query( uri ), "=", 2 ); + + gmyth_debug( "Channel tuple is [ %s, %s ]", chan_key_value[0], chan_key_value[1] ); + + if ( chan_key_value[1] != NULL ) + { + channel = g_ascii_strtoull( chan_key_value[1], NULL, 10 ); + } + + if ( chan_key_value ) + g_strfreev( chan_key_value ); + } + + gmyth_debug( "Got channel decimal value from the URI: %d", channel ); + + return channel; + +} diff -r a24bacc8d752 -r 5a224299ab37 gmyth/src/gmyth_uri.h --- a/gmyth/src/gmyth_uri.h Fri Jan 19 13:09:21 2007 +0000 +++ b/gmyth/src/gmyth_uri.h Fri Jan 19 18:05:58 2007 +0000 @@ -67,6 +67,7 @@ #define GMYTH_URI_EBLACET_DELIM "]" #define GMYTH_URI_SHARP_DELIM "#" #define GMYTH_URI_QUESTION_DELIM "?" +#define GMYTH_URI_E_DELIM "&" #define GMYTH_URI_ESCAPING_CHAR "%" #define GMYTH_URI_PROTOCOL_MYTH "myth" @@ -104,9 +105,13 @@ GType gmyth_uri_get_type (void); GMythURI* gmyth_uri_new (void); GMythURI* gmyth_uri_new_with_value (const gchar *value); -gboolean gmyth_uri_is_equals (GMythURI* uri1, GMythURI* uri2); +gboolean gmyth_uri_is_equals ( GMythURI* uri1, GMythURI* uri2 ); +gboolean gmyth_uri_is_livetv ( GMythURI* uri ); +gint gmyth_uri_get_channel_num( GMythURI* uri ); + + #define gmyth_uri_get_host(urip) ( urip->host != NULL ? urip->host->str : "" ) -#define gmyth_uri_get_port(urip) (urip->port) +#define gmyth_uri_get_port(urip) ( urip->port ) #define gmyth_uri_get_protocol(urip) ( urip->protocol != NULL ? urip->protocol->str : "" ) #define gmyth_uri_get_path(urip) ( urip->path != NULL ? urip->path->str : "" ) #define gmyth_uri_get_user(urip) ( urip->user != NULL ? urip->user->str : "" )