Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1596)

Unified Diff: content/common/gpu/media/video_decode_accelerator_unittest.cc

Issue 1822983002: Support external buffer import in VDA interface and add a V4L2SVDA impl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/common/gpu/media/video_decode_accelerator_unittest.cc
diff --git a/content/common/gpu/media/video_decode_accelerator_unittest.cc b/content/common/gpu/media/video_decode_accelerator_unittest.cc
index 920dbd5c90fa48c62a41463171eb1ec59d8d0bae..f86c8ce5e69c47ed74bba1c1a48db67025b1916c 100644
--- a/content/common/gpu/media/video_decode_accelerator_unittest.cc
+++ b/content/common/gpu/media/video_decode_accelerator_unittest.cc
@@ -75,8 +75,10 @@
#endif // OS_WIN
#if defined(USE_OZONE)
+#include "ui/ozone/public/native_pixmap.h"
#include "ui/ozone/public/ozone_gpu_test_helper.h"
#include "ui/ozone/public/ozone_platform.h"
+#include "ui/ozone/public/surface_factory_ozone.h"
#endif // defined(USE_OZONE)
using media::VideoDecodeAccelerator;
@@ -126,6 +128,10 @@ int g_num_play_throughs = 0;
// Fake decode
int g_fake_decoder = 0;
+// Test buffer import into VDA, providing buffers allocated by us, instead of
+// requesting the VDA itself to allocate buffers.
+bool g_test_import = false;
+
// Environment to store rendering thread.
class VideoDecodeAcceleratorTestEnvironment;
VideoDecodeAcceleratorTestEnvironment* g_env;
@@ -273,16 +279,22 @@ class VideoDecodeAcceleratorTestEnvironment : public ::testing::Environment {
// A helper class used to manage the lifetime of a Texture.
class TextureRef : public base::RefCounted<TextureRef> {
public:
- TextureRef(uint32_t texture_id, const base::Closure& no_longer_needed_cb)
- : texture_id_(texture_id), no_longer_needed_cb_(no_longer_needed_cb) {}
+ TextureRef(uint32_t texture_id,
+ const scoped_refptr<ui::NativePixmap>& pixmap,
+ const base::Closure& no_longer_needed_cb)
+ : texture_id_(texture_id),
+ pixmap_(pixmap),
+ no_longer_needed_cb_(no_longer_needed_cb) {}
int32_t texture_id() const { return texture_id_; }
+ scoped_refptr<ui::NativePixmap> pixmap() { return pixmap_; }
private:
friend class base::RefCounted<TextureRef>;
~TextureRef();
uint32_t texture_id_;
+ scoped_refptr<ui::NativePixmap> pixmap_;
base::Closure no_longer_needed_cb_;
};
@@ -530,6 +542,10 @@ void GLRenderingVDAClient::CreateAndStartDecoder() {
}
VideoDecodeAccelerator::Config config(profile_);
+ if (g_test_import) {
+ config.output_mode =
+ media::VideoDecodeAccelerator::Config::OutputMode::IMPORT;
+ }
gpu::GpuPreferences gpu_preferences;
#if defined(OS_WIN)
const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
@@ -548,6 +564,23 @@ void GLRenderingVDAClient::CreateAndStartDecoder() {
FinishInitialization();
}
+namespace {
+gfx::BufferFormat VideoPixelFormatToGfxBufferFormat(
+ media::VideoPixelFormat pixel_format) {
+ switch (pixel_format) {
+ case media::VideoPixelFormat::PIXEL_FORMAT_ARGB:
+ return gfx::BufferFormat::BGRA_8888;
+ case media::VideoPixelFormat::PIXEL_FORMAT_XRGB:
+ return gfx::BufferFormat::BGRX_8888;
+ case media::VideoPixelFormat::PIXEL_FORMAT_NV12:
+ return gfx::BufferFormat::YUV_420_BIPLANAR;
+ default:
+ LOG_ASSERT(false) << "Unknown VideoPixelFormat";
+ return gfx::BufferFormat::BGRX_8888;
+ }
+}
+}
+
void GLRenderingVDAClient::ProvidePictureBuffers(
uint32_t requested_num_of_buffers,
const gfx::Size& dimensions,
@@ -566,20 +599,50 @@ void GLRenderingVDAClient::ProvidePictureBuffers(
texture_target_, &texture_id, dimensions, &done);
done.Wait();
+ scoped_refptr<ui::NativePixmap> pixmap;
+ if (g_test_import) {
+ ui::OzonePlatform* platform = ui::OzonePlatform::GetInstance();
+ ui::SurfaceFactoryOzone* factory = platform->GetSurfaceFactoryOzone();
+ gfx::BufferFormat buffer_format =
+ VideoPixelFormatToGfxBufferFormat(decoder_->GetOutputFormat());
+ pixmap =
+ factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, dimensions,
+ buffer_format, gfx::BufferUsage::SCANOUT);
+ LOG_ASSERT(pixmap);
+ }
+
int32_t picture_buffer_id = next_picture_buffer_id_++;
- LOG_ASSERT(active_textures_
- .insert(std::make_pair(
- picture_buffer_id,
- new TextureRef(texture_id,
- base::Bind(&RenderingHelper::DeleteTexture,
- base::Unretained(rendering_helper_),
- texture_id))))
- .second);
+ LOG_ASSERT(
+ active_textures_
+ .insert(std::make_pair(
+ picture_buffer_id,
+ new TextureRef(texture_id, pixmap,
+ base::Bind(&RenderingHelper::DeleteTexture,
+ base::Unretained(rendering_helper_),
+ texture_id))))
+ .second);
buffers.push_back(
media::PictureBuffer(picture_buffer_id, dimensions, texture_id));
}
decoder_->AssignPictureBuffers(buffers);
+
+ if (g_test_import) {
+ for (const auto& buffer : buffers) {
+ TextureRefMap::iterator texture_it = active_textures_.find(buffer.id());
+ ASSERT_NE(active_textures_.end(), texture_it);
+
+ scoped_refptr<ui::NativePixmap> pixmap = texture_it->second->pixmap();
+ int duped_fd = HANDLE_EINTR(dup(pixmap->GetDmaBufFd()));
+ ASSERT_NE(duped_fd, -1);
+ gfx::GpuMemoryBufferHandle handle;
+ handle.type = gfx::OZONE_NATIVE_PIXMAP;
+ handle.native_pixmap_handle.fd = base::FileDescriptor(duped_fd, true);
+ std::vector<gfx::GpuMemoryBufferHandle> handles;
+ handles.push_back(handle);
+ decoder_->ImportBufferForPicture(buffer.id(), handles);
+ }
+ }
}
void GLRenderingVDAClient::DismissPictureBuffer(int32_t picture_buffer_id) {
@@ -1558,6 +1621,10 @@ int main(int argc, char **argv) {
continue;
if (it->first == "ozone-platform" || it->first == "ozone-use-surfaceless")
continue;
+ if (it->first == "test_import") {
+ content::g_test_import = true;
+ continue;
+ }
LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second;
}

Powered by Google App Engine
This is Rietveld 408576698