ViSP  2.8.0
vpDirectShowDevice.cpp
1 /****************************************************************************
2  *
3  * $Id: vpDirectShowDevice.cpp 4056 2013-01-05 13:04:42Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * DirectShow device description.
36  *
37  * Authors:
38  * Bruno Renier
39  *
40  *****************************************************************************/
41 
42 #ifndef DOXYGEN_SHOULD_SKIP_THIS
43 
44 #include <stdio.h>
45 #include <visp/vpConfig.h>
46 #if ( defined(VISP_HAVE_DIRECTSHOW) )
47 
48 #include <visp/vpDirectShowDevice.h>
49 
50 
56 bool vpDirectShowDevice::init(const CComPtr<IMoniker>& pMoniker)
57 {
58  HRESULT hr;
59 
60  //Get the properties
61  CComPtr<IPropertyBag> pPropBag;
62  hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag,
63  (void**)(&pPropBag));
64 
65  //get the name of the input
66  VARIANT varName;
67  VARIANT varDesc;
68  VARIANT varDevPath;
69  VariantInit(&varName);
70  VariantInit(&varDesc);
71  VariantInit(&varDevPath);
72  char tmp[FILENAME_MAX];
73 
74  hr = pPropBag->Read(L"FriendlyName", &varName, 0);
75 
76  //successfully got the name
77  if (SUCCEEDED(hr))
78  {
79  sprintf(tmp, "%S", varName.bstrVal);
80  name = tmp;
81  }
82 
83  VariantClear(&varName);
84 
85  hr = pPropBag->Read(L"Description", &varDesc, 0);
86 
87  //successfully got the description
88  if (SUCCEEDED(hr))
89  {
90  sprintf(tmp, "%S", varDesc.bstrVal);
91  desc = tmp;
92  }
93 
94  VariantClear(&varDesc);
95 
96  hr = pPropBag->Read(L"DevicePath", &varDevPath, 0);
97 
98  //successfully got the device path
99  if (SUCCEEDED(hr))
100  {
101  sprintf(tmp, "%S",varDevPath.bstrVal);
102  devPath = tmp;
103  }
104 
105  VariantClear(&varDevPath);
106 
107  inUse=false;
108 
109  return true;
110 }
111 
116 bool vpDirectShowDevice::operator==(vpDirectShowDevice& dev)
117 {
118  return name==dev.name
119  && desc==dev.desc
120  && devPath==dev.devPath;
121 }
122 
123 #endif
124 #endif