Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chromecast / common / media / cma_param_traits.cc
blobab0f62a32b0517e7edaa532252fb14d134c50c11
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chromecast/common/media/cma_param_traits.h"
7 #include <vector>
9 #include "chromecast/common/media/cma_param_traits_macros.h"
10 #include "content/public/common/common_param_traits.h"
11 #include "ipc/ipc_message_macros.h"
12 #include "media/base/audio_decoder_config.h"
13 #include "media/base/video_decoder_config.h"
14 #include "ui/gfx/ipc/gfx_param_traits.h"
16 // Note(gunsch): these are currently defined in content/, but not declared in
17 // content/public/. These headers need to be forward-declared for chromecast/,
18 // but without new implementations linked in.
19 // The correct long-term fix is to use Mojo instead of the content/ IPCs.
20 IPC_ENUM_TRAITS_MIN_MAX_VALUE(media::ChannelLayout,
21 media::ChannelLayout::CHANNEL_LAYOUT_NONE,
22 media::ChannelLayout::CHANNEL_LAYOUT_MAX)
23 IPC_ENUM_TRAITS_MIN_MAX_VALUE(media::VideoCodecProfile,
24 media::VIDEO_CODEC_PROFILE_MIN,
25 media::VIDEO_CODEC_PROFILE_MAX)
26 IPC_ENUM_TRAITS_MAX_VALUE(media::VideoPixelFormat, media::PIXEL_FORMAT_MAX)
28 namespace IPC {
30 void ParamTraits<media::AudioDecoderConfig>::Write(
31 Message* m, const media::AudioDecoderConfig& p) {
32 WriteParam(m, p.codec());
33 WriteParam(m, p.sample_format());
34 WriteParam(m, p.channel_layout());
35 WriteParam(m, p.samples_per_second());
36 WriteParam(m, p.is_encrypted());
37 std::vector<uint8> extra_data;
38 if (p.extra_data_size() > 0) {
39 extra_data =
40 std::vector<uint8>(p.extra_data(),
41 p.extra_data() + p.extra_data_size());
43 WriteParam(m, extra_data);
46 bool ParamTraits<media::AudioDecoderConfig>::Read(
47 const Message* m,
48 base::PickleIterator* iter,
49 media::AudioDecoderConfig* r) {
50 media::AudioCodec codec;
51 media::SampleFormat sample_format;
52 media::ChannelLayout channel_layout;
53 int samples_per_second;
54 bool is_encrypted;
55 std::vector<uint8> extra_data;
56 if (!ReadParam(m, iter, &codec) || !ReadParam(m, iter, &sample_format) ||
57 !ReadParam(m, iter, &channel_layout) ||
58 !ReadParam(m, iter, &samples_per_second) ||
59 !ReadParam(m, iter, &is_encrypted) || !ReadParam(m, iter, &extra_data))
60 return false;
61 const uint8* extra_data_ptr = nullptr;
62 if (!extra_data.empty())
63 extra_data_ptr = &extra_data[0];
64 *r = media::AudioDecoderConfig(codec, sample_format, channel_layout,
65 samples_per_second,
66 extra_data_ptr, extra_data.size(),
67 is_encrypted);
68 return true;
71 void ParamTraits<media::AudioDecoderConfig>::Log(
72 const media::AudioDecoderConfig& p, std::string* l) {
73 l->append(base::StringPrintf("<AudioDecoderConfig>"));
76 void ParamTraits<media::VideoDecoderConfig>::Write(
77 Message* m, const media::VideoDecoderConfig& p) {
78 WriteParam(m, p.codec());
79 WriteParam(m, p.profile());
80 WriteParam(m, p.format());
81 WriteParam(m, p.color_space());
82 WriteParam(m, p.coded_size());
83 WriteParam(m, p.visible_rect());
84 WriteParam(m, p.natural_size());
85 WriteParam(m, p.is_encrypted());
86 std::vector<uint8> extra_data;
87 if (p.extra_data_size() > 0) {
88 extra_data =
89 std::vector<uint8>(p.extra_data(),
90 p.extra_data() + p.extra_data_size());
92 WriteParam(m, extra_data);
95 bool ParamTraits<media::VideoDecoderConfig>::Read(
96 const Message* m,
97 base::PickleIterator* iter,
98 media::VideoDecoderConfig* r) {
99 media::VideoCodec codec;
100 media::VideoCodecProfile profile;
101 media::VideoPixelFormat format;
102 media::ColorSpace color_space;
103 gfx::Size coded_size;
104 gfx::Rect visible_rect;
105 gfx::Size natural_size;
106 bool is_encrypted;
107 std::vector<uint8> extra_data;
108 if (!ReadParam(m, iter, &codec) || !ReadParam(m, iter, &profile) ||
109 !ReadParam(m, iter, &format) || !ReadParam(m, iter, &color_space) ||
110 !ReadParam(m, iter, &coded_size) || !ReadParam(m, iter, &visible_rect) ||
111 !ReadParam(m, iter, &natural_size) ||
112 !ReadParam(m, iter, &is_encrypted) || !ReadParam(m, iter, &extra_data))
113 return false;
114 const uint8* extra_data_ptr = nullptr;
115 if (!extra_data.empty())
116 extra_data_ptr = &extra_data[0];
117 *r = media::VideoDecoderConfig(codec, profile, format, color_space,
118 coded_size, visible_rect, natural_size,
119 extra_data_ptr, extra_data.size(),
120 is_encrypted);
121 return true;
124 void ParamTraits<media::VideoDecoderConfig>::Log(
125 const media::VideoDecoderConfig& p, std::string* l) {
126 l->append(base::StringPrintf("<VideoDecoderConfig>"));
129 } // namespace IPC