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

media/gpu shared memory: update vaapi 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: Ie3379f1dabb0c0fa7fae7451534bd5fa1b01416e
Reviewed-on: https://chromium-review.googlesource.com/1117696Reviewed-by: default avatarDaniele Castagna <dcastagna@chromium.org>
Reviewed-by: default avatarAlexandr Ilin <alexilin@chromium.org>
Commit-Queue: Matthew Cary <mattcary@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577823}
parent db4960bf
......@@ -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;
};
......@@ -297,17 +297,19 @@ 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());
// The bitstream_buffer handle will no longer be used and can be closed.
bitstream_buffer.handle().Close();
if (!shm->IsValid()) {
VLOGF(1) << "Failed to map input buffer";
NotifyErrorFromDecoderThread(bitstream_buffer.id(), UNREADABLE_INPUT);
return;
......
......@@ -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,13 @@ 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());
// After mapping, the exif buffer handle is no longer needed.
exif_buffer->handle().Close();
if (!exif_shm->IsValid()) {
VLOGF(1) << "Failed to map exif buffer";
task_runner_->PostTask(
FROM_HERE, base::BindOnce(&VaapiJpegEncodeAccelerator::NotifyError,
......@@ -307,10 +308,11 @@ 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());
// After mapping, the output buffer handle is no longer needed.
output_buffer.handle().Close();
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);
......@@ -307,11 +307,13 @@ 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());
// The handle is no longer needed after mapping.
bitstream_buffer.handle().Close();
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,15 @@ 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())) {
// The handle is no longer needed.
buffer.handle().Close();
}
const int32_t id;
const std::unique_ptr<UnalignedSharedMemory> shm;
const off_t offset;
const std::unique_ptr<WritableUnalignedMapping> shm;
};
VideoEncodeAccelerator::SupportedProfiles
......@@ -419,6 +421,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;
......@@ -556,7 +559,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