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

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

Issue 2815643002: Make V4L2CaptureDelegate non-ref-counted (Closed)
Patch Set: mcasas@ comment 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
« no previous file with comments | « media/capture/video/linux/video_capture_device_linux.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 capture_impl_->GetWeakPtr(),
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 capture_impl_->GetWeakPtr()));
85 v4l2_thread_.task_runner()->DeleteSoon(FROM_HERE, capture_impl_.release());
84 v4l2_thread_.Stop(); 86 v4l2_thread_.Stop();
85 87
86 capture_impl_ = nullptr; 88 capture_impl_ = nullptr;
87 } 89 }
88 90
89 void VideoCaptureDeviceLinux::TakePhoto(TakePhotoCallback callback) { 91 void VideoCaptureDeviceLinux::TakePhoto(TakePhotoCallback callback) {
90 DCHECK(capture_impl_); 92 DCHECK(capture_impl_);
91 auto functor = base::Bind(&V4L2CaptureDelegate::TakePhoto, capture_impl_, 93 auto functor =
92 base::Passed(&callback)); 94 base::Bind(&V4L2CaptureDelegate::TakePhoto, capture_impl_->GetWeakPtr(),
95 base::Passed(&callback));
93 if (!v4l2_thread_.IsRunning()) { 96 if (!v4l2_thread_.IsRunning()) {
94 // We have to wait until we get the device AllocateAndStart()ed. 97 // We have to wait until we get the device AllocateAndStart()ed.
95 photo_requests_queue_.push_back(std::move(functor)); 98 photo_requests_queue_.push_back(std::move(functor));
96 return; 99 return;
97 } 100 }
98 v4l2_thread_.task_runner()->PostTask(FROM_HERE, std::move(functor)); 101 v4l2_thread_.task_runner()->PostTask(FROM_HERE, std::move(functor));
99 } 102 }
100 103
101 void VideoCaptureDeviceLinux::GetPhotoCapabilities( 104 void VideoCaptureDeviceLinux::GetPhotoCapabilities(
102 GetPhotoCapabilitiesCallback callback) { 105 GetPhotoCapabilitiesCallback callback) {
103 auto functor = base::Bind(&V4L2CaptureDelegate::GetPhotoCapabilities, 106 auto functor =
104 capture_impl_, base::Passed(&callback)); 107 base::Bind(&V4L2CaptureDelegate::GetPhotoCapabilities,
108 capture_impl_->GetWeakPtr(), base::Passed(&callback));
105 if (!v4l2_thread_.IsRunning()) { 109 if (!v4l2_thread_.IsRunning()) {
106 // We have to wait until we get the device AllocateAndStart()ed. 110 // We have to wait until we get the device AllocateAndStart()ed.
107 photo_requests_queue_.push_back(std::move(functor)); 111 photo_requests_queue_.push_back(std::move(functor));
108 return; 112 return;
109 } 113 }
110 v4l2_thread_.task_runner()->PostTask(FROM_HERE, std::move(functor)); 114 v4l2_thread_.task_runner()->PostTask(FROM_HERE, std::move(functor));
111 } 115 }
112 116
113 void VideoCaptureDeviceLinux::SetPhotoOptions( 117 void VideoCaptureDeviceLinux::SetPhotoOptions(
114 mojom::PhotoSettingsPtr settings, 118 mojom::PhotoSettingsPtr settings,
115 SetPhotoOptionsCallback callback) { 119 SetPhotoOptionsCallback callback) {
116 auto functor = 120 auto functor = base::Bind(&V4L2CaptureDelegate::SetPhotoOptions,
117 base::Bind(&V4L2CaptureDelegate::SetPhotoOptions, capture_impl_, 121 capture_impl_->GetWeakPtr(),
118 base::Passed(&settings), base::Passed(&callback)); 122 base::Passed(&settings), base::Passed(&callback));
119 if (!v4l2_thread_.IsRunning()) { 123 if (!v4l2_thread_.IsRunning()) {
120 // We have to wait until we get the device AllocateAndStart()ed. 124 // We have to wait until we get the device AllocateAndStart()ed.
121 photo_requests_queue_.push_back(std::move(functor)); 125 photo_requests_queue_.push_back(std::move(functor));
122 return; 126 return;
123 } 127 }
124 v4l2_thread_.task_runner()->PostTask(FROM_HERE, std::move(functor)); 128 v4l2_thread_.task_runner()->PostTask(FROM_HERE, std::move(functor));
125 } 129 }
126 130
127 void VideoCaptureDeviceLinux::SetRotation(int rotation) { 131 void VideoCaptureDeviceLinux::SetRotation(int rotation) {
128 if (v4l2_thread_.IsRunning()) { 132 if (v4l2_thread_.IsRunning()) {
129 v4l2_thread_.task_runner()->PostTask( 133 v4l2_thread_.task_runner()->PostTask(
130 FROM_HERE, 134 FROM_HERE, base::Bind(&V4L2CaptureDelegate::SetRotation,
131 base::Bind(&V4L2CaptureDelegate::SetRotation, capture_impl_, rotation)); 135 capture_impl_->GetWeakPtr(), rotation));
132 } 136 }
133 } 137 }
134 138
135 // static 139 // static
136 int VideoCaptureDeviceLinux::TranslatePowerLineFrequencyToV4L2( 140 int VideoCaptureDeviceLinux::TranslatePowerLineFrequencyToV4L2(
137 PowerLineFrequency frequency) { 141 PowerLineFrequency frequency) {
138 switch (frequency) { 142 switch (frequency) {
139 case media::PowerLineFrequency::FREQUENCY_50HZ: 143 case media::PowerLineFrequency::FREQUENCY_50HZ:
140 return V4L2_CID_POWER_LINE_FREQUENCY_50HZ; 144 return V4L2_CID_POWER_LINE_FREQUENCY_50HZ;
141 case media::PowerLineFrequency::FREQUENCY_60HZ: 145 case media::PowerLineFrequency::FREQUENCY_60HZ:
142 return V4L2_CID_POWER_LINE_FREQUENCY_60HZ; 146 return V4L2_CID_POWER_LINE_FREQUENCY_60HZ;
143 default: 147 default:
144 // If we have no idea of the frequency, at least try and set it to AUTO. 148 // If we have no idea of the frequency, at least try and set it to AUTO.
145 return V4L2_CID_POWER_LINE_FREQUENCY_AUTO; 149 return V4L2_CID_POWER_LINE_FREQUENCY_AUTO;
146 } 150 }
147 } 151 }
148 152
149 } // namespace media 153 } // namespace media
OLDNEW
« no previous file with comments | « media/capture/video/linux/video_capture_device_linux.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698