Changeset 2dfa55bd53357dc8bfcb6c94ec9a204dc9d3fe65

Show
Ignore:
Timestamp:
20/12/06 23:11:54 (2 years ago)
Author:
Jean-Paul Saman <jpsaman@videolan.org>
git-committer:
Jean-Paul Saman <jpsaman@videolan.org> 1166652714 +0000
git-parent:

[b2009aee6f2c6892c3c48bd85a147ae1c1ba8ac0]

git-author:
Jean-Paul Saman <jpsaman@videolan.org> 1166652714 +0000
Message:

Audio track and channel support for JavaScript? API. The ActiveX vlc.audio.channel interface still has a bug left.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • activex/axvlc.idl

    rdc1ce79 r2dfa55b  
    206206        HRESULT track([in] long track); 
    207207 
    208         [propget, helpstring("Returns audio channel: reverse, stereo, left, right, dolby.")] 
     208        [propget, helpstring("Returns audio channel: reverse stereo, stereo, left, right, dolby.")] 
    209209        HRESULT channel([out, retval] BSTR* channel); 
    210         [propput, helpstring("Sets audio channel to: reverse, stereo, left, right, dolby.")] 
     210        [propput, helpstring("Sets audio channel to: reverse stereo, stereo, left, right, dolby.")] 
    211211        HRESULT channel([in] BSTR channel); 
    212212    }; 
  • activex/vlccontrol2.cpp

    rf386482 r2dfa55b  
    212212        libvlc_exception_init(&ex); 
    213213 
    214         *track = libvlc_audio_get_track(p_libvlc, &ex); 
     214        libvlc_input_t *p_input = libvlc_playlist_get_input(p_libvlc, &ex); 
     215        *track = libvlc_audio_get_track(p_input, &ex); 
     216        libvlc_input_free(p_input); 
    215217        if( libvlc_exception_raised(&ex) ) 
    216218        { 
     
    233235        libvlc_exception_init(&ex); 
    234236 
    235         libvlc_audio_set_track(p_libvlc, track, &ex); 
     237        libvlc_input_t *p_input = libvlc_playlist_get_input(p_libvlc, &ex); 
     238        libvlc_audio_set_track(p_input, track, &ex); 
     239        libvlc_input_free(p_input); 
    236240        if( libvlc_exception_raised(&ex) ) 
    237241        { 
     
    266270            *channel = BSTRFromCStr(CP_UTF8, psz_channel); 
    267271            free( psz_channel ); 
    268             return NOERROR; 
     272            psz_channel = NULL; 
     273            return (NULL == *channel) ? E_OUTOFMEMORY : NOERROR; 
    269274        } 
    270275        if( psz_channel ) free( psz_channel ); 
     276        psz_channel = NULL; 
    271277        _p_instance->setErrorInfo(IID_IVLCAudio, 
    272278                    libvlc_exception_get_message(&ex)); 
     
    298304 
    299305        libvlc_audio_set_channel(p_libvlc, psz_channel, &ex); 
    300  
    301306        CoTaskMemFree(psz_channel); 
    302307        if( libvlc_exception_raised(&ex) ) 
     
    20882093                    return E_OUTOFMEMORY; 
    20892094 
    2090                 *aspect = SysAllocStringByteLen(psz_aspect, strlen(psz_aspect)); 
     2095                *aspect = BSTRFromCStr(CP_UTF8, psz_aspect); 
    20912096                free( psz_aspect ); 
    20922097                psz_aspect = NULL; 
    2093                 return NOERROR; 
     2098                return (NULL == *aspect) ? E_OUTOFMEMORY : NOERROR; 
    20942099            } 
    20952100            if( psz_aspect ) free( psz_aspect ); 
     2101            psz_aspect = NULL; 
    20962102        } 
    20972103        _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex)); 
     
    24672473    return E_OUTOFMEMORY; 
    24682474}; 
    2469  
  • include/vlc/libvlc.h

    rb28e412 r2dfa55b  
    493493 
    494494/** 
    495  * Get current audio track 
    496  * \param p_instance libvlc instance 
    497  * \param p_exception an initialized exception 
    498  * \return the audio track (int) 
    499  */ 
    500 int libvlc_audio_get_track( libvlc_instance_t *, libvlc_exception_t * ); 
     495+ * Get current audio track 
     496+  * \param p_input input instance 
     497+ * \param p_exception an initialized exception 
     498+ * \return the audio track (int) 
     499+ */ 
     500int libvlc_audio_get_track( libvlc_input_t *, libvlc_exception_t * ); 
    501501 
    502502/** 
    503503 * Set current audio track 
    504  * \param p_instance libvlc instance 
     504 * \param p_input input instance 
    505505 * \param i_track the track (int) 
    506506 * \param p_exception an initialized exception 
    507507 * \return void 
    508508 */ 
    509 void libvlc_audio_set_track( libvlc_instance_t *, int, libvlc_exception_t * ); 
     509void libvlc_audio_set_track( libvlc_input_t *, int, libvlc_exception_t * ); 
    510510 
    511511/** 
    512512 * Get current audio channel 
    513  * \param p_instance libvlc instance 
     513 * \param p_instance input instance 
    514514 * \param p_exception an initialized exception 
    515515 * \return the audio channel (char *) 
     
    518518 
    519519/** 
    520  * Set current audio track 
    521  * \param p_instance libvlc instance 
     520 * Set current audio channel 
     521 * \param p_instance input instance 
    522522 * \param psz_channel the audio channel (char *) 
    523523 * \param p_exception an initialized exception 
  • mozilla/control/npolibvlc.cpp

    rdc1ce79 r2dfa55b  
    200200        libvlc_exception_init(&ex); 
    201201 
     202        libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex); 
     203        if( libvlc_exception_raised(&ex) ) 
     204        { 
     205            NPN_SetException(this, libvlc_exception_get_message(&ex)); 
     206            libvlc_exception_clear(&ex); 
     207            return INVOKERESULT_GENERIC_ERROR; 
     208        } 
     209 
    202210        switch( index ) 
    203211        { 
     
    205213            { 
    206214                vlc_bool_t muted = libvlc_audio_get_mute(p_plugin->getVLC(), &ex); 
     215                libvlc_input_free(p_input); 
    207216                if( libvlc_exception_raised(&ex) ) 
    208217                { 
     
    217226            { 
    218227                int volume = libvlc_audio_get_volume(p_plugin->getVLC(), &ex); 
     228                libvlc_input_free(p_input); 
    219229                if( libvlc_exception_raised(&ex) ) 
    220230                { 
     
    228238            case ID_audio_track: 
    229239            { 
    230                 int track = libvlc_audio_get_track(p_plugin->getVLC(), &ex); 
     240                int track = libvlc_audio_get_track(p_input, &ex); 
     241                libvlc_input_free(p_input); 
    231242                if( libvlc_exception_raised(&ex) ) 
    232243                { 
     
    240251            case ID_audio_channel: 
    241252            { 
    242                 char *channel = libvlc_audio_get_channel(p_plugin->getVLC(), &ex); 
    243                 if( libvlc_exception_raised(&ex) ) 
    244                 { 
    245                     NPN_SetException(this, libvlc_exception_get_message(&ex)); 
    246                     libvlc_exception_clear(&ex); 
    247                     return INVOKERESULT_GENERIC_ERROR; 
    248                 } 
    249                 if( channel ) 
    250                 { 
    251                     int len = strlen(channel); 
    252                     NPUTF8 *retval = (NPUTF8*)NPN_MemAlloc(len); 
    253                     if( retval ) 
    254                     { 
    255                         memcpy(retval, channel, len); 
    256                         STRINGN_TO_NPVARIANT(retval, len, result); 
    257                     } 
    258                     else 
    259                     { 
    260                         NULL_TO_NPVARIANT(result); 
    261                     } 
    262                     free( channel ); 
    263                     channel = NULL; 
    264                     return INVOKERESULT_NO_ERROR; 
    265                 } 
    266                 return INVOKERESULT_NO_SUCH_METHOD; 
     253                NPUTF8 *psz_channel = libvlc_audio_get_channel(p_plugin->getVLC(), &ex); 
     254                libvlc_input_free(p_input); 
     255                if( libvlc_exception_raised(&ex) ) 
     256                { 
     257                    NPN_SetException(this, libvlc_exception_get_message(&ex)); 
     258                    libvlc_exception_clear(&ex); 
     259                    return INVOKERESULT_GENERIC_ERROR; 
     260                } 
     261                if( !psz_channel ) 
     262                    return INVOKERESULT_GENERIC_ERROR; 
     263 
     264                STRINGZ_TO_NPVARIANT(psz_channel, result); 
     265                return INVOKERESULT_NO_ERROR; 
    267266            } 
    268267            default: 
    269268                ; 
    270269        } 
     270        libvlc_input_free(p_input); 
    271271    } 
    272272    return INVOKERESULT_GENERIC_ERROR; 
     
    281281        libvlc_exception_init(&ex); 
    282282 
     283        libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex); 
     284        if( libvlc_exception_raised(&ex) ) 
     285        { 
     286            NPN_SetException(this, libvlc_exception_get_message(&ex)); 
     287            libvlc_exception_clear(&ex); 
     288            return INVOKERESULT_GENERIC_ERROR; 
     289        } 
     290 
    283291        switch( index ) 
    284292        { 
     
    288296                    libvlc_audio_set_mute(p_plugin->getVLC(), 
    289297                                          NPVARIANT_TO_BOOLEAN(value), &ex); 
     298                    libvlc_input_free(p_input); 
    290299                    if( libvlc_exception_raised(&ex) ) 
    291300                    { 
     
    298307                return INVOKERESULT_INVALID_VALUE; 
    299308            case ID_audio_volume: 
     309                libvlc_input_free(p_input); 
    300310                if( isNumberValue(value) ) 
    301311                { 
     
    314324                if( isNumberValue(value) ) 
    315325                { 
    316                     libvlc_audio_set_track(p_plugin->getVLC()
     326                    libvlc_audio_set_track(p_input
    317327                                           numberValue(value), &ex); 
     328                    libvlc_input_free(p_input); 
    318329                    if( libvlc_exception_raised(&ex) ) 
    319330                    { 
     
    324335                    return INVOKERESULT_NO_ERROR; 
    325336                } 
     337                libvlc_input_free(p_input); 
    326338                return INVOKERESULT_INVALID_VALUE; 
    327339            case ID_audio_channel: 
     
    329341                char *psz_channel = NULL; 
    330342 
     343                libvlc_input_free(p_input); 
    331344                if( ! NPVARIANT_IS_STRING(value) ) 
    332                 { 
    333345                    return INVOKERESULT_INVALID_VALUE; 
    334                 } 
    335346 
    336347                psz_channel = stringValue(NPVARIANT_TO_STRING(value)); 
     
    353364                ; 
    354365        } 
     366        libvlc_input_free(p_input); 
    355367    } 
    356368    return INVOKERESULT_GENERIC_ERROR; 
     
    19011913                psz_aspect = stringValue(NPVARIANT_TO_STRING(value)); 
    19021914                if( !psz_aspect ) 
    1903                     return INVOKERESULT_GENERIC_ERROR; 
     1915                { 
     1916                    libvlc_input_free(p_input); 
     1917                    return INVOKERESULT_GENERIC_ERROR; 
     1918                } 
    19041919 
    19051920                libvlc_video_set_aspect_ratio(p_input, psz_aspect, &ex); 
  • mozilla/control/npolibvlc.h

    rec07766 r2dfa55b  
    8181    LibvlcInputNPObject(NPP instance, const NPClass *aClass) : 
    8282        RuntimeNPObject(instance, aClass) {}; 
    83          
     83 
    8484    virtual ~LibvlcInputNPObject() {}; 
    8585 
     
    107107    LibvlcMessageNPObject(NPP instance, const NPClass *aClass) : 
    108108        RuntimeNPObject(instance, aClass) {}; 
    109          
     109 
    110110    virtual ~LibvlcMessageNPObject() {}; 
    111111 
     
    153153    LibvlcMessagesNPObject(NPP instance, const NPClass *aClass) : 
    154154        RuntimeNPObject(instance, aClass) {}; 
    155          
     155 
    156156    virtual ~LibvlcMessagesNPObject() {}; 
    157157 
  • src/control/audio.c

    rd9d80e1 r2dfa55b  
    2626#include <vlc/libvlc.h> 
    2727 
     28#include <vlc_input.h> 
    2829#include <vlc_aout.h> 
     30 
     31/* 
     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 *GetInput( libvlc_input_t *p_input, 
     36                                 libvlc_exception_t *p_exception ) 
     37{ 
     38    input_thread_t *p_input_thread = NULL; 
     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/* 
     59 * Remember to release the returned aout_instance_t since it is locked at 
     60 * the end of this function. 
     61 */ 
     62static aout_instance_t *GetAOut( libvlc_instance_t *p_instance, 
     63                                 libvlc_exception_t *p_exception ) 
     64{ 
     65    aout_instance_t * p_aout = NULL; 
     66 
     67    p_aout = vlc_object_find( p_instance->p_libvlc_int, VLC_OBJECT_AOUT, FIND_CHILD ); 
     68    if( !p_aout ) 
     69    { 
     70        libvlc_exception_raise( p_exception, "No active audio output" ); 
     71        return NULL; 
     72    } 
     73 
     74    return p_aout; 
     75} 
     76 
    2977 
    3078/***************************************************************************** 
     
    95143 * libvlc_audio_get_track : Get the current audio track 
    96144 *****************************************************************************/ 
    97 int libvlc_audio_get_track( libvlc_instance_t *p_instance
     145int libvlc_audio_get_track( libvlc_input_t *p_input
    98146                            libvlc_exception_t *p_e ) 
    99147{ 
     148    input_thread_t *p_input_thread = GetInput( p_input, p_e ); 
    100149    int i_track = 0; 
    101150 
    102     i_track = var_GetInteger( p_instance->p_libvlc_int, "audio-track" ); 
     151    i_track = var_GetInteger( p_input_thread, "audio-es" ); 
     152    vlc_object_release( p_input_thread ); 
    103153 
    104154    return i_track; 
     
    108158 * libvlc_audio_set_track : Set the current audio track 
    109159 *****************************************************************************/ 
    110 void libvlc_audio_set_track( libvlc_instance_t *p_instance, int i_track, 
     160void libvlc_audio_set_track( libvlc_input_t *p_input, int i_track, 
    111161                             libvlc_exception_t *p_e ) 
    112162{ 
     163    input_thread_t *p_input_thread = GetInput( p_input, p_e ); 
     164    vlc_value_t val_list; 
    113165    int i_ret = -1; 
    114  
    115     i_ret = var_SetInteger( p_instance->p_libvlc_int, "audio-track", i_track ); 
    116  
    117     if( i_ret < 0 ) 
    118     { 
    119         libvlc_exception_raise( p_e, "Setting audio track failed" ); 
    120     } 
     166    int i; 
     167 
     168    var_Change( p_input_thread, "audio-es", VLC_VAR_GETCHOICES, &val_list, NULL ); 
     169    for( i = 0; i < val_list.p_list->i_count; i++ ) 
     170    { 
     171        vlc_value_t val = val_list.p_list->p_values[i]; 
     172        if( i_track == val.i_int ) 
     173        { 
     174            i_ret = var_SetInteger( p_input_thread, "audio-es", i_track ); 
     175            if( i_ret < 0 ) 
     176            { 
     177                libvlc_exception_raise( p_e, "Setting audio track failed" ); 
     178            } 
     179            vlc_object_release( p_input_thread ); 
     180            return; 
     181        } 
     182    } 
     183    libvlc_exception_raise( p_e, "Audio track out of range" ); 
     184    vlc_object_release( p_input_thread ); 
    121185} 
    122186 
     
    127191                                libvlc_exception_t *p_e ) 
    128192{ 
     193    aout_instance_t *p_aout = GetAOut( p_instance, p_e ); 
    129194    char *psz_channel = NULL; 
    130     int i_channel = 0
    131  
    132     i_channel = var_GetInteger( p_instance->p_libvlc_int, "audio-channel" ); 
    133     switch( i_channel
     195    vlc_value_t val
     196 
     197    var_Get( p_aout, "audio-channels", &val ); 
     198    switch( val.i_int
    134199    { 
    135200        case AOUT_VAR_CHAN_RSTEREO: 
    136             psz_channel = strdup("reverse"); 
     201            psz_channel = strdup("reverse stereo"); 
    137202            break; 
    138203        case AOUT_VAR_CHAN_STEREO: 
     
    152217            break; 
    153218    } 
     219    vlc_object_release( p_aout ); 
    154220    return psz_channel; 
    155221} 
     
    161227                               libvlc_exception_t *p_e ) 
    162228{ 
    163     int i_ret = -1; 
    164     int i_channel = 0; 
    165  
    166     if( !psz_channel ) 
    167     { 
    168         libvlc_exception_raise( p_e, "Audio track out of range" ); 
    169     } 
    170     else 
    171     { 
    172         if( strncmp( psz_channel, "reverse", 7 ) == 0 ) 
    173             i_channel = AOUT_VAR_CHAN_RSTEREO; 
    174         else if( strncmp( psz_channel, "stereo", 6 ) == 0 ) 
    175             i_channel = AOUT_VAR_CHAN_STEREO; 
    176         else if( strncmp( psz_channel, "left", 4 ) == 0 ) 
    177             i_channel = AOUT_VAR_CHAN_LEFT; 
    178         else if( strncmp( psz_channel, "right", 5 ) == 0 ) 
    179             i_channel = AOUT_VAR_CHAN_RIGHT; 
    180         else if( strncmp( psz_channel, "dolby", 5 ) == 0 ) 
    181             i_channel = AOUT_VAR_CHAN_DOLBYS; 
    182  
    183         i_ret = var_SetInteger( p_instance->p_libvlc_int, "audio-channel", i_channel ); 
    184         if( i_ret < 0 ) 
     229    aout_instance_t *p_aout = GetAOut( p_instance, p_e ); 
     230    vlc_value_t val_list, text_list; 
     231    int i_ret = -1, i; 
     232 
     233    i_ret = var_Change( p_aout, "audio-channels", VLC_VAR_GETCHOICES, &val_list, &text_list ); 
     234    if( (i_ret < 0) || !psz_channel ) 
     235    { 
     236        libvlc_exception_raise( p_e, "Audio channel out of range" ); 
     237        vlc_object_release( p_aout ); 
     238        return; 
     239    } 
     240 
     241    for( i = 0; i < val_list.p_list->i_count; i++ ) 
     242    { 
     243        vlc_value_t val = val_list.p_list->p_values[i]; 
     244        vlc_value_t text = text_list.p_list->p_values[i]; 
     245 
     246        if( strncasecmp( psz_channel, text.psz_string, strlen(text.psz_string) ) == 0 ) 
    185247        { 
    186             libvlc_exception_raise( p_e, "Audio track out of range" ); 
     248            i_ret = var_Set( p_aout, "audio-channels", val ); 
     249            if( i_ret < 0 ) 
     250            { 
     251                break; 
     252            } 
    187253        } 
    188254    } 
    189 
     255    libvlc_exception_raise( p_e, "Audio channel out of range" ); 
     256    vlc_object_release( p_aout ); 
     257
     258 
  • src/control/video.c

    ra10792f r2dfa55b  
    201201    { 
    202202        if ( strcmp( "No active video output", libvlc_exception_get_message( p_e ) ) == 0 ) 
    203    
    204        libvlc_exception_clear( p_e ); 
    205    
    206    return VLC_FALSE; 
     203       
     204            libvlc_exception_clear( p_e ); 
     205       
     206        return VLC_FALSE; 
    207207    } 
    208208 
     
    222222        return 0; 
    223223    } 
    224      
     224 
    225225    vout_Control( p_vout , VOUT_REPARENT, d); 
    226226    vlc_object_release( p_vout );