gmyth/tests/gmyth_test_livetv.c
author morphbr
Fri Jun 01 13:48:21 2007 +0100 (2007-06-01)
branchtrunk
changeset 736 1bc4c47e4ad8
parent 594 f36075170a4e
child 750 312d6bc514f3
permissions -rw-r--r--
[svn r742] * GMyth-Streamer
- mencoder's tv test ;-)
     1 #include <glib-object.h>
     2 
     3 #include "common.h"
     4 
     5 #include <gmyth/gmyth_uri.h>
     6 #include <gmyth/gmyth_backendinfo.h>
     7 #include <gmyth/gmyth_livetv.h>
     8 #include <gmyth/gmyth_file.h>
     9 #include <gmyth/gmyth_file_transfer.h>
    10 #include <gmyth/gmyth_file_local.h>
    11 #include <gmyth/gmyth_common.h>
    12 
    13 #define URI_DEFAULT	"myth://192.168.3.165:6543/livetv?channel=9"
    14 
    15 static gboolean
    16 test_livetv_setup ( gchar *uri )
    17 {
    18   GMythLiveTV *livetv = NULL;
    19   GMythFile *file = NULL;
    20   gchar *channel_name = NULL;
    21   gboolean ret = TRUE;
    22   gboolean live_tv = FALSE;
    23   
    24   if ( NULL == uri )
    25     uri = g_strdup( URI_DEFAULT );
    26 
    27   GMythURI *gmyth_uri = gmyth_uri_new_with_value( uri );
    28 
    29   GMythBackendInfo* backend_info = gmyth_backend_info_new_with_uri (uri);
    30   live_tv = gmyth_uri_is_livetv( gmyth_uri );
    31   if ( live_tv ) {
    32     livetv = gmyth_livetv_new (backend_info);
    33     
    34     gchar* ch = gmyth_uri_get_channel_name( gmyth_uri );
    35     if ( ch != NULL )
    36         channel_name = ch;
    37         
    38     if (channel_name != NULL) {
    39       if (gmyth_livetv_channel_name_setup (livetv, channel_name) == FALSE) {
    40         g_debug("LiveTV setup felt down on error.");
    41         ret = FALSE;
    42         goto init_failed;
    43       }
    44     } else {
    45       if (gmyth_livetv_setup (livetv) == FALSE) {
    46         g_debug("LiveTV setup felt down on error");
    47         ret = FALSE;
    48         goto init_failed;
    49       }
    50     }
    51 
    52     file = GMYTH_FILE( gmyth_livetv_create_file_transfer (livetv) );
    53 
    54     if (NULL == file) {
    55       g_debug("[LiveTV] FileTransfer equals to NULL");
    56       ret = FALSE;
    57       goto init_failed;
    58     }
    59     
    60     /* Check if the file is local to this specific client renderer */
    61     if ( gmyth_uri_is_local_file(gmyth_uri) )
    62         ret = gmyth_file_local_open( GMYTH_FILE_LOCAL(file) );
    63     else
    64         ret = gmyth_file_transfer_open( GMYTH_FILE_TRANSFER(file), livetv->uri != NULL ? 
    65             gmyth_uri_get_path(livetv->uri) : 
    66             livetv->proginfo->pathname->str );
    67 
    68     if ( !ret )
    69     {
    70         g_debug("Error: couldn't open the FileTransfer from LiveTV source!" );
    71         goto init_failed;
    72     }
    73   } else {
    74     
    75     /* Check if the file is local to this specific client renderer, and tries to open
    76      * a local connection
    77      */
    78     if ( gmyth_uri_is_local_file(gmyth_uri) )
    79     {
    80         g_debug ( "Opening local file connection to download..." );
    81         file = GMYTH_FILE(gmyth_file_local_new(backend_info));
    82         ret = gmyth_file_local_open ( GMYTH_FILE_LOCAL( file ) );      
    83     } else {
    84         g_debug ( "Opening remote file connection to download..." );
    85         file = GMYTH_FILE(gmyth_file_transfer_new(backend_info));
    86         ret = gmyth_file_transfer_open ( GMYTH_FILE_TRANSFER(file), uri );
    87     }
    88 
    89   } /* if (else) - recorded FileTransfer */
    90 
    91   if (NULL == file) {
    92     g_debug("FileTransfer is NULL");
    93     ret = FALSE;
    94     goto init_failed;
    95   }
    96   g_debug( "uri = %s", uri);
    97 
    98   if (ret == FALSE) {
    99       g_debug("MythTV FileTransfer request failed when setting up socket connection!");
   100       goto init_failed;
   101   }
   102 
   103   g_debug( "MythTV FileTransfer filesize = %lld",
   104       gmyth_file_get_filesize( file ));
   105 
   106 init_failed:
   107     if ( livetv != NULL )
   108         g_object_unref(livetv);
   109   
   110     if ( file != NULL )
   111         g_object_unref(file);
   112     
   113 //    if ( uri != NULL )
   114 //        g_free( uri );
   115   
   116     if ( gmyth_uri != NULL )
   117         g_object_unref( gmyth_uri );
   118 
   119 //    if ( backend_info != NULL )
   120 //       g_object_unref( backend_info );
   121 
   122     return ret;
   123     
   124 }
   125 
   126 gint
   127 main (gint args, const gchar **argv)
   128 {
   129     gboolean ret;
   130 
   131     g_type_init ();
   132     
   133     g_thread_init (NULL);
   134 
   135     fprintf(stdout, SYNC_STRING);
   136     fflush(NULL);
   137     getchar();
   138     
   139     if ( args > 1 )
   140 	ret = test_livetv_setup ( argv[1] );
   141     else
   142     	ret = test_livetv_setup ( NULL );
   143     
   144     if ( !ret )
   145         g_debug ("Error when running LiveTV setup test script!");
   146     else
   147         g_debug ("LiveTV setup test script finished with success.");
   148 
   149     return(0);
   150 }
   151 
   152 
   153 
   154