| 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_ |
| (...skipping 15 matching lines...) Expand all Loading... |
| 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 namespace media { | 28 namespace media { |
| 29 | 29 |
| 30 // All the methods in the class can only be run on a COM initialized thread. | 30 // All the methods in the class can only be run on a COM initialized thread. |
| 31 class VideoCaptureDeviceWin | 31 class VideoCaptureDeviceWin |
| 32 : public base::NonThreadSafe, | 32 : public base::NonThreadSafe, |
| 33 public VideoCaptureDevice, | 33 public VideoCaptureDevice, |
| 34 public SinkFilterObserver { | 34 public SinkFilterObserver { |
| 35 public: | 35 public: |
| 36 // A utility class that wraps the AM_MEDIA_TYPE type and guarantees that |
| 37 // we free the structure when exiting the scope. DCHECKing is also done to |
| 38 // avoid memory leaks. |
| 39 class ScopedMediaType { |
| 40 public: |
| 41 ScopedMediaType() : media_type_(NULL) {} |
| 42 ~ScopedMediaType() { Free(); } |
| 43 |
| 44 AM_MEDIA_TYPE* operator->() { return media_type_; } |
| 45 AM_MEDIA_TYPE* get() { return media_type_; } |
| 46 void Free(); |
| 47 AM_MEDIA_TYPE** Receive(); |
| 48 |
| 49 private: |
| 50 void FreeMediaType(AM_MEDIA_TYPE* mt); |
| 51 void DeleteMediaType(AM_MEDIA_TYPE* mt); |
| 52 |
| 53 AM_MEDIA_TYPE* media_type_; |
| 54 }; |
| 55 |
| 56 static HRESULT GetDeviceFilter(const Name& device_name, |
| 57 IBaseFilter** filter); |
| 58 static bool PinMatchesCategory(IPin* pin, REFGUID category); |
| 59 static base::win::ScopedComPtr<IPin> GetPin(IBaseFilter* filter, |
| 60 PIN_DIRECTION pin_dir, |
| 61 REFGUID category); |
| 62 static VideoPixelFormat TranslateMediaSubtypeToPixelFormat( |
| 63 const GUID& sub_type); |
| 64 |
| 36 explicit VideoCaptureDeviceWin(const Name& device_name); | 65 explicit VideoCaptureDeviceWin(const Name& device_name); |
| 37 virtual ~VideoCaptureDeviceWin(); | 66 virtual ~VideoCaptureDeviceWin(); |
| 38 // Opens the device driver for this device. | 67 // Opens the device driver for this device. |
| 39 // This function is used by the static VideoCaptureDevice::Create function. | |
| 40 bool Init(); | 68 bool Init(); |
| 41 | 69 |
| 42 // VideoCaptureDevice implementation. | 70 // VideoCaptureDevice implementation. |
| 43 virtual void AllocateAndStart( | 71 virtual void AllocateAndStart( |
| 44 const VideoCaptureParams& params, | 72 const VideoCaptureParams& params, |
| 45 scoped_ptr<VideoCaptureDevice::Client> client) OVERRIDE; | 73 scoped_ptr<VideoCaptureDevice::Client> client) OVERRIDE; |
| 46 virtual void StopAndDeAllocate() OVERRIDE; | 74 virtual void StopAndDeAllocate() OVERRIDE; |
| 47 | 75 |
| 48 static void GetDeviceNames(Names* device_names); | |
| 49 static void GetDeviceSupportedFormats(const Name& device, | |
| 50 VideoCaptureFormats* formats); | |
| 51 | |
| 52 private: | 76 private: |
| 53 enum InternalState { | 77 enum InternalState { |
| 54 kIdle, // The device driver is opened but camera is not in use. | 78 kIdle, // The device driver is opened but camera is not in use. |
| 55 kCapturing, // Video is being captured. | 79 kCapturing, // Video is being captured. |
| 56 kError // Error accessing HW functions. | 80 kError // Error accessing HW functions. |
| 57 // User needs to recover by destroying the object. | 81 // User needs to recover by destroying the object. |
| 58 }; | 82 }; |
| 59 | 83 |
| 60 // Implements SinkFilterObserver. | 84 // Implements SinkFilterObserver. |
| 61 virtual void FrameReceived(const uint8* buffer, int length); | 85 virtual void FrameReceived(const uint8* buffer, int length); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 83 // Map of all capabilities this device support. | 107 // Map of all capabilities this device support. |
| 84 CapabilityList capabilities_; | 108 CapabilityList capabilities_; |
| 85 VideoCaptureFormat capture_format_; | 109 VideoCaptureFormat capture_format_; |
| 86 | 110 |
| 87 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceWin); | 111 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceWin); |
| 88 }; | 112 }; |
| 89 | 113 |
| 90 } // namespace media | 114 } // namespace media |
| 91 | 115 |
| 92 #endif // MEDIA_VIDEO_CAPTURE_WIN_VIDEO_CAPTURE_DEVICE_WIN_H_ | 116 #endif // MEDIA_VIDEO_CAPTURE_WIN_VIDEO_CAPTURE_DEVICE_WIN_H_ |
| OLD | NEW |