Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / media / video / capture / win / video_capture_device_mf_win.h
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.
4
5 // Windows specific implementation of VideoCaptureDevice.
6 // DirectShow is used for capturing. DirectShow provide its own threads
7 // for capturing.
8
9 #ifndef MEDIA_VIDEO_CAPTURE_WIN_VIDEO_CAPTURE_DEVICE_MF_WIN_H_
10 #define MEDIA_VIDEO_CAPTURE_WIN_VIDEO_CAPTURE_DEVICE_MF_WIN_H_
11
12 #include <mfidl.h>
13 #include <mfreadwrite.h>
14
15 #include <vector>
16
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"
22
23 interface IMFSourceReader;
24
25 namespace media {
26
27 class MFReaderCallback;
28
29 class MEDIA_EXPORT VideoCaptureDeviceMFWin
30     : public base::NonThreadSafe,
31       public VideoCaptureDevice {
32  public:
33   explicit VideoCaptureDeviceMFWin(const Name& device_name);
34   virtual ~VideoCaptureDeviceMFWin();
35
36   // Opens the device driver for this device.
37   // This function is used by the static VideoCaptureDevice::Create function.
38   bool Init();
39
40   // VideoCaptureDevice implementation.
41   virtual void AllocateAndStart(const VideoCaptureParams& params,
42                                 scoped_ptr<VideoCaptureDevice::Client> client)
43       OVERRIDE;
44   virtual void StopAndDeAllocate() OVERRIDE;
45
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 a new video frame.
59   void OnIncomingCapturedFrame(const uint8* data,
60                                int length,
61                                const base::TimeTicks& time_stamp,
62                                int rotation);
63
64  private:
65   void OnError(HRESULT hr);
66
67   Name name_;
68   base::win::ScopedComPtr<IMFActivate> device_;
69   scoped_refptr<MFReaderCallback> callback_;
70
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_;
75   bool capture_;
76
77   DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceMFWin);
78 };
79
80 }  // namespace media
81
82 #endif  // MEDIA_VIDEO_CAPTURE_WIN_VIDEO_CAPTURE_DEVICE_MF_WIN_H_