Commit 2a59da47 authored by Chih-Yu Huang's avatar Chih-Yu Huang Committed by Commit Bot

components/arc: Create mojo struct for media::VideoFrame.

We need media::VideoFrame for passing information of output buffers in
VideoDecoder migration at ARC++. This CL adds the mojo struct for it.

BUG=b:136716638
TEST=components_unittests --gtest_filter=VideoAcceleratorStructTraitsTest.*

Change-Id: I8ba1a47d20bdc07c5281e57ce7d78636144b36a0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1697502
Commit-Queue: Chih-Yu Huang <akahuang@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarHirokazu Honda <hiroh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697076}
parent a3388959
...@@ -269,4 +269,31 @@ bool StructTraits<arc::mojom::VideoFrameLayoutDataView, ...@@ -269,4 +269,31 @@ bool StructTraits<arc::mojom::VideoFrameLayoutDataView,
return true; return true;
} }
// static
bool StructTraits<arc::mojom::VideoFrameDataView,
scoped_refptr<media::VideoFrame>>::
Read(arc::mojom::VideoFrameDataView data,
scoped_refptr<media::VideoFrame>* out) {
gfx::Rect visible_rect;
if (data.id() == 0 || !data.ReadVisibleRect(&visible_rect)) {
return false;
}
// We store id at the first 8 byte of the mailbox.
const uint64_t id = data.id();
static_assert(GL_MAILBOX_SIZE_CHROMIUM >= sizeof(id),
"Size of Mailbox is too small to store id.");
gpu::Mailbox mailbox;
memcpy(mailbox.name, &id, sizeof(id));
gpu::MailboxHolder mailbox_holders[media::VideoFrame::kMaxPlanes];
mailbox_holders[0] = gpu::MailboxHolder(mailbox, gpu::SyncToken(), 0);
// We don't store pixel format and coded_size in Mojo struct. Use dummy value.
*out = media::VideoFrame::WrapNativeTextures(
media::PIXEL_FORMAT_I420, mailbox_holders,
media::VideoFrame::ReleaseMailboxCB(), visible_rect.size(), visible_rect,
visible_rect.size(), base::TimeDelta::FromMilliseconds(data.timestamp()));
return true;
}
} // namespace mojo } // namespace mojo
...@@ -5,12 +5,16 @@ ...@@ -5,12 +5,16 @@
#ifndef COMPONENTS_ARC_MOJOM_VIDEO_ACCELERATOR_MOJOM_TRAITS_H_ #ifndef COMPONENTS_ARC_MOJOM_VIDEO_ACCELERATOR_MOJOM_TRAITS_H_
#define COMPONENTS_ARC_MOJOM_VIDEO_ACCELERATOR_MOJOM_TRAITS_H_ #define COMPONENTS_ARC_MOJOM_VIDEO_ACCELERATOR_MOJOM_TRAITS_H_
#include <string.h>
#include <memory> #include <memory>
#include "components/arc/mojom/arc_gfx_mojom_traits.h"
#include "components/arc/mojom/video_common.mojom.h" #include "components/arc/mojom/video_common.mojom.h"
#include "components/arc/video_accelerator/video_frame_plane.h" #include "components/arc/video_accelerator/video_frame_plane.h"
#include "media/base/decode_status.h" #include "media/base/decode_status.h"
#include "media/base/video_codecs.h" #include "media/base/video_codecs.h"
#include "media/base/video_frame.h"
#include "media/base/video_frame_layout.h" #include "media/base/video_frame_layout.h"
#include "media/base/video_types.h" #include "media/base/video_types.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
...@@ -145,6 +149,46 @@ struct EnumTraits<arc::mojom::DecodeStatus, media::DecodeStatus> { ...@@ -145,6 +149,46 @@ struct EnumTraits<arc::mojom::DecodeStatus, media::DecodeStatus> {
media::DecodeStatus* output); media::DecodeStatus* output);
}; };
template <>
struct StructTraits<arc::mojom::VideoFrameDataView,
scoped_refptr<media::VideoFrame>> {
static bool IsNull(const scoped_refptr<media::VideoFrame> input) {
return !input;
}
static void SetToNull(scoped_refptr<media::VideoFrame>* output) {
output->reset();
}
static uint64_t id(const scoped_refptr<media::VideoFrame> input) {
DCHECK(input);
DCHECK(!input->mailbox_holder(0).mailbox.IsZero());
// We store id at the first 8 byte of the mailbox.
uint64_t id;
static_assert(GL_MAILBOX_SIZE_CHROMIUM >= sizeof(id),
"Size of Mailbox is too small to store id.");
const int8_t* const name = input->mailbox_holder(0).mailbox.name;
memcpy(&id, name, sizeof(id));
return id;
}
static gfx::Rect visible_rect(const scoped_refptr<media::VideoFrame> input) {
DCHECK(input);
return input->visible_rect();
}
static int64_t timestamp(const scoped_refptr<media::VideoFrame> input) {
DCHECK(input);
return input->timestamp().InMilliseconds();
}
static bool Read(arc::mojom::VideoFrameDataView data,
scoped_refptr<media::VideoFrame>* out);
};
} // namespace mojo } // namespace mojo
#endif // COMPONENTS_ARC_MOJOM_VIDEO_ACCELERATOR_MOJOM_TRAITS_H_ #endif // COMPONENTS_ARC_MOJOM_VIDEO_ACCELERATOR_MOJOM_TRAITS_H_
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
namespace mojo { namespace mojo {
namespace { namespace {
constexpr int64_t kTimestamp = 1234;
constexpr int kWidth = 640; constexpr int kWidth = 640;
constexpr int kHeight = 480; constexpr int kHeight = 480;
constexpr media::VideoPixelFormat kFormat = media::PIXEL_FORMAT_I420; constexpr media::VideoPixelFormat kFormat = media::PIXEL_FORMAT_I420;
...@@ -58,4 +59,41 @@ TEST(VideoAcceleratorStructTraitsTest, ConvertNullVideoFrameLayout) { ...@@ -58,4 +59,41 @@ TEST(VideoAcceleratorStructTraitsTest, ConvertNullVideoFrameLayout) {
EXPECT_FALSE(output); EXPECT_FALSE(output);
} }
TEST(VideoAcceleratorStructTraitsTest, ConvertVideoFrame) {
// We store id in the first 8 bytes of kMailbox.
gpu::Mailbox kMailbox;
kMailbox.name[0] = 0xff;
kMailbox.name[1] = 0xed;
kMailbox.name[2] = 0xfb;
kMailbox.name[3] = 0xea;
kMailbox.name[4] = 0xf9;
kMailbox.name[5] = 0x7e;
kMailbox.name[6] = 0xe5;
kMailbox.name[7] = 0xe3;
gpu::MailboxHolder mailbox_holders[media::VideoFrame::kMaxPlanes];
mailbox_holders[0] = gpu::MailboxHolder(kMailbox, gpu::SyncToken(), 0);
scoped_refptr<media::VideoFrame> input =
media::VideoFrame::WrapNativeTextures(
kFormat, mailbox_holders, media::VideoFrame::ReleaseMailboxCB(),
kCodedSize, gfx::Rect(kCodedSize), kCodedSize,
base::TimeDelta::FromMilliseconds(kTimestamp));
scoped_refptr<media::VideoFrame> output;
mojo::test::SerializeAndDeserialize<arc::mojom::VideoFrame>(&input, &output);
// Verify the fields of input and output frames.
EXPECT_EQ(output->mailbox_holder(0).mailbox, kMailbox);
EXPECT_EQ(output->visible_rect(), input->visible_rect());
EXPECT_EQ(output->timestamp(), input->timestamp());
}
TEST(VideoAcceleratorStructTraitsTest, ConvertNullVideoFrame) {
scoped_refptr<media::VideoFrame> input;
scoped_refptr<media::VideoFrame> output;
mojo::test::SerializeAndDeserialize<arc::mojom::VideoFrame>(&input, &output);
EXPECT_FALSE(output);
}
} // namespace mojo } // namespace mojo
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
module arc.mojom; module arc.mojom;
import "components/arc/mojom/gfx.mojom";
[Extensible] [Extensible]
enum VideoCodecProfile { enum VideoCodecProfile {
// The values must match to the values in media::VideoCodecProfile. // The values must match to the values in media::VideoCodecProfile.
...@@ -120,3 +122,11 @@ struct VideoFrameLayout { ...@@ -120,3 +122,11 @@ struct VideoFrameLayout {
uint32 buffer_addr_align; uint32 buffer_addr_align;
uint64 modifier; uint64 modifier;
}; };
struct VideoFrame {
// Identifier of the buffer. The value of a valid frame should be non-zero.
uint64 id;
Rect visible_rect;
// timestamp in milliseconds.
int64 timestamp;
};
...@@ -7,6 +7,7 @@ public_headers = [ ...@@ -7,6 +7,7 @@ public_headers = [
"//components/arc/video_accelerator/video_frame_plane.h", "//components/arc/video_accelerator/video_frame_plane.h",
"//media/base/decode_status.h", "//media/base/decode_status.h",
"//media/base/video_codecs.h", "//media/base/video_codecs.h",
"//media/base/video_frame.h",
"//media/base/video_frame_layout.h", "//media/base/video_frame_layout.h",
"//media/base/video_types.h", "//media/base/video_types.h",
"//ui/gfx/geometry/size.h", "//ui/gfx/geometry/size.h",
...@@ -32,6 +33,7 @@ type_mappings = [ ...@@ -32,6 +33,7 @@ type_mappings = [
"arc.mojom.MediaVideoFramePlane=media::VideoFrameLayout::Plane", "arc.mojom.MediaVideoFramePlane=media::VideoFrameLayout::Plane",
"arc.mojom.Size=gfx::Size", "arc.mojom.Size=gfx::Size",
"arc.mojom.VideoCodecProfile=media::VideoCodecProfile", "arc.mojom.VideoCodecProfile=media::VideoCodecProfile",
"arc.mojom.VideoFrame=scoped_refptr<media::VideoFrame>[nullable_is_same_type]",
# media::VideoFrameLayout doesn't have default constructor, so we cannot # media::VideoFrameLayout doesn't have default constructor, so we cannot
# convert directly. # convert directly.
......
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