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

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: include reland of crrev.com/1643123003 with fixes and rebase Created 4 years, 8 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 b62a9089b06ce7a047eac5a3db5054989319c261..94c0b3664a5f693730c56aafa15500881644ba68 100644
--- a/content/common/gpu/media/video_decode_accelerator_unittest.cc
+++ b/content/common/gpu/media/video_decode_accelerator_unittest.cc
@@ -74,8 +74,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;
@@ -125,6 +127,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;
@@ -272,16 +278,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_;
};
@@ -531,6 +543,10 @@ void GLRenderingVDAClient::CreateAndStartDecoder() {
}
VideoDecodeAccelerator::Config config(profile_);
+ if (g_test_import) {
+ config.output_mode =
+ media::VideoDecodeAccelerator::Config::OutputMode::IMPORT;
+ }
gpu::GpuPreferences gpu_preferences;
decoder_ = vda_factory_->CreateVDA(this, config, gpu_preferences);
}
@@ -544,6 +560,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,
uint32_t textures_per_buffer,
@@ -564,21 +597,54 @@ 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();
+ media::VideoPixelFormat pixel_format = decoder_->GetOutputFormat();
+ if (pixel_format == media::PIXEL_FORMAT_UNKNOWN)
+ pixel_format = media::PIXEL_FORMAT_ARGB;
+ gfx::BufferFormat buffer_format =
+ VideoPixelFormatToGfxBufferFormat(pixel_format);
+ 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);
media::PictureBuffer::TextureIds ids;
ids.push_back(texture_id);
buffers.push_back(media::PictureBuffer(picture_buffer_id, dimensions, ids));
}
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) {
@@ -1557,6 +1623,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