aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Staessens <dstaessens@google.com>2020-08-31 09:23:25 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-08-31 09:23:25 +0000
commit544de3455491f2b2e472109b6f9f4a0f19063d7a (patch)
tree38c6e6ec876adff5e8ed7f0ae46bd23cd56e3c65
parent32f260322e14e0a475347436635c6190f0f6912b (diff)
parentebffb44dfd1dca111f2c02cde6a7f265838bb718 (diff)
downloadv4l2_codec2-544de3455491f2b2e472109b6f9f4a0f19063d7a.tar.gz
v4l2_codec2: Deprecate use of ::base::ScopedFD. am: 72ae41cdc4 am: ebffb44dfd
Original change: https://googleplex-android-review.googlesource.com/c/platform/external/v4l2_codec2/+/12269723 Change-Id: I86b853266782ad2b21d5d09e133673f200a88dde
-rw-r--r--accel/v4l2_device.cc16
-rw-r--r--accel/v4l2_device.h14
-rw-r--r--components/V4L2DecodeComponent.cpp17
-rw-r--r--components/V4L2Decoder.cpp2
-rw-r--r--components/V4L2EncodeComponent.cpp9
-rw-r--r--components/VideoFrame.cpp14
-rw-r--r--components/include/v4l2_codec2/components/BitstreamBuffer.h10
-rw-r--r--components/include/v4l2_codec2/components/V4L2EncodeComponent.h7
-rw-r--r--components/include/v4l2_codec2/components/VideoDecoder.h1
-rw-r--r--components/include/v4l2_codec2/components/VideoFrame.h7
10 files changed, 50 insertions, 47 deletions
diff --git a/accel/v4l2_device.cc b/accel/v4l2_device.cc
index 8ab9898..5c258ab 100644
--- a/accel/v4l2_device.cc
+++ b/accel/v4l2_device.cc
@@ -468,7 +468,19 @@ bool V4L2WritableBufferRef::QueueUserPtr(const std::vector<void*>& ptrs,
return std::move(self).DoQueue(request_ref);
}
-bool V4L2WritableBufferRef::QueueDMABuf(const std::vector<base::ScopedFD>& fds,
+bool V4L2WritableBufferRef::QueueDMABuf(const std::vector<base::ScopedFD>& scoped_fds,
+ V4L2RequestRef* request_ref) && {
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
+
+ std::vector<int> fds;
+ fds.reserve(scoped_fds.size());
+ for (const base::ScopedFD& scoped_fd : scoped_fds)
+ fds.push_back(scoped_fd.get());
+
+ return std::move(*this).QueueDMABuf(fds, request_ref);
+}
+
+bool V4L2WritableBufferRef::QueueDMABuf(const std::vector<int>& fds,
V4L2RequestRef* request_ref) && {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(buffer_data_);
@@ -486,7 +498,7 @@ bool V4L2WritableBufferRef::QueueDMABuf(const std::vector<base::ScopedFD>& fds,
size_t num_planes = self.PlanesCount();
for (size_t i = 0; i < num_planes; i++)
- self.buffer_data_->v4l2_buffer_.m.planes[i].m.fd = fds[i].get();
+ self.buffer_data_->v4l2_buffer_.m.planes[i].m.fd = fds[i];
return std::move(self).DoQueue(request_ref);
}
diff --git a/accel/v4l2_device.h b/accel/v4l2_device.h
index 09b98f0..f00a604 100644
--- a/accel/v4l2_device.h
+++ b/accel/v4l2_device.h
@@ -122,7 +122,19 @@ class V4L2WritableBufferRef {
// so this reference becomes invalid.
// In case of error, false is returned and the buffer is returned to the free
// list.
- bool QueueDMABuf(const std::vector<base::ScopedFD>& fds,
+ bool QueueDMABuf(const std::vector<base::ScopedFD>& scoped_fds,
+ V4L2RequestRef* request_ref = nullptr) &&;
+ // Queue a DMABUF buffer, assigning |fds| as file descriptors for each plane.
+ // It is allowed the number of |fds| might be greater than the number of
+ // planes of this buffer. It happens when the v4l2 pixel format is single
+ // planar. The fd of the first plane is only used in that case.
+ // When requests are supported, a |request_ref| can be passed along this
+ // the buffer to be submitted.
+ // If successful, true is returned and the reference to the buffer is dropped
+ // so this reference becomes invalid.
+ // In case of error, false is returned and the buffer is returned to the free
+ // list.
+ bool QueueDMABuf(const std::vector<int>& fds,
V4L2RequestRef* request_ref = nullptr) &&;
// Returns the number of planes in this buffer.
diff --git a/components/V4L2DecodeComponent.cpp b/components/V4L2DecodeComponent.cpp
index 0548267..1c8a0e8 100644
--- a/components/V4L2DecodeComponent.cpp
+++ b/components/V4L2DecodeComponent.cpp
@@ -40,19 +40,6 @@ int32_t frameIndexToBitstreamId(c2_cntr64_t frameIndex) {
return static_cast<int32_t>(frameIndex.peeku() & 0x3FFFFFFF);
}
-std::unique_ptr<BitstreamBuffer> C2BlockToBitstreamBuffer(const C2ConstLinearBlock& block,
- const int32_t bitstreamId) {
- const int fd = block.handle()->data[0];
- auto dupFd = ::base::ScopedFD(dup(fd));
- if (!dupFd.is_valid()) {
- ALOGE("Failed to dup(%d) input buffer (bitstreamId=%d), errno=%d", fd, bitstreamId, errno);
- return nullptr;
- }
-
- return std::make_unique<BitstreamBuffer>(bitstreamId, std::move(dupFd), block.offset(),
- block.size());
-}
-
bool parseCodedColorAspects(const C2ConstLinearBlock& input,
C2StreamColorAspectsInfo::input* codedAspects) {
C2ReadView view = input.map().get();
@@ -466,7 +453,9 @@ void V4L2DecodeComponent::pumpPendingWorks() {
}
}
- auto buffer = C2BlockToBitstreamBuffer(linearBlock, bitstreamId);
+ std::unique_ptr<BitstreamBuffer> buffer =
+ std::make_unique<BitstreamBuffer>(bitstreamId, linearBlock.handle()->data[0],
+ linearBlock.offset(), linearBlock.size());
if (!buffer) {
reportError(C2_CORRUPTED);
return;
diff --git a/components/V4L2Decoder.cpp b/components/V4L2Decoder.cpp
index 4432222..0a58e20 100644
--- a/components/V4L2Decoder.cpp
+++ b/components/V4L2Decoder.cpp
@@ -284,7 +284,7 @@ void V4L2Decoder::pumpDecodeRequest() {
request.buffer->offset);
inputBuffer->SetPlaneDataOffset(0, request.buffer->offset);
inputBuffer->SetPlaneBytesUsed(0, request.buffer->offset + request.buffer->size);
- std::vector<::base::ScopedFD> fds;
+ std::vector<int> fds;
fds.push_back(std::move(request.buffer->dmabuf_fd));
std::move(*inputBuffer).QueueDMABuf(fds);
diff --git a/components/V4L2EncodeComponent.cpp b/components/V4L2EncodeComponent.cpp
index c13537e..f5c0456 100644
--- a/components/V4L2EncodeComponent.cpp
+++ b/components/V4L2EncodeComponent.cpp
@@ -180,15 +180,10 @@ constexpr size_t kOutputBufferCount = 2;
// static
std::unique_ptr<V4L2EncodeComponent::InputFrame> V4L2EncodeComponent::InputFrame::Create(
const C2ConstGraphicBlock& block) {
- std::vector<::base::ScopedFD> fds;
+ std::vector<int> fds;
const C2Handle* const handle = block.handle();
for (int i = 0; i < handle->numFds; i++) {
- fds.emplace_back(dup(handle->data[i]));
- if (!fds.back().is_valid()) {
- ALOGE("Failed to duplicate input graphic block handle %d (errno: %d)", handle->data[i],
- errno);
- return nullptr;
- }
+ fds.emplace_back(handle->data[i]);
}
return std::unique_ptr<InputFrame>(new InputFrame(std::move(fds)));
diff --git a/components/VideoFrame.cpp b/components/VideoFrame.cpp
index bcdb283..cb5efb7 100644
--- a/components/VideoFrame.cpp
+++ b/components/VideoFrame.cpp
@@ -16,25 +16,21 @@ namespace android {
std::unique_ptr<VideoFrame> VideoFrame::Create(std::shared_ptr<C2GraphicBlock> block) {
if (!block) return nullptr;
- std::vector<::base::ScopedFD> fds;
+ std::vector<int> fds;
const C2Handle* const handle = block->handle();
for (int i = 0; i < handle->numFds; i++) {
- fds.emplace_back(dup(handle->data[i]));
- if (!fds.back().is_valid()) {
- ALOGE("Failed to dup(%d), errno=%d", handle->data[i], errno);
- return nullptr;
- }
+ fds.emplace_back(handle->data[i]);
}
return std::unique_ptr<VideoFrame>(new VideoFrame(std::move(block), std::move(fds)));
}
-VideoFrame::VideoFrame(std::shared_ptr<C2GraphicBlock> block, std::vector<::base::ScopedFD> fds)
- : mGraphicBlock(std::move(block)), mFds(std::move(fds)) {}
+VideoFrame::VideoFrame(std::shared_ptr<C2GraphicBlock> block, std::vector<int> fds)
+ : mGraphicBlock(std::move(block)), mFds(fds) {}
VideoFrame::~VideoFrame() = default;
-const std::vector<::base::ScopedFD>& VideoFrame::getFDs() const {
+const std::vector<int>& VideoFrame::getFDs() const {
return mFds;
}
diff --git a/components/include/v4l2_codec2/components/BitstreamBuffer.h b/components/include/v4l2_codec2/components/BitstreamBuffer.h
index cc8d3f6..ec8a917 100644
--- a/components/include/v4l2_codec2/components/BitstreamBuffer.h
+++ b/components/include/v4l2_codec2/components/BitstreamBuffer.h
@@ -11,14 +11,16 @@
namespace android {
+// The BitstreamBuffer class can be used to store encoded video data.
+// Note: The BitstreamBuffer does not take ownership of the data. The file descriptor is not
+// duplicated and the caller is responsible for keeping the data alive.
struct BitstreamBuffer {
- BitstreamBuffer(const int32_t id, base::ScopedFD dmabuf_fd, const size_t offset,
- const size_t size)
- : id(id), dmabuf_fd(std::move(dmabuf_fd)), offset(offset), size(size) {}
+ BitstreamBuffer(const int32_t id, int dmabuf_fd, const size_t offset, const size_t size)
+ : id(id), dmabuf_fd(dmabuf_fd), offset(offset), size(size) {}
~BitstreamBuffer() = default;
const int32_t id;
- base::ScopedFD dmabuf_fd;
+ int dmabuf_fd;
const size_t offset;
const size_t size;
};
diff --git a/components/include/v4l2_codec2/components/V4L2EncodeComponent.h b/components/include/v4l2_codec2/components/V4L2EncodeComponent.h
index 8a9459c..4d51c03 100644
--- a/components/include/v4l2_codec2/components/V4L2EncodeComponent.h
+++ b/components/include/v4l2_codec2/components/V4L2EncodeComponent.h
@@ -16,7 +16,6 @@
#include <C2Param.h>
#include <C2ParamDef.h>
#include <SimpleC2Interface.h>
-#include <base/files/scoped_file.h>
#include <base/memory/scoped_refptr.h>
#include <base/single_thread_task_runner.h>
#include <base/synchronization/waitable_event.h>
@@ -69,11 +68,11 @@ private:
static std::unique_ptr<InputFrame> Create(const C2ConstGraphicBlock& block);
~InputFrame() = default;
- const std::vector<::base::ScopedFD>& getFDs() const { return mFds; }
+ const std::vector<int>& getFDs() const { return mFds; }
private:
- InputFrame(std::vector<::base::ScopedFD> fds) : mFds(std::move(fds)) {}
- const std::vector<::base::ScopedFD> mFds;
+ InputFrame(std::vector<int> fds) : mFds(std::move(fds)) {}
+ const std::vector<int> mFds;
};
// Possible component states.
diff --git a/components/include/v4l2_codec2/components/VideoDecoder.h b/components/include/v4l2_codec2/components/VideoDecoder.h
index 99d16b3..42b57c1 100644
--- a/components/include/v4l2_codec2/components/VideoDecoder.h
+++ b/components/include/v4l2_codec2/components/VideoDecoder.h
@@ -9,7 +9,6 @@
#include <memory>
#include <base/callback.h>
-#include <base/files/scoped_file.h>
#include <v4l2_codec2/components/BitstreamBuffer.h>
#include <v4l2_codec2/components/VideoFrame.h>
diff --git a/components/include/v4l2_codec2/components/VideoFrame.h b/components/include/v4l2_codec2/components/VideoFrame.h
index f666f4d..395a52b 100644
--- a/components/include/v4l2_codec2/components/VideoFrame.h
+++ b/components/include/v4l2_codec2/components/VideoFrame.h
@@ -9,7 +9,6 @@
#include <vector>
#include <C2Buffer.h>
-#include <base/files/scoped_file.h>
#include <rect.h>
@@ -23,7 +22,7 @@ public:
~VideoFrame();
// Return the file descriptors of the corresponding buffer.
- const std::vector<::base::ScopedFD>& getFDs() const;
+ const std::vector<int>& getFDs() const;
// Getter and setter of the visible rectangle.
void setVisibleRect(const media::Rect& visibleRect);
@@ -37,10 +36,10 @@ public:
C2ConstGraphicBlock getGraphicBlock();
private:
- VideoFrame(std::shared_ptr<C2GraphicBlock> block, std::vector<::base::ScopedFD> fds);
+ VideoFrame(std::shared_ptr<C2GraphicBlock> block, std::vector<int> fds);
std::shared_ptr<C2GraphicBlock> mGraphicBlock;
- std::vector<::base::ScopedFD> mFds;
+ std::vector<int> mFds;
media::Rect mVisibleRect;
int32_t mBitstreamId = -1;
};