summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-14 05:37:08 +0000
committerthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-14 05:37:08 +0000
commitface3686c641e6d055c424a55a29d0f562a4110a (patch)
tree29f9eae2bc0c9c65a16924e3d5a330f6257579be /media
parent523e42f663d1b5f8766103c567287f3b33fb7508 (diff)
downloadchromium_src-face3686c641e6d055c424a55a29d0f562a4110a.zip
chromium_src-face3686c641e6d055c424a55a29d0f562a4110a.tar.gz
chromium_src-face3686c641e6d055c424a55a29d0f562a4110a.tar.bz2
Revert of Implement ScopedFD in terms of ScopedGeneric. (https://codereview.chromium.org/191673003/)
Reason for revert: Doesn't build on android: FAILED: /mnt/data/b/build/goma/gomacc ../../third_party/llvm-build/Release+Asserts/bin/clang++ -MMD -MF obj/base/memory/base.discardable_memory_allocator_android.o.d -DV8_DEPRECATION_WARNINGS -DBLINK_SCALE_FILTERS_AT_RECORD_TIME -D_FILE_OFFSET_BITS=64 -DNO_TCMALLOC -DDISABLE_NACL -DCHROMIUM_BUILD -DCOMPONENT_BUILD -DUSE_LIBJPEG_TURBO=1 -DENABLE_WEBRTC=1 -DUSE_PROPRIETARY_CODECS -DENABLE_CONFIGURATION_POLICY -DENABLE_NEW_GAMEPAD_API=1 -DDISCARDABLE_MEMORY_ALWAYS_SUPPORTED_NATIVELY -DSYSTEM_NATIVELY_SIGNALS_MEMORY_PRESSURE -DENABLE_EGLIMAGE=1 -DENABLE_AUTOFILL_DIALOG=1 -DCLD_VERSION=1 -DENABLE_PRINTING=1 -DENABLE_MANAGED_USERS=1 -DUSE_OPENSSL=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -DBASE_IMPLEMENTATION -DANDROID -D__GNU_SOURCE=1 -DUSE_STLPORT=1 -D_STLP_USE_PTR_SPECIALIZATIONS=1 '-DCHROME_BUILD_ID=""' -DHAVE_SYS_UIO_H -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DWTF_USE_DYNAMIC_ANNOTATIONS=1 -D_DEBUG -Igen/base -I../../third_party/android_tools/ndk/sources/android/cpufeatures -I../.. -fstack-protector --param=ssp-buffer-size=4 -Werror -fno-exceptions -fno-strict-aliasing -Wall -Wno-unused-parameter -Wno-missing-field-initializers -fvisibility=hidden -pipe -fPIC -Wheader-hygiene -Wno-char-subscripts -Wno-unneeded-internal-declaration -Wno-covered-switch-default -Wstring-conversion -Wno-c++11-narrowing -Wno-reserved-user-defined-literal -Wno-deprecated-register -Xclang -load -Xclang /mnt/data/b/build/slave/Android_Clang_Builder__dbg_/build/src/tools/clang/scripts/../../../third_party/llvm-build/Release+Asserts/lib/libFindBadConstructs.so -Xclang -add-plugin -Xclang find-bad-constructs -Xclang -plugin-arg-find-bad-constructs -Xclang check-url-directory -fcolor-diagnostics -Wexit-time-destructors -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -mthumb -no-integrated-as -B/mnt/data/b/build/slave/Android_Clang_Builder__dbg_/build/src/third_party/android_tools/ndk//toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin -ffunction-sections -funwind-tables -g -fstack-protector -fno-short-enums -Wa,--noexecstack -D__compiler_offsetof=__builtin_offsetof -Dnan=__builtin_nan -target arm-linux-androideabi -mllvm -arm-enable-ehabi --sysroot=/mnt/data/b/build/slave/Android_Clang_Builder__dbg_/build/src/third_party/android_tools/ndk//platforms/android-14/arch-arm -I/mnt/data/b/build/slave/Android_Clang_Builder__dbg_/build/src/third_party/android_tools/ndk//sources/cxx-stl/stlport/stlport -Os -g -fomit-frame-pointer -fdata-sections -ffunction-sections -funwind-tables -g0 -fno-rtti -fno-threadsafe-statics -fvisibility-inlines-hidden -Wsign-compare -std=gnu++11 -Wno-implicit-exception-spec-mismatch -Wno-abi -c ../../base/memory/discardable_memory_allocator_android.cc -o obj/base/memory/base.discardable_memory_allocator_android.o ../../base/memory/discardable_memory_allocator_android.cc:84:25:error: no matching function for call to 'mmap' void* const address = mmap( ^~~~ /mnt/data/b/build/slave/Android_Clang_Builder__dbg_/build/src/third_party/android_tools/ndk//platforms/android-14/arch-arm/usr/include/sys/mman.h:47:15: note: candidate function not viable: no known conversion from 'base::ScopedFD' (aka 'ScopedGeneric<int, internal::ScopedFDCloseTraits>') to 'int' for 5th argument extern void* mmap(void *, size_t, int, int, int, off_t); ^ 1 error generated. Original issue's description: > Implement ScopedFD in terms of ScopedGeneric. > > Move to a new file base/files/scoped_file.h. I will also add ScopedFILE to here (currently in file_util.h) later. > > I think there is a crash in the old code in content/browser/zygote_host/zygote_host_impl_linux.cc that this patch should fix. The old ScopedFD took the address of something in a vector that is being modified. > > I removed SafeScopedFD from content/common/sandbox_linux/sandbox_linux.cc since base's ScopedFD not CHECKs on close failure (this is a more recent addition). > > BUG= > R=agl@chromium.org, viettrungluu@chromium.org > > Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=257001 TBR=viettrungluu@chromium.org,agl@chromium.org,brettw@chromium.org NOTREECHECKS=true NOTRY=true BUG= Review URL: https://codereview.chromium.org/197873014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@257005 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/video/capture/linux/video_capture_device_linux.cc77
-rw-r--r--media/video/capture/linux/video_capture_device_linux.h4
2 files changed, 42 insertions, 39 deletions
diff --git a/media/video/capture/linux/video_capture_device_linux.cc b/media/video/capture/linux/video_capture_device_linux.cc
index 7a9ed69..fa3f83b 100644
--- a/media/video/capture/linux/video_capture_device_linux.cc
+++ b/media/video/capture/linux/video_capture_device_linux.cc
@@ -19,7 +19,6 @@
#include "base/bind.h"
#include "base/files/file_enumerator.h"
-#include "base/files/scoped_file.h"
#include "base/posix/eintr_wrapper.h"
#include "base/strings/stringprintf.h"
@@ -120,18 +119,19 @@ void VideoCaptureDevice::GetDeviceNames(Names* device_names) {
base::FileEnumerator::FileInfo info = enumerator.GetInfo();
std::string unique_id = path.value() + info.GetName().value();
- base::ScopedFD fd(HANDLE_EINTR(open(unique_id.c_str(), O_RDONLY)));
- if (!fd.is_valid()) {
+ int fd;
+ if ((fd = HANDLE_EINTR(open(unique_id.c_str() , O_RDONLY))) < 0) {
// Failed to open this device.
continue;
}
+ file_util::ScopedFD fd_closer(&fd);
// Test if this is a V4L2 capture device.
v4l2_capability cap;
- if ((HANDLE_EINTR(ioctl(fd.get(), VIDIOC_QUERYCAP, &cap)) == 0) &&
+ if ((HANDLE_EINTR(ioctl(fd, VIDIOC_QUERYCAP, &cap)) == 0) &&
(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) &&
!(cap.capabilities & V4L2_CAP_VIDEO_OUTPUT)) {
// This is a V4L2 video capture device
- if (HasUsableFormats(fd.get())) {
+ if (HasUsableFormats(fd)) {
Name device_name(base::StringPrintf("%s", cap.card), unique_id);
device_names->push_back(device_name);
} else {
@@ -146,18 +146,19 @@ void VideoCaptureDevice::GetDeviceSupportedFormats(
VideoCaptureFormats* supported_formats) {
if (device.id().empty())
return;
- base::ScopedFD fd(HANDLE_EINTR(open(device.id().c_str(), O_RDONLY)));
- if (!fd.is_valid()) {
+ int fd;
+ if ((fd = HANDLE_EINTR(open(device.id().c_str(), O_RDONLY))) < 0) {
// Failed to open this device.
return;
}
+ file_util::ScopedFD fd_closer(&fd);
supported_formats->clear();
// Retrieve the caps one by one, first get pixel format, then sizes, then
// frame rates. See http://linuxtv.org/downloads/v4l-dvb-apis for reference.
v4l2_fmtdesc pixel_format = {};
pixel_format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- while (HANDLE_EINTR(ioctl(fd.get(), VIDIOC_ENUM_FMT, &pixel_format)) == 0) {
+ while (HANDLE_EINTR(ioctl(fd, VIDIOC_ENUM_FMT, &pixel_format)) == 0) {
VideoCaptureFormat supported_format;
supported_format.pixel_format =
V4l2ColorToVideoCaptureColorFormat((int32)pixel_format.pixelformat);
@@ -168,8 +169,7 @@ void VideoCaptureDevice::GetDeviceSupportedFormats(
v4l2_frmsizeenum frame_size = {};
frame_size.pixel_format = pixel_format.pixelformat;
- while (HANDLE_EINTR(ioctl(fd.get(), VIDIOC_ENUM_FRAMESIZES, &frame_size)) ==
- 0) {
+ while (HANDLE_EINTR(ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &frame_size)) == 0) {
if (frame_size.type == V4L2_FRMSIZE_TYPE_DISCRETE) {
supported_format.frame_size.SetSize(
frame_size.discrete.width, frame_size.discrete.height);
@@ -184,8 +184,8 @@ void VideoCaptureDevice::GetDeviceSupportedFormats(
frame_interval.pixel_format = pixel_format.pixelformat;
frame_interval.width = frame_size.discrete.width;
frame_interval.height = frame_size.discrete.height;
- while (HANDLE_EINTR(ioctl(
- fd.get(), VIDIOC_ENUM_FRAMEINTERVALS, &frame_interval)) == 0) {
+ while (HANDLE_EINTR(
+ ioctl(fd, VIDIOC_ENUM_FRAMEINTERVALS, &frame_interval)) == 0) {
if (frame_interval.type == V4L2_FRMIVAL_TYPE_DISCRETE) {
if (frame_interval.discrete.numerator != 0) {
supported_format.frame_rate =
@@ -255,12 +255,13 @@ VideoCaptureDevice* VideoCaptureDevice::Create(const Name& device_name) {
// Test opening the device driver. This is to make sure it is available.
// We will reopen it again in our worker thread when someone
// allocates the camera.
- base::ScopedFD fd(HANDLE_EINTR(open(device_name.id().c_str(), O_RDONLY)));
- if (!fd.is_valid()) {
+ int fd = HANDLE_EINTR(open(device_name.id().c_str(), O_RDONLY));
+ if (fd < 0) {
DVLOG(1) << "Cannot open device";
delete self;
return NULL;
}
+ close(fd);
return self;
}
@@ -268,6 +269,7 @@ VideoCaptureDevice* VideoCaptureDevice::Create(const Name& device_name) {
VideoCaptureDeviceLinux::VideoCaptureDeviceLinux(const Name& device_name)
: state_(kIdle),
device_name_(device_name),
+ device_fd_(-1),
v4l2_thread_("V4L2Thread"),
buffer_pool_(NULL),
buffer_pool_size_(0),
@@ -322,19 +324,21 @@ void VideoCaptureDeviceLinux::OnAllocateAndStart(int width,
client_ = client.Pass();
// Need to open camera with O_RDWR after Linux kernel 3.3.
- device_fd_.reset(HANDLE_EINTR(open(device_name_.id().c_str(), O_RDWR)));
- if (!device_fd_.is_valid()) {
+ device_fd_ = HANDLE_EINTR(open(device_name_.id().c_str(), O_RDWR));
+ if (device_fd_ < 0) {
SetErrorState("Failed to open V4L2 device driver.");
return;
}
+ device_fd_closer_.reset(&device_fd_);
// Test if this is a V4L2 capture device.
v4l2_capability cap;
- if (!((HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_QUERYCAP, &cap)) == 0) &&
+ if (!((HANDLE_EINTR(ioctl(device_fd_, VIDIOC_QUERYCAP, &cap)) == 0) &&
(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) &&
!(cap.capabilities & V4L2_CAP_VIDEO_OUTPUT))) {
// This is not a V4L2 video capture device.
- device_fd_.reset();
+ device_fd_closer_.reset();
+ device_fd_ = -1;
SetErrorState("This is not a V4L2 video capture device");
return;
}
@@ -351,8 +355,7 @@ void VideoCaptureDeviceLinux::OnAllocateAndStart(int width,
// Enumerate image formats.
std::list<int>::iterator best = v4l2_formats.end();
- while (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_ENUM_FMT, &fmtdesc)) ==
- 0) {
+ while (HANDLE_EINTR(ioctl(device_fd_, VIDIOC_ENUM_FMT, &fmtdesc)) == 0) {
best = std::find(v4l2_formats.begin(), best, fmtdesc.pixelformat);
fmtdesc.index++;
}
@@ -371,7 +374,7 @@ void VideoCaptureDeviceLinux::OnAllocateAndStart(int width,
video_fmt.fmt.pix.height = height;
video_fmt.fmt.pix.pixelformat = *best;
- if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_S_FMT, &video_fmt)) < 0) {
+ if (HANDLE_EINTR(ioctl(device_fd_, VIDIOC_S_FMT, &video_fmt)) < 0) {
SetErrorState("Failed to set camera format");
return;
}
@@ -381,15 +384,14 @@ void VideoCaptureDeviceLinux::OnAllocateAndStart(int width,
memset(&streamparm, 0, sizeof(v4l2_streamparm));
streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
// The following line checks that the driver knows about framerate get/set.
- if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_G_PARM, &streamparm)) >= 0) {
+ if (HANDLE_EINTR(ioctl(device_fd_, VIDIOC_G_PARM, &streamparm)) >= 0) {
// Now check if the device is able to accept a capture framerate set.
if (streamparm.parm.capture.capability & V4L2_CAP_TIMEPERFRAME) {
streamparm.parm.capture.timeperframe.numerator = 1;
streamparm.parm.capture.timeperframe.denominator =
(frame_rate) ? frame_rate : kTypicalFramerate;
- if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_S_PARM, &streamparm)) <
- 0) {
+ if (HANDLE_EINTR(ioctl(device_fd_, VIDIOC_S_PARM, &streamparm)) < 0) {
SetErrorState("Failed to set camera framerate");
return;
}
@@ -417,7 +419,7 @@ void VideoCaptureDeviceLinux::OnAllocateAndStart(int width,
// Start UVC camera.
v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_STREAMON, &type)) == -1) {
+ if (HANDLE_EINTR(ioctl(device_fd_, VIDIOC_STREAMON, &type)) == -1) {
SetErrorState("VIDIOC_STREAMON failed");
return;
}
@@ -434,7 +436,7 @@ void VideoCaptureDeviceLinux::OnStopAndDeAllocate() {
DCHECK_EQ(v4l2_thread_.message_loop(), base::MessageLoop::current());
v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_STREAMOFF, &type)) < 0) {
+ if (HANDLE_EINTR(ioctl(device_fd_, VIDIOC_STREAMOFF, &type)) < 0) {
SetErrorState("VIDIOC_STREAMOFF failed");
return;
}
@@ -445,7 +447,8 @@ void VideoCaptureDeviceLinux::OnStopAndDeAllocate() {
// We need to close and open the device if we want to change the settings
// Otherwise VIDIOC_S_FMT will return error
// Sad but true.
- device_fd_.reset();
+ device_fd_closer_.reset();
+ device_fd_ = -1;
state_ = kIdle;
client_.reset();
}
@@ -459,7 +462,7 @@ void VideoCaptureDeviceLinux::OnCaptureTask() {
fd_set r_set;
FD_ZERO(&r_set);
- FD_SET(device_fd_.get(), &r_set);
+ FD_SET(device_fd_, &r_set);
timeval timeout;
timeout.tv_sec = 0;
@@ -468,7 +471,7 @@ void VideoCaptureDeviceLinux::OnCaptureTask() {
// First argument to select is the highest numbered file descriptor +1.
// Refer to http://linux.die.net/man/2/select for more information.
int result =
- HANDLE_EINTR(select(device_fd_.get() + 1, &r_set, NULL, NULL, &timeout));
+ HANDLE_EINTR(select(device_fd_ + 1, &r_set, NULL, NULL, &timeout));
// Check if select have failed.
if (result < 0) {
// EINTR is a signal. This is not really an error.
@@ -497,13 +500,13 @@ void VideoCaptureDeviceLinux::OnCaptureTask() {
}
// Check if the driver have filled a buffer.
- if (FD_ISSET(device_fd_.get(), &r_set)) {
+ if (FD_ISSET(device_fd_, &r_set)) {
v4l2_buffer buffer;
memset(&buffer, 0, sizeof(buffer));
buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buffer.memory = V4L2_MEMORY_MMAP;
// Dequeue a buffer.
- if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_DQBUF, &buffer)) == 0) {
+ if (HANDLE_EINTR(ioctl(device_fd_, VIDIOC_DQBUF, &buffer)) == 0) {
client_->OnIncomingCapturedData(
static_cast<uint8*>(buffer_pool_[buffer.index].start),
buffer.bytesused,
@@ -512,7 +515,7 @@ void VideoCaptureDeviceLinux::OnCaptureTask() {
base::TimeTicks::Now());
// Enqueue the buffer again.
- if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_QBUF, &buffer)) == -1) {
+ if (HANDLE_EINTR(ioctl(device_fd_, VIDIOC_QBUF, &buffer)) == -1) {
SetErrorState(base::StringPrintf(
"Failed to enqueue capture buffer errno %d", errno));
}
@@ -537,7 +540,7 @@ bool VideoCaptureDeviceLinux::AllocateVideoBuffers() {
r_buffer.memory = V4L2_MEMORY_MMAP;
r_buffer.count = kMaxVideoBuffers;
- if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_REQBUFS, &r_buffer)) < 0) {
+ if (HANDLE_EINTR(ioctl(device_fd_, VIDIOC_REQBUFS, &r_buffer)) < 0) {
return false;
}
@@ -556,20 +559,20 @@ bool VideoCaptureDeviceLinux::AllocateVideoBuffers() {
buffer.memory = V4L2_MEMORY_MMAP;
buffer.index = i;
- if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_QUERYBUF, &buffer)) < 0) {
+ if (HANDLE_EINTR(ioctl(device_fd_, VIDIOC_QUERYBUF, &buffer)) < 0) {
return false;
}
// Some devices require mmap() to be called with both READ and WRITE.
// See crbug.com/178582.
buffer_pool_[i].start = mmap(NULL, buffer.length, PROT_READ | PROT_WRITE,
- MAP_SHARED, device_fd_.get(), buffer.m.offset);
+ MAP_SHARED, device_fd_, buffer.m.offset);
if (buffer_pool_[i].start == MAP_FAILED) {
return false;
}
buffer_pool_[i].length = buffer.length;
// Enqueue the buffer in the drivers incoming queue.
- if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_QBUF, &buffer)) < 0) {
+ if (HANDLE_EINTR(ioctl(device_fd_, VIDIOC_QBUF, &buffer)) < 0) {
return false;
}
}
@@ -590,7 +593,7 @@ void VideoCaptureDeviceLinux::DeAllocateVideoBuffers() {
r_buffer.memory = V4L2_MEMORY_MMAP;
r_buffer.count = 0;
- if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_REQBUFS, &r_buffer)) < 0) {
+ if (HANDLE_EINTR(ioctl(device_fd_, VIDIOC_REQBUFS, &r_buffer)) < 0) {
SetErrorState("Failed to reset buf.");
}
diff --git a/media/video/capture/linux/video_capture_device_linux.h b/media/video/capture/linux/video_capture_device_linux.h
index 6a8dcee..4cc1597 100644
--- a/media/video/capture/linux/video_capture_device_linux.h
+++ b/media/video/capture/linux/video_capture_device_linux.h
@@ -13,7 +13,6 @@
#include <string>
#include "base/file_util.h"
-#include "base/files/scoped_file.h"
#include "base/threading/thread.h"
#include "media/video/capture/video_capture_device.h"
#include "media/video/capture/video_capture_types.h"
@@ -61,7 +60,8 @@ class VideoCaptureDeviceLinux : public VideoCaptureDevice {
InternalState state_;
scoped_ptr<VideoCaptureDevice::Client> client_;
Name device_name_;
- base::ScopedFD device_fd_; // File descriptor for the opened camera device.
+ int device_fd_; // File descriptor for the opened camera device.
+ file_util::ScopedFD device_fd_closer_;
base::Thread v4l2_thread_; // Thread used for reading data from the device.
Buffer* buffer_pool_;
int buffer_pool_size_; // Number of allocated buffers.