Skip to content

Commit

Permalink
media: Use native video enum types in media mojo interfaces
Browse files Browse the repository at this point in the history
TBR=jrummell@chromium.org, mcasas@chromium.org
BUG=611224,655205
TEST=mojo_media_unittests still pass

Review-Url: https://codereview.chromium.org/2419793003
Cr-Commit-Position: refs/heads/master@{#425275}
  • Loading branch information
xhwang-chromium authored and Commit bot committed Oct 14, 2016
1 parent 83d310b commit 241b69b
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 220 deletions.
2 changes: 1 addition & 1 deletion content/browser/renderer_host/media/video_capture_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void VideoCaptureHost::OnBufferReady(
video_frame->metadata()->MergeInternalValuesInto(&info->metadata);

DCHECK_EQ(media::PIXEL_FORMAT_I420, video_frame->format());
info->pixel_format = media::mojom::VideoFormat::I420;
info->pixel_format = media::PIXEL_FORMAT_I420;
info->storage_type = media::PIXEL_STORAGE_CPU;
info->coded_size = video_frame->coded_size();
info->visible_rect = video_frame->visible_rect();
Expand Down
2 changes: 1 addition & 1 deletion content/common/video_capture.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct VideoCaptureParams {
struct VideoFrameInfo{
mojo.common.mojom.TimeDelta timestamp;
mojo.common.mojom.DictionaryValue metadata;
media.mojom.VideoFormat pixel_format;
media.mojom.VideoPixelFormat pixel_format;
video_capture.mojom.VideoPixelStorage storage_type;
gfx.mojom.Size coded_size;
gfx.mojom.Rect visible_rect;
Expand Down
4 changes: 2 additions & 2 deletions content/renderer/media/video_capture_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,11 @@ void VideoCaptureImpl::OnBufferReady(int32_t buffer_id,
DVLOG(1) << __func__ << " buffer_id: " << buffer_id;

DCHECK(io_task_runner_->BelongsToCurrentThread());
DCHECK_EQ(media::mojom::VideoFormat::I420, info->pixel_format);
DCHECK_EQ(media::PIXEL_FORMAT_I420, info->pixel_format);
DCHECK_EQ(media::PIXEL_STORAGE_CPU, info->storage_type);

if (state_ != VIDEO_CAPTURE_STATE_STARTED ||
info->pixel_format != media::mojom::VideoFormat::I420 ||
info->pixel_format != media::PIXEL_FORMAT_I420 ||
info->storage_type != media::PIXEL_STORAGE_CPU) {
GetVideoCaptureHost()->ReleaseBuffer(device_id_, buffer_id,
gpu::SyncToken(), -1.0);
Expand Down
2 changes: 1 addition & 1 deletion content/renderer/media/video_capture_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class VideoCaptureImplTest : public ::testing::Test {
frame_metadata.MergeInternalValuesInto(&info->metadata);

info->timestamp = now - base::TimeTicks();
info->pixel_format = media::mojom::VideoFormat::I420;
info->pixel_format = media::PIXEL_FORMAT_I420;
info->storage_type = media::PIXEL_STORAGE_CPU;
info->coded_size = size;
info->visible_rect = gfx::Rect(size);
Expand Down
9 changes: 9 additions & 0 deletions media/base/ipc/media_param_traits_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "media/base/sample_format.h"
#include "media/base/subsample_entry.h"
#include "media/base/video_capture_types.h"
#include "media/base/video_codecs.h"
#include "media/base/video_types.h"

IPC_ENUM_TRAITS_MAX_VALUE(media::AudioCodec, media::AudioCodec::kAudioCodecMax)
Expand All @@ -29,11 +30,19 @@ IPC_ENUM_TRAITS_MAX_VALUE(media::BufferingState,

IPC_ENUM_TRAITS_MAX_VALUE(media::ChannelLayout, media::CHANNEL_LAYOUT_MAX)

IPC_ENUM_TRAITS_MAX_VALUE(media::ColorSpace, media::COLOR_SPACE_MAX)

IPC_ENUM_TRAITS_MAX_VALUE(media::DecodeStatus,
media::DecodeStatus::DECODE_STATUS_MAX)

IPC_ENUM_TRAITS_MAX_VALUE(media::SampleFormat, media::kSampleFormatMax)

IPC_ENUM_TRAITS_MAX_VALUE(media::VideoCodec, media::kVideoCodecMax)

IPC_ENUM_TRAITS_MIN_MAX_VALUE(media::VideoCodecProfile,
media::VIDEO_CODEC_PROFILE_MIN,
media::VIDEO_CODEC_PROFILE_MAX)

IPC_ENUM_TRAITS_MAX_VALUE(media::VideoPixelFormat, media::PIXEL_FORMAT_MAX)

IPC_ENUM_TRAITS_MAX_VALUE(media::VideoPixelStorage, media::PIXEL_STORAGE_MAX)
Expand Down
5 changes: 0 additions & 5 deletions media/gpu/ipc/common/media_param_traits_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,13 @@

#include "gpu/config/gpu_info.h"
#include "ipc/ipc_message_macros.h"
#include "media/base/decrypt_config.h"
#include "media/base/ipc/media_param_traits_macros.h"
#include "media/base/video_codecs.h"
#include "media/gpu/ipc/common/create_video_encoder_params.h"
#include "media/video/jpeg_decode_accelerator.h"
#include "media/video/video_decode_accelerator.h"
#include "media/video/video_encode_accelerator.h"
#include "ui/gfx/ipc/geometry/gfx_param_traits.h"

IPC_ENUM_TRAITS_MIN_MAX_VALUE(media::VideoCodecProfile,
media::VIDEO_CODEC_PROFILE_MIN,
media::VIDEO_CODEC_PROFILE_MAX)
IPC_ENUM_TRAITS_MAX_VALUE(media::JpegDecodeAccelerator::Error,
media::JpegDecodeAccelerator::LARGEST_ERROR_ENUM)
IPC_ENUM_TRAITS_MAX_VALUE(media::VideoEncodeAccelerator::Error,
Expand Down
128 changes: 10 additions & 118 deletions media/mojo/common/media_type_converters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,109 +68,6 @@ ASSERT_ENUM_EQ_RAW(DemuxerStream::Status,
DemuxerStream::kConfigChanged,
DemuxerStream::Status::CONFIG_CHANGED);

// VideoFormat.
ASSERT_ENUM_EQ_RAW(VideoPixelFormat,
PIXEL_FORMAT_UNKNOWN,
VideoFormat::UNKNOWN);
ASSERT_ENUM_EQ_RAW(VideoPixelFormat, PIXEL_FORMAT_I420, VideoFormat::I420);
ASSERT_ENUM_EQ_RAW(VideoPixelFormat, PIXEL_FORMAT_YV12, VideoFormat::YV12);
ASSERT_ENUM_EQ_RAW(VideoPixelFormat, PIXEL_FORMAT_YV16, VideoFormat::YV16);
ASSERT_ENUM_EQ_RAW(VideoPixelFormat, PIXEL_FORMAT_YV12A, VideoFormat::YV12A);
ASSERT_ENUM_EQ_RAW(VideoPixelFormat, PIXEL_FORMAT_YV24, VideoFormat::YV24);
ASSERT_ENUM_EQ_RAW(VideoPixelFormat, PIXEL_FORMAT_NV12, VideoFormat::NV12);
ASSERT_ENUM_EQ_RAW(VideoPixelFormat, PIXEL_FORMAT_NV21, VideoFormat::NV21);
ASSERT_ENUM_EQ_RAW(VideoPixelFormat, PIXEL_FORMAT_UYVY, VideoFormat::UYVY);
ASSERT_ENUM_EQ_RAW(VideoPixelFormat, PIXEL_FORMAT_YUY2, VideoFormat::YUY2);
ASSERT_ENUM_EQ_RAW(VideoPixelFormat, PIXEL_FORMAT_ARGB, VideoFormat::ARGB);
ASSERT_ENUM_EQ_RAW(VideoPixelFormat, PIXEL_FORMAT_XRGB, VideoFormat::XRGB);
ASSERT_ENUM_EQ_RAW(VideoPixelFormat, PIXEL_FORMAT_RGB24, VideoFormat::RGB24);
ASSERT_ENUM_EQ_RAW(VideoPixelFormat, PIXEL_FORMAT_RGB32, VideoFormat::RGB32);
ASSERT_ENUM_EQ_RAW(VideoPixelFormat, PIXEL_FORMAT_MJPEG, VideoFormat::MJPEG);
ASSERT_ENUM_EQ_RAW(VideoPixelFormat, PIXEL_FORMAT_MT21, VideoFormat::MT21);
ASSERT_ENUM_EQ_RAW(VideoPixelFormat,
PIXEL_FORMAT_YUV420P9,
VideoFormat::YUV420P9);
ASSERT_ENUM_EQ_RAW(VideoPixelFormat,
PIXEL_FORMAT_YUV422P9,
VideoFormat::YUV422P9);
ASSERT_ENUM_EQ_RAW(VideoPixelFormat,
PIXEL_FORMAT_YUV444P9,
VideoFormat::YUV444P9);
ASSERT_ENUM_EQ_RAW(VideoPixelFormat,
PIXEL_FORMAT_YUV420P10,
VideoFormat::YUV420P10);
ASSERT_ENUM_EQ_RAW(VideoPixelFormat,
PIXEL_FORMAT_YUV422P10,
VideoFormat::YUV422P10);
ASSERT_ENUM_EQ_RAW(VideoPixelFormat,
PIXEL_FORMAT_YUV444P10,
VideoFormat::YUV444P10);
ASSERT_ENUM_EQ_RAW(VideoPixelFormat,
PIXEL_FORMAT_YUV420P12,
VideoFormat::YUV420P12);
ASSERT_ENUM_EQ_RAW(VideoPixelFormat,
PIXEL_FORMAT_YUV422P12,
VideoFormat::YUV422P12);
ASSERT_ENUM_EQ_RAW(VideoPixelFormat,
PIXEL_FORMAT_YUV444P12,
VideoFormat::YUV444P12);
ASSERT_ENUM_EQ_RAW(VideoPixelFormat, PIXEL_FORMAT_Y8, VideoFormat::Y8);
ASSERT_ENUM_EQ_RAW(VideoPixelFormat, PIXEL_FORMAT_Y16, VideoFormat::Y16);
ASSERT_ENUM_EQ_RAW(VideoPixelFormat, PIXEL_FORMAT_MAX, VideoFormat::FORMAT_MAX);

// ColorSpace.
ASSERT_ENUM_EQ_RAW(ColorSpace,
COLOR_SPACE_UNSPECIFIED,
ColorSpace::UNSPECIFIED);
ASSERT_ENUM_EQ_RAW(ColorSpace, COLOR_SPACE_JPEG, ColorSpace::JPEG);
ASSERT_ENUM_EQ_RAW(ColorSpace, COLOR_SPACE_HD_REC709, ColorSpace::HD_REC709);
ASSERT_ENUM_EQ_RAW(ColorSpace, COLOR_SPACE_SD_REC601, ColorSpace::SD_REC601);
ASSERT_ENUM_EQ_RAW(ColorSpace, COLOR_SPACE_MAX, ColorSpace::MAX);

// VideoCodec
ASSERT_ENUM_EQ_RAW(VideoCodec, kUnknownVideoCodec, VideoCodec::UNKNOWN);
ASSERT_ENUM_EQ(VideoCodec, kCodec, , H264);
ASSERT_ENUM_EQ(VideoCodec, kCodec, , HEVC);
ASSERT_ENUM_EQ(VideoCodec, kCodec, , VC1);
ASSERT_ENUM_EQ(VideoCodec, kCodec, , MPEG2);
ASSERT_ENUM_EQ(VideoCodec, kCodec, , MPEG4);
ASSERT_ENUM_EQ(VideoCodec, kCodec, , Theora);
ASSERT_ENUM_EQ(VideoCodec, kCodec, , VP8);
ASSERT_ENUM_EQ(VideoCodec, kCodec, , VP9);
ASSERT_ENUM_EQ_RAW(VideoCodec, kVideoCodecMax, VideoCodec::Max);

// VideoCodecProfile
ASSERT_ENUM_EQ(VideoCodecProfile, , , VIDEO_CODEC_PROFILE_UNKNOWN);
ASSERT_ENUM_EQ(VideoCodecProfile, , , VIDEO_CODEC_PROFILE_MIN);
ASSERT_ENUM_EQ(VideoCodecProfile, , , H264PROFILE_MIN);
ASSERT_ENUM_EQ(VideoCodecProfile, , , H264PROFILE_BASELINE);
ASSERT_ENUM_EQ(VideoCodecProfile, , , H264PROFILE_MAIN);
ASSERT_ENUM_EQ(VideoCodecProfile, , , H264PROFILE_EXTENDED);
ASSERT_ENUM_EQ(VideoCodecProfile, , , H264PROFILE_HIGH);
ASSERT_ENUM_EQ(VideoCodecProfile, , , H264PROFILE_HIGH10PROFILE);
ASSERT_ENUM_EQ(VideoCodecProfile, , , H264PROFILE_HIGH422PROFILE);
ASSERT_ENUM_EQ(VideoCodecProfile, , , H264PROFILE_HIGH444PREDICTIVEPROFILE);
ASSERT_ENUM_EQ(VideoCodecProfile, , , H264PROFILE_SCALABLEBASELINE);
ASSERT_ENUM_EQ(VideoCodecProfile, , , H264PROFILE_SCALABLEHIGH);
ASSERT_ENUM_EQ(VideoCodecProfile, , , H264PROFILE_STEREOHIGH);
ASSERT_ENUM_EQ(VideoCodecProfile, , , H264PROFILE_MULTIVIEWHIGH);
ASSERT_ENUM_EQ(VideoCodecProfile, , , H264PROFILE_MAX);
ASSERT_ENUM_EQ(VideoCodecProfile, , , VP8PROFILE_MIN);
ASSERT_ENUM_EQ(VideoCodecProfile, , , VP8PROFILE_ANY);
ASSERT_ENUM_EQ(VideoCodecProfile, , , VP8PROFILE_MAX);
ASSERT_ENUM_EQ(VideoCodecProfile, , , VP9PROFILE_MIN);
ASSERT_ENUM_EQ(VideoCodecProfile, , , VP9PROFILE_PROFILE0);
ASSERT_ENUM_EQ(VideoCodecProfile, , , VP9PROFILE_PROFILE1);
ASSERT_ENUM_EQ(VideoCodecProfile, , , VP9PROFILE_PROFILE2);
ASSERT_ENUM_EQ(VideoCodecProfile, , , VP9PROFILE_PROFILE3);
ASSERT_ENUM_EQ(VideoCodecProfile, , , VP9PROFILE_MAX);
ASSERT_ENUM_EQ(VideoCodecProfile, , , HEVCPROFILE_MIN);
ASSERT_ENUM_EQ(VideoCodecProfile, , , HEVCPROFILE_MAIN);
ASSERT_ENUM_EQ(VideoCodecProfile, , , HEVCPROFILE_MAIN10);
ASSERT_ENUM_EQ(VideoCodecProfile, , , HEVCPROFILE_MAIN_STILL_PICTURE);
ASSERT_ENUM_EQ(VideoCodecProfile, , , HEVCPROFILE_MAX);
ASSERT_ENUM_EQ(VideoCodecProfile, , , VIDEO_CODEC_PROFILE_MAX);

// CipherMode
ASSERT_ENUM_EQ_RAW(EncryptionScheme::CipherMode,
EncryptionScheme::CipherMode::CIPHER_MODE_UNENCRYPTED,
Expand Down Expand Up @@ -446,12 +343,10 @@ TypeConverter<media::mojom::VideoDecoderConfigPtr, media::VideoDecoderConfig>::
Convert(const media::VideoDecoderConfig& input) {
media::mojom::VideoDecoderConfigPtr config(
media::mojom::VideoDecoderConfig::New());
config->codec = static_cast<media::mojom::VideoCodec>(input.codec());
config->profile =
static_cast<media::mojom::VideoCodecProfile>(input.profile());
config->format = static_cast<media::mojom::VideoFormat>(input.format());
config->color_space =
static_cast<media::mojom::ColorSpace>(input.color_space());
config->codec = input.codec();
config->profile = input.profile();
config->format = input.format();
config->color_space = input.color_space();
config->coded_size = input.coded_size();
config->visible_rect = input.visible_rect();
config->natural_size = input.natural_size();
Expand All @@ -466,12 +361,9 @@ media::VideoDecoderConfig
TypeConverter<media::VideoDecoderConfig, media::mojom::VideoDecoderConfigPtr>::
Convert(const media::mojom::VideoDecoderConfigPtr& input) {
media::VideoDecoderConfig config;
config.Initialize(static_cast<media::VideoCodec>(input->codec),
static_cast<media::VideoCodecProfile>(input->profile),
static_cast<media::VideoPixelFormat>(input->format),
static_cast<media::ColorSpace>(input->color_space),
input->coded_size, input->visible_rect, input->natural_size,
input->extra_data,
config.Initialize(input->codec, input->profile, input->format,
input->color_space, input->coded_size, input->visible_rect,
input->natural_size, input->extra_data,
input->encryption_scheme.To<media::EncryptionScheme>());
return config;
}
Expand Down Expand Up @@ -584,7 +476,7 @@ TypeConverter<media::mojom::VideoFramePtr, scoped_refptr<media::VideoFrame>>::
input_frame->Handle().Clone();
CHECK(duplicated_handle.is_valid());

frame->format = static_cast<media::mojom::VideoFormat>(input->format());
frame->format = input->format();
frame->coded_size = input->coded_size();
frame->visible_rect = input->visible_rect();
frame->natural_size = input->natural_size();
Expand All @@ -608,8 +500,8 @@ TypeConverter<scoped_refptr<media::VideoFrame>, media::mojom::VideoFramePtr>::
return media::VideoFrame::CreateEOSFrame();

return media::MojoSharedBufferVideoFrame::Create(
static_cast<media::VideoPixelFormat>(input->format), input->coded_size,
input->visible_rect, input->natural_size, std::move(input->frame_data),
input->format, input->coded_size, input->visible_rect,
input->natural_size, std::move(input->frame_data),
base::saturated_cast<size_t>(input->frame_data_size),
base::saturated_cast<size_t>(input->y_offset),
base::saturated_cast<size_t>(input->u_offset),
Expand Down
102 changes: 13 additions & 89 deletions media/mojo/interfaces/media_types.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -28,96 +28,20 @@ enum ChannelLayout;
enum SampleFormat;

// See media/base/video_types.h for descriptions.
// Kept in sync with media::VideoPixelFormat via static_asserts.
enum VideoFormat {
UNKNOWN = 0,
I420,
YV12,
YV16,
YV12A,
YV24,
NV12,
NV21,
UYVY,
YUY2,
ARGB,
XRGB,
RGB24,
RGB32,
MJPEG,
MT21,
YUV420P9,
YUV420P10,
YUV422P9,
YUV422P10,
YUV444P9,
YUV444P10,
YUV420P12,
YUV422P12,
YUV444P12,
Y8,
Y16,
FORMAT_MAX = Y16,
};
[Native]
enum VideoPixelFormat;

// Kept in sync with media::ColorSpace via static_asserts.
enum ColorSpace {
UNSPECIFIED = 0,
JPEG = 1,
HD_REC709 = 2,
SD_REC601 = 3,
MAX = SD_REC601,
};
// See media/base/video_types.h for descriptions.
[Native]
enum ColorSpace;

// See media/base/video_decoder_config.h for descriptions.
// Kept in sync with media::VideoCodec via static_asserts.
enum VideoCodec {
UNKNOWN = 0,
H264,
VC1,
MPEG2,
MPEG4,
Theora,
VP8,
VP9,
HEVC,
Max = HEVC,
};
// See media/base/video_codecs.h for descriptions.
[Native]
enum VideoCodec;

// See media/base/video_decoder_config.h for descriptions.
// Kept in sync with media::VideoCodecProfile via static_asserts.
enum VideoCodecProfile {
VIDEO_CODEC_PROFILE_UNKNOWN = -1,
VIDEO_CODEC_PROFILE_MIN = VIDEO_CODEC_PROFILE_UNKNOWN,
H264PROFILE_MIN = 0,
H264PROFILE_BASELINE = H264PROFILE_MIN,
H264PROFILE_MAIN,
H264PROFILE_EXTENDED,
H264PROFILE_HIGH,
H264PROFILE_HIGH10PROFILE,
H264PROFILE_HIGH422PROFILE,
H264PROFILE_HIGH444PREDICTIVEPROFILE,
H264PROFILE_SCALABLEBASELINE,
H264PROFILE_SCALABLEHIGH,
H264PROFILE_STEREOHIGH,
H264PROFILE_MULTIVIEWHIGH,
H264PROFILE_MAX = H264PROFILE_MULTIVIEWHIGH,
VP8PROFILE_MIN,
VP8PROFILE_ANY = VP8PROFILE_MIN,
VP8PROFILE_MAX = VP8PROFILE_ANY,
VP9PROFILE_MIN,
VP9PROFILE_PROFILE0 = VP9PROFILE_MIN,
VP9PROFILE_PROFILE1,
VP9PROFILE_PROFILE2,
VP9PROFILE_PROFILE3,
VP9PROFILE_MAX = VP9PROFILE_PROFILE3,
HEVCPROFILE_MIN,
HEVCPROFILE_MAIN = HEVCPROFILE_MIN,
HEVCPROFILE_MAIN10,
HEVCPROFILE_MAIN_STILL_PICTURE,
HEVCPROFILE_MAX = HEVCPROFILE_MAIN_STILL_PICTURE,
VIDEO_CODEC_PROFILE_MAX = HEVCPROFILE_MAX,
};
// See media/base/video_codecs.h for descriptions.
[Native]
enum VideoCodecProfile;

// See media/base/encryption_scheme.h.
// Kept in sync with media::CipherMode via static_asserts.
Expand Down Expand Up @@ -160,7 +84,7 @@ struct AudioDecoderConfig {
struct VideoDecoderConfig {
VideoCodec codec;
VideoCodecProfile profile;
VideoFormat format;
VideoPixelFormat format;
ColorSpace color_space;
gfx.mojom.Size coded_size;
gfx.mojom.Rect visible_rect;
Expand Down Expand Up @@ -237,7 +161,7 @@ struct AudioBuffer {
// This defines a mojo transport format for media::VideoFrame.
struct VideoFrame {
// Format of the frame.
VideoFormat format;
VideoPixelFormat format;

// Width and height of the video frame, in pixels.
gfx.mojom.Size coded_size;
Expand Down
6 changes: 6 additions & 0 deletions media/mojo/interfaces/media_types.typemap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public_headers = [
"//media/base/decode_status.h",
"//media/base/sample_format.h",
"//media/base/subsample_entry.h",
"//media/base/video_codecs.h",
"//media/base/video_types.h",
]

traits_headers = [ "//media/base/ipc/media_param_traits_macros.h" ]
Expand All @@ -24,7 +26,11 @@ type_mappings = [
"media.mojom.AudioCodec=media::AudioCodec",
"media.mojom.BufferingState=media::BufferingState",
"media.mojom.ChannelLayout=media::ChannelLayout",
"media.mojom.ColorSpace=media::ColorSpace",
"media.mojom.DecodeStatus=media::DecodeStatus",
"media.mojom.SampleFormat=media::SampleFormat",
"media.mojom.SubsampleEntry=media::SubsampleEntry",
"media.mojom.VideoCodec=media::VideoCodec",
"media.mojom.VideoCodecProfile=media::VideoCodecProfile",
"media.mojom.VideoPixelFormat=media::VideoPixelFormat",
]
Loading

0 comments on commit 241b69b

Please sign in to comment.