]> git.sesse.net Git - vlc/blobdiff - activex/vlccontrol2.cpp
Fix SRTP Roll-Over-Counter handling
[vlc] / activex / vlccontrol2.cpp
index addee00639ffbb863cacbc881810dfcb5e8c4902..9cf4930ba84777b81a9fc8a4a5d63048bacd1b75 100644 (file)
@@ -211,7 +211,9 @@ STDMETHODIMP VLCAudio::get_track(long* track)
         libvlc_exception_t ex;
         libvlc_exception_init(&ex);
 
-        *track = libvlc_audio_get_track(p_libvlc, &ex);
+        libvlc_input_t *p_input = libvlc_playlist_get_input(p_libvlc, &ex);
+        *track = libvlc_audio_get_track(p_input, &ex);
+        libvlc_input_free(p_input);
         if( libvlc_exception_raised(&ex) )
         {
             _p_instance->setErrorInfo(IID_IVLCAudio, libvlc_exception_get_message(&ex));
@@ -232,7 +234,9 @@ STDMETHODIMP VLCAudio::put_track(long track)
         libvlc_exception_t ex;
         libvlc_exception_init(&ex);
 
-        libvlc_audio_set_track(p_libvlc, track, &ex);
+        libvlc_input_t *p_input = libvlc_playlist_get_input(p_libvlc, &ex);
+        libvlc_audio_set_track(p_input, track, &ex);
+        libvlc_input_free(p_input);
         if( libvlc_exception_raised(&ex) )
         {
             _p_instance->setErrorInfo(IID_IVLCAudio, libvlc_exception_get_message(&ex));
@@ -244,7 +248,7 @@ STDMETHODIMP VLCAudio::put_track(long track)
     return hr;
 };
 
-STDMETHODIMP VLCAudio::get_channel(BSTR *channel)
+STDMETHODIMP VLCAudio::get_channel(long *channel)
 {
     if( NULL == channel )
         return E_POINTER;
@@ -253,53 +257,32 @@ STDMETHODIMP VLCAudio::get_channel(BSTR *channel)
     HRESULT hr = _p_instance->getVLC(&p_libvlc);
     if( SUCCEEDED(hr) )
     {
-        char *psz_channel = NULL;
         libvlc_exception_t ex;
         libvlc_exception_init(&ex);
 
-        psz_channel = libvlc_audio_get_channel(p_libvlc, &ex);
-        if( libvlc_exception_raised(&ex) )
+        *channel = libvlc_audio_get_channel(p_libvlc, &ex);
+        if( libvlc_exception_raised(&ex) )
         {
-            if( NULL == psz_channel )
-                return E_OUTOFMEMORY;
-
-            *channel = SysAllocStringByteLen(psz_channel, strlen(psz_channel));
-            free( psz_channel );
-            psz_channel = NULL;
-            return NOERROR;
+            _p_instance->setErrorInfo(IID_IVLCAudio,
+                        libvlc_exception_get_message(&ex));
+            libvlc_exception_clear(&ex);
+            return E_FAIL;
         }
-        if( psz_channel ) free( psz_channel );
-        _p_instance->setErrorInfo(IID_IVLCAudio,
-                    libvlc_exception_get_message(&ex));
-        libvlc_exception_clear(&ex);
-        return E_FAIL;
+        return NOERROR;
     }
     return hr;
 };
 
-STDMETHODIMP VLCAudio::put_channel(BSTR channel)
+STDMETHODIMP VLCAudio::put_channel(long channel)
 {
-    if( NULL == channel )
-        return E_POINTER;
-
-    if( 0 == SysStringLen(channel) )
-        return E_INVALIDARG;
-
     libvlc_instance_t* p_libvlc;
     HRESULT hr = _p_instance->getVLC(&p_libvlc);
     if( SUCCEEDED(hr) )
     {
-        char *psz_channel = NULL;
         libvlc_exception_t ex;
         libvlc_exception_init(&ex);
 
-        psz_channel = CStrFromBSTR(CP_UTF8, channel);
-        if( NULL == psz_channel )
-            return E_OUTOFMEMORY;
-
-        libvlc_audio_set_channel(p_libvlc, psz_channel, &ex);
-
-        CoTaskMemFree(psz_channel);
+        libvlc_audio_set_channel(p_libvlc, channel, &ex);
         if( libvlc_exception_raised(&ex) )
         {
             _p_instance->setErrorInfo(IID_IVLCAudio,
@@ -870,6 +853,89 @@ STDMETHODIMP VLCLog::put_verbosity(long verbosity)
 
 /*******************************************************************************/
 
+/* STL forward iterator used by VLCEnumIterator class to implement IEnumVARIANT */
+
+class VLCMessageSTLIterator
+{
+
+public:
+
+    VLCMessageSTLIterator(IVLCMessageIterator* iter) : iter(iter), msg(NULL)
+    {
+        // get first message
+        operator++();
+    };
+
+    VLCMessageSTLIterator(const VLCMessageSTLIterator& other)
+    {
+        iter = other.iter;
+        if( iter )
+            iter->AddRef();
+        msg = other.msg;
+        if( msg )
+            msg->AddRef();
+    };
+
+    virtual ~VLCMessageSTLIterator()
+    {
+        if( msg )
+            msg->Release();
+
+        if( iter )
+            iter->Release();
+    };
+
+    // we only need prefix ++ operator
+    VLCMessageSTLIterator& operator++()
+    {
+        VARIANT_BOOL hasNext = VARIANT_FALSE;
+        if( iter )
+        {
+            iter->get_hasNext(&hasNext);
+
+            if( msg )
+            {
+                msg->Release();
+                msg = NULL;
+            }
+            if( VARIANT_TRUE == hasNext ) {
+                iter->next(&msg);
+            }
+        }
+        return *this;
+    };
+
+    VARIANT operator*() const
+    {
+        VARIANT v;
+        VariantInit(&v);
+        if( msg )
+        {
+            if( SUCCEEDED(msg->QueryInterface(IID_IDispatch, (LPVOID*)&V_DISPATCH(&v))) )
+            {
+                V_VT(&v) = VT_DISPATCH;
+            }
+        }
+        return v;
+    };
+
+    bool operator==(const VLCMessageSTLIterator& other) const
+    {
+        return msg == other.msg;
+    };
+
+    bool operator!=(const VLCMessageSTLIterator& other) const
+    {
+        return msg != other.msg;
+    };
+
+private:
+    IVLCMessageIterator* iter;
+    IVLCMessage*         msg;
+};
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
 VLCMessages::~VLCMessages()
 {
     if( _p_typeinfo )
@@ -952,9 +1018,16 @@ STDMETHODIMP VLCMessages::get__NewEnum(LPUNKNOWN* _NewEnum)
     if( NULL == _NewEnum )
         return E_POINTER;
 
-    // TODO
-    *_NewEnum = NULL;
-    return E_NOTIMPL;
+    IVLCMessageIterator* iter = NULL;
+    iterator(&iter);
+
+    *_NewEnum= new VLCEnumIterator<IID_IEnumVARIANT,
+                       IEnumVARIANT,
+                       VARIANT,
+                       VLCMessageSTLIterator>
+                       (VLCMessageSTLIterator(iter), VLCMessageSTLIterator(NULL));
+
+    return *_NewEnum ? S_OK : E_OUTOFMEMORY;
 };
 
 STDMETHODIMP VLCMessages::clear()
@@ -1663,11 +1736,11 @@ STDMETHODIMP VLCPlaylist::add(BSTR uri, VARIANT name, VARIANT options, long* ite
         }
 
         *item = libvlc_playlist_add_extended(p_libvlc,
-            psz_uri,
-            psz_name,
-            i_options,
-            const_cast<const char **>(ppsz_options),
-            &ex);
+                    psz_uri,
+                    psz_name,
+                    i_options,
+                    const_cast<const char **>(ppsz_options),
+                    &ex);
 
         VLCControl::FreeTargetOptions(ppsz_options, i_options);
         CoTaskMemFree(psz_uri);
@@ -2088,12 +2161,13 @@ STDMETHODIMP VLCVideo::get_aspectRatio(BSTR* aspect)
                 if( NULL == psz_aspect )
                     return E_OUTOFMEMORY;
 
-                *aspect = SysAllocStringByteLen(psz_aspect, strlen(psz_aspect));
+                *aspect = BSTRFromCStr(CP_UTF8, psz_aspect);
                 free( psz_aspect );
                 psz_aspect = NULL;
-                return NOERROR;
+                return (NULL == aspect) ? E_OUTOFMEMORY : NOERROR;
             }
             if( psz_aspect ) free( psz_aspect );
+            psz_aspect = NULL;
         }
         _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
         libvlc_exception_clear(&ex);
@@ -2114,14 +2188,13 @@ STDMETHODIMP VLCVideo::put_aspectRatio(BSTR aspect)
     HRESULT hr = _p_instance->getVLC(&p_libvlc);
     if( SUCCEEDED(hr) )
     {
-        char *psz_aspect = NULL;
         libvlc_exception_t ex;
         libvlc_exception_init(&ex);
 
         libvlc_input_t *p_input = libvlc_playlist_get_input(p_libvlc, &ex);
         if( ! libvlc_exception_raised(&ex) )
         {
-            psz_aspect = CStrFromBSTR(CP_UTF8, aspect);
+            char *psz_aspect = CStrFromBSTR(CP_UTF8, aspect);
             if( NULL == psz_aspect )
             {
                 return E_OUTOFMEMORY;
@@ -2144,6 +2217,124 @@ STDMETHODIMP VLCVideo::put_aspectRatio(BSTR aspect)
     return hr;
 };
 
+STDMETHODIMP VLCVideo::get_crop(BSTR* geometry)
+{
+    if( NULL == geometry )
+        return E_POINTER;
+
+    libvlc_instance_t* p_libvlc;
+    HRESULT hr = _p_instance->getVLC(&p_libvlc);
+    if( SUCCEEDED(hr) )
+    {
+        libvlc_exception_t ex;
+        libvlc_exception_init(&ex);
+
+        libvlc_input_t *p_input = libvlc_playlist_get_input(p_libvlc, &ex);
+        if( ! libvlc_exception_raised(&ex) )
+        {
+            char *psz_geometry = libvlc_video_get_crop_geometry(p_input, &ex);
+
+            libvlc_input_free(p_input);
+            if( ! libvlc_exception_raised(&ex) )
+            {
+                if( NULL == psz_geometry )
+                    return E_OUTOFMEMORY;
+
+                *geometry = BSTRFromCStr(CP_UTF8, psz_geometry);
+                free( psz_geometry );
+                psz_geometry = NULL;
+                return (NULL == geometry) ? E_OUTOFMEMORY : NOERROR;
+            }
+            if( psz_geometry ) free( psz_geometry );
+            psz_geometry = NULL;
+        }
+        _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
+        libvlc_exception_clear(&ex);
+        return E_FAIL;
+    }
+    return hr;
+};
+
+STDMETHODIMP VLCVideo::put_crop(BSTR geometry)
+{
+    if( NULL == geometry )
+        return E_POINTER;
+
+    if( 0 == SysStringLen(geometry) )
+        return E_INVALIDARG;
+
+    libvlc_instance_t* p_libvlc;
+    HRESULT hr = _p_instance->getVLC(&p_libvlc);
+    if( SUCCEEDED(hr) )
+    {
+        libvlc_exception_t ex;
+        libvlc_exception_init(&ex);
+
+        libvlc_input_t *p_input = libvlc_playlist_get_input(p_libvlc, &ex);
+        if( ! libvlc_exception_raised(&ex) )
+        {
+            char *psz_geometry = CStrFromBSTR(CP_UTF8, geometry);
+            if( NULL == psz_geometry )
+            {
+                return E_OUTOFMEMORY;
+            }
+
+            libvlc_video_set_crop_geometry(p_input, psz_geometry, &ex);
+
+            CoTaskMemFree(psz_geometry);
+            libvlc_input_free(p_input);
+            if( libvlc_exception_raised(&ex) )
+            {
+                _p_instance->setErrorInfo(IID_IVLCVideo,
+                    libvlc_exception_get_message(&ex));
+                libvlc_exception_clear(&ex);
+                return E_FAIL;
+            }
+        }
+        return NOERROR;
+    }
+    return hr;
+};
+
+STDMETHODIMP VLCVideo::takeSnapshot(BSTR filePath)
+{
+    if( NULL == filePath )
+        return E_POINTER;
+
+    if( 0 == SysStringLen(filePath) )
+        return E_INVALIDARG;
+
+    libvlc_instance_t* p_libvlc;
+    HRESULT hr = _p_instance->getVLC(&p_libvlc);
+    if( SUCCEEDED(hr) )
+    {
+        libvlc_exception_t ex;
+        libvlc_exception_init(&ex);
+
+        libvlc_input_t *p_input = libvlc_playlist_get_input(p_libvlc, &ex);
+        if( ! libvlc_exception_raised(&ex) )
+        {
+            char *psz_filepath = CStrFromBSTR(CP_UTF8, filePath);
+            if( NULL == psz_filepath )
+            {
+                return E_OUTOFMEMORY;
+            }
+            /* TODO: check file security */
+
+            libvlc_video_take_snapshot(p_input, psz_filepath, &ex);
+            libvlc_input_free(p_input);
+            if( ! libvlc_exception_raised(&ex) )
+            {
+                return NOERROR;
+            }
+        }
+        _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
+        libvlc_exception_clear(&ex);
+        return E_FAIL;
+    }
+    return hr;
+};
+
 STDMETHODIMP VLCVideo::toggleFullscreen()
 {
     libvlc_instance_t* p_libvlc;
@@ -2342,14 +2533,14 @@ STDMETHODIMP VLCControl2::get_StartTime(long *seconds)
 
     return S_OK;
 };
-     
+
 STDMETHODIMP VLCControl2::put_StartTime(long seconds)
 {
     _p_instance->setStartTime(seconds);
 
     return NOERROR;
 };
-        
+
 STDMETHODIMP VLCControl2::get_VersionInfo(BSTR *version)
 {
     if( NULL == version )
@@ -2358,8 +2549,7 @@ STDMETHODIMP VLCControl2::get_VersionInfo(BSTR *version)
     const char *versionStr = VLC_Version();
     if( NULL != versionStr )
     {
-        *version = BSTRFromCStr(_p_instance->getCodePage(), versionStr);
-        
+        *version = BSTRFromCStr(CP_UTF8, versionStr);
         return NULL == *version ? E_OUTOFMEMORY : NOERROR;
     }
     *version = NULL;
@@ -2467,4 +2657,3 @@ STDMETHODIMP VLCControl2::get_video(IVLCVideo** obj)
     }
     return E_OUTOFMEMORY;
 };
-