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

Side by Side Diff: media/capture/video/linux/video_capture_device_linux.cc

Issue 2815643002: Make V4L2CaptureDelegate non-ref-counted (Closed)
Patch Set: Created 3 years, 8 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/capture/video/linux/video_capture_device_linux.h" 5 #include "media/capture/video/linux/video_capture_device_linux.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <list> 9 #include <list>
10 10
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 void VideoCaptureDeviceLinux::AllocateAndStart( 50 void VideoCaptureDeviceLinux::AllocateAndStart(
51 const VideoCaptureParams& params, 51 const VideoCaptureParams& params,
52 std::unique_ptr<VideoCaptureDevice::Client> client) { 52 std::unique_ptr<VideoCaptureDevice::Client> client) {
53 DCHECK(!capture_impl_); 53 DCHECK(!capture_impl_);
54 if (v4l2_thread_.IsRunning()) 54 if (v4l2_thread_.IsRunning())
55 return; // Wrong state. 55 return; // Wrong state.
56 v4l2_thread_.Start(); 56 v4l2_thread_.Start();
57 57
58 const int line_frequency = 58 const int line_frequency =
59 TranslatePowerLineFrequencyToV4L2(GetPowerLineFrequency(params)); 59 TranslatePowerLineFrequencyToV4L2(GetPowerLineFrequency(params));
60 capture_impl_ = new V4L2CaptureDelegate( 60 capture_impl_ = base::MakeUnique<V4L2CaptureDelegate>(
61 device_descriptor_, v4l2_thread_.task_runner(), line_frequency); 61 device_descriptor_, v4l2_thread_.task_runner(), line_frequency);
62 if (!capture_impl_) { 62 if (!capture_impl_) {
63 client->OnError(FROM_HERE, "Failed to create VideoCaptureDelegate"); 63 client->OnError(FROM_HERE, "Failed to create VideoCaptureDelegate");
64 return; 64 return;
65 } 65 }
66 v4l2_thread_.task_runner()->PostTask( 66 v4l2_thread_.task_runner()->PostTask(
67 FROM_HERE, 67 FROM_HERE,
68 base::Bind(&V4L2CaptureDelegate::AllocateAndStart, capture_impl_, 68 base::Bind(&V4L2CaptureDelegate::AllocateAndStart,
69 base::Unretained(capture_impl_.get()),
69 params.requested_format.frame_size.width(), 70 params.requested_format.frame_size.width(),
70 params.requested_format.frame_size.height(), 71 params.requested_format.frame_size.height(),
71 params.requested_format.frame_rate, base::Passed(&client))); 72 params.requested_format.frame_rate, base::Passed(&client)));
72 73
73 for (const auto& request : photo_requests_queue_) 74 for (const auto& request : photo_requests_queue_)
74 v4l2_thread_.task_runner()->PostTask(FROM_HERE, request); 75 v4l2_thread_.task_runner()->PostTask(FROM_HERE, request);
75 photo_requests_queue_.clear(); 76 photo_requests_queue_.clear();
76 } 77 }
77 78
78 void VideoCaptureDeviceLinux::StopAndDeAllocate() { 79 void VideoCaptureDeviceLinux::StopAndDeAllocate() {
79 if (!v4l2_thread_.IsRunning()) 80 if (!v4l2_thread_.IsRunning())
80 return; // Wrong state. 81 return; // Wrong state.
81 v4l2_thread_.task_runner()->PostTask( 82 v4l2_thread_.task_runner()->PostTask(
82 FROM_HERE, 83 FROM_HERE, base::Bind(&V4L2CaptureDelegate::StopAndDeAllocate,
83 base::Bind(&V4L2CaptureDelegate::StopAndDeAllocate, capture_impl_)); 84 base::Unretained(capture_impl_.get())));
84 v4l2_thread_.Stop(); 85 v4l2_thread_.Stop();
85 86
86 capture_impl_ = nullptr; 87 capture_impl_ = nullptr;
87 } 88 }
88 89
89 void VideoCaptureDeviceLinux::TakePhoto(TakePhotoCallback callback) { 90 void VideoCaptureDeviceLinux::TakePhoto(TakePhotoCallback callback) {
90 DCHECK(capture_impl_); 91 DCHECK(capture_impl_);
91 auto functor = base::Bind(&V4L2CaptureDelegate::TakePhoto, capture_impl_, 92 auto functor = base::Bind(&V4L2CaptureDelegate::TakePhoto,
93 base::Unretained(capture_impl_.get()),
92 base::Passed(&callback)); 94 base::Passed(&callback));
93 if (!v4l2_thread_.IsRunning()) { 95 if (!v4l2_thread_.IsRunning()) {
94 // We have to wait until we get the device AllocateAndStart()ed. 96 // We have to wait until we get the device AllocateAndStart()ed.
95 photo_requests_queue_.push_back(std::move(functor)); 97 photo_requests_queue_.push_back(std::move(functor));
96 return; 98 return;
97 } 99 }
98 v4l2_thread_.task_runner()->PostTask(FROM_HERE, std::move(functor)); 100 v4l2_thread_.task_runner()->PostTask(FROM_HERE, std::move(functor));
99 } 101 }
100 102
101 void VideoCaptureDeviceLinux::GetPhotoCapabilities( 103 void VideoCaptureDeviceLinux::GetPhotoCapabilities(
102 GetPhotoCapabilitiesCallback callback) { 104 GetPhotoCapabilitiesCallback callback) {
103 auto functor = base::Bind(&V4L2CaptureDelegate::GetPhotoCapabilities, 105 auto functor = base::Bind(&V4L2CaptureDelegate::GetPhotoCapabilities,
104 capture_impl_, base::Passed(&callback)); 106 base::Unretained(capture_impl_.get()),
107 base::Passed(&callback));
105 if (!v4l2_thread_.IsRunning()) { 108 if (!v4l2_thread_.IsRunning()) {
106 // We have to wait until we get the device AllocateAndStart()ed. 109 // We have to wait until we get the device AllocateAndStart()ed.
107 photo_requests_queue_.push_back(std::move(functor)); 110 photo_requests_queue_.push_back(std::move(functor));
108 return; 111 return;
109 } 112 }
110 v4l2_thread_.task_runner()->PostTask(FROM_HERE, std::move(functor)); 113 v4l2_thread_.task_runner()->PostTask(FROM_HERE, std::move(functor));
111 } 114 }
112 115
113 void VideoCaptureDeviceLinux::SetPhotoOptions( 116 void VideoCaptureDeviceLinux::SetPhotoOptions(
114 mojom::PhotoSettingsPtr settings, 117 mojom::PhotoSettingsPtr settings,
115 SetPhotoOptionsCallback callback) { 118 SetPhotoOptionsCallback callback) {
116 auto functor = 119 auto functor = base::Bind(&V4L2CaptureDelegate::SetPhotoOptions,
117 base::Bind(&V4L2CaptureDelegate::SetPhotoOptions, capture_impl_, 120 base::Unretained(capture_impl_.get()),
118 base::Passed(&settings), base::Passed(&callback)); 121 base::Passed(&settings), base::Passed(&callback));
119 if (!v4l2_thread_.IsRunning()) { 122 if (!v4l2_thread_.IsRunning()) {
120 // We have to wait until we get the device AllocateAndStart()ed. 123 // We have to wait until we get the device AllocateAndStart()ed.
121 photo_requests_queue_.push_back(std::move(functor)); 124 photo_requests_queue_.push_back(std::move(functor));
122 return; 125 return;
123 } 126 }
124 v4l2_thread_.task_runner()->PostTask(FROM_HERE, std::move(functor)); 127 v4l2_thread_.task_runner()->PostTask(FROM_HERE, std::move(functor));
125 } 128 }
126 129
127 void VideoCaptureDeviceLinux::SetRotation(int rotation) { 130 void VideoCaptureDeviceLinux::SetRotation(int rotation) {
128 if (v4l2_thread_.IsRunning()) { 131 if (v4l2_thread_.IsRunning()) {
129 v4l2_thread_.task_runner()->PostTask( 132 v4l2_thread_.task_runner()->PostTask(
130 FROM_HERE, 133 FROM_HERE, base::Bind(&V4L2CaptureDelegate::SetRotation,
131 base::Bind(&V4L2CaptureDelegate::SetRotation, capture_impl_, rotation)); 134 base::Unretained(capture_impl_.get()), rotation));
132 } 135 }
133 } 136 }
134 137
135 // static 138 // static
136 int VideoCaptureDeviceLinux::TranslatePowerLineFrequencyToV4L2( 139 int VideoCaptureDeviceLinux::TranslatePowerLineFrequencyToV4L2(
137 PowerLineFrequency frequency) { 140 PowerLineFrequency frequency) {
138 switch (frequency) { 141 switch (frequency) {
139 case media::PowerLineFrequency::FREQUENCY_50HZ: 142 case media::PowerLineFrequency::FREQUENCY_50HZ:
140 return V4L2_CID_POWER_LINE_FREQUENCY_50HZ; 143 return V4L2_CID_POWER_LINE_FREQUENCY_50HZ;
141 case media::PowerLineFrequency::FREQUENCY_60HZ: 144 case media::PowerLineFrequency::FREQUENCY_60HZ:
142 return V4L2_CID_POWER_LINE_FREQUENCY_60HZ; 145 return V4L2_CID_POWER_LINE_FREQUENCY_60HZ;
143 default: 146 default:
144 // If we have no idea of the frequency, at least try and set it to AUTO. 147 // If we have no idea of the frequency, at least try and set it to AUTO.
145 return V4L2_CID_POWER_LINE_FREQUENCY_AUTO; 148 return V4L2_CID_POWER_LINE_FREQUENCY_AUTO;
146 } 149 }
147 } 150 }
148 151
149 } // namespace media 152 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698