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
3 // found in the LICENSE file.
5 // Windows specific implementation of VideoCaptureDevice.
6 // DirectShow is used for capturing. DirectShow provide its own threads
9 #ifndef MEDIA_VIDEO_CAPTURE_WIN_VIDEO_CAPTURE_DEVICE_MF_WIN_H_
10 #define MEDIA_VIDEO_CAPTURE_WIN_VIDEO_CAPTURE_DEVICE_MF_WIN_H_
13 #include <mfreadwrite.h>
17 #include "base/synchronization/lock.h"
18 #include "base/threading/non_thread_safe.h"
19 #include "base/win/scoped_comptr.h"
20 #include "media/base/media_export.h"
21 #include "media/video/capture/video_capture_device.h"
23 interface IMFSourceReader;
27 class MFReaderCallback;
29 class MEDIA_EXPORT VideoCaptureDeviceMFWin
30 : public base::NonThreadSafe,
31 public VideoCaptureDevice {
33 explicit VideoCaptureDeviceMFWin(const Name& device_name);
34 virtual ~VideoCaptureDeviceMFWin();
36 // Opens the device driver for this device.
37 // This function is used by the static VideoCaptureDevice::Create function.
40 // VideoCaptureDevice implementation.
41 virtual void AllocateAndStart(const VideoCaptureParams& params,
42 scoped_ptr<VideoCaptureDevice::Client> client)
44 virtual void StopAndDeAllocate() OVERRIDE;
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();
53 static void GetDeviceNames(Names* device_names);
55 static void GetDeviceSupportedFormats(const Name& device,
56 VideoCaptureFormats* formats);
58 // Captured a new video frame.
59 void OnIncomingCapturedFrame(const uint8* data,
61 const base::TimeTicks& time_stamp,
65 void OnError(HRESULT hr);
68 base::win::ScopedComPtr<IMFActivate> device_;
69 scoped_refptr<MFReaderCallback> callback_;
71 base::Lock lock_; // Used to guard the below variables.
72 scoped_ptr<VideoCaptureDevice::Client> client_;
73 base::win::ScopedComPtr<IMFSourceReader> reader_;
74 VideoCaptureFormat capture_format_;
77 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceMFWin);
82 #endif // MEDIA_VIDEO_CAPTURE_WIN_VIDEO_CAPTURE_DEVICE_MF_WIN_H_