Commit 2b779eac authored by Sheng-Hao Tsao's avatar Sheng-Hao Tsao Committed by Commit Bot

Revert "media/gpu shared memory: Use WritableUnalignedMapping for vaapi."

This reverts commit e30ad9f8.

Reasons for revert: breaks CrOS JEA functionality.
Details are in:
https://b.corp.google.com/issues/112573321

fine.

Bug: b:112573321
Test: After reverting the CL, image capture in Chrome camera app works
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: I2fe0458e8997906c10506f8511645ebd2514afe1
Reviewed-on: https://chromium-review.googlesource.com/1175707Reviewed-by: default avatarRicky Liang <jcliang@chromium.org>
Commit-Queue: Sheng-hao Tsao <shenghao@google.com>
Cr-Commit-Position: refs/heads/master@{#583213}
parent 75f3875b
......@@ -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<WritableUnalignedMapping> shm,
std::unique_ptr<UnalignedSharedMemory> 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<WritableUnalignedMapping> shm;
std::unique_ptr<UnalignedSharedMemory> 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;
}
auto shm = std::make_unique<WritableUnalignedMapping>(
bitstream_buffer.handle(), bitstream_buffer.size(),
bitstream_buffer.offset());
if (!shm->IsValid()) {
if (!shm->MapAt(bitstream_buffer.offset(), bitstream_buffer.size())) {
VLOGF(1) << "Failed to map input buffer";
NotifyErrorFromDecoderThread(bitstream_buffer.id(), UNREADABLE_INPUT);
return;
......
......@@ -16,6 +16,7 @@
#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<WritableUnalignedMapping> exif_shm,
std::unique_ptr<WritableUnalignedMapping> output_shm,
std::unique_ptr<UnalignedSharedMemory> exif_shm,
std::unique_ptr<UnalignedSharedMemory> output_shm,
int quality)
: buffer_id(buffer_id),
video_frame(std::move(video_frame)),
......@@ -286,11 +286,12 @@ void VaapiJpegEncodeAccelerator::Encode(
return;
}
std::unique_ptr<WritableUnalignedMapping> exif_shm;
std::unique_ptr<UnalignedSharedMemory> exif_shm;
if (exif_buffer) {
exif_shm = std::make_unique<WritableUnalignedMapping>(
exif_buffer->handle(), exif_buffer->size(), exif_buffer->offset());
if (!exif_shm->IsValid()) {
// |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())) {
VLOGF(1) << "Failed to map exif buffer";
task_runner_->PostTask(
FROM_HERE, base::BindOnce(&VaapiJpegEncodeAccelerator::NotifyError,
......@@ -306,9 +307,10 @@ void VaapiJpegEncodeAccelerator::Encode(
}
}
auto output_shm = std::make_unique<WritableUnalignedMapping>(
output_buffer.handle(), output_buffer.size(), output_buffer.offset());
if (!output_shm->IsValid()) {
// |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())) {
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<WritableUnalignedMapping> exif_shm,
std::unique_ptr<WritableUnalignedMapping> output_shm,
std::unique_ptr<UnalignedSharedMemory> exif_shm,
std::unique_ptr<UnalignedSharedMemory> output_shm,
int quality);
~EncodeRequest();
int32_t buffer_id;
scoped_refptr<media::VideoFrame> video_frame;
std::unique_ptr<WritableUnalignedMapping> exif_shm;
std::unique_ptr<WritableUnalignedMapping> output_shm;
std::unique_ptr<UnalignedSharedMemory> exif_shm;
std::unique_ptr<UnalignedSharedMemory> 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<WritableUnalignedMapping> shm,
std::unique_ptr<UnalignedSharedMemory> 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_; }
WritableUnalignedMapping* shm() const { return shm_.get(); }
UnalignedSharedMemory* shm() const { return shm_.get(); }
private:
const int32_t id_ = -1;
const std::unique_ptr<WritableUnalignedMapping> shm_;
const std::unique_ptr<UnalignedSharedMemory> 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<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 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 input_buffer = std::make_unique<InputBuffer>(
bitstream_buffer.id(), std::move(shm),
......
......@@ -126,12 +126,13 @@ struct VaapiVideoEncodeAccelerator::InputFrameRef {
struct VaapiVideoEncodeAccelerator::BitstreamBufferRef {
BitstreamBufferRef(int32_t id, const BitstreamBuffer& buffer)
: id(id),
shm(std::make_unique<WritableUnalignedMapping>(buffer.handle(),
buffer.size(),
buffer.offset())) {}
shm(std::make_unique<UnalignedSharedMemory>(buffer.handle(),
buffer.size(),
false)),
offset(buffer.offset()) {}
const int32_t id;
const std::unique_ptr<WritableUnalignedMapping> shm;
const std::unique_ptr<UnalignedSharedMemory> shm;
const off_t offset;
};
VideoEncodeAccelerator::SupportedProfiles
......@@ -414,7 +415,6 @@ 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;
......@@ -552,7 +552,7 @@ void VaapiVideoEncodeAccelerator::UseOutputBitstreamBufferTask(
DCHECK(encoder_thread_task_runner_->BelongsToCurrentThread());
DCHECK_NE(state_, kUninitialized);
if (!buffer_ref->shm->IsValid()) {
if (!buffer_ref->shm->MapAt(buffer_ref->offset, buffer_ref->shm->size())) {
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