Chromium Code Reviews| Index: services/video_capture/public/interfaces/video_capture_format_traits.h |
| diff --git a/services/video_capture/public/interfaces/video_capture_format_traits.h b/services/video_capture/public/interfaces/video_capture_format_traits.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e55ed927cea74185adba77db11fb31021bcc59b3 |
| --- /dev/null |
| +++ b/services/video_capture/public/interfaces/video_capture_format_traits.h |
| @@ -0,0 +1,55 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef SERVICES_VIDEO_CAPTURE_PUBLIC_INTERFACES_VIDEO_CAPTURE_FORMAT_TYPEMAP_H_ |
| +#define SERVICES_VIDEO_CAPTURE_PUBLIC_INTERFACES_VIDEO_CAPTURE_FORMAT_TYPEMAP_H_ |
| + |
| +#include "media/base/video_capture_types.h" |
| +#include "mojo/common/common_custom_types_struct_traits.h" |
| +#include "services/video_capture/public/interfaces/video_capture_format.mojom.h" |
| +#include "ui/gfx/geometry/mojo/geometry.mojom.h" |
| +#include "ui/gfx/geometry/mojo/geometry_struct_traits.h" |
| + |
| +namespace mojo { |
| + |
| +template <> |
| +struct StructTraits<video_capture::mojom::VideoCaptureFormatDataView, |
| + media::VideoCaptureFormat> { |
| + |
| + static gfx::Size frame_size(const media::VideoCaptureFormat& r) { |
| + return gfx::Size(r.frame_size.width(), r.frame_size.height()); |
| + } |
| + |
| + static float frame_rate(const media::VideoCaptureFormat& r) { |
| + return r.frame_rate; |
| + } |
| + |
| + static media::mojom::VideoFormat pixel_format( |
| + const media::VideoCaptureFormat& r) { |
| + return static_cast<media::mojom::VideoFormat>(r.pixel_format); |
|
dcheng
2016/10/03 01:03:08
Mojo has EnumTraits for mapping enums. Example: ht
mcasas
2016/10/03 07:31:51
Using it for VideoPixelStorage in l.33, but re. th
chfremer
2016/10/03 16:26:59
In my take on using the typmapping, I ended up rem
dcheng
2016/10/03 20:45:53
My recollection is the //media code predated the a
|
| + } |
| + |
| + static video_capture::mojom::VideoPixelStorage pixel_storage( |
| + const media::VideoCaptureFormat& r) { |
| + return static_cast<video_capture::mojom::VideoPixelStorage>( |
| + r.pixel_storage); |
| + } |
| + |
| + static bool Read(video_capture::mojom::VideoCaptureFormatDataView data, |
|
dcheng
2016/10/03 01:03:08
Nit: Out-of-line this.
mcasas
2016/10/03 07:31:51
Done.
|
| + media::VideoCaptureFormat* out) { |
| + gfx::Size frame_size; |
| + data.ReadFrameSize(&frame_size); |
|
dcheng
2016/10/03 01:03:08
Nit: read directly into out->frame_size, and check
mcasas
2016/10/03 07:31:51
Done.
|
| + out->frame_size = frame_size; |
| + out->frame_rate = data.frame_rate(); |
| + out->pixel_format = |
| + static_cast<media::VideoPixelFormat>(data.pixel_format()); |
| + out->pixel_storage = |
| + static_cast<media::VideoPixelStorage>(data.pixel_storage()); |
| + return true; |
| + } |
| +}; |
| + |
| +} |
| + |
| +#endif // SERVICES_VIDEO_CAPTURE_PUBLIC_INTERFACES_VIDEO_CAPTURE_FORMAT_TYPEMAP_H_ |