Changeset f57e6b34ac3071db72254470076c150d73356999

Show
Ignore:
Timestamp:
05/03/07 16:30:29 (2 years ago)
Author:
Damien Fouilleul <damienf@videolan.org>
git-committer:
Damien Fouilleul <damienf@videolan.org> 1173108629 +0000
git-parent:

[0832b7e2168d2b76acba61ce870eaced4cd1396a]

git-author:
Damien Fouilleul <damienf@videolan.org> 1173108629 +0000
Message:

- control/video.c: clean up and more error/exception checks

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/control/video.c

    r63f5561 rf57e6b3  
    3030 
    3131/* 
     32 * Remember to release the returned input_thread_t since it is locked at 
     33 * the end of this function. 
     34 */ 
     35static input_thread_t *GetInputThread( libvlc_input_t *p_input, 
     36                               libvlc_exception_t *p_exception ) 
     37{ 
     38    input_thread_t *p_input_thread; 
     39 
     40    if( !p_input ) 
     41    { 
     42        libvlc_exception_raise( p_exception, "Input is NULL" ); 
     43        return NULL; 
     44    } 
     45 
     46    p_input_thread = (input_thread_t*)vlc_object_get( 
     47                                 p_input->p_instance->p_libvlc_int, 
     48                                 p_input->i_input_id ); 
     49    if( !p_input_thread ) 
     50    { 
     51        libvlc_exception_raise( p_exception, "Input does not exist" ); 
     52        return NULL; 
     53    } 
     54 
     55    return p_input_thread;; 
     56} 
     57 
     58/* 
    3259 * Remember to release the returned vout_thread_t since it is locked at 
    3360 * the end of this function. 
     
    3663                               libvlc_exception_t *p_exception ) 
    3764{ 
     65    input_thread_t *p_input_thread = GetInputThread(p_input, p_exception); 
     66    vout_thread_t *p_vout = NULL; 
     67 
     68    if( p_input_thread ) 
     69    { 
     70        p_vout = vlc_object_find( p_input_thread, VLC_OBJECT_VOUT, FIND_CHILD ); 
     71        if( !p_vout ) 
     72        { 
     73            libvlc_exception_raise( p_exception, "No active video output" ); 
     74        } 
     75        vlc_object_release( p_input_thread ); 
     76    } 
     77    return p_vout; 
     78} 
     79 
     80/********************************************************************** 
     81 * Exported functions 
     82 **********************************************************************/ 
     83 
     84void libvlc_set_fullscreen( libvlc_input_t *p_input, int b_fullscreen, 
     85                            libvlc_exception_t *p_e ) 
     86{ 
     87    /* We only work on the first vout */ 
     88    vout_thread_t *p_vout1 = GetVout( p_input, p_e ); 
     89    vlc_value_t val; int i_ret; 
     90 
     91    /* GetVout will raise the exception for us */ 
     92    if( !p_vout1 ) 
     93    { 
     94        return; 
     95    } 
     96 
     97    if( b_fullscreen ) val.b_bool = VLC_TRUE; 
     98    else               val.b_bool = VLC_FALSE; 
     99 
     100    i_ret = var_Set( p_vout1, "fullscreen", val ); 
     101    if( i_ret ) 
     102        libvlc_exception_raise( p_e, 
     103                        "Unexpected error while setting fullscreen value" ); 
     104 
     105    vlc_object_release( p_vout1 ); 
     106} 
     107 
     108int libvlc_get_fullscreen( libvlc_input_t *p_input, 
     109                            libvlc_exception_t *p_e ) 
     110{ 
     111    /* We only work on the first vout */ 
     112    vout_thread_t *p_vout1 = GetVout( p_input, p_e ); 
     113    vlc_value_t val; int i_ret; 
     114 
     115    /* GetVout will raise the exception for us */ 
     116    if( !p_vout1 ) 
     117        return 0; 
     118 
     119    i_ret = var_Get( p_vout1, "fullscreen", &val ); 
     120    if( i_ret ) 
     121        libvlc_exception_raise( p_e, 
     122                        "Unexpected error while looking up fullscreen value" ); 
     123 
     124    return val.b_bool == VLC_TRUE ? 1 : 0; 
     125} 
     126 
     127void libvlc_toggle_fullscreen( libvlc_input_t *p_input, 
     128                               libvlc_exception_t *p_e ) 
     129{ 
     130    /* We only work on the first vout */ 
     131    vout_thread_t *p_vout1 = GetVout( p_input, p_e ); 
     132    vlc_value_t val; int i_ret; 
     133 
     134    /* GetVout will raise the exception for us */ 
     135    if( !p_vout1 ) 
     136        return; 
     137 
     138    i_ret = var_Get( p_vout1, "fullscreen", &val ); 
     139    if( i_ret ) 
     140        libvlc_exception_raise( p_e, 
     141                        "Unexpected error while looking up fullscreen value" ); 
     142 
     143    val.b_bool = !val.b_bool; 
     144    i_ret = var_Set( p_vout1, "fullscreen", val ); 
     145    if( i_ret ) 
     146        libvlc_exception_raise( p_e, 
     147                        "Unexpected error while setting fullscreen value" ); 
     148 
     149    vlc_object_release( p_vout1 ); 
     150} 
     151 
     152void 
     153libvlc_video_take_snapshot( libvlc_input_t *p_input, char *psz_filepath, 
     154                       libvlc_exception_t *p_e ) 
     155{ 
     156    vout_thread_t *p_vout = GetVout( p_input, p_e ); 
    38157    input_thread_t *p_input_thread; 
    39     vout_thread_t *p_vout; 
    40  
    41     if( !p_input ) 
    42     { 
    43         libvlc_exception_raise( p_exception, "Input is NULL" ); 
    44         return NULL; 
     158 
     159    char path[256]; 
     160 
     161    /* GetVout will raise the exception for us */ 
     162    if( !p_vout ) 
     163    { 
     164        return; 
    45165    } 
    46166 
     
    50170    if( !p_input_thread ) 
    51171    { 
    52         libvlc_exception_raise( p_exception, "Input does not exist" ); 
    53         return NULL; 
    54     } 
    55  
    56     p_vout = vlc_object_find( p_input_thread, VLC_OBJECT_VOUT, FIND_CHILD ); 
    57     if( !p_vout ) 
    58     { 
    59         vlc_object_release( p_input_thread ); 
    60         libvlc_exception_raise( p_exception, "No active video output" ); 
    61         return NULL; 
    62     } 
    63     vlc_object_release( p_input_thread ); 
    64  
    65     return p_vout; 
    66 } 
    67 /********************************************************************** 
    68  * Exported functions 
    69  **********************************************************************/ 
    70  
    71 void libvlc_set_fullscreen( libvlc_input_t *p_input, int b_fullscreen, 
    72                             libvlc_exception_t *p_e ) 
    73 { 
    74     /* We only work on the first vout */ 
    75     vout_thread_t *p_vout1 = GetVout( p_input, p_e ); 
    76     vlc_value_t val; int i_ret; 
    77  
    78     /* GetVout will raise the exception for us */ 
    79     if( !p_vout1 ) 
    80     { 
    81         return; 
    82     } 
    83  
    84     if( b_fullscreen ) val.b_bool = VLC_TRUE; 
    85     else               val.b_bool = VLC_FALSE; 
    86  
    87     i_ret = var_Set( p_vout1, "fullscreen", val ); 
    88     if( i_ret ) 
    89         libvlc_exception_raise( p_e, 
    90                         "Unexpected error while setting fullscreen value" ); 
    91  
    92     vlc_object_release( p_vout1 ); 
    93 } 
    94  
    95 int libvlc_get_fullscreen( libvlc_input_t *p_input, 
    96                             libvlc_exception_t *p_e ) 
    97 { 
    98     /* We only work on the first vout */ 
    99     vout_thread_t *p_vout1 = GetVout( p_input, p_e ); 
    100     vlc_value_t val; int i_ret; 
    101  
    102     /* GetVout will raise the exception for us */ 
    103     if( !p_vout1 ) 
    104         return 0; 
    105  
    106     i_ret = var_Get( p_vout1, "fullscreen", &val ); 
    107     if( i_ret ) 
    108         libvlc_exception_raise( p_e, 
    109                         "Unexpected error while looking up fullscreen value" ); 
    110  
    111     return val.b_bool == VLC_TRUE ? 1 : 0; 
    112 } 
    113  
    114 void libvlc_toggle_fullscreen( libvlc_input_t *p_input, 
    115                                libvlc_exception_t *p_e ) 
    116 { 
    117     /* We only work on the first vout */ 
    118     vout_thread_t *p_vout1 = GetVout( p_input, p_e ); 
    119     vlc_value_t val; int i_ret; 
    120  
    121     /* GetVout will raise the exception for us */ 
    122     if( !p_vout1 ) 
    123         return; 
    124  
    125     i_ret = var_Get( p_vout1, "fullscreen", &val ); 
    126     if( i_ret ) 
    127         libvlc_exception_raise( p_e, 
    128                         "Unexpected error while looking up fullscreen value" ); 
    129  
    130     val.b_bool = !val.b_bool; 
    131     i_ret = var_Set( p_vout1, "fullscreen", val ); 
    132     if( i_ret ) 
    133         libvlc_exception_raise( p_e, 
    134                         "Unexpected error while setting fullscreen value" ); 
    135  
    136     vlc_object_release( p_vout1 ); 
    137 } 
    138  
    139 void 
    140 libvlc_video_take_snapshot( libvlc_input_t *p_input, char *psz_filepath, 
    141                        libvlc_exception_t *p_e ) 
    142 { 
    143     vout_thread_t *p_vout = GetVout( p_input, p_e ); 
    144     input_thread_t *p_input_thread; 
    145  
    146     char path[256]; 
    147  
    148     /* GetVout will raise the exception for us */ 
    149     if( !p_vout ) 
    150     { 
    151         return; 
    152     } 
    153  
    154     p_input_thread = (input_thread_t*)vlc_object_get( 
    155                                  p_input->p_instance->p_libvlc_int, 
    156                                  p_input->i_input_id ); 
    157     if( !p_input_thread ) 
    158     { 
    159172        libvlc_exception_raise( p_e, "Input does not exist" ); 
    160173        return; 
     
    197210                                  libvlc_exception_t *p_e ) 
    198211{ 
    199     vout_thread_t *p_vout = GetVout( p_input, p_e ); 
    200     if ( NULL == p_vout ) 
    201     { 
    202         if ( libvlc_exception_raised( p_e ) 
    203          &&  strcmp( "No active video output", libvlc_exception_get_message( p_e ) ) == 0 ) 
     212    input_thread_t *p_input_thread = GetInputThread(p_input, p_e); 
     213    vlc_bool_t has_vout = VLC_FALSE; 
     214 
     215    if( p_input_thread ) 
     216    { 
     217        vout_thread_t *p_vout; 
     218 
     219        p_vout = vlc_object_find( p_input_thread, VLC_OBJECT_VOUT, FIND_CHILD ); 
     220        if( p_vout ) 
    204221        { 
    205             libvlc_exception_clear( p_e ); 
     222            has_vout = VLC_TRUE; 
     223            vlc_object_release( p_vout ); 
    206224        } 
    207         return VLC_FALSE; 
    208     } 
    209  
    210     vlc_object_release( p_vout ); 
    211  
    212     return VLC_TRUE; 
     225        vlc_object_release( p_input_thread ); 
     226    } 
     227    return has_vout; 
    213228} 
    214229 
     
    218233    vout_thread_t *p_vout = GetVout( p_input, p_e ); 
    219234 
    220     if ( p_vout == NULL) 
    221     { 
    222         /// \todo: set exception 
    223         return 0; 
    224     } 
    225  
    226     vout_Control( p_vout , VOUT_REPARENT, d); 
    227     vlc_object_release( p_vout ); 
    228  
     235    if( p_vout ) 
     236    { 
     237        vout_Control( p_vout , VOUT_REPARENT, d); 
     238        vlc_object_release( p_vout ); 
     239    } 
    229240    return 0; 
    230241} 
     
    233244{ 
    234245    vout_thread_t *p_vout = GetVout( p_input, p_e ); 
    235     vout_Control( p_vout, VOUT_SET_SIZE, width, height ); 
    236     vlc_object_release( p_vout ); 
     246    if( p_vout ) 
     247    { 
     248        vout_Control( p_vout, VOUT_SET_SIZE, width, height ); 
     249        vlc_object_release( p_vout ); 
     250    } 
    237251} 
    238252