• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   static bool FormatFromGuid(const GUID& guid, VideoPixelFormat* format);
34 
35   explicit VideoCaptureDeviceMFWin(const Name& device_name);
36   virtual ~VideoCaptureDeviceMFWin();
37 
38   // Opens the device driver for this device.
39   bool Init(const base::win::ScopedComPtr<IMFMediaSource>& source);
40 
41   // VideoCaptureDevice implementation.
42   virtual void AllocateAndStart(const VideoCaptureParams& params,
43                                 scoped_ptr<VideoCaptureDevice::Client> client)
44       OVERRIDE;
45   virtual void StopAndDeAllocate() OVERRIDE;
46 
47   // Captured new video data.
48   void OnIncomingCapturedData(const uint8* data,
49                               int length,
50                               int rotation,
51                               const base::TimeTicks& time_stamp);
52 
53  private:
54   void OnError(HRESULT hr);
55 
56   Name name_;
57   base::win::ScopedComPtr<IMFActivate> device_;
58   scoped_refptr<MFReaderCallback> callback_;
59 
60   base::Lock lock_;  // Used to guard the below variables.
61   scoped_ptr<VideoCaptureDevice::Client> client_;
62   base::win::ScopedComPtr<IMFSourceReader> reader_;
63   VideoCaptureFormat capture_format_;
64   bool capture_;
65 
66   DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceMFWin);
67 };
68 
69 }  // namespace media
70 
71 #endif  // MEDIA_VIDEO_CAPTURE_WIN_VIDEO_CAPTURE_DEVICE_MF_WIN_H_
72