Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / media / video / capture / win / video_capture_device_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_WIN_H_
10 #define MEDIA_VIDEO_CAPTURE_WIN_VIDEO_CAPTURE_DEVICE_WIN_H_
11
12 // Avoid including strsafe.h via dshow as it will cause build warnings.
13 #define NO_DSHOW_STRSAFE
14 #include <dshow.h>
15
16 #include <map>
17 #include <string>
18
19 #include "base/threading/non_thread_safe.h"
20 #include "base/threading/thread.h"
21 #include "base/win/scoped_comptr.h"
22 #include "media/video/capture/video_capture_device.h"
23 #include "media/video/capture/video_capture_types.h"
24 #include "media/video/capture/win/capability_list_win.h"
25 #include "media/video/capture/win/sink_filter_win.h"
26 #include "media/video/capture/win/sink_input_pin_win.h"
27
28 namespace media {
29
30 // All the methods in the class can only be run on a COM initialized thread.
31 class VideoCaptureDeviceWin
32     : public base::NonThreadSafe,
33       public VideoCaptureDevice,
34       public SinkFilterObserver {
35  public:
36   explicit VideoCaptureDeviceWin(const Name& device_name);
37   virtual ~VideoCaptureDeviceWin();
38   // Opens the device driver for this device.
39   // This function is used by the static VideoCaptureDevice::Create function.
40   bool Init();
41
42   // VideoCaptureDevice implementation.
43   virtual void AllocateAndStart(
44       const VideoCaptureParams& params,
45       scoped_ptr<VideoCaptureDevice::Client> client) OVERRIDE;
46   virtual void StopAndDeAllocate() OVERRIDE;
47
48   static void GetDeviceNames(Names* device_names);
49   static void GetDeviceSupportedFormats(const Name& device,
50                                         VideoCaptureFormats* formats);
51
52  private:
53   enum InternalState {
54     kIdle,  // The device driver is opened but camera is not in use.
55     kCapturing,  // Video is being captured.
56     kError  // Error accessing HW functions.
57             // User needs to recover by destroying the object.
58   };
59
60   // Implements SinkFilterObserver.
61   virtual void FrameReceived(const uint8* buffer, int length);
62
63   bool CreateCapabilityMap();
64   void SetAntiFlickerInCaptureFilter();
65   void SetErrorState(const std::string& reason);
66
67   Name device_name_;
68   InternalState state_;
69   scoped_ptr<VideoCaptureDevice::Client> client_;
70
71   base::win::ScopedComPtr<IBaseFilter> capture_filter_;
72   base::win::ScopedComPtr<IGraphBuilder> graph_builder_;
73   base::win::ScopedComPtr<IMediaControl> media_control_;
74   base::win::ScopedComPtr<IPin> input_sink_pin_;
75   base::win::ScopedComPtr<IPin> output_capture_pin_;
76   // Used when using a MJPEG decoder.
77   base::win::ScopedComPtr<IBaseFilter> mjpg_filter_;
78   base::win::ScopedComPtr<IPin> input_mjpg_pin_;
79   base::win::ScopedComPtr<IPin> output_mjpg_pin_;
80
81   scoped_refptr<SinkFilter> sink_filter_;
82
83   // Map of all capabilities this device support.
84   CapabilityList capabilities_;
85   VideoCaptureFormat capture_format_;
86
87   DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceWin);
88 };
89
90 }  // namespace media
91
92 #endif  // MEDIA_VIDEO_CAPTURE_WIN_VIDEO_CAPTURE_DEVICE_WIN_H_