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

Unified Diff: media/capture/video/linux/video_capture_device_linux.cc

Issue 2815643002: Make V4L2CaptureDelegate non-ref-counted (Closed)
Patch Set: Added weak pointer to V4L2CaptureDelegate 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 side-by-side diff with in-line comments
Download patch
Index: media/capture/video/linux/video_capture_device_linux.cc
diff --git a/media/capture/video/linux/video_capture_device_linux.cc b/media/capture/video/linux/video_capture_device_linux.cc
index d9b25b409e1b9cab072d87be4515700b6c57b1dd..7bb4ad09cfb02e31f5806c227eab04fa8e84df5a 100644
--- a/media/capture/video/linux/video_capture_device_linux.cc
+++ b/media/capture/video/linux/video_capture_device_linux.cc
@@ -57,7 +57,7 @@ void VideoCaptureDeviceLinux::AllocateAndStart(
const int line_frequency =
TranslatePowerLineFrequencyToV4L2(GetPowerLineFrequency(params));
- capture_impl_ = new V4L2CaptureDelegate(
+ capture_impl_ = base::MakeUnique<V4L2CaptureDelegate>(
device_descriptor_, v4l2_thread_.task_runner(), line_frequency);
if (!capture_impl_) {
client->OnError(FROM_HERE, "Failed to create VideoCaptureDelegate");
@@ -65,7 +65,8 @@ void VideoCaptureDeviceLinux::AllocateAndStart(
}
v4l2_thread_.task_runner()->PostTask(
FROM_HERE,
- base::Bind(&V4L2CaptureDelegate::AllocateAndStart, capture_impl_,
+ base::Bind(&V4L2CaptureDelegate::AllocateAndStart,
+ base::Unretained(capture_impl_.get()),
mcasas 2017/04/12 17:32:55 Get a WeakPtr to |capture_impl_| to be used on |v4
Chandan 2017/04/13 09:06:07 Done.
params.requested_format.frame_size.width(),
params.requested_format.frame_size.height(),
params.requested_format.frame_rate, base::Passed(&client)));
chfremer 2017/04/12 17:13:46 Please add a comment explaining why the use of bas
Chandan 2017/04/13 09:06:07 We now use WeakPtr to |capture_impl_| instead of b
@@ -79,16 +80,16 @@ void VideoCaptureDeviceLinux::StopAndDeAllocate() {
if (!v4l2_thread_.IsRunning())
return; // Wrong state.
v4l2_thread_.task_runner()->PostTask(
- FROM_HERE,
- base::Bind(&V4L2CaptureDelegate::StopAndDeAllocate, capture_impl_));
+ FROM_HERE, base::Bind(&V4L2CaptureDelegate::StopAndDeAllocate,
+ base::Unretained(capture_impl_.get())));
+ v4l2_thread_.task_runner()->DeleteSoon(FROM_HERE, capture_impl_.release());
v4l2_thread_.Stop();
-
- capture_impl_ = nullptr;
}
void VideoCaptureDeviceLinux::TakePhoto(TakePhotoCallback callback) {
DCHECK(capture_impl_);
- auto functor = base::Bind(&V4L2CaptureDelegate::TakePhoto, capture_impl_,
+ auto functor = base::Bind(&V4L2CaptureDelegate::TakePhoto,
+ base::Unretained(capture_impl_.get()),
base::Passed(&callback));
if (!v4l2_thread_.IsRunning()) {
// We have to wait until we get the device AllocateAndStart()ed.
@@ -101,7 +102,8 @@ void VideoCaptureDeviceLinux::TakePhoto(TakePhotoCallback callback) {
void VideoCaptureDeviceLinux::GetPhotoCapabilities(
GetPhotoCapabilitiesCallback callback) {
auto functor = base::Bind(&V4L2CaptureDelegate::GetPhotoCapabilities,
- capture_impl_, base::Passed(&callback));
+ base::Unretained(capture_impl_.get()),
+ base::Passed(&callback));
if (!v4l2_thread_.IsRunning()) {
// We have to wait until we get the device AllocateAndStart()ed.
photo_requests_queue_.push_back(std::move(functor));
@@ -113,9 +115,9 @@ void VideoCaptureDeviceLinux::GetPhotoCapabilities(
void VideoCaptureDeviceLinux::SetPhotoOptions(
mojom::PhotoSettingsPtr settings,
SetPhotoOptionsCallback callback) {
- auto functor =
- base::Bind(&V4L2CaptureDelegate::SetPhotoOptions, capture_impl_,
- base::Passed(&settings), base::Passed(&callback));
+ auto functor = base::Bind(&V4L2CaptureDelegate::SetPhotoOptions,
+ base::Unretained(capture_impl_.get()),
+ base::Passed(&settings), base::Passed(&callback));
if (!v4l2_thread_.IsRunning()) {
// We have to wait until we get the device AllocateAndStart()ed.
photo_requests_queue_.push_back(std::move(functor));
@@ -127,8 +129,8 @@ void VideoCaptureDeviceLinux::SetPhotoOptions(
void VideoCaptureDeviceLinux::SetRotation(int rotation) {
if (v4l2_thread_.IsRunning()) {
v4l2_thread_.task_runner()->PostTask(
- FROM_HERE,
- base::Bind(&V4L2CaptureDelegate::SetRotation, capture_impl_, rotation));
+ FROM_HERE, base::Bind(&V4L2CaptureDelegate::SetRotation,
+ base::Unretained(capture_impl_.get()), rotation));
}
}

Powered by Google App Engine
This is Rietveld 408576698