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"
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::VideoFrame::Format
,
27 media::VideoFrame::FORMAT_MAX
)
31 void ParamTraits
<media::AudioDecoderConfig
>::Write(
32 Message
* m
, const media::AudioDecoderConfig
& p
) {
33 ParamTraits
<media::AudioCodec
>::Write(m
, p
.codec());
34 ParamTraits
<media::SampleFormat
>::Write(m
, p
.sample_format());
35 ParamTraits
<media::ChannelLayout
>::Write(m
, p
.channel_layout());
36 ParamTraits
<int>::Write(m
, p
.samples_per_second());
37 ParamTraits
<bool>::Write(m
, p
.is_encrypted());
38 std::vector
<uint8
> extra_data
;
39 if (p
.extra_data_size() > 0) {
41 std::vector
<uint8
>(p
.extra_data(),
42 p
.extra_data() + p
.extra_data_size());
44 ParamTraits
<std::vector
<uint8
> >::Write(m
, extra_data
);
47 bool ParamTraits
<media::AudioDecoderConfig
>::Read(
48 const Message
* m
, 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
;
55 if (!ParamTraits
<media::AudioCodec
>::Read(m
, iter
, &codec
) ||
56 !ParamTraits
<media::SampleFormat
>::Read(m
, iter
, &sample_format
) ||
57 !ParamTraits
<media::ChannelLayout
>::Read(m
, iter
, &channel_layout
) ||
58 !ParamTraits
<int>::Read(m
, iter
, &samples_per_second
) ||
59 !ParamTraits
<bool>::Read(m
, iter
, &is_encrypted
)) {
62 std::vector
<uint8
> extra_data
;
63 if (!ParamTraits
<std::vector
<uint8
> >::Read(m
, iter
, &extra_data
))
65 const uint8
* extra_data_ptr
= NULL
;
66 if (extra_data
.size() > 0)
67 extra_data_ptr
= &extra_data
[0];
68 *r
= media::AudioDecoderConfig(codec
, sample_format
, channel_layout
,
70 extra_data_ptr
, extra_data
.size(),
75 void ParamTraits
<media::AudioDecoderConfig
>::Log(
76 const media::AudioDecoderConfig
& p
, std::string
* l
) {
77 l
->append(base::StringPrintf("<AudioDecoderConfig>"));
80 void ParamTraits
<media::VideoDecoderConfig
>::Write(
81 Message
* m
, const media::VideoDecoderConfig
& p
) {
82 ParamTraits
<media::VideoCodec
>::Write(m
, p
.codec());
83 ParamTraits
<media::VideoCodecProfile
>::Write(m
, p
.profile());
84 ParamTraits
<media::VideoFrame::Format
>::Write(m
, p
.format());
85 ParamTraits
<gfx::Size
>::Write(m
, p
.coded_size());
86 ParamTraits
<gfx::Rect
>::Write(m
, p
.visible_rect());
87 ParamTraits
<gfx::Size
>::Write(m
, p
.natural_size());
88 ParamTraits
<bool>::Write(m
, p
.is_encrypted());
89 std::vector
<uint8
> extra_data
;
90 if (p
.extra_data_size() > 0) {
92 std::vector
<uint8
>(p
.extra_data(),
93 p
.extra_data() + p
.extra_data_size());
95 ParamTraits
<std::vector
<uint8
> >::Write(m
, extra_data
);
98 bool ParamTraits
<media::VideoDecoderConfig
>::Read(
99 const Message
* m
, PickleIterator
* iter
,
100 media::VideoDecoderConfig
* r
) {
101 media::VideoCodec codec
;
102 media::VideoCodecProfile profile
;
103 media::VideoFrame::Format format
;
104 gfx::Size coded_size
;
105 gfx::Rect visible_rect
;
106 gfx::Size natural_size
;
108 if (!ParamTraits
<media::VideoCodec
>::Read(m
, iter
, &codec
) ||
109 !ParamTraits
<media::VideoCodecProfile
>::Read(m
, iter
, &profile
) ||
110 !ParamTraits
<media::VideoFrame::Format
>::Read(m
, iter
, &format
) ||
111 !ParamTraits
<gfx::Size
>::Read(m
, iter
, &coded_size
) ||
112 !ParamTraits
<gfx::Rect
>::Read(m
, iter
, &visible_rect
) ||
113 !ParamTraits
<gfx::Size
>::Read(m
, iter
, &natural_size
) ||
114 !ParamTraits
<bool>::Read(m
, iter
, &is_encrypted
)) {
117 std::vector
<uint8
> extra_data
;
118 if (!ParamTraits
<std::vector
<uint8
> >::Read(m
, iter
, &extra_data
))
120 const uint8
* extra_data_ptr
= NULL
;
121 if (extra_data
.size() > 0)
122 extra_data_ptr
= &extra_data
[0];
123 *r
= media::VideoDecoderConfig(codec
, profile
, format
,
124 coded_size
, visible_rect
, natural_size
,
125 extra_data_ptr
, extra_data
.size(),
130 void ParamTraits
<media::VideoDecoderConfig
>::Log(
131 const media::VideoDecoderConfig
& p
, std::string
* l
) {
132 l
->append(base::StringPrintf("<VideoDecoderConfig>"));