Commit cfe635ce authored by Matthew Cary's avatar Matthew Cary Committed by Commit Bot

media/gpu shared memory: update v4l2 UnalignedSharedMemory

Uses the new WritableUnalignedMapping class, which changes the ownership
semantics. See the bug for details on the overall plan.

Bug: 849207
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: Idacc45e249291bd9d42ff7bf9a8abffe8636f6cf
Reviewed-on: https://chromium-review.googlesource.com/1117692
Commit-Queue: Matthew Cary <mattcary@chromium.org>
Reviewed-by: default avatarDaniele Castagna <dcastagna@chromium.org>
Reviewed-by: default avatarAlexandr Ilin <alexilin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582270}
parent 5ee8761e
...@@ -133,8 +133,9 @@ V4L2JpegDecodeAccelerator::JobRecord::JobRecord( ...@@ -133,8 +133,9 @@ V4L2JpegDecodeAccelerator::JobRecord::JobRecord(
const BitstreamBuffer& bitstream_buffer, const BitstreamBuffer& bitstream_buffer,
scoped_refptr<VideoFrame> video_frame) scoped_refptr<VideoFrame> video_frame)
: bitstream_buffer_id(bitstream_buffer.id()), : bitstream_buffer_id(bitstream_buffer.id()),
shm(bitstream_buffer.handle(), bitstream_buffer.size(), true), shm(bitstream_buffer.handle(),
offset(bitstream_buffer.offset()), bitstream_buffer.size(),
bitstream_buffer.offset()),
out_frame(video_frame) {} out_frame(video_frame) {}
V4L2JpegDecodeAccelerator::JobRecord::~JobRecord() {} V4L2JpegDecodeAccelerator::JobRecord::~JobRecord() {}
...@@ -289,7 +290,7 @@ bool V4L2JpegDecodeAccelerator::IsSupported() { ...@@ -289,7 +290,7 @@ bool V4L2JpegDecodeAccelerator::IsSupported() {
void V4L2JpegDecodeAccelerator::DecodeTask( void V4L2JpegDecodeAccelerator::DecodeTask(
std::unique_ptr<JobRecord> job_record) { std::unique_ptr<JobRecord> job_record) {
DCHECK(decoder_task_runner_->BelongsToCurrentThread()); DCHECK(decoder_task_runner_->BelongsToCurrentThread());
if (!job_record->shm.MapAt(job_record->offset, job_record->shm.size())) { if (!job_record->shm.IsValid()) {
VPLOGF(1) << "could not map bitstream_buffer"; VPLOGF(1) << "could not map bitstream_buffer";
PostNotifyError(job_record->bitstream_buffer_id, UNREADABLE_INPUT); PostNotifyError(job_record->bitstream_buffer_id, UNREADABLE_INPUT);
return; return;
......
...@@ -67,9 +67,7 @@ class MEDIA_GPU_EXPORT V4L2JpegDecodeAccelerator ...@@ -67,9 +67,7 @@ class MEDIA_GPU_EXPORT V4L2JpegDecodeAccelerator
// Input image buffer ID. // Input image buffer ID.
int32_t bitstream_buffer_id; int32_t bitstream_buffer_id;
// Memory mapped from |bitstream_buffer|. // Memory mapped from |bitstream_buffer|.
UnalignedSharedMemory shm; WritableUnalignedMapping shm;
// Offset used for shm.
off_t offset;
// Output frame buffer. // Output frame buffer.
scoped_refptr<VideoFrame> out_frame; scoped_refptr<VideoFrame> out_frame;
}; };
......
...@@ -201,8 +201,7 @@ struct V4L2SliceVideoDecodeAccelerator::BitstreamBufferRef { ...@@ -201,8 +201,7 @@ struct V4L2SliceVideoDecodeAccelerator::BitstreamBufferRef {
~BitstreamBufferRef(); ~BitstreamBufferRef();
const base::WeakPtr<VideoDecodeAccelerator::Client> client; const base::WeakPtr<VideoDecodeAccelerator::Client> client;
const scoped_refptr<base::SingleThreadTaskRunner> client_task_runner; const scoped_refptr<base::SingleThreadTaskRunner> client_task_runner;
const std::unique_ptr<UnalignedSharedMemory> shm; const std::unique_ptr<WritableUnalignedMapping> shm;
off_t offset;
off_t bytes_used; off_t bytes_used;
const int32_t input_id; const int32_t input_id;
}; };
...@@ -214,11 +213,10 @@ V4L2SliceVideoDecodeAccelerator::BitstreamBufferRef::BitstreamBufferRef( ...@@ -214,11 +213,10 @@ V4L2SliceVideoDecodeAccelerator::BitstreamBufferRef::BitstreamBufferRef(
int32_t input_id) int32_t input_id)
: client(client), : client(client),
client_task_runner(client_task_runner), client_task_runner(client_task_runner),
shm(buffer ? std::make_unique<UnalignedSharedMemory>(buffer->handle(), shm(buffer ? std::make_unique<WritableUnalignedMapping>(buffer->handle(),
buffer->size(), buffer->size(),
true) buffer->offset())
: nullptr), : nullptr),
offset(buffer ? buffer->offset() : 0),
bytes_used(0), bytes_used(0),
input_id(input_id) {} input_id(input_id) {}
...@@ -1349,12 +1347,12 @@ void V4L2SliceVideoDecodeAccelerator::DecodeTask( ...@@ -1349,12 +1347,12 @@ void V4L2SliceVideoDecodeAccelerator::DecodeTask(
new BitstreamBufferRef(decode_client_, decode_task_runner_, new BitstreamBufferRef(decode_client_, decode_task_runner_,
&bitstream_buffer, bitstream_buffer.id())); &bitstream_buffer, bitstream_buffer.id()));
// Skip empty buffer. // Skip empty buffer. This must be done after creating bitstream_record as the
// handle in the bitstream_buffer needs to be consumed.
if (bitstream_buffer.size() == 0) if (bitstream_buffer.size() == 0)
return; return;
if (!bitstream_record->shm->MapAt(bitstream_record->offset, if (!bitstream_record->shm->IsValid()) {
bitstream_record->shm->size())) {
VLOGF(1) << "Could not map bitstream_buffer"; VLOGF(1) << "Could not map bitstream_buffer";
NOTIFY_ERROR(UNREADABLE_INPUT); NOTIFY_ERROR(UNREADABLE_INPUT);
return; return;
......
...@@ -78,8 +78,7 @@ struct V4L2VideoDecodeAccelerator::BitstreamBufferRef { ...@@ -78,8 +78,7 @@ struct V4L2VideoDecodeAccelerator::BitstreamBufferRef {
~BitstreamBufferRef(); ~BitstreamBufferRef();
const base::WeakPtr<Client> client; const base::WeakPtr<Client> client;
const scoped_refptr<base::SingleThreadTaskRunner> client_task_runner; const scoped_refptr<base::SingleThreadTaskRunner> client_task_runner;
const std::unique_ptr<UnalignedSharedMemory> shm; const std::unique_ptr<WritableUnalignedMapping> shm;
off_t offset;
size_t bytes_used; size_t bytes_used;
const int32_t input_id; const int32_t input_id;
}; };
...@@ -98,11 +97,10 @@ V4L2VideoDecodeAccelerator::BitstreamBufferRef::BitstreamBufferRef( ...@@ -98,11 +97,10 @@ V4L2VideoDecodeAccelerator::BitstreamBufferRef::BitstreamBufferRef(
int32_t input_id) int32_t input_id)
: client(client), : client(client),
client_task_runner(client_task_runner), client_task_runner(client_task_runner),
shm(buffer ? std::make_unique<UnalignedSharedMemory>(buffer->handle(), shm(buffer ? std::make_unique<WritableUnalignedMapping>(buffer->handle(),
buffer->size(), buffer->size(),
true) buffer->offset())
: nullptr), : nullptr),
offset(buffer ? buffer->offset() : 0),
bytes_used(0), bytes_used(0),
input_id(input_id) {} input_id(input_id) {}
...@@ -779,12 +777,12 @@ void V4L2VideoDecodeAccelerator::DecodeTask( ...@@ -779,12 +777,12 @@ void V4L2VideoDecodeAccelerator::DecodeTask(
new BitstreamBufferRef(decode_client_, decode_task_runner_, new BitstreamBufferRef(decode_client_, decode_task_runner_,
&bitstream_buffer, bitstream_buffer.id())); &bitstream_buffer, bitstream_buffer.id()));
// Skip empty buffer. // Skip empty buffer. This must be done after creating bitstream_record as the
// handle in the bitstream_buffer needs to be consumed.
if (bitstream_buffer.size() == 0) if (bitstream_buffer.size() == 0)
return; return;
if (!bitstream_record->shm->MapAt(bitstream_record->offset, if (!bitstream_record->shm->IsValid()) {
bitstream_record->shm->size())) {
VLOGF(1) << "could not map bitstream_buffer"; VLOGF(1) << "could not map bitstream_buffer";
NOTIFY_ERROR(UNREADABLE_INPUT); NOTIFY_ERROR(UNREADABLE_INPUT);
return; return;
......
...@@ -89,10 +89,10 @@ static void CopyNALUPrependingStartCode(const uint8_t* src, ...@@ -89,10 +89,10 @@ static void CopyNALUPrependingStartCode(const uint8_t* src,
namespace media { namespace media {
struct V4L2VideoEncodeAccelerator::BitstreamBufferRef { struct V4L2VideoEncodeAccelerator::BitstreamBufferRef {
BitstreamBufferRef(int32_t id, std::unique_ptr<UnalignedSharedMemory> shm) BitstreamBufferRef(int32_t id, std::unique_ptr<WritableUnalignedMapping> shm)
: id(id), shm(std::move(shm)) {} : id(id), shm(std::move(shm)) {}
const int32_t id; const int32_t id;
const std::unique_ptr<UnalignedSharedMemory> shm; const std::unique_ptr<WritableUnalignedMapping> shm;
}; };
V4L2VideoEncodeAccelerator::InputRecord::InputRecord() : at_device(false) {} V4L2VideoEncodeAccelerator::InputRecord::InputRecord() : at_device(false) {}
...@@ -307,9 +307,9 @@ void V4L2VideoEncodeAccelerator::UseOutputBitstreamBuffer( ...@@ -307,9 +307,9 @@ void V4L2VideoEncodeAccelerator::UseOutputBitstreamBuffer(
return; return;
} }
auto shm = std::make_unique<UnalignedSharedMemory>(buffer.handle(), auto shm = std::make_unique<WritableUnalignedMapping>(
buffer.size(), false); buffer.handle(), buffer.size(), buffer.offset());
if (!shm->MapAt(buffer.offset(), buffer.size())) { if (!shm->IsValid()) {
NOTIFY_ERROR(kPlatformFailureError); NOTIFY_ERROR(kPlatformFailureError);
return; return;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment