[M120 Migration][MM] Framerate calculation
[platform/framework/web/chromium-efl.git] / media / mojo / mojom / video_frame_mojom_traits.h
1 // Copyright 2017 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef MEDIA_MOJO_MOJOM_VIDEO_FRAME_MOJOM_TRAITS_H_
6 #define MEDIA_MOJO_MOJOM_VIDEO_FRAME_MOJOM_TRAITS_H_
7
8 #include "base/memory/scoped_refptr.h"
9 #include "gpu/ipc/common/mailbox_holder_mojom_traits.h"
10 #include "gpu/ipc/common/vulkan_ycbcr_info_mojom_traits.h"
11 #include "media/base/ipc/media_param_traits_macros.h"
12 #include "media/base/video_frame.h"
13 #include "media/mojo/mojom/media_types.mojom.h"
14 #include "mojo/public/cpp/bindings/enum_traits.h"
15 #include "mojo/public/cpp/bindings/struct_traits.h"
16 #include "third_party/abseil-cpp/absl/types/optional.h"
17 #include "ui/gfx/geometry/mojom/geometry_mojom_traits.h"
18 #include "ui/gfx/ipc/color/gfx_param_traits.h"
19
20 namespace mojo {
21
22 template <>
23 struct EnumTraits<media::mojom::SharedImageFormatType,
24                   media::SharedImageFormatType> {
25   static media::mojom::SharedImageFormatType ToMojom(
26       media::SharedImageFormatType type);
27
28   static bool FromMojom(media::mojom::SharedImageFormatType input,
29                         media::SharedImageFormatType* out);
30 };
31
32 template <>
33 struct StructTraits<media::mojom::VideoFrameDataView,
34                     scoped_refptr<media::VideoFrame>> {
35   static bool IsNull(const scoped_refptr<media::VideoFrame>& input) {
36     return !input;
37   }
38
39   static void SetToNull(scoped_refptr<media::VideoFrame>* input) {
40     *input = nullptr;
41   }
42
43   static media::VideoPixelFormat format(
44       const scoped_refptr<media::VideoFrame>& input) {
45     return input->format();
46   }
47
48   static const gfx::Size& coded_size(
49       const scoped_refptr<media::VideoFrame>& input) {
50     return input->coded_size();
51   }
52
53   static const gfx::Rect& visible_rect(
54       const scoped_refptr<media::VideoFrame>& input) {
55     return input->visible_rect();
56   }
57
58   static const gfx::Size& natural_size(
59       const scoped_refptr<media::VideoFrame>& input) {
60     return input->natural_size();
61   }
62
63   static base::TimeDelta timestamp(
64       const scoped_refptr<media::VideoFrame>& input) {
65     return input->timestamp();
66   }
67
68   // TODO(hubbe): Return const ref when VideoFrame::ColorSpace()
69   // returns const ref.
70   static gfx::ColorSpace color_space(
71       const scoped_refptr<media::VideoFrame>& input) {
72     return input->ColorSpace();
73   }
74
75   static const absl::optional<gfx::HDRMetadata>& hdr_metadata(
76       const scoped_refptr<media::VideoFrame>& input) {
77     return input->hdr_metadata();
78   }
79
80   static media::SharedImageFormatType shared_image_format_type(
81       const scoped_refptr<media::VideoFrame>& input) {
82     return input->shared_image_format_type();
83   }
84
85   static const absl::optional<gpu::VulkanYCbCrInfo>& ycbcr_info(
86       const scoped_refptr<media::VideoFrame>& input) {
87     return input->ycbcr_info();
88   }
89
90   static media::mojom::VideoFrameDataPtr data(
91       const scoped_refptr<media::VideoFrame>& input);
92
93   static const media::VideoFrameMetadata& metadata(
94       const scoped_refptr<media::VideoFrame>& input) {
95     return input->metadata();
96   }
97
98   static bool Read(media::mojom::VideoFrameDataView input,
99                    scoped_refptr<media::VideoFrame>* output);
100 };
101
102 }  // namespace mojo
103
104 #endif  // MEDIA_MOJO_MOJOM_VIDEO_FRAME_MOJOM_TRAITS_H_