maemo_input.c
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:6k
源码类别:

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2. * maemo_input.c : Input handling for the maemo plugin
  3. *****************************************************************************
  4. * Copyright (C) 2008 the VideoLAN team
  5. * $Id: de7ba9800d2b966133a546ac6ceb8eabeb3cce13 $
  6. *
  7. * Authors: Antoine Lejeune <phytos@videolan.org>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  22. *****************************************************************************/
  23. #ifdef HAVE_CONFIG_H
  24. # include "config.h"
  25. #endif
  26. #include <vlc_common.h>
  27. #include "maemo.h"
  28. #include "maemo_input.h"
  29. static int input_event_cb( vlc_object_t *p_this, const char *psz_var,
  30.                            vlc_value_t oldval, vlc_value_t newval, void *param );
  31. gboolean process_events( gpointer data )
  32. {
  33.     intf_thread_t *p_intf = (intf_thread_t *)data;
  34.     vlc_spin_lock( &p_intf->p_sys->event_lock );
  35.     int i_event = p_intf->p_sys->i_event;
  36.     p_intf->p_sys->i_event = 0;
  37.     vlc_spin_unlock( &p_intf->p_sys->event_lock );
  38.     if( i_event )
  39.     {
  40.         if( i_event & EVENT_PLAYLIST_CURRENT )
  41.             item_changed_pl( p_intf );
  42.         if( i_event & EVENT_ACTIVITY )
  43.             item_changed_pl( p_intf );
  44.         if( i_event & EVENT_ITEM_CHANGED )
  45.             item_changed( p_intf );
  46.         if( i_event & EVENT_INTF_CHANGED )
  47.             update_position( p_intf );
  48.     }
  49.     return TRUE;
  50. }
  51. void set_input( intf_thread_t *p_intf, input_thread_t *p_input )
  52. {
  53.     if( p_input && !( p_input->b_die || p_input->b_dead ) )
  54.     {
  55.         p_intf->p_sys->p_input = p_input;
  56.         vlc_object_hold( p_input );
  57.         var_AddCallback( p_input, "intf-event", input_event_cb, p_intf );
  58.         // "Activate" the seekbar
  59.         gtk_widget_set_sensitive( GTK_WIDGET( p_intf->p_sys->p_seekbar ), TRUE );
  60.     }
  61.     else
  62.         p_intf->p_sys->p_input = NULL;
  63. }
  64. void delete_input( intf_thread_t *p_intf )
  65. {
  66.     if( p_intf->p_sys->p_input )
  67.     {
  68.         var_DelCallback( p_intf->p_sys->p_input, "intf-event",
  69.                          input_event_cb, p_intf );
  70.         vlc_object_release( p_intf->p_sys->p_input );
  71.         p_intf->p_sys->p_input = NULL;
  72.         // Reset the seekbar
  73.         hildon_seekbar_set_position( p_intf->p_sys->p_seekbar, 0 );
  74.         gtk_widget_set_sensitive( GTK_WIDGET( p_intf->p_sys->p_seekbar ), FALSE );
  75.     }
  76. }
  77. void item_changed_pl( intf_thread_t *p_intf )
  78. {
  79.     if( p_intf->p_sys->p_input &&
  80.         ( p_intf->p_sys->p_input->b_dead || p_intf->p_sys->p_input->b_die ) )
  81.     {
  82.         delete_input( p_intf );
  83.         return;
  84.     }
  85.     if( !p_intf->p_sys->p_input )
  86.     {
  87.         set_input( p_intf, playlist_CurrentInput( p_intf->p_sys->p_playlist ) );
  88.     }
  89.     return;
  90. }
  91. int playlist_current_cb( vlc_object_t *p_this, const char *psz_var,
  92.                          vlc_value_t oldval, vlc_value_t newval, void *param )
  93. {
  94.     (void)p_this; (void)psz_var; (void)oldval; (void)newval;
  95.     intf_thread_t *p_intf = (intf_thread_t *)param;
  96.     vlc_spin_lock( &p_intf->p_sys->event_lock );
  97.     p_intf->p_sys->i_event |= EVENT_PLAYLIST_CURRENT;
  98.     vlc_spin_unlock( &p_intf->p_sys->event_lock );
  99.     return VLC_SUCCESS;
  100. }
  101. int activity_cb( vlc_object_t *p_this, const char *psz_var,
  102.                  vlc_value_t oldval, vlc_value_t newval, void *param )
  103. {
  104.     (void)p_this; (void)psz_var; (void)oldval; (void)newval;
  105.     intf_thread_t *p_intf = (intf_thread_t *)param;
  106.     vlc_spin_lock( &p_intf->p_sys->event_lock );
  107.     p_intf->p_sys->i_event |= EVENT_ACTIVITY;
  108.     vlc_spin_unlock( &p_intf->p_sys->event_lock );
  109.     return VLC_SUCCESS;
  110. }
  111. void item_changed( intf_thread_t *p_intf )
  112. {
  113.     GtkButton *p_button = GTK_BUTTON( p_intf->p_sys->p_play_button );
  114.     vlc_value_t state;
  115.     if( !p_intf->p_sys->p_input )
  116.         return;
  117.     var_Get( p_intf->p_sys->p_input, "state", &state );
  118.     // We change the "play" button
  119.     if( state.i_int == PLAYING_S )
  120.         gtk_button_set_image( p_button, gtk_image_new_from_stock( "vlc-pause",
  121.                               GTK_ICON_SIZE_BUTTON ) );
  122.     else
  123.         gtk_button_set_image( p_button, gtk_image_new_from_stock( "vlc-play",
  124.                               GTK_ICON_SIZE_BUTTON ) );
  125. }
  126. int item_changed_cb( vlc_object_t *p_this, const char *psz_var,
  127.                      vlc_value_t oldval, vlc_value_t newval, void *param )
  128. {
  129.     (void)p_this; (void)psz_var; (void)oldval; (void)newval;
  130.     intf_thread_t *p_intf = (intf_thread_t *)param;
  131.     vlc_spin_lock( &p_intf->p_sys->event_lock );
  132.     p_intf->p_sys->i_event |= EVENT_ITEM_CHANGED;
  133.     vlc_spin_unlock( &p_intf->p_sys->event_lock );
  134.     return VLC_SUCCESS;
  135. }
  136. void update_position( intf_thread_t *p_intf )
  137. {
  138.     if( p_intf->p_sys->p_input )
  139.     {
  140.         hildon_seekbar_set_total_time( p_intf->p_sys->p_seekbar,
  141.                     var_GetTime( p_intf->p_sys->p_input, "length" )/1000000 );
  142.         hildon_seekbar_set_position( p_intf->p_sys->p_seekbar,
  143.                     var_GetTime( p_intf->p_sys->p_input, "time" )/1000000 );
  144.     }
  145. }
  146. int interface_changed_cb( vlc_object_t *p_this, const char *psz_var,
  147.                           vlc_value_t oldval, vlc_value_t newval, void *param )
  148. {
  149.     (void)p_this; (void)psz_var; (void)oldval; (void)newval;
  150.     intf_thread_t *p_intf = (intf_thread_t *)param;
  151.     vlc_spin_lock( &p_intf->p_sys->event_lock );
  152.     p_intf->p_sys->i_event |= EVENT_INTF_CHANGED;
  153.     vlc_spin_unlock( &p_intf->p_sys->event_lock );
  154.     return VLC_SUCCESS;
  155. }
  156. static int input_event_cb( vlc_object_t *p_this, const char *psz_var,
  157.                            vlc_value_t oldval, vlc_value_t newval, void *param )
  158. {
  159.     if( newval.i_int == INPUT_EVENT_STATE )
  160.         return item_changed_cb( p_this, psz_var, oldval, newval, param );
  161.     else
  162.         return interface_changed_cb( p_this, psz_var, oldval, newval, param );
  163. }