[svn r323] Some updates in the LiveTV. trunk
authorrosfran
Thu Feb 01 22:10:18 2007 +0000 (2007-02-01)
branchtrunk
changeset 3211c020e9ef06d
parent 320 22a17127789e
child 322 eb6b0b1409b5
[svn r323] Some updates in the LiveTV.
gmyth/src/gmyth_file_transfer.c
gmyth/src/gmyth_livetv.c
gmyth/src/gmyth_programinfo.c
gmyth/src/gmyth_recorder.c
gmyth/src/gmyth_recorder.h
gmyth/src/gmyth_tvchain.h
     1.1 --- a/gmyth/src/gmyth_file_transfer.c	Thu Feb 01 18:42:01 2007 +0000
     1.2 +++ b/gmyth/src/gmyth_file_transfer.c	Thu Feb 01 22:10:18 2007 +0000
     1.3 @@ -301,6 +301,7 @@
     1.4  
     1.5    transfer->sock = gmyth_socket_new ();
     1.6    gmyth_socket_connect (transfer->sock, transfer->backend_info->hostname, transfer->backend_info->port);
     1.7 +  gmyth_debug("Connecting file transfer... (%s, %d)", transfer->backend_info->hostname, transfer->backend_info->port);
     1.8  
     1.9    strlist = gmyth_string_list_new();
    1.10    hostname = gmyth_socket_get_local_hostname();
     2.1 --- a/gmyth/src/gmyth_livetv.c	Thu Feb 01 18:42:01 2007 +0000
     2.2 +++ b/gmyth/src/gmyth_livetv.c	Thu Feb 01 22:10:18 2007 +0000
     2.3 @@ -381,7 +381,28 @@
     2.4  	{
     2.5  		gmyth_debug( "ProgramInfo is equals to NULL!!!" );
     2.6  		
     2.7 -		return FALSE;
     2.8 +    gint i;
     2.9 +    gchar *channame = NULL;
    2.10 +
    2.11 +    fprintf(stderr, "problem getting current proginfo!\n");
    2.12 +
    2.13 +    /*
    2.14 +     * mythbackend must not be tuned in to a channel, so keep
    2.15 +     * changing channels until we find a valid one, or until
    2.16 +     * we decide to give up.
    2.17 +     */
    2.18 +    for (i=1; i<1000; i++) {
    2.19 +			if ( channame != NULL )
    2.20 +				g_free(channame);
    2.21 +      channame = g_strdup_printf( "%d", i );
    2.22 +      if (gmyth_recorder_set_channel_name(livetv->recorder, channame) < 0) {
    2.23 +      	continue;
    2.24 +      }
    2.25 +      prog_info = gmyth_recorder_get_next_program_info(livetv->recorder, BROWSE_DIRECTION_UP);
    2.26 +      if (prog_info != NULL)
    2.27 +      	break;
    2.28 +    }
    2.29 +		
    2.30  	}
    2.31  	/* prints program info data text */ 
    2.32  	gmyth_debug( "New ProgramInfo...\n" );
    2.33 @@ -390,6 +411,11 @@
    2.34  	gmyth_debug( "Old ProgramInfo...\n" );
    2.35  	gmyth_program_info_print( livetv->proginfo );
    2.36  	
    2.37 +	GMythProgramInfo* prog_inf = gmyth_recorder_get_next_program_info( livetv->recorder, BROWSE_DIRECTION_UP );
    2.38 +	
    2.39 +	gmyth_debug( "Next ProgramInfo...\n" );
    2.40 +	gmyth_program_info_print( prog_inf );
    2.41 +	
    2.42  	/* check if the program chain could be obtained from the MythTV protocol message */
    2.43  	if ( prog_info != NULL )
    2.44  	{
    2.45 @@ -507,9 +533,9 @@
    2.46  		goto error;		
    2.47  	}
    2.48  	
    2.49 -	//if ( !gmyth_livetv_monitor_handler_start( livetv ) )
    2.50 -	//	goto error;
    2.51 -	prog_info = gmyth_recorder_get_current_program_info( livetv->recorder );
    2.52 +	prog_info = gmyth_recorder_get_next_program_info( livetv->recorder, BROWSE_DIRECTION_RIGHT );
    2.53 +	
    2.54 +	gmyth_debug( "Next ProgramInfo...\n" );
    2.55  	
    2.56  	if ( NULL == prog_info )
    2.57  	{
    2.58 @@ -576,9 +602,9 @@
    2.59  	}
    2.60  	
    2.61  	if ( livetv->proginfo != NULL )
    2.62 -  	gmyth_debug( "URI path = %s.\n", livetv->proginfo->pathname->str );
    2.63 +  	gmyth_debug( "URI path (from program info) = %s.\n", livetv->proginfo->pathname->str );
    2.64    else
    2.65 -  	gmyth_debug( "URI path = %s.\n", livetv->uri->uri->str ); 
    2.66 +  	gmyth_debug( "URI path (from URI) = %s.\n", livetv->uri->uri->str ); 
    2.67    
    2.68    g_static_mutex_lock( &lock );
    2.69    
    2.70 @@ -589,23 +615,20 @@
    2.71    	livetv->file_transfer = NULL;
    2.72    }  	
    2.73  
    2.74 -	livetv->file_transfer = gmyth_file_transfer_new( livetv->backend_info );
    2.75 -
    2.76 -  if ( NULL == livetv->file_transfer ) 
    2.77 +  if ( livetv->uri != NULL )  
    2.78    {
    2.79 -  	gmyth_debug( "Error: couldn't create the FileTransfer from LiveTV source!" );
    2.80 -    goto done;
    2.81 -  }
    2.82 -  
    2.83 -  if ( livetv->uri != NULL )  
    2.84 -  { 
    2.85 +  	/* 
    2.86    	if ( livetv->uri->path != NULL )
    2.87    	{
    2.88    		g_string_free( livetv->uri->path, FALSE );
    2.89    		livetv->uri->path = NULL;
    2.90    	}
    2.91 +  	*/
    2.92 +  	gmyth_debug( "URI is NULL, creating from the ProgramInfo pathname... (%s)", livetv->proginfo->pathname->str );
    2.93 +  	livetv->uri->path = g_string_erase(livetv->uri->path, 0, -1);
    2.94    	livetv->uri->path = g_string_new( g_strrstr( livetv->proginfo->pathname->str, "/" ) );
    2.95    } else {
    2.96 +  	gmyth_debug( "URI is NULL, creating from the ProgramInfo pathname... (%s)", livetv->proginfo->pathname->str );
    2.97    	livetv->uri = gmyth_uri_new_with_value( livetv->proginfo->pathname->str );
    2.98    }
    2.99    	
   2.100 @@ -614,6 +637,14 @@
   2.101    	gmyth_debug( "Couldn't parse the URI to start LiveTV! [ uri = %s ]", livetv->proginfo->pathname->str );
   2.102    	goto done;  	
   2.103    }
   2.104 +  
   2.105 +	livetv->file_transfer = gmyth_file_transfer_new( livetv->backend_info );
   2.106 +
   2.107 +  if ( NULL == livetv->file_transfer ) 
   2.108 +  {
   2.109 +  	gmyth_debug( "Error: couldn't create the FileTransfer from LiveTV source!" );
   2.110 +    goto done;
   2.111 +  }
   2.112  
   2.113  	if ( !gmyth_file_transfer_open( livetv->file_transfer, livetv->uri != NULL ? gmyth_uri_get_path(livetv->uri) : 
   2.114  				livetv->proginfo->pathname->str ) )
     3.1 --- a/gmyth/src/gmyth_programinfo.c	Thu Feb 01 18:42:01 2007 +0000
     3.2 +++ b/gmyth/src/gmyth_programinfo.c	Thu Feb 01 22:10:18 2007 +0000
     3.3 @@ -309,10 +309,11 @@
     3.4      gmyth_string_list_append_string (slist, prog->chansign); /* 6 */
     3.5      gmyth_string_list_append_string (slist, prog->channame); /* 7 */
     3.6      gmyth_string_list_append_string (slist, prog->pathname); /* 8 */
     3.7 +    gmyth_string_list_append_int (slist, 0); /* 11 */
     3.8  
     3.9      // fixme
    3.10 -    gmyth_string_list_append_int64 (slist, 100/*prog->filesize*/); /* 9 */
    3.11 -    gmyth_string_list_append_int64 (slist, 10); /* 11 */
    3.12 +    //gmyth_string_list_append_int64 (slist, 100/*prog->filesize*/); /* 9 */
    3.13 +    gmyth_string_list_append_int64 (slist, 0); /* 11 */
    3.14  
    3.15      if (prog->startts)
    3.16          gmyth_string_list_append_int (slist, prog->startts->tv_sec);  /* 11 */ //DATETIME_TO_LIST(startts)
    3.17 @@ -346,7 +347,7 @@
    3.18      gmyth_string_list_append_string (slist, prog->chanOutputFilters); /* 32 */
    3.19      gmyth_string_list_append_string (slist, prog->seriesid); /* 33 */
    3.20      gmyth_string_list_append_string (slist, prog->programid); /* 34 */
    3.21 -    gmyth_string_list_append_string (slist, ""); /* 35 */
    3.22 +    gmyth_string_list_append_char_array (slist, ""); /* 35 */
    3.23      gmyth_string_list_append_int (slist, prog->lastmodified != NULL ? prog->lastmodified->tv_sec : 0);  /* 36 */ //DATETIME_TO_LIST(lastmodified)
    3.24      gmyth_string_list_append_int (slist, 0);  /* 37 */ //FLOAT_TO_LIST(stars)
    3.25      gmyth_string_list_append_int (slist, prog->originalAirDate != NULL ? prog->originalAirDate->tv_sec : 0);  /* 38 */ //DATETIME_TO_LIST(QDateTime(originalAirDate))
    3.26 @@ -410,16 +411,18 @@
    3.27      prog->subtitle = gmyth_string_list_get_string (slist, 1);
    3.28      prog->description = gmyth_string_list_get_string (slist, 2);
    3.29      prog->category = gmyth_string_list_get_string (slist, 3);
    3.30 +    //gmyth_string_list_get_string (slist, 4);
    3.31      prog->chanid = gmyth_string_list_get_string (slist, 4);
    3.32 -    prog->chanstr = gmyth_string_list_get_string (slist, 5);
    3.33 -    prog->chansign = gmyth_string_list_get_string (slist, 6);
    3.34 -    prog->channame = gmyth_string_list_get_string (slist, 7);
    3.35 -    prog->pathname = gmyth_string_list_get_string (slist, 8);
    3.36 +    prog->channame = gmyth_string_list_get_string (slist, 5);
    3.37 +    prog->chanstr = gmyth_string_list_get_string (slist, 6);    
    3.38 +    prog->chansign = gmyth_string_list_get_string (slist, 7);    
    3.39 +    prog->pathname = gmyth_string_list_get_string (slist, 8);    
    3.40 +    //gmyth_string_list_get_int (slist, 9);
    3.41 +    
    3.42      prog->filesize = gmyth_string_list_get_int64 (slist, 9);
    3.43 -    gmyth_string_list_get_int64 (slist, 10);
    3.44  
    3.45      prog->startts = gmyth_util_string_to_time_val( (gmyth_util_time_to_isoformat( 
    3.46 -    					(time_t)gmyth_string_list_get_int (slist, 11) ))->str ); //DATETIME_TO_LIST(startts)
    3.47 +    					(time_t)gmyth_string_list_get_int64 (slist, 11) ))->str ); //DATETIME_TO_LIST(startts)
    3.48      prog->endts = gmyth_util_string_to_time_val( (gmyth_util_time_to_isoformat( 
    3.49      					(time_t)gmyth_string_list_get_int (slist, 12) ))->str ); //DATETIME_TO_LIST(endts)
    3.50      prog->duplicate = gmyth_string_list_get_int (slist, 13);
     4.1 --- a/gmyth/src/gmyth_recorder.c	Thu Feb 01 18:42:01 2007 +0000
     4.2 +++ b/gmyth/src/gmyth_recorder.c	Thu Feb 01 22:10:18 2007 +0000
     4.3 @@ -583,6 +583,171 @@
     4.4  
     4.5  }
     4.6  
     4.7 +/**
     4.8 + * Requests the actual program info from the MythTV backend server.
     4.9 + * 
    4.10 + * @param rec_id The GMythRecorder record number.
    4.11 + * @return The GMythRecorder instance.
    4.12 + */
    4.13 +GMythRecorder *
    4.14 +gmyth_recorder_get_recorder_from_num ( gint rec_id )
    4.15 +{
    4.16 +	GMythRecorder* recorder = NULL;
    4.17 +	GMythStringList *str_list;
    4.18 +	GString *tmp_str = g_string_new( "GET_RECORDER_FROM_NUM" );
    4.19 +	gint command_size = 0;
    4.20 +	
    4.21 +	gchar *recorder_host = NULL;
    4.22 +	gint recorder_port;
    4.23 +	
    4.24 +	str_list = gmyth_string_list_new ();
    4.25 +	
    4.26 +	/* g_string_append_printf ( tmp_str, " %d", recorder->recorder_num ); */
    4.27 +	 
    4.28 +	gmyth_string_list_append_string (str_list, tmp_str);
    4.29 +	gmyth_string_list_append_int (str_list, rec_id);
    4.30 +
    4.31 +	command_size = gmyth_socket_sendreceive_stringlist (recorder->myth_socket, str_list);
    4.32 +
    4.33 +  g_string_free (tmp_str, TRUE);
    4.34 +
    4.35 +  if (str_list == NULL) {
    4.36 +  	g_warning ("[%s] GET_RECORDER_FROM_NUM request returned. Error getting recorder number %d, it is equals to NULL!!!", 
    4.37 +		  			__FUNCTION__, rec_id);
    4.38 +  	return NULL;
    4.39 +	}
    4.40 +	
    4.41 +	if ( command_size > 0 )
    4.42 +	{
    4.43 +		recorder_host = gmyth_string_list_get_char_array( str_list, 0 );
    4.44 +		recorder_port = gmyth_string_list_get_int( str_list, 1 );
    4.45 +		
    4.46 +		if ( g_strstr_len( recorder_host, strlen(recorder_host), "nohost" ) != NULL )
    4.47 +		{
    4.48 +			gmyth_debug( "No available recorder with the recorder ID number %d!", rec_id );
    4.49 +		} else {
    4.50 +	  
    4.51 +		  recorder = gmyth_recorder_new( rec_id, g_string_new( recorder_host ), (gshort)recorder_port );
    4.52 +		
    4.53 +		  if ( NULL == recorder ) {
    4.54 +		  	g_warning ("[%s] GET_RECORDER_FROM_NUM request returned. Error getting recorder number %d, it is equals to NULL!!!", 
    4.55 +		  			__FUNCTION__, rec_id);
    4.56 +		    g_object_unref (recorder);
    4.57 +		  	return NULL;
    4.58 +		  }
    4.59 +		  
    4.60 +		}
    4.61 +	  
    4.62 +	} else {
    4.63 +		gmyth_debug( "Cannot find a valuable recorder with the recorder ID number %d, backend server error!", rec_id );
    4.64 +	}
    4.65 +
    4.66 +  g_object_unref (str_list);
    4.67 +  
    4.68 +  if ( recorder_host != NULL )
    4.69 +  	g_free( recorder_host );
    4.70 +  
    4.71 +  return recorder;
    4.72 +
    4.73 +}
    4.74 +
    4.75 +/**
    4.76 + * Requests the actual program info from the MythTV backend server.
    4.77 + * 
    4.78 + * @param recorder The GMythRecorder instance.
    4.79 + * @return The GMythProgramInfo next program info instance.
    4.80 + */
    4.81 +GMythProgramInfo *
    4.82 +gmyth_recorder_get_next_program_info ( GMythRecorder *recorder, const GMythRecorderBrowseDirection direction )
    4.83 +{
    4.84 +	GMythProgramInfo* actual_proginfo = NULL;
    4.85 +	GMythProgramInfo* program_info = NULL;
    4.86 +	GMythStringList *str_list;
    4.87 +	GString *tmp_str = g_string_new( GMYTHTV_RECORDER_HEADER );
    4.88 +	
    4.89 +	gchar *date = NULL;
    4.90 +  struct tm *tm;
    4.91 +  time_t t;
    4.92 +  
    4.93 +  actual_proginfo = gmyth_recorder_get_current_program_info(recorder);
    4.94 +	
    4.95 +	str_list = gmyth_string_list_new ();
    4.96 +	
    4.97 +	g_string_append_printf ( tmp_str, " %d", recorder->recorder_num );
    4.98 +	 
    4.99 +  t = time(NULL);
   4.100 +  tm = localtime(&t);
   4.101 +  date = g_strdup_printf("%.4d%.2d%.2d%.2d%.2d%.2d",
   4.102 +           tm->tm_year + 1900, tm->tm_mon + 1,
   4.103 +           tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
   4.104 +
   4.105 +	gmyth_string_list_append_string (str_list, tmp_str);
   4.106 +	gmyth_string_list_append_char_array (str_list, "GET_NEXT_PROGRAM_INFO");
   4.107 +	gmyth_string_list_append_string (str_list, actual_proginfo->channame);
   4.108 +  gmyth_string_list_append_string (str_list, actual_proginfo->chanid);
   4.109 +  gmyth_string_list_append_int (str_list, direction);
   4.110 +  gmyth_string_list_append_char_array (str_list, date);
   4.111 +	
   4.112 +	if ( gmyth_socket_sendreceive_stringlist (recorder->myth_socket, str_list) > 0 )
   4.113 +	{
   4.114 +  
   4.115 +	  if (str_list == NULL) {
   4.116 +	  	g_warning ("[%s] GET_NEXT_PROGRAM_INFO request returned. Error getting program info, it is equals to NULL!!!", 
   4.117 +			  			__FUNCTION__);
   4.118 +	  	goto done;
   4.119 +		}
   4.120 +		program_info = gmyth_program_info_new();
   4.121 +		
   4.122 +	  if ( NULL == program_info ) {
   4.123 +	  	g_warning ("[%s] GET_NEXT_PROGRAM_INFO request returned. Error getting next program info, it is equals to NULL!!!", 
   4.124 +	  			__FUNCTION__);
   4.125 +	    g_object_unref (program_info);
   4.126 +	  	goto done;
   4.127 +	  }
   4.128 +	  
   4.129 +		program_info->title = gmyth_string_list_get_string (str_list, 0);
   4.130 +		program_info->subtitle = gmyth_string_list_get_string (str_list, 1);
   4.131 +		program_info->description = gmyth_string_list_get_string (str_list, 2);
   4.132 +		program_info->category = gmyth_string_list_get_string (str_list, 3);
   4.133 +		program_info->startts = gmyth_util_string_to_time_val( (gmyth_util_time_to_isoformat( 
   4.134 +    					(time_t)gmyth_string_list_get_int (str_list, 4) ))->str );
   4.135 +		program_info->endts = gmyth_util_string_to_time_val( (gmyth_util_time_to_isoformat( 
   4.136 +    					(time_t)gmyth_string_list_get_int (str_list, 6) ))->str );
   4.137 +	
   4.138 +	  program_info->chansign = gmyth_string_list_get_string (str_list, 8);
   4.139 +	  program_info->pathname = gmyth_string_list_get_string (str_list, 9);
   4.140 +	  program_info->channame = gmyth_string_list_get_string (str_list, 10);
   4.141 +	  program_info->chanid = gmyth_string_list_get_string (str_list, 11);
   4.142 +	  if ( recorder->myth_socket->mythtv_version >= 12 ) {
   4.143 +	          program_info->seriesid = gmyth_string_list_get_string (str_list, 12);
   4.144 +	          program_info->programid = gmyth_string_list_get_string (str_list, 13);
   4.145 +	  }
   4.146 +	  
   4.147 +	  if ( ( program_info->chanid != NULL && strlen( program_info->chanid->str ) > 0  ) &&
   4.148 +	  	( program_info->channame != NULL && strlen( program_info->channame->str ) > 0 ) &&
   4.149 +	  	( program_info->title != NULL && strlen( program_info->title->str ) > 0 ) ) 
   4.150 +	  {
   4.151 +	  		gmyth_debug( "OK!!! Got the next program info..." );
   4.152 +	  } else {
   4.153 +	  	gmyth_debug ("GET_NEXT_PROGRAM_INFO request returned. Error getting next program info, it is equals to NULL!!!" );
   4.154 +	    g_object_unref (program_info);
   4.155 +	    program_info = NULL;
   4.156 +	  }
   4.157 +	  
   4.158 +	} /* if */
   4.159 +
   4.160 +done:
   4.161 +  g_string_free (tmp_str, TRUE);
   4.162 +
   4.163 +  g_object_unref (str_list);
   4.164 +  
   4.165 +  if ( date != NULL )
   4.166 +  	g_free( date );
   4.167 +  
   4.168 +  return program_info;
   4.169 +
   4.170 +}
   4.171 +
   4.172  gint64
   4.173  gmyth_recorder_get_file_position ( GMythRecorder *recorder )
   4.174  {
     5.1 --- a/gmyth/src/gmyth_recorder.h	Thu Feb 01 18:42:01 2007 +0000
     5.2 +++ b/gmyth/src/gmyth_recorder.h	Thu Feb 01 22:10:18 2007 +0000
     5.3 @@ -80,7 +80,16 @@
     5.4  	CHANNEL_DIRECTION_SAME
     5.5  } GMythRecorderChannelChangeDirection;
     5.6  
     5.7 -GType   gmyth_recorder_get_type   (void);
     5.8 +typedef enum _GMythRecorderBrowseDirection {
     5.9 +	BROWSE_DIRECTION_SAME = 0,     	  /* Stay in the same place */
    5.10 + 	BROWSE_DIRECTION_UP,          		/* Move up one slot (down one channel) */
    5.11 +	BROWSE_DIRECTION_DOWN,        		/* Move down one slot (up one channel) */
    5.12 +	BROWSE_DIRECTION_LEFT,        		/* Move left one slot (down one time slot) */
    5.13 +	BROWSE_DIRECTION_RIGHT,       		/* Move right one slot (up one time slot) */
    5.14 +	BROWSE_DIRECTION_FAVORITE    			/* Move to the next favorite slot */
    5.15 +} GMythRecorderBrowseDirection;
    5.16 +
    5.17 +GType   gmyth_recorder_get_type   	(void);
    5.18  
    5.19  GMythRecorder* gmyth_recorder_new    (int num,
    5.20  	                                     GString *hostname,
    5.21 @@ -112,7 +121,12 @@
    5.22  gboolean gmyth_recorder_pause_recording ( GMythRecorder *recorder );
    5.23  
    5.24  GMythProgramInfo *gmyth_recorder_get_current_program_info ( GMythRecorder *recorder );
    5.25 -                                         
    5.26 +
    5.27 +GMythProgramInfo *gmyth_recorder_get_next_program_info ( GMythRecorder *recorder,
    5.28 +												const GMythRecorderBrowseDirection direction);
    5.29 +												
    5.30 +GMythRecorder *gmyth_recorder_get_recorder_from_num ( gint rec_id );
    5.31 +
    5.32  gint64 	 gmyth_recorder_get_file_position ( GMythRecorder *recorder );
    5.33  
    5.34  gboolean gmyth_recorder_is_recording ( GMythRecorder *recorder );
     6.1 --- a/gmyth/src/gmyth_tvchain.h	Thu Feb 01 18:42:01 2007 +0000
     6.2 +++ b/gmyth/src/gmyth_tvchain.h	Thu Feb 01 22:10:18 2007 +0000
     6.3 @@ -74,7 +74,7 @@
     6.4  
     6.5  struct _GMythTVChain
     6.6  {
     6.7 -    GObject parent;
     6.8 +  GObject parent;
     6.9  
    6.10  	GString *tvchain_id;
    6.11  	GList   *tvchain_list;
    6.12 @@ -83,7 +83,7 @@
    6.13  	GString *cur_chanid;
    6.14  	gint     cur_pos;
    6.15  
    6.16 -    GMythBackendInfo *backend_info;
    6.17 +  GMythBackendInfo *backend_info;
    6.18  };
    6.19  
    6.20