OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromecast/common/media/cma_param_traits.h" | 5 #include "chromecast/common/media/cma_param_traits.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "chromecast/common/media/cma_param_traits_macros.h" | 11 #include "chromecast/common/media/cma_param_traits_macros.h" |
12 #include "content/public/common/common_param_traits.h" | 12 #include "content/public/common/common_param_traits.h" |
13 #include "ipc/ipc_message_macros.h" | 13 #include "ipc/ipc_message_macros.h" |
14 #include "media/base/audio_decoder_config.h" | 14 #include "media/base/audio_decoder_config.h" |
15 #include "media/base/encryption_scheme.h" | |
16 #include "media/base/video_decoder_config.h" | 15 #include "media/base/video_decoder_config.h" |
17 #include "ui/gfx/ipc/gfx_param_traits.h" | 16 #include "ui/gfx/ipc/gfx_param_traits.h" |
18 | 17 |
19 // Note(gunsch): these are currently defined in content/, but not declared in | 18 // Note(gunsch): these are currently defined in content/, but not declared in |
20 // content/public/. These headers need to be forward-declared for chromecast/, | 19 // content/public/. These headers need to be forward-declared for chromecast/, |
21 // but without new implementations linked in. | 20 // but without new implementations linked in. |
22 // The correct long-term fix is to use Mojo instead of the content/ IPCs. | 21 // The correct long-term fix is to use Mojo instead of the content/ IPCs. |
23 IPC_ENUM_TRAITS_MIN_MAX_VALUE(media::ChannelLayout, | 22 IPC_ENUM_TRAITS_MIN_MAX_VALUE(media::ChannelLayout, |
24 media::ChannelLayout::CHANNEL_LAYOUT_NONE, | 23 media::ChannelLayout::CHANNEL_LAYOUT_NONE, |
25 media::ChannelLayout::CHANNEL_LAYOUT_MAX) | 24 media::ChannelLayout::CHANNEL_LAYOUT_MAX) |
26 IPC_ENUM_TRAITS_MIN_MAX_VALUE(media::VideoCodecProfile, | 25 IPC_ENUM_TRAITS_MIN_MAX_VALUE(media::VideoCodecProfile, |
27 media::VIDEO_CODEC_PROFILE_MIN, | 26 media::VIDEO_CODEC_PROFILE_MIN, |
28 media::VIDEO_CODEC_PROFILE_MAX) | 27 media::VIDEO_CODEC_PROFILE_MAX) |
29 IPC_ENUM_TRAITS_MAX_VALUE(media::VideoPixelFormat, media::PIXEL_FORMAT_MAX) | 28 IPC_ENUM_TRAITS_MAX_VALUE(media::VideoPixelFormat, media::PIXEL_FORMAT_MAX) |
30 | 29 |
31 namespace IPC { | 30 namespace IPC { |
32 | 31 |
33 template <> | |
34 struct ParamTraits<media::EncryptionScheme::Pattern> { | |
35 typedef media::EncryptionScheme::Pattern param_type; | |
36 static void Write(base::Pickle* m, const param_type& p); | |
37 static bool Read(const base::Pickle* m, base::PickleIterator* iter, | |
38 param_type* r); | |
39 static void Log(const param_type& p, std::string* l); | |
40 }; | |
41 | |
42 | |
43 void ParamTraits<media::AudioDecoderConfig>::Write( | 32 void ParamTraits<media::AudioDecoderConfig>::Write( |
44 base::Pickle* m, | 33 base::Pickle* m, |
45 const media::AudioDecoderConfig& p) { | 34 const media::AudioDecoderConfig& p) { |
46 WriteParam(m, p.codec()); | 35 WriteParam(m, p.codec()); |
47 WriteParam(m, p.sample_format()); | 36 WriteParam(m, p.sample_format()); |
48 WriteParam(m, p.channel_layout()); | 37 WriteParam(m, p.channel_layout()); |
49 WriteParam(m, p.samples_per_second()); | 38 WriteParam(m, p.samples_per_second()); |
50 WriteParam(m, p.encryption_scheme()); | 39 WriteParam(m, p.is_encrypted()); |
51 WriteParam(m, p.extra_data()); | 40 WriteParam(m, p.extra_data()); |
52 } | 41 } |
53 | 42 |
54 bool ParamTraits<media::AudioDecoderConfig>::Read( | 43 bool ParamTraits<media::AudioDecoderConfig>::Read( |
55 const base::Pickle* m, | 44 const base::Pickle* m, |
56 base::PickleIterator* iter, | 45 base::PickleIterator* iter, |
57 media::AudioDecoderConfig* r) { | 46 media::AudioDecoderConfig* r) { |
58 media::AudioCodec codec; | 47 media::AudioCodec codec; |
59 media::SampleFormat sample_format; | 48 media::SampleFormat sample_format; |
60 media::ChannelLayout channel_layout; | 49 media::ChannelLayout channel_layout; |
61 int samples_per_second; | 50 int samples_per_second; |
62 media::EncryptionScheme encryption_scheme; | 51 bool is_encrypted; |
63 std::vector<uint8_t> extra_data; | 52 std::vector<uint8_t> extra_data; |
64 if (!ReadParam(m, iter, &codec) || !ReadParam(m, iter, &sample_format) || | 53 if (!ReadParam(m, iter, &codec) || !ReadParam(m, iter, &sample_format) || |
65 !ReadParam(m, iter, &channel_layout) || | 54 !ReadParam(m, iter, &channel_layout) || |
66 !ReadParam(m, iter, &samples_per_second) || | 55 !ReadParam(m, iter, &samples_per_second) || |
67 !ReadParam(m, iter, &encryption_scheme) || | 56 !ReadParam(m, iter, &is_encrypted) || !ReadParam(m, iter, &extra_data)) |
68 !ReadParam(m, iter, &extra_data)) | |
69 return false; | 57 return false; |
70 *r = media::AudioDecoderConfig(codec, sample_format, channel_layout, | 58 *r = media::AudioDecoderConfig(codec, sample_format, channel_layout, |
71 samples_per_second, extra_data, | 59 samples_per_second, extra_data, is_encrypted); |
72 encryption_scheme); | |
73 return true; | 60 return true; |
74 } | 61 } |
75 | 62 |
76 void ParamTraits<media::AudioDecoderConfig>::Log( | 63 void ParamTraits<media::AudioDecoderConfig>::Log( |
77 const media::AudioDecoderConfig& p, std::string* l) { | 64 const media::AudioDecoderConfig& p, std::string* l) { |
78 l->append(base::StringPrintf("<AudioDecoderConfig>")); | 65 l->append(base::StringPrintf("<AudioDecoderConfig>")); |
79 } | 66 } |
80 | 67 |
81 void ParamTraits<media::VideoDecoderConfig>::Write( | 68 void ParamTraits<media::VideoDecoderConfig>::Write( |
82 base::Pickle* m, | 69 base::Pickle* m, |
83 const media::VideoDecoderConfig& p) { | 70 const media::VideoDecoderConfig& p) { |
84 WriteParam(m, p.codec()); | 71 WriteParam(m, p.codec()); |
85 WriteParam(m, p.profile()); | 72 WriteParam(m, p.profile()); |
86 WriteParam(m, p.format()); | 73 WriteParam(m, p.format()); |
87 WriteParam(m, p.color_space()); | 74 WriteParam(m, p.color_space()); |
88 WriteParam(m, p.coded_size()); | 75 WriteParam(m, p.coded_size()); |
89 WriteParam(m, p.visible_rect()); | 76 WriteParam(m, p.visible_rect()); |
90 WriteParam(m, p.natural_size()); | 77 WriteParam(m, p.natural_size()); |
91 WriteParam(m, p.encryption_scheme()); | 78 WriteParam(m, p.is_encrypted()); |
92 WriteParam(m, p.extra_data()); | 79 WriteParam(m, p.extra_data()); |
93 } | 80 } |
94 | 81 |
95 bool ParamTraits<media::VideoDecoderConfig>::Read( | 82 bool ParamTraits<media::VideoDecoderConfig>::Read( |
96 const base::Pickle* m, | 83 const base::Pickle* m, |
97 base::PickleIterator* iter, | 84 base::PickleIterator* iter, |
98 media::VideoDecoderConfig* r) { | 85 media::VideoDecoderConfig* r) { |
99 media::VideoCodec codec; | 86 media::VideoCodec codec; |
100 media::VideoCodecProfile profile; | 87 media::VideoCodecProfile profile; |
101 media::VideoPixelFormat format; | 88 media::VideoPixelFormat format; |
102 media::ColorSpace color_space; | 89 media::ColorSpace color_space; |
103 gfx::Size coded_size; | 90 gfx::Size coded_size; |
104 gfx::Rect visible_rect; | 91 gfx::Rect visible_rect; |
105 gfx::Size natural_size; | 92 gfx::Size natural_size; |
106 media::EncryptionScheme encryption_scheme; | 93 bool is_encrypted; |
107 std::vector<uint8_t> extra_data; | 94 std::vector<uint8_t> extra_data; |
108 if (!ReadParam(m, iter, &codec) || !ReadParam(m, iter, &profile) || | 95 if (!ReadParam(m, iter, &codec) || !ReadParam(m, iter, &profile) || |
109 !ReadParam(m, iter, &format) || !ReadParam(m, iter, &color_space) || | 96 !ReadParam(m, iter, &format) || !ReadParam(m, iter, &color_space) || |
110 !ReadParam(m, iter, &coded_size) || !ReadParam(m, iter, &visible_rect) || | 97 !ReadParam(m, iter, &coded_size) || !ReadParam(m, iter, &visible_rect) || |
111 !ReadParam(m, iter, &natural_size) || | 98 !ReadParam(m, iter, &natural_size) || |
112 !ReadParam(m, iter, &encryption_scheme) || | 99 !ReadParam(m, iter, &is_encrypted) || !ReadParam(m, iter, &extra_data)) |
113 !ReadParam(m, iter, &extra_data)) | |
114 return false; | 100 return false; |
115 *r = media::VideoDecoderConfig(codec, profile, format, color_space, | 101 *r = media::VideoDecoderConfig(codec, profile, format, color_space, |
116 coded_size, visible_rect, natural_size, | 102 coded_size, visible_rect, natural_size, |
117 extra_data, encryption_scheme); | 103 extra_data, is_encrypted); |
118 return true; | 104 return true; |
119 } | 105 } |
120 | 106 |
121 void ParamTraits<media::VideoDecoderConfig>::Log( | 107 void ParamTraits<media::VideoDecoderConfig>::Log( |
122 const media::VideoDecoderConfig& p, std::string* l) { | 108 const media::VideoDecoderConfig& p, std::string* l) { |
123 l->append(base::StringPrintf("<VideoDecoderConfig>")); | 109 l->append(base::StringPrintf("<VideoDecoderConfig>")); |
124 } | 110 } |
125 | 111 |
126 void ParamTraits<media::EncryptionScheme>::Write( | |
127 base::Pickle* m, const param_type& p) { | |
128 WriteParam(m, p.mode()); | |
129 WriteParam(m, p.pattern()); | |
130 } | |
131 | |
132 bool ParamTraits<media::EncryptionScheme>::Read( | |
133 const base::Pickle* m, base::PickleIterator* iter, param_type* r) { | |
134 media::EncryptionScheme::CipherMode mode; | |
135 media::EncryptionScheme::Pattern pattern; | |
136 if (!ReadParam(m, iter, &mode) || !ReadParam(m, iter, &pattern)) | |
137 return false; | |
138 *r = media::EncryptionScheme(mode, pattern); | |
139 return true; | |
140 } | |
141 | |
142 void ParamTraits<media::EncryptionScheme>::Log( | |
143 const param_type& p, std::string* l) { | |
144 l->append(base::StringPrintf("<EncryptionScheme>")); | |
145 } | |
146 | |
147 void ParamTraits<media::EncryptionScheme::Pattern>::Write( | |
148 base::Pickle* m, const param_type& p) { | |
149 WriteParam(m, p.encrypt_blocks()); | |
150 WriteParam(m, p.skip_blocks()); | |
151 } | |
152 | |
153 bool ParamTraits<media::EncryptionScheme::Pattern>::Read( | |
154 const base::Pickle* m, base::PickleIterator* iter, param_type* r) { | |
155 uint32_t encrypt_blocks, skip_blocks; | |
156 if (!ReadParam(m, iter, &encrypt_blocks) || !ReadParam(m, iter, &skip_blocks)) | |
157 return false; | |
158 *r = media::EncryptionScheme::Pattern(encrypt_blocks, skip_blocks); | |
159 return true; | |
160 } | |
161 | |
162 void ParamTraits<media::EncryptionScheme::Pattern>::Log( | |
163 const param_type& p, std::string* l) { | |
164 l->append(base::StringPrintf("<Pattern>")); | |
165 } | |
166 | |
167 } // namespace IPC | 112 } // namespace IPC |
OLD | NEW |