OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Windows specific implementation of VideoCaptureDevice. | 5 // Windows specific implementation of VideoCaptureDevice. |
6 // DirectShow is used for capturing. DirectShow provide its own threads | 6 // DirectShow is used for capturing. DirectShow provide its own threads |
7 // for capturing. | 7 // for capturing. |
8 | 8 |
9 #ifndef MEDIA_VIDEO_CAPTURE_WIN_VIDEO_CAPTURE_DEVICE_WIN_H_ | 9 #ifndef MEDIA_VIDEO_CAPTURE_WIN_VIDEO_CAPTURE_DEVICE_WIN_H_ |
10 #define MEDIA_VIDEO_CAPTURE_WIN_VIDEO_CAPTURE_DEVICE_WIN_H_ | 10 #define MEDIA_VIDEO_CAPTURE_WIN_VIDEO_CAPTURE_DEVICE_WIN_H_ |
11 | 11 |
12 // Avoid including strsafe.h via dshow as it will cause build warnings. | 12 // Avoid including strsafe.h via dshow as it will cause build warnings. |
13 #define NO_DSHOW_STRSAFE | 13 #define NO_DSHOW_STRSAFE |
14 #include <dshow.h> | 14 #include <dshow.h> |
15 | 15 |
16 #include <map> | 16 #include <map> |
17 #include <string> | 17 #include <string> |
18 | 18 |
19 #include "base/threading/non_thread_safe.h" | 19 #include "base/threading/non_thread_safe.h" |
20 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" |
21 #include "base/win/scoped_comptr.h" | 21 #include "base/win/scoped_comptr.h" |
22 #include "media/video/capture/video_capture_device.h" | 22 #include "media/video/capture/video_capture_device.h" |
23 #include "media/video/capture/video_capture_types.h" | 23 #include "media/video/capture/video_capture_types.h" |
24 #include "media/video/capture/win/capability_list_win.h" | 24 #include "media/video/capture/win/capability_list_win.h" |
25 #include "media/video/capture/win/sink_filter_win.h" | 25 #include "media/video/capture/win/sink_filter_win.h" |
26 #include "media/video/capture/win/sink_input_pin_win.h" | 26 #include "media/video/capture/win/sink_input_pin_win.h" |
27 | 27 |
28 using base::win::ScopedComPtr; | |
tommi (sloooow) - chröme
2014/05/15 15:18:33
if you remove the other one, then please this one
mcasas
2014/05/15 16:03:23
Done.
| |
29 | |
28 namespace media { | 30 namespace media { |
29 | 31 |
30 // All the methods in the class can only be run on a COM initialized thread. | 32 // All the methods in the class can only be run on a COM initialized thread. |
31 class VideoCaptureDeviceWin | 33 class VideoCaptureDeviceWin |
32 : public base::NonThreadSafe, | 34 : public base::NonThreadSafe, |
33 public VideoCaptureDevice, | 35 public VideoCaptureDevice, |
34 public SinkFilterObserver { | 36 public SinkFilterObserver { |
35 public: | 37 public: |
38 // A utility class that wraps the AM_MEDIA_TYPE type and guarantees that | |
39 // we free the structure when exiting the scope. DCHECKing is also done to | |
40 // avoid memory leaks. | |
41 class ScopedMediaType { | |
42 public: | |
43 ScopedMediaType() : media_type_(NULL) {} | |
44 ~ScopedMediaType() { Free(); } | |
45 | |
46 AM_MEDIA_TYPE* operator->() { return media_type_; } | |
47 AM_MEDIA_TYPE* get() { return media_type_; } | |
48 void Free(); | |
49 AM_MEDIA_TYPE** Receive(); | |
50 | |
51 private: | |
52 void FreeMediaType(AM_MEDIA_TYPE* mt); | |
53 void DeleteMediaType(AM_MEDIA_TYPE* mt); | |
54 | |
55 AM_MEDIA_TYPE* media_type_; | |
56 }; | |
57 | |
58 static HRESULT GetDeviceFilter(const Name& device_name, | |
59 IBaseFilter** filter); | |
60 static bool PinMatchesCategory(IPin* pin, REFGUID category); | |
61 static ScopedComPtr<IPin> GetPin(IBaseFilter* filter, | |
62 PIN_DIRECTION pin_dir, | |
63 REFGUID category); | |
64 static VideoPixelFormat TranslateMediaSubtypeToPixelFormat( | |
65 const GUID& sub_type); | |
66 | |
36 explicit VideoCaptureDeviceWin(const Name& device_name); | 67 explicit VideoCaptureDeviceWin(const Name& device_name); |
37 virtual ~VideoCaptureDeviceWin(); | 68 virtual ~VideoCaptureDeviceWin(); |
38 // Opens the device driver for this device. | 69 // Opens the device driver for this device. |
39 // This function is used by the static VideoCaptureDevice::Create function. | |
40 bool Init(); | 70 bool Init(); |
41 | 71 |
42 // VideoCaptureDevice implementation. | 72 // VideoCaptureDevice implementation. |
43 virtual void AllocateAndStart( | 73 virtual void AllocateAndStart( |
44 const VideoCaptureParams& params, | 74 const VideoCaptureParams& params, |
45 scoped_ptr<VideoCaptureDevice::Client> client) OVERRIDE; | 75 scoped_ptr<VideoCaptureDevice::Client> client) OVERRIDE; |
46 virtual void StopAndDeAllocate() OVERRIDE; | 76 virtual void StopAndDeAllocate() OVERRIDE; |
47 | 77 |
48 static void GetDeviceNames(Names* device_names); | |
49 static void GetDeviceSupportedFormats(const Name& device, | |
50 VideoCaptureFormats* formats); | |
51 | |
52 private: | 78 private: |
53 enum InternalState { | 79 enum InternalState { |
54 kIdle, // The device driver is opened but camera is not in use. | 80 kIdle, // The device driver is opened but camera is not in use. |
55 kCapturing, // Video is being captured. | 81 kCapturing, // Video is being captured. |
56 kError // Error accessing HW functions. | 82 kError // Error accessing HW functions. |
57 // User needs to recover by destroying the object. | 83 // User needs to recover by destroying the object. |
58 }; | 84 }; |
59 | 85 |
60 // Implements SinkFilterObserver. | 86 // Implements SinkFilterObserver. |
61 virtual void FrameReceived(const uint8* buffer, int length); | 87 virtual void FrameReceived(const uint8* buffer, int length); |
(...skipping 21 matching lines...) Expand all Loading... | |
83 // Map of all capabilities this device support. | 109 // Map of all capabilities this device support. |
84 CapabilityList capabilities_; | 110 CapabilityList capabilities_; |
85 VideoCaptureFormat capture_format_; | 111 VideoCaptureFormat capture_format_; |
86 | 112 |
87 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceWin); | 113 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceWin); |
88 }; | 114 }; |
89 | 115 |
90 } // namespace media | 116 } // namespace media |
91 | 117 |
92 #endif // MEDIA_VIDEO_CAPTURE_WIN_VIDEO_CAPTURE_DEVICE_WIN_H_ | 118 #endif // MEDIA_VIDEO_CAPTURE_WIN_VIDEO_CAPTURE_DEVICE_WIN_H_ |
OLD | NEW |