]> git.sesse.net Git - vlc/commitdiff
- activex: support for taking a snapshot into a Picture object
authorDamien Fouilleul <damienf@videolan.org>
Tue, 10 Apr 2007 18:20:26 +0000 (18:20 +0000)
committerDamien Fouilleul <damienf@videolan.org>
Tue, 10 Apr 2007 18:20:26 +0000 (18:20 +0000)
activex/axvlc.idl
activex/axvlc.tlb
activex/axvlc_idl.c
activex/axvlc_idl.h
activex/plugin.cpp
activex/vlccontrol2.cpp
activex/vlccontrol2.h

index bc2e1844c92d257abf5f4e817bbe2cb2e0b11e59..ada8e8c8fa56a7203b895816e09c0e4e086a3ca5 100644 (file)
@@ -24,7 +24,7 @@
 //comments terminated by [t] are by tonsofpcs, regarding the string review.  April 02, 2006. [t]\r
 //Possibly change all instances of "the current playlist" to "the playlist" and "current playlist" to "the playlist" [t]\r
 \r
-import "oaidl.idl";\r
+import "ocidl.idl";\r
 \r
 [\r
   uuid(DF2BBE39-40A8-433b-A279-073F48DA94B6),\r
@@ -435,8 +435,8 @@ library AXVLC
         [helpstring("toggle fullscreen/windowed state.")]\r
         HRESULT toggleFullscreen();\r
 \r
-        [helpstring("take video snapshot and save into into filePath.")]\r
-        HRESULT takeSnapshot(BSTR filePath);\r
+        [helpstring("take video snapshot and save it into picture object.")]\r
+        HRESULT takeSnapshot([out, retval] IPictureDisp** picture);\r
     };\r
 \r
     [\r
index 99342d71e55919ef338609338b0507bb56bb7ec5..7be8d5d84404d3c8a418974f5e490364adf4b07a 100644 (file)
Binary files a/activex/axvlc.tlb and b/activex/axvlc.tlb differ
index 7313f35c2bf9ba21df4aa4dd361297eab51baa82..17b6b830cc50268faa6077ff59f875211fa4e5aa 100644 (file)
@@ -1,4 +1,4 @@
-/*** Autogenerated by WIDL 0.9.30 from axvlc.idl - Do not edit ***/
+/*** Autogenerated by WIDL 0.9.27 from axvlc.idl - Do not edit ***/
 
 #include <rpc.h>
 #include <rpcndr.h>
index 722cf809341d4e75748fab2acb43eb1e25f96c81..f35b6feac6bce58bd5c5c097516d6ad118a4f667 100644 (file)
@@ -1,4 +1,4 @@
-/*** Autogenerated by WIDL 0.9.30 from axvlc.idl - Do not edit ***/
+/*** Autogenerated by WIDL 0.9.27 from axvlc.idl - Do not edit ***/
 #include <rpc.h>
 #include <rpcndr.h>
 
@@ -7,7 +7,7 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
-#include <oaidl.h>
+#include <ocidl.h>
 
 DEFINE_GUID(LIBID_AXVLC, 0xdf2bbe39, 0x40a8, 0x433b, 0xa2,0x79, 0x07,0x3f,0x48,0xda,0x94,0xb6);
 
@@ -2269,7 +2269,7 @@ interface IVLCVideo : public IDispatch
         ) = 0;
 
     virtual HRESULT STDMETHODCALLTYPE takeSnapshot(
-        BSTR filePath) = 0;
+        IPictureDisp** picture) = 0;
 
 };
 #else
@@ -2364,7 +2364,7 @@ typedef struct IVLCVideoVtbl {
 
     HRESULT (STDMETHODCALLTYPE *takeSnapshot)(
         IVLCVideo* This,
-        BSTR filePath);
+        IPictureDisp** picture);
 
     END_INTERFACE
 } IVLCVideoVtbl;
@@ -2488,7 +2488,7 @@ void __RPC_STUB IVLCVideo_toggleFullscreen_Stub(
     DWORD* pdwStubPhase);
 HRESULT CALLBACK IVLCVideo_takeSnapshot_Proxy(
     IVLCVideo* This,
-    BSTR filePath);
+    IPictureDisp** picture);
 void __RPC_STUB IVLCVideo_takeSnapshot_Stub(
     IRpcStubBuffer* This,
     IRpcChannelBuffer* pRpcChannelBuffer,
index 348d1419b57f23e5055bf0f373e806258285a32d..4dceeeaa8f1a6f627fa886c48bbfc17e7c6fe648 100644 (file)
@@ -497,8 +497,6 @@ HRESULT VLCPlugin::getVLC(libvlc_instance_t** pp_libvlc)
             ppsz_argv[ppsz_argc++] = "--win9x-cv-method=1";
         }
 
-DebugBreak();
-
         _p_libvlc = libvlc_new(ppsz_argc, ppsz_argv, NULL);
         if( NULL == _p_libvlc )
         {
index a04228203f89d288325e243d950b9ccc3bc6510f..4d882476427ddafd827cb8627b7f47ca57e89658 100644 (file)
@@ -29,6 +29,7 @@
 
 #include <shlwapi.h>
 #include <wininet.h>
+#include <tchar.h>
 
 using namespace std;
 
@@ -2353,14 +2354,11 @@ STDMETHODIMP VLCVideo::put_crop(BSTR geometry)
     return hr;
 };
 
-STDMETHODIMP VLCVideo::takeSnapshot(BSTR filePath)
+STDMETHODIMP VLCVideo::takeSnapshot(LPPICTUREDISP* picture)
 {
-    if( NULL == filePath )
+    if( NULL == picture )
         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) )
@@ -2371,18 +2369,89 @@ STDMETHODIMP VLCVideo::takeSnapshot(BSTR filePath)
         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 )
+            static int uniqueId = 0;
+            TCHAR path[MAX_PATH+1];
+
+            int pathlen = GetTempPath(MAX_PATH-24, path);
+            if( (0 == pathlen) || (pathlen > (MAX_PATH-24)) )
+                return E_FAIL;
+
+            /* check temp directory path by openning it */
             {
-                return E_OUTOFMEMORY;
+                HANDLE dirHandle = CreateFile(path,
+                                              GENERIC_READ,
+                                              FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+                                              NULL,
+                                              OPEN_EXISTING,
+                                              FILE_FLAG_BACKUP_SEMANTICS, NULL);
+                if( INVALID_HANDLE_VALUE == dirHandle )
+                {
+                    _p_instance->setErrorInfo(IID_IVLCVideo,
+                            "Invalid temporary directory for snapshot images, check values of TMP, TEMP envars.");
+                    return E_FAIL;
+                }
+                else
+                {
+                    BY_HANDLE_FILE_INFORMATION bhfi;
+                    BOOL res = GetFileInformationByHandle(dirHandle, &bhfi);
+                    CloseHandle(dirHandle);
+                    if( !res || !(bhfi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
+                    {
+                        _p_instance->setErrorInfo(IID_IVLCVideo,
+                                "Invalid temporary directory for snapshot images, check values of TMP, TEMP envars.");
+                        return E_FAIL;
+                    }
+                }
             }
-            /* TODO: check file security */
 
+            TCHAR filepath[MAX_PATH+1];
+
+            _stprintf(filepath, TEXT("%sAXVLC%lXS%lX.bmp"),
+                     path, GetCurrentProcessId(), ++uniqueId);
+
+#ifdef _UNICODE
+            /* reuse path storage for UTF8 string */
+            char *psz_filepath = (char *)path;
+            WCHAR* wpath = filepath;
+#else
+            char *psz_filepath = path;
+            /* first convert to unicode using current code page */
+            WCHAR wpath[MAX_PATH+1];
+            if( 0 == MultiByteToWideChar(CP_ACP, 0, filepath, -1, wpath, sizeof(wpath)/sizeof(WCHAR)) )
+                return E_FAIL;
+#endif
+            /* convert to UTF8 */
+            pathlen = WideCharToMultiByte(CP_UTF8, 0, wpath, -1, psz_filepath, sizeof(path), NULL, NULL);
+            // fail if path is 0 or too short (i.e pathlen is the same as storage size)
+            if( (0 == pathlen) || (sizeof(path) == pathlen) )
+                return E_FAIL;
+
+            /* take snapshot into file */
             libvlc_video_take_snapshot(p_input, psz_filepath, &ex);
             libvlc_input_free(p_input);
             if( ! libvlc_exception_raised(&ex) )
             {
-                return NOERROR;
+                hr = E_FAIL;
+                /* open snapshot file */
+                HANDLE snapPic = LoadImage(NULL, filepath, IMAGE_BITMAP,0, 0, LR_CREATEDIBSECTION|LR_LOADFROMFILE);
+                if( snapPic )
+                {
+                    PICTDESC snapDesc;
+
+                    snapDesc.cbSizeofstruct = sizeof(PICTDESC);
+                    snapDesc.picType        = PICTYPE_BITMAP;
+                    snapDesc.bmp.hbitmap    = (HBITMAP)snapPic;
+                    snapDesc.bmp.hpal       = NULL;
+
+                    hr = OleCreatePictureIndirect(&snapDesc, IID_IPictureDisp, TRUE, (LPVOID*)picture);
+                    if( FAILED(hr) )
+                    {
+                        *picture = NULL;
+                        DeleteObject(snapPic);
+                    }
+                }
+                DeleteFile(filepath);
+                return hr;
             }
         }
         _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
index 832e1a93f83ff0f4006550d54378e717d92cbd41..4eefafecf7101de708e3ae471d429049cbc95a56 100644 (file)
@@ -526,7 +526,7 @@ public:
     STDMETHODIMP put_subtitle(long);
     STDMETHODIMP get_crop(BSTR*);
     STDMETHODIMP put_crop(BSTR);
-    STDMETHODIMP takeSnapshot(BSTR);
+    STDMETHODIMP takeSnapshot(LPPICTUREDISP*);
     STDMETHODIMP toggleFullscreen();
 
 protected: