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

Side by Side Diff: media/capture/video/mac/video_capture_device_mac.h

Issue 2214533002: move //media/capture to //device/capture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 // MacOSX implementation of generic VideoCaptureDevice, using AVFoundation as
6 // native capture API. AVFoundation is available in versions 10.7 (Lion) and
7 // later.
8
9 #ifndef MEDIA_CAPTURE_VIDEO_MAC_VIDEO_CAPTURE_DEVICE_MAC_H_
10 #define MEDIA_CAPTURE_VIDEO_MAC_VIDEO_CAPTURE_DEVICE_MAC_H_
11
12 #import <Foundation/Foundation.h>
13 #include <stdint.h>
14
15 #include <string>
16
17 #include "base/compiler_specific.h"
18 #include "base/mac/scoped_nsobject.h"
19 #include "base/macros.h"
20 #include "base/memory/ref_counted.h"
21 #include "base/memory/weak_ptr.h"
22 #include "media/base/video_capture_types.h"
23 #include "media/capture/video/video_capture_device.h"
24
25 @class VideoCaptureDeviceAVFoundation;
26
27 namespace base {
28 class SingleThreadTaskRunner;
29 }
30
31 namespace tracked_objects {
32 class Location;
33 } // namespace tracked_objects
34
35 // Small class to bundle device name and connection type into a dictionary.
36 CAPTURE_EXPORT
37 @interface DeviceNameAndTransportType : NSObject {
38 @private
39 base::scoped_nsobject<NSString> deviceName_;
40 // The transport type of the device (USB, PCI, etc), values are defined in
41 // <IOKit/audio/IOAudioTypes.h> as kIOAudioDeviceTransportType*.
42 int32_t transportType_;
43 }
44
45 - (id)initWithName:(NSString*)name transportType:(int32_t)transportType;
46
47 - (NSString*)deviceName;
48 - (int32_t)transportType;
49 @end
50
51 namespace media {
52
53 // Called by VideoCaptureManager to open, close and start, stop Mac video
54 // capture devices.
55 class VideoCaptureDeviceMac : public VideoCaptureDevice {
56 public:
57 explicit VideoCaptureDeviceMac(
58 const VideoCaptureDeviceDescriptor& device_descriptor);
59 ~VideoCaptureDeviceMac() override;
60
61 // VideoCaptureDevice implementation.
62 void AllocateAndStart(
63 const VideoCaptureParams& params,
64 std::unique_ptr<VideoCaptureDevice::Client> client) override;
65 void StopAndDeAllocate() override;
66 void TakePhoto(TakePhotoCallback callback) override;
67
68 bool Init(VideoCaptureApi capture_api_type);
69
70 // Called to deliver captured video frames. It's safe to call this method
71 // from any thread, including those controlled by AVFoundation.
72 void ReceiveFrame(const uint8_t* video_frame,
73 int video_frame_length,
74 const VideoCaptureFormat& frame_format,
75 int aspect_numerator,
76 int aspect_denominator,
77 base::TimeDelta timestamp);
78
79 // Callbacks with the result of a still image capture, or in case of error,
80 // respectively. It's safe to call these methods from any thread.
81 void OnPhotoTaken(const uint8_t* image_data,
82 size_t image_length,
83 const std::string& mime_type);
84 void OnPhotoError();
85
86 // Forwarder to VideoCaptureDevice::Client::OnError().
87 void ReceiveError(const tracked_objects::Location& from_here,
88 const std::string& reason);
89
90 // Forwarder to VideoCaptureDevice::Client::OnLog().
91 void LogMessage(const std::string& message);
92
93 static std::string GetDeviceModelId(const std::string& device_id,
94 VideoCaptureApi capture_api,
95 VideoCaptureTransportType transport_type);
96
97 private:
98 void SetErrorState(const tracked_objects::Location& from_here,
99 const std::string& reason);
100 bool UpdateCaptureResolution();
101
102 // Flag indicating the internal state.
103 enum InternalState { kNotInitialized, kIdle, kCapturing, kError };
104
105 VideoCaptureDeviceDescriptor device_descriptor_;
106 std::unique_ptr<VideoCaptureDevice::Client> client_;
107
108 VideoCaptureFormat capture_format_;
109
110 // Only read and write state_ from inside this loop.
111 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
112 InternalState state_;
113
114 base::scoped_nsobject<VideoCaptureDeviceAVFoundation> capture_device_;
115
116 // To hold on to the TakePhotoCallback while the picture is being taken.
117 std::unique_ptr<TakePhotoCallback> photo_callback_;
118
119 // Used with Bind and PostTask to ensure that methods aren't called after the
120 // VideoCaptureDeviceMac is destroyed.
121 // NOTE: Weak pointers must be invalidated before all other member variables.
122 base::WeakPtrFactory<VideoCaptureDeviceMac> weak_factory_;
123
124 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceMac);
125 };
126
127 } // namespace media
128
129 #endif // MEDIA_CAPTURE_VIDEO_MAC_VIDEO_CAPTURE_DEVICE_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698