[svn r467] Addded functions to help stopping LiveTV recording. trunk
authorrosfran
Tue Mar 27 20:27:51 2007 +0100 (2007-03-27)
branchtrunk
changeset 4620e6de3b59f57
parent 461 0683ea324deb
child 463 771f91aa9d5d
[svn r467] Addded functions to help stopping LiveTV recording.
gmyth/src/gmyth_recorder.c
gmyth/src/gmyth_recorder.h
     1.1 --- a/gmyth/src/gmyth_recorder.c	Tue Mar 27 16:45:00 2007 +0100
     1.2 +++ b/gmyth/src/gmyth_recorder.c	Tue Mar 27 20:27:51 2007 +0100
     1.3 @@ -74,6 +74,11 @@
     1.4  
     1.5      gmyth_recorder_close(recorder);
     1.6  
     1.7 +    if ( recorder->mutex != NULL) {
     1.8 +        g_mutex_free(recorder->mutex);
     1.9 +        recorder->mutex = NULL;
    1.10 +    }
    1.11 +    
    1.12      if ( recorder->myth_socket != NULL) {
    1.13          g_object_unref(recorder->myth_socket);
    1.14          recorder->myth_socket = NULL;
    1.15 @@ -97,6 +102,7 @@
    1.16  void
    1.17  gmyth_recorder_close(GMythRecorder *recorder) 
    1.18  {
    1.19 +    gmyth_recorder_stop_playing(recorder);
    1.20      gmyth_recorder_finish_recording(recorder);
    1.21  }
    1.22  
    1.23 @@ -113,6 +119,10 @@
    1.24      encoder->recorder_num = num;
    1.25      encoder->hostname = g_string_new(hostname->str);
    1.26      encoder->port = port;
    1.27 +    
    1.28 +    encoder->mutex = g_mutex_new();
    1.29 +    
    1.30 +    encoder->progs_info_list = NULL;
    1.31  
    1.32      return encoder;
    1.33  }
    1.34 @@ -162,6 +172,8 @@
    1.35      gmyth_debug ("[%s] Spawntv with tvchain_id = %s", __FUNCTION__, tvchain_id->str);
    1.36  
    1.37      str_list = gmyth_string_list_new ();
    1.38 +    
    1.39 +    g_mutex_lock( recorder->mutex );
    1.40  
    1.41      g_string_append_printf ( tmp_str, " %d", recorder->recorder_num );
    1.42  
    1.43 @@ -190,6 +202,8 @@
    1.44      }
    1.45  
    1.46  cleanup:
    1.47 +    g_mutex_unlock( recorder->mutex );
    1.48 +    
    1.49      g_string_free (tmp_str, TRUE);
    1.50      g_object_unref (str_list);
    1.51  
    1.52 @@ -213,6 +227,8 @@
    1.53      gmyth_debug ("[%s] Spawntv, no TV chain!", __FUNCTION__);
    1.54  
    1.55      str_list = gmyth_string_list_new ();
    1.56 +    
    1.57 +    g_mutex_lock( recorder->mutex );
    1.58  
    1.59      g_string_append_printf ( tmp_str, " %d", recorder->recorder_num );
    1.60  
    1.61 @@ -237,7 +253,9 @@
    1.62          goto cleanup;
    1.63      }
    1.64  
    1.65 -cleanup:
    1.66 +cleanup:    
    1.67 +    g_mutex_unlock( recorder->mutex );
    1.68 +    
    1.69      g_string_free (tmp_str, TRUE);
    1.70      g_object_unref (str_list);
    1.71  
    1.72 @@ -258,6 +276,8 @@
    1.73      gmyth_debug ("[%s]", __FUNCTION__);
    1.74  
    1.75      str_list = gmyth_string_list_new ();
    1.76 +    
    1.77 +    g_mutex_lock( recorder->mutex );
    1.78  
    1.79      g_string_append_printf ( tmp_str, " %d", recorder->recorder_num );
    1.80  
    1.81 @@ -277,6 +297,7 @@
    1.82      }
    1.83  
    1.84  cleanup:
    1.85 +    g_mutex_unlock( recorder->mutex );
    1.86      g_string_free (tmp_str, TRUE);
    1.87      g_object_unref (str_list);
    1.88  
    1.89 @@ -298,6 +319,8 @@
    1.90      gmyth_debug ( "[%s] FRONTEND_READY with recorder id = %d", __FUNCTION__, recorder->recorder_num );
    1.91  
    1.92      str_list = gmyth_string_list_new ();
    1.93 +    
    1.94 +    g_mutex_lock( recorder->mutex );
    1.95  
    1.96      g_string_append_printf ( tmp_str, " %d", recorder->recorder_num );
    1.97  
    1.98 @@ -324,6 +347,7 @@
    1.99      }
   1.100  
   1.101  cleanup:
   1.102 +    g_mutex_unlock( recorder->mutex );
   1.103      g_string_free (tmp_str, TRUE);
   1.104      g_object_unref (str_list);
   1.105  
   1.106 @@ -347,6 +371,8 @@
   1.107      gmyth_debug ("[%s] CHECK_CHANNEL with channel = %s", __FUNCTION__, channel);
   1.108  
   1.109      str_list = gmyth_string_list_new ();
   1.110 +    
   1.111 +    g_mutex_lock( recorder->mutex );
   1.112  
   1.113      g_string_append_printf ( tmp_str, " %d", recorder->recorder_num );
   1.114  
   1.115 @@ -374,6 +400,7 @@
   1.116      }
   1.117  
   1.118  cleanup:
   1.119 +    g_mutex_unlock( recorder->mutex );
   1.120      g_string_free (tmp_str, TRUE);
   1.121      g_object_unref (str_list);
   1.122  
   1.123 @@ -409,6 +436,8 @@
   1.124      gmyth_debug ("[%s] SET_CHANNEL with channel = %d", __FUNCTION__, channel);
   1.125  
   1.126      str_list = gmyth_string_list_new ();
   1.127 +    
   1.128 +    g_mutex_lock( recorder->mutex );
   1.129  
   1.130      g_string_append_printf ( tmp_str, " %d", recorder->recorder_num );
   1.131  
   1.132 @@ -436,6 +465,7 @@
   1.133      }
   1.134  
   1.135  cleanup:
   1.136 +    g_mutex_unlock( recorder->mutex );
   1.137      g_string_free (tmp_str, TRUE);
   1.138      g_object_unref (str_list);
   1.139  
   1.140 @@ -459,6 +489,8 @@
   1.141      gmyth_debug ("[%s] SET_CHANNEL with channel name = %s", __FUNCTION__, channel);
   1.142  
   1.143      str_list = gmyth_string_list_new ();
   1.144 +    
   1.145 +    g_mutex_lock( recorder->mutex );
   1.146  
   1.147      g_string_append_printf ( tmp_str, " %d", recorder->recorder_num );
   1.148  
   1.149 @@ -485,6 +517,7 @@
   1.150      }
   1.151  
   1.152  cleanup:
   1.153 +    g_mutex_unlock( recorder->mutex );
   1.154      g_string_free (tmp_str, TRUE);
   1.155      g_object_unref (str_list);
   1.156  
   1.157 @@ -516,6 +549,8 @@
   1.158      gmyth_debug ("[%s] CHANGE_CHANNEL to the channel direction = %u", __FUNCTION__, direction);
   1.159  
   1.160      str_list = gmyth_string_list_new ();
   1.161 +    
   1.162 +    g_mutex_lock( recorder->mutex );
   1.163  
   1.164      g_string_append_printf ( tmp_str, " %d", recorder->recorder_num );
   1.165  
   1.166 @@ -542,6 +577,7 @@
   1.167      }
   1.168  
   1.169  cleanup:
   1.170 +    g_mutex_unlock( recorder->mutex );
   1.171      g_string_free (tmp_str, TRUE);
   1.172      g_object_unref (str_list);
   1.173  
   1.174 @@ -563,6 +599,8 @@
   1.175      gmyth_debug ("[%s] PAUSE", __FUNCTION__);
   1.176  
   1.177      str_list = gmyth_string_list_new ();
   1.178 +    
   1.179 +    g_mutex_lock( recorder->mutex );
   1.180  
   1.181      g_string_append_printf ( tmp_str, " %d", recorder->recorder_num );
   1.182  
   1.183 @@ -588,6 +626,7 @@
   1.184      }
   1.185  
   1.186  cleanup:
   1.187 +    g_mutex_unlock( recorder->mutex );
   1.188      g_string_free (tmp_str, TRUE);
   1.189      g_object_unref (str_list);
   1.190  
   1.191 @@ -597,8 +636,11 @@
   1.192  static gboolean 
   1.193  gmyth_recorder_find_if_program_exists( GMythRecorder* recorder, GMythProgramInfo* prog )
   1.194  {
   1.195 -    GSList *lst = NULL;
   1.196 -    for ( lst = recorder->progs_info_list; lst != NULL; lst = g_slist_next( lst ) )
   1.197 +    GList *lst = NULL;
   1.198 +    
   1.199 +    g_return_val_if_fail( recorder != NULL && recorder->progs_info_list != NULL, FALSE );
   1.200 +    
   1.201 +    for ( lst = recorder->progs_info_list; lst != NULL; lst = g_list_next( lst ) )
   1.202      {
   1.203          gmyth_debug ( "Got program info from list = [%s]", 
   1.204                  gmyth_program_info_to_string( (GMythProgramInfo*)lst->data ) );
   1.205 @@ -623,6 +665,8 @@
   1.206      GString *tmp_str = g_string_new( GMYTHTV_RECORDER_HEADER);
   1.207  
   1.208      str_list = gmyth_string_list_new();
   1.209 +    
   1.210 +    g_mutex_lock( recorder->mutex );
   1.211  
   1.212      g_string_append_printf( tmp_str, " %d", recorder->recorder_num);
   1.213  
   1.214 @@ -657,9 +701,10 @@
   1.215      }
   1.216      
   1.217      if ( !gmyth_recorder_find_if_program_exists( recorder, program_info ) )
   1.218 -        recorder->progs_info_list = g_slist_append( recorder->progs_info_list, 
   1.219 +        recorder->progs_info_list = g_list_append( recorder->progs_info_list, 
   1.220                                                      g_object_ref(program_info) );
   1.221  cleanup:
   1.222 +    g_mutex_unlock( recorder->mutex );
   1.223      g_string_free (tmp_str, TRUE);
   1.224      g_object_unref (str_list);
   1.225  
   1.226 @@ -686,6 +731,8 @@
   1.227      str_list = gmyth_string_list_new();
   1.228  
   1.229      /* g_string_append_printf ( tmp_str, " %d", recorder->recorder_num ); */
   1.230 +    
   1.231 +    g_mutex_lock( recorder->mutex );
   1.232  
   1.233      gmyth_string_list_append_string(str_list, tmp_str);
   1.234  
   1.235 @@ -725,6 +772,8 @@
   1.236      } else {
   1.237          gmyth_debug( "Cannot find a valuable recorder with the recorder ID number %d, backend server error!", rec_id );
   1.238      }
   1.239 +    
   1.240 +    g_mutex_unlock( recorder->mutex );
   1.241  
   1.242      g_object_unref(str_list);
   1.243  
   1.244 @@ -757,6 +806,8 @@
   1.245      actual_proginfo = gmyth_recorder_get_current_program_info(recorder);
   1.246  
   1.247      str_list = gmyth_string_list_new();
   1.248 +    
   1.249 +    g_mutex_lock( recorder->mutex );
   1.250  
   1.251      g_string_append_printf( tmp_str, " %d", recorder->recorder_num);
   1.252  
   1.253 @@ -819,8 +870,10 @@
   1.254  
   1.255      } /* if */
   1.256  
   1.257 -done: 
   1.258 -
   1.259 +done:
   1.260 +    
   1.261 +    g_mutex_unlock( recorder->mutex );
   1.262 +    
   1.263      g_object_unref(actual_proginfo);
   1.264      g_object_unref(str_list);
   1.265  
   1.266 @@ -845,6 +898,8 @@
   1.267      GString *query = g_string_new( GMYTHTV_RECORDER_HEADER);
   1.268  
   1.269      GMythStringList *str_list = gmyth_string_list_new();
   1.270 +    
   1.271 +    g_mutex_lock( recorder->mutex );
   1.272  
   1.273      g_string_append_printf( query, " %d", recorder->recorder_num);
   1.274  
   1.275 @@ -862,6 +917,8 @@
   1.276  #ifndef GMYTHTV_ENABLE_DEBUG
   1.277      g_print( "[%s] Got file position = %lld\n", __FUNCTION__, pos);
   1.278  #endif
   1.279 +    
   1.280 +    g_mutex_unlock( recorder->mutex );
   1.281  
   1.282      if (str_list!=NULL)
   1.283          g_object_unref(str_list);
   1.284 @@ -886,6 +943,8 @@
   1.285  
   1.286      GMythStringList *str_list = gmyth_string_list_new();
   1.287      GString *message = g_string_new("");
   1.288 +    
   1.289 +    g_mutex_lock( recorder->mutex );
   1.290  
   1.291      g_string_printf( message, "%s %d", GMYTHTV_RECORDER_HEADER,
   1.292              recorder->recorder_num);
   1.293 @@ -908,6 +967,8 @@
   1.294  
   1.295      gmyth_debug( "%s, stream is %s being recorded!\n", ret ? "YES" : "NO", ret ? "" : "NOT" );
   1.296      //g_static_mutex_unlock (&mutex);
   1.297 +    
   1.298 +    g_mutex_unlock( recorder->mutex );
   1.299  
   1.300      if ( str_list != NULL )
   1.301          g_object_unref (str_list);
   1.302 @@ -933,6 +994,8 @@
   1.303  
   1.304      GMythStringList *str_list = gmyth_string_list_new();
   1.305      GString *message = g_string_new("");
   1.306 +    
   1.307 +    g_mutex_lock( recorder->mutex );
   1.308  
   1.309      g_string_printf( message, "%s %d", GMYTHTV_RECORDER_HEADER,
   1.310              recorder->recorder_num);
   1.311 @@ -954,8 +1017,10 @@
   1.312          g_string_free (str, TRUE);
   1.313      }
   1.314  
   1.315 -    gmyth_debug( "%s, stream is %s being recorded!\n", ret ? "YES" : "NO", ret ? "" : "NOT" );
   1.316 +    gmyth_debug( "%s, stream is %s finished!\n", ret ? "YES" : "NO", ret ? "" : "NOT" );
   1.317      //g_static_mutex_unlock (&mutex);
   1.318 +    
   1.319 +    g_mutex_unlock( recorder->mutex );
   1.320  
   1.321      if ( str_list != NULL )
   1.322          g_object_unref (str_list);
   1.323 @@ -964,3 +1029,53 @@
   1.324  
   1.325      return ret;
   1.326  }
   1.327 +
   1.328 +
   1.329 +/**
   1.330 + * Stops playing the remote file.
   1.331 + * 
   1.332 + * @param recorder The GMythRecorder instance.
   1.333 + * 
   1.334 + * @return <code>true</code>, if the recording had been actually stopped.
   1.335 + */
   1.336 +gboolean
   1.337 +gmyth_recorder_stop_playing( GMythRecorder *recorder) {
   1.338 +    gboolean ret = TRUE;
   1.339 +
   1.340 +    g_return_val_if_fail( recorder != NULL, FALSE );
   1.341 +
   1.342 +    GMythStringList *str_list = gmyth_string_list_new();
   1.343 +    GString *message = g_string_new("");
   1.344 +    
   1.345 +    g_mutex_lock( recorder->mutex );
   1.346 +
   1.347 +    g_string_printf( message, "%s %d", GMYTHTV_RECORDER_HEADER,
   1.348 +            recorder->recorder_num);
   1.349 +    gmyth_string_list_append_string(str_list, message);
   1.350 +    gmyth_string_list_append_char_array(str_list, "STOP_PLAYING");
   1.351 +
   1.352 +    gmyth_socket_sendreceive_stringlist( recorder->myth_socket, str_list);
   1.353 +
   1.354 +    if ( str_list != NULL && gmyth_string_list_length(str_list)> 0) {
   1.355 +        GString *str=  NULL;
   1.356 +        if ( ( str = gmyth_string_list_get_string( str_list, 0 ) ) != NULL && 
   1.357 +                strcmp( str->str, "ok")!= 0) {
   1.358 +            gint is_rec = gmyth_string_list_get_int( str_list, 0);
   1.359 +            if ( is_rec != 0)
   1.360 +                ret = TRUE;
   1.361 +            else
   1.362 +                ret = FALSE;
   1.363 +        }
   1.364 +        g_string_free (str, TRUE);
   1.365 +    }
   1.366 +
   1.367 +    gmyth_debug( "%s, stream is %s stopped!\n", ret ? "YES" : "NO", ret ? "" : "NOT" );
   1.368 +    g_mutex_unlock ( recorder->mutex );
   1.369 +
   1.370 +    if ( str_list != NULL )
   1.371 +        g_object_unref (str_list);
   1.372 +    
   1.373 +    g_string_free (message, TRUE);
   1.374 +
   1.375 +    return ret;
   1.376 +}
     2.1 --- a/gmyth/src/gmyth_recorder.h	Tue Mar 27 16:45:00 2007 +0100
     2.2 +++ b/gmyth/src/gmyth_recorder.h	Tue Mar 27 20:27:51 2007 +0100
     2.3 @@ -75,7 +75,9 @@
     2.4      GString *hostname;
     2.5      gint port;
     2.6      
     2.7 -    GSList* progs_info_list;
     2.8 +    GList* progs_info_list;
     2.9 +    
    2.10 +    GMutex *mutex;
    2.11  };
    2.12  
    2.13  typedef enum _GMythRecorderChannelChangeDirection {
    2.14 @@ -140,6 +142,8 @@
    2.15  
    2.16  gboolean 	gmyth_recorder_finish_recording ( GMythRecorder *recorder );
    2.17  
    2.18 +gboolean    gmyth_recorder_stop_playing( GMythRecorder *recorder);
    2.19 +
    2.20  G_END_DECLS
    2.21  
    2.22  #endif /* __GMYTH_REMOTE_ENCODER_H__ */