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

media/gpu shared memory: Use WritableUnalignedMapping for vaapi.

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

This is a reland of crrev.com/c/1117696, now that mojo is initialized
for the unittests is fixed, and also removes a double-close for the
shared memory handles.

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: Ib065caedfed8a33fd0f112ce22a72bda4b9bf99e
Reviewed-on: https://chromium-review.googlesource.com/1158567Reviewed-by: default avatarDaniele Castagna <dcastagna@chromium.org>
Commit-Queue: Matthew Cary <mattcary@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582177}
parent 44cd1928
......@@ -84,7 +84,7 @@ static unsigned int VaSurfaceFormatForJpeg(
// consumption, provided by the client.
struct VaapiJpegDecodeAccelerator::DecodeRequest {
DecodeRequest(int32_t bitstream_buffer_id,
std::unique_ptr<UnalignedSharedMemory> shm,
std::unique_ptr<WritableUnalignedMapping> shm,
const scoped_refptr<VideoFrame>& video_frame)
: bitstream_buffer_id(bitstream_buffer_id),
shm(std::move(shm)),
......@@ -92,7 +92,7 @@ struct VaapiJpegDecodeAccelerator::DecodeRequest {
~DecodeRequest() = default;
int32_t bitstream_buffer_id;
std::unique_ptr<UnalignedSharedMemory> shm;
std::unique_ptr<WritableUnalignedMapping> shm;
scoped_refptr<VideoFrame> video_frame;
};
......@@ -310,17 +310,17 @@ void VaapiJpegDecodeAccelerator::Decode(
DVLOGF(4) << "Mapping new input buffer id: " << bitstream_buffer.id()
<< " size: " << bitstream_buffer.size();
// UnalignedSharedMemory will take over the |bitstream_buffer.handle()|.
auto shm = std::make_unique<UnalignedSharedMemory>(
bitstream_buffer.handle(), bitstream_buffer.size(), true);
if (bitstream_buffer.id() < 0) {
VLOGF(1) << "Invalid bitstream_buffer, id: " << bitstream_buffer.id();
NotifyErrorFromDecoderThread(bitstream_buffer.id(), INVALID_ARGUMENT);
return;
}
if (!shm->MapAt(bitstream_buffer.offset(), bitstream_buffer.size())) {
auto shm = std::make_unique<WritableUnalignedMapping>(
bitstream_buffer.handle(), bitstream_buffer.size(),
bitstream_buffer.offset());
if (!shm->IsValid()) {
VLOGF(1) << "Failed to map input buffer";
NotifyErrorFromDecoderThread(bitstream_buffer.id(), UNREADABLE_INPUT);
return;
......
......@@ -16,7 +16,6 @@
#include "base/synchronization/lock.h"
#include "base/threading/thread.h"
#include "media/base/bitstream_buffer.h"
#include "media/base/unaligned_shared_memory.h"
#include "media/gpu/media_gpu_export.h"
#include "media/gpu/vaapi/vaapi_jpeg_decoder.h"
#include "media/gpu/vaapi/vaapi_wrapper.h"
......
......@@ -50,8 +50,8 @@ static void ReportToUMA(VAJEAEncoderResult result) {
VaapiJpegEncodeAccelerator::EncodeRequest::EncodeRequest(
int32_t buffer_id,
scoped_refptr<media::VideoFrame> video_frame,
std::unique_ptr<UnalignedSharedMemory> exif_shm,
std::unique_ptr<UnalignedSharedMemory> output_shm,
std::unique_ptr<WritableUnalignedMapping> exif_shm,
std::unique_ptr<WritableUnalignedMapping> output_shm,
int quality)
: buffer_id(buffer_id),
video_frame(std::move(video_frame)),
......@@ -286,12 +286,11 @@ void VaapiJpegEncodeAccelerator::Encode(
return;
}
std::unique_ptr<UnalignedSharedMemory> exif_shm;
std::unique_ptr<WritableUnalignedMapping> exif_shm;
if (exif_buffer) {
// |exif_shm| will take ownership of the |exif_buffer->handle()|.
exif_shm = std::make_unique<UnalignedSharedMemory>(
exif_buffer->handle(), exif_buffer->size(), true);
if (!exif_shm->MapAt(exif_buffer->offset(), exif_buffer->size())) {
exif_shm = std::make_unique<WritableUnalignedMapping>(
exif_buffer->handle(), exif_buffer->size(), exif_buffer->offset());
if (!exif_shm->IsValid()) {
VLOGF(1) << "Failed to map exif buffer";
task_runner_->PostTask(
FROM_HERE, base::BindOnce(&VaapiJpegEncodeAccelerator::NotifyError,
......@@ -307,10 +306,9 @@ void VaapiJpegEncodeAccelerator::Encode(
}
}
// |output_shm| will take ownership of the |output_buffer.handle()|.
auto output_shm = std::make_unique<UnalignedSharedMemory>(
output_buffer.handle(), output_buffer.size(), false);
if (!output_shm->MapAt(output_buffer.offset(), output_buffer.size())) {
auto output_shm = std::make_unique<WritableUnalignedMapping>(
output_buffer.handle(), output_buffer.size(), output_buffer.offset());
if (!output_shm->IsValid()) {
VLOGF(1) << "Failed to map output buffer";
task_runner_->PostTask(
FROM_HERE,
......
......@@ -50,15 +50,15 @@ class MEDIA_GPU_EXPORT VaapiJpegEncodeAccelerator
struct EncodeRequest {
EncodeRequest(int32_t buffer_id,
scoped_refptr<media::VideoFrame> video_frame,
std::unique_ptr<UnalignedSharedMemory> exif_shm,
std::unique_ptr<UnalignedSharedMemory> output_shm,
std::unique_ptr<WritableUnalignedMapping> exif_shm,
std::unique_ptr<WritableUnalignedMapping> output_shm,
int quality);
~EncodeRequest();
int32_t buffer_id;
scoped_refptr<media::VideoFrame> video_frame;
std::unique_ptr<UnalignedSharedMemory> exif_shm;
std::unique_ptr<UnalignedSharedMemory> output_shm;
std::unique_ptr<WritableUnalignedMapping> exif_shm;
std::unique_ptr<WritableUnalignedMapping> output_shm;
int quality;
DISALLOW_COPY_AND_ASSIGN(EncodeRequest);
......
......@@ -86,7 +86,7 @@ class VaapiVideoDecodeAccelerator::InputBuffer {
public:
InputBuffer() = default;
InputBuffer(uint32_t id,
std::unique_ptr<UnalignedSharedMemory> shm,
std::unique_ptr<WritableUnalignedMapping> shm,
base::OnceCallback<void(int32_t id)> release_cb)
: id_(id), shm_(std::move(shm)), release_cb_(std::move(release_cb)) {}
~InputBuffer() {
......@@ -98,11 +98,11 @@ class VaapiVideoDecodeAccelerator::InputBuffer {
// Indicates this is a dummy buffer for flush request.
bool IsFlushRequest() const { return shm_ == nullptr; }
int32_t id() const { return id_; }
UnalignedSharedMemory* shm() const { return shm_.get(); }
WritableUnalignedMapping* shm() const { return shm_.get(); }
private:
const int32_t id_ = -1;
const std::unique_ptr<UnalignedSharedMemory> shm_;
const std::unique_ptr<WritableUnalignedMapping> shm_;
base::OnceCallback<void(int32_t id)> release_cb_;
DISALLOW_COPY_AND_ASSIGN(InputBuffer);
......@@ -287,11 +287,11 @@ void VaapiVideoDecodeAccelerator::QueueInputBuffer(
DCHECK(flush_buffer->IsFlushRequest());
input_buffers_.push(std::move(flush_buffer));
} else {
auto shm = std::make_unique<UnalignedSharedMemory>(
bitstream_buffer.handle(), bitstream_buffer.size(), true);
RETURN_AND_NOTIFY_ON_FAILURE(
shm->MapAt(bitstream_buffer.offset(), bitstream_buffer.size()),
"Failed to map input buffer", UNREADABLE_INPUT, );
auto shm = std::make_unique<WritableUnalignedMapping>(
bitstream_buffer.handle(), bitstream_buffer.size(),
bitstream_buffer.offset());
RETURN_AND_NOTIFY_ON_FAILURE(shm->IsValid(), "Failed to map input buffer",
UNREADABLE_INPUT, );
auto input_buffer = std::make_unique<InputBuffer>(
bitstream_buffer.id(), std::move(shm),
......
......@@ -126,13 +126,12 @@ struct VaapiVideoEncodeAccelerator::InputFrameRef {
struct VaapiVideoEncodeAccelerator::BitstreamBufferRef {
BitstreamBufferRef(int32_t id, const BitstreamBuffer& buffer)
: id(id),
shm(std::make_unique<UnalignedSharedMemory>(buffer.handle(),
buffer.size(),
false)),
offset(buffer.offset()) {}
shm(std::make_unique<WritableUnalignedMapping>(buffer.handle(),
buffer.size(),
buffer.offset())) {}
const int32_t id;
const std::unique_ptr<UnalignedSharedMemory> shm;
const off_t offset;
const std::unique_ptr<WritableUnalignedMapping> shm;
};
VideoEncodeAccelerator::SupportedProfiles
......@@ -413,6 +412,7 @@ void VaapiVideoEncodeAccelerator::ReturnBitstreamBuffer(
scoped_refptr<VaapiEncodeJob> encode_job,
std::unique_ptr<BitstreamBufferRef> buffer) {
DCHECK(encoder_thread_task_runner_->BelongsToCurrentThread());
DCHECK(buffer->shm->IsValid());
uint8_t* target_data = reinterpret_cast<uint8_t*>(buffer->shm->memory());
size_t data_size = 0;
......@@ -550,7 +550,7 @@ void VaapiVideoEncodeAccelerator::UseOutputBitstreamBufferTask(
DCHECK(encoder_thread_task_runner_->BelongsToCurrentThread());
DCHECK_NE(state_, kUninitialized);
if (!buffer_ref->shm->MapAt(buffer_ref->offset, buffer_ref->shm->size())) {
if (!buffer_ref->shm->IsValid()) {
NOTIFY_ERROR(kPlatformFailureError, "Failed mapping shared memory.");
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