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..ff0402bfa1278db5c3696143878331c7ff852aba 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, |
+ capture_impl_->GetWeakPtr(), |
params.requested_format.frame_size.width(), |
params.requested_format.frame_size.height(), |
params.requested_format.frame_rate, base::Passed(&client))); |
@@ -79,8 +80,9 @@ 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, |
+ capture_impl_->GetWeakPtr())); |
+ v4l2_thread_.task_runner()->DeleteSoon(FROM_HERE, capture_impl_.release()); |
v4l2_thread_.Stop(); |
capture_impl_ = nullptr; |
@@ -88,8 +90,9 @@ void VideoCaptureDeviceLinux::StopAndDeAllocate() { |
void VideoCaptureDeviceLinux::TakePhoto(TakePhotoCallback callback) { |
DCHECK(capture_impl_); |
- auto functor = base::Bind(&V4L2CaptureDelegate::TakePhoto, capture_impl_, |
- base::Passed(&callback)); |
+ auto functor = |
+ base::Bind(&V4L2CaptureDelegate::TakePhoto, capture_impl_->GetWeakPtr(), |
+ 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)); |
@@ -100,8 +103,9 @@ void VideoCaptureDeviceLinux::TakePhoto(TakePhotoCallback callback) { |
void VideoCaptureDeviceLinux::GetPhotoCapabilities( |
GetPhotoCapabilitiesCallback callback) { |
- auto functor = base::Bind(&V4L2CaptureDelegate::GetPhotoCapabilities, |
- capture_impl_, base::Passed(&callback)); |
+ auto functor = |
+ base::Bind(&V4L2CaptureDelegate::GetPhotoCapabilities, |
+ capture_impl_->GetWeakPtr(), 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 +117,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, |
+ capture_impl_->GetWeakPtr(), |
+ 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 +131,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, |
+ capture_impl_->GetWeakPtr(), rotation)); |
} |
} |