Chromium Code Reviews| 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_MF_WIN_H_ | 9 #ifndef MEDIA_VIDEO_CAPTURE_WIN_VIDEO_CAPTURE_DEVICE_MF_WIN_H_ |
| 10 #define MEDIA_VIDEO_CAPTURE_WIN_VIDEO_CAPTURE_DEVICE_MF_WIN_H_ | 10 #define MEDIA_VIDEO_CAPTURE_WIN_VIDEO_CAPTURE_DEVICE_MF_WIN_H_ |
| 11 | 11 |
| 12 #include <mfidl.h> | 12 #include <mfidl.h> |
| 13 #include <mfreadwrite.h> | 13 #include <mfreadwrite.h> |
| 14 | 14 |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
| 18 #include "base/threading/non_thread_safe.h" | 18 #include "base/threading/non_thread_safe.h" |
| 19 #include "base/win/scoped_comptr.h" | 19 #include "base/win/scoped_comptr.h" |
| 20 #include "media/base/media_export.h" | 20 #include "media/base/media_export.h" |
| 21 #include "media/video/capture/video_capture_device.h" | 21 #include "media/video/capture/video_capture_device.h" |
| 22 | 22 |
| 23 interface IMFSourceReader; | 23 interface IMFSourceReader; |
| 24 | 24 |
| 25 using base::win::ScopedComPtr; | |
|
tommi (sloooow) - chröme
2014/05/15 15:18:33
nit: I *think* we try to avoid using "using" in he
mcasas
2014/05/15 16:03:23
I wasn't sure of this but now I am. Removing.
| |
| 26 | |
| 25 namespace media { | 27 namespace media { |
| 26 | 28 |
| 27 class MFReaderCallback; | 29 class MFReaderCallback; |
| 28 | 30 |
| 29 class MEDIA_EXPORT VideoCaptureDeviceMFWin | 31 class MEDIA_EXPORT VideoCaptureDeviceMFWin |
| 30 : public base::NonThreadSafe, | 32 : public base::NonThreadSafe, |
| 31 public VideoCaptureDevice { | 33 public VideoCaptureDevice { |
| 32 public: | 34 public: |
| 35 static bool FormatFromGuid(const GUID& guid, VideoPixelFormat* format); | |
| 36 | |
| 33 explicit VideoCaptureDeviceMFWin(const Name& device_name); | 37 explicit VideoCaptureDeviceMFWin(const Name& device_name); |
| 34 virtual ~VideoCaptureDeviceMFWin(); | 38 virtual ~VideoCaptureDeviceMFWin(); |
| 35 | 39 |
| 36 // Opens the device driver for this device. | 40 // Opens the device driver for this device. |
| 37 // This function is used by the static VideoCaptureDevice::Create function. | 41 bool Init(ScopedComPtr<IMFMediaSource> source); |
|
tommi (sloooow) - chröme
2014/05/15 15:18:33
const &
mcasas
2014/05/15 16:03:23
Done.
| |
| 38 bool Init(); | |
| 39 | 42 |
| 40 // VideoCaptureDevice implementation. | 43 // VideoCaptureDevice implementation. |
| 41 virtual void AllocateAndStart(const VideoCaptureParams& params, | 44 virtual void AllocateAndStart(const VideoCaptureParams& params, |
| 42 scoped_ptr<VideoCaptureDevice::Client> client) | 45 scoped_ptr<VideoCaptureDevice::Client> client) |
| 43 OVERRIDE; | 46 OVERRIDE; |
| 44 virtual void StopAndDeAllocate() OVERRIDE; | 47 virtual void StopAndDeAllocate() OVERRIDE; |
| 45 | 48 |
| 46 // Returns true iff the current platform supports the Media Foundation API | |
| 47 // and that the DLLs are available. On Vista this API is an optional download | |
| 48 // but the API is advertised as a part of Windows 7 and onwards. However, | |
| 49 // we've seen that the required DLLs are not available in some Win7 | |
| 50 // distributions such as Windows 7 N and Windows 7 KN. | |
| 51 static bool PlatformSupported(); | |
| 52 | |
| 53 static void GetDeviceNames(Names* device_names); | |
| 54 | |
| 55 static void GetDeviceSupportedFormats(const Name& device, | |
| 56 VideoCaptureFormats* formats); | |
| 57 | |
| 58 // Captured new video data. | 49 // Captured new video data. |
| 59 void OnIncomingCapturedData(const uint8* data, | 50 void OnIncomingCapturedData(const uint8* data, |
| 60 int length, | 51 int length, |
| 61 int rotation, | 52 int rotation, |
| 62 const base::TimeTicks& time_stamp); | 53 const base::TimeTicks& time_stamp); |
| 63 | 54 |
| 64 private: | 55 private: |
| 65 void OnError(HRESULT hr); | 56 void OnError(HRESULT hr); |
| 66 | 57 |
| 67 Name name_; | 58 Name name_; |
| 68 base::win::ScopedComPtr<IMFActivate> device_; | 59 base::win::ScopedComPtr<IMFActivate> device_; |
| 69 scoped_refptr<MFReaderCallback> callback_; | 60 scoped_refptr<MFReaderCallback> callback_; |
| 70 | 61 |
| 71 base::Lock lock_; // Used to guard the below variables. | 62 base::Lock lock_; // Used to guard the below variables. |
| 72 scoped_ptr<VideoCaptureDevice::Client> client_; | 63 scoped_ptr<VideoCaptureDevice::Client> client_; |
| 73 base::win::ScopedComPtr<IMFSourceReader> reader_; | 64 base::win::ScopedComPtr<IMFSourceReader> reader_; |
| 74 VideoCaptureFormat capture_format_; | 65 VideoCaptureFormat capture_format_; |
| 75 bool capture_; | 66 bool capture_; |
| 76 | 67 |
| 77 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceMFWin); | 68 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceMFWin); |
| 78 }; | 69 }; |
| 79 | 70 |
| 80 } // namespace media | 71 } // namespace media |
| 81 | 72 |
| 82 #endif // MEDIA_VIDEO_CAPTURE_WIN_VIDEO_CAPTURE_DEVICE_MF_WIN_H_ | 73 #endif // MEDIA_VIDEO_CAPTURE_WIN_VIDEO_CAPTURE_DEVICE_MF_WIN_H_ |
| OLD | NEW |