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