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

Side by Side Diff: media/capture/video/linux/v4l2_capture_delegate.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/v4l2_capture_delegate.h" 5 #include "media/capture/video/linux/v4l2_capture_delegate.h"
6 6
7 #include <linux/version.h> 7 #include <linux/version.h>
8 #include <linux/videodev2.h> 8 #include <linux/videodev2.h>
9 #include <poll.h> 9 #include <poll.h>
10 #include <sys/fcntl.h> 10 #include <sys/fcntl.h>
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 0) { 499 0) {
500 SetErrorState(FROM_HERE, "VIDIOC_STREAMON failed"); 500 SetErrorState(FROM_HERE, "VIDIOC_STREAMON failed");
501 return; 501 return;
502 } 502 }
503 503
504 client_->OnStarted(); 504 client_->OnStarted();
505 is_capturing_ = true; 505 is_capturing_ = true;
506 506
507 // Post task to start fetching frames from v4l2. 507 // Post task to start fetching frames from v4l2.
508 v4l2_task_runner_->PostTask( 508 v4l2_task_runner_->PostTask(
509 FROM_HERE, base::Bind(&V4L2CaptureDelegate::DoCapture, this)); 509 FROM_HERE,
510 base::Bind(&V4L2CaptureDelegate::DoCapture, base::Unretained(this)));
mcasas 2017/04/11 17:17:34 How would you guarantee that |this| is alive when
Chandan 2017/04/11 19:46:43 Need to use weak pointer then? What do you suggest
510 } 511 }
511 512
512 void V4L2CaptureDelegate::StopAndDeAllocate() { 513 void V4L2CaptureDelegate::StopAndDeAllocate() {
513 DCHECK(v4l2_task_runner_->BelongsToCurrentThread()); 514 DCHECK(v4l2_task_runner_->BelongsToCurrentThread());
514 // The order is important: stop streaming, clear |buffer_pool_|, 515 // The order is important: stop streaming, clear |buffer_pool_|,
515 // thus munmap()ing the v4l2_buffers, and then return them to the OS. 516 // thus munmap()ing the v4l2_buffers, and then return them to the OS.
516 v4l2_buf_type capture_type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 517 v4l2_buf_type capture_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
517 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_STREAMOFF, &capture_type)) < 518 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_STREAMOFF, &capture_type)) <
518 0) { 519 0) {
519 SetErrorState(FROM_HERE, "VIDIOC_STREAMOFF failed"); 520 SetErrorState(FROM_HERE, "VIDIOC_STREAMOFF failed");
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 cb.Run(std::move(blob)); 814 cb.Run(std::move(blob));
814 } 815 }
815 816
816 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_QBUF, &buffer)) < 0) { 817 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_QBUF, &buffer)) < 0) {
817 SetErrorState(FROM_HERE, "Failed to enqueue capture buffer"); 818 SetErrorState(FROM_HERE, "Failed to enqueue capture buffer");
818 return; 819 return;
819 } 820 }
820 } 821 }
821 822
822 v4l2_task_runner_->PostTask( 823 v4l2_task_runner_->PostTask(
823 FROM_HERE, base::Bind(&V4L2CaptureDelegate::DoCapture, this)); 824 FROM_HERE,
825 base::Bind(&V4L2CaptureDelegate::DoCapture, base::Unretained(this)));
824 } 826 }
825 827
826 void V4L2CaptureDelegate::SetErrorState( 828 void V4L2CaptureDelegate::SetErrorState(
827 const tracked_objects::Location& from_here, 829 const tracked_objects::Location& from_here,
828 const std::string& reason) { 830 const std::string& reason) {
829 DCHECK(v4l2_task_runner_->BelongsToCurrentThread()); 831 DCHECK(v4l2_task_runner_->BelongsToCurrentThread());
830 is_capturing_ = false; 832 is_capturing_ = false;
831 client_->OnError(from_here, reason); 833 client_->OnError(from_here, reason);
832 } 834 }
833 835
(...skipping 16 matching lines...) Expand all
850 DLOG(ERROR) << "Error mmap()ing a V4L2 buffer into userspace"; 852 DLOG(ERROR) << "Error mmap()ing a V4L2 buffer into userspace";
851 return false; 853 return false;
852 } 854 }
853 start_ = static_cast<uint8_t*>(start); 855 start_ = static_cast<uint8_t*>(start);
854 length_ = buffer.length; 856 length_ = buffer.length;
855 payload_size_ = 0; 857 payload_size_ = 0;
856 return true; 858 return true;
857 } 859 }
858 860
859 } // namespace media 861 } // namespace media
OLDNEW
« no previous file with comments | « media/capture/video/linux/v4l2_capture_delegate.h ('k') | media/capture/video/linux/v4l2_capture_delegate_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698