Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(836)

Side by Side Diff: media/capture/video/win/video_capture_device_win.h

Issue 2143903003: [WIP] Move media/capture to device/capture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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. DirectShow is used for
6 // capturing. DirectShow provide its own threads for capturing.
7
8 #ifndef MEDIA_CAPTURE_VIDEO_WIN_VIDEO_CAPTURE_DEVICE_WIN_H_
9 #define MEDIA_CAPTURE_VIDEO_WIN_VIDEO_CAPTURE_DEVICE_WIN_H_
10
11 // Avoid including strsafe.h via dshow as it will cause build warnings.
12 #define NO_DSHOW_STRSAFE
13 #include <dshow.h>
14 #include <stdint.h>
15
16 #include <map>
17 #include <string>
18
19 #include "base/macros.h"
20 #include "base/threading/thread_checker.h"
21 #include "base/win/scoped_comptr.h"
22 #include "media/base/video_capture_types.h"
23 #include "media/capture/video/video_capture_device.h"
24 #include "media/capture/video/win/capability_list_win.h"
25 #include "media/capture/video/win/sink_filter_win.h"
26 #include "media/capture/video/win/sink_input_pin_win.h"
27
28 namespace tracked_objects {
29 class Location;
30 } // namespace tracked_objects
31
32 namespace media {
33
34 // All the methods in the class can only be run on a COM initialized thread.
35 class VideoCaptureDeviceWin : public VideoCaptureDevice,
36 public SinkFilterObserver {
37 public:
38 // A utility class that wraps the AM_MEDIA_TYPE type and guarantees that
39 // we free the structure when exiting the scope. DCHECKing is also done to
40 // avoid memory leaks.
41 class ScopedMediaType {
42 public:
43 ScopedMediaType() : media_type_(NULL) {}
44 ~ScopedMediaType() { Free(); }
45
46 AM_MEDIA_TYPE* operator->() { return media_type_; }
47 AM_MEDIA_TYPE* get() { return media_type_; }
48 void Free();
49 AM_MEDIA_TYPE** Receive();
50
51 private:
52 void FreeMediaType(AM_MEDIA_TYPE* mt);
53 void DeleteMediaType(AM_MEDIA_TYPE* mt);
54
55 AM_MEDIA_TYPE* media_type_;
56 };
57
58 static HRESULT GetDeviceFilter(const std::string& device_id,
59 IBaseFilter** filter);
60 static base::win::ScopedComPtr<IPin> GetPin(IBaseFilter* filter,
61 PIN_DIRECTION pin_dir,
62 REFGUID category,
63 REFGUID major_type);
64 static VideoPixelFormat TranslateMediaSubtypeToPixelFormat(
65 const GUID& sub_type);
66
67 explicit VideoCaptureDeviceWin(const Name& device_name);
68 ~VideoCaptureDeviceWin() override;
69 // Opens the device driver for this device.
70 bool Init();
71
72 // VideoCaptureDevice implementation.
73 void AllocateAndStart(
74 const VideoCaptureParams& params,
75 std::unique_ptr<VideoCaptureDevice::Client> client) override;
76 void StopAndDeAllocate() override;
77
78 private:
79 enum InternalState {
80 kIdle, // The device driver is opened but camera is not in use.
81 kCapturing, // Video is being captured.
82 kError // Error accessing HW functions.
83 // User needs to recover by destroying the object.
84 };
85
86 // Implements SinkFilterObserver.
87 void FrameReceived(const uint8_t* buffer,
88 int length,
89 base::TimeDelta timestamp) override;
90
91 bool CreateCapabilityMap();
92 void SetAntiFlickerInCaptureFilter(const VideoCaptureParams& params);
93 void SetErrorState(const tracked_objects::Location& from_here,
94 const std::string& reason);
95
96 const Name device_name_;
97 InternalState state_;
98 std::unique_ptr<VideoCaptureDevice::Client> client_;
99
100 base::win::ScopedComPtr<IBaseFilter> capture_filter_;
101
102 base::win::ScopedComPtr<IGraphBuilder> graph_builder_;
103 base::win::ScopedComPtr<ICaptureGraphBuilder2> capture_graph_builder_;
104
105 base::win::ScopedComPtr<IMediaControl> media_control_;
106 base::win::ScopedComPtr<IPin> input_sink_pin_;
107 base::win::ScopedComPtr<IPin> output_capture_pin_;
108
109 scoped_refptr<SinkFilter> sink_filter_;
110
111 // Map of all capabilities this device support.
112 CapabilityList capabilities_;
113 VideoCaptureFormat capture_format_;
114
115 base::TimeTicks first_ref_time_;
116
117 base::ThreadChecker thread_checker_;
118
119 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceWin);
120 };
121
122 } // namespace media
123
124 #endif // MEDIA_CAPTURE_VIDEO_WIN_VIDEO_CAPTURE_DEVICE_WIN_H_
OLDNEW
« no previous file with comments | « media/capture/video/win/video_capture_device_mf_win.cc ('k') | media/capture/video/win/video_capture_device_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698