1 // Copyright (c) 2012 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 "content/common/media/media_param_traits.h"
7 #include "base/strings/stringprintf.h"
8 #include "content/common/media/audio_messages.h"
9 #include "content/common/media/video_capture_messages.h"
10 #include "ipc/ipc_message_utils.h"
11 #include "media/audio/audio_parameters.h"
12 #include "media/audio/point.h"
13 #include "media/base/limits.h"
14 #include "ui/gfx/ipc/gfx_param_traits.h"
16 using media::AudioParameters
;
17 using media::ChannelLayout
;
18 using media::VideoCaptureFormat
;
22 void ParamTraits
<AudioParameters
>::Write(Message
* m
,
23 const AudioParameters
& p
) {
24 WriteParam(m
, p
.format());
25 WriteParam(m
, p
.channel_layout());
26 WriteParam(m
, p
.sample_rate());
27 WriteParam(m
, p
.bits_per_sample());
28 WriteParam(m
, p
.frames_per_buffer());
29 WriteParam(m
, p
.channels());
30 WriteParam(m
, p
.effects());
31 WriteParam(m
, p
.mic_positions());
34 bool ParamTraits
<AudioParameters
>::Read(const Message
* m
,
35 base::PickleIterator
* iter
,
37 AudioParameters::Format format
;
38 ChannelLayout channel_layout
;
39 int sample_rate
, bits_per_sample
, frames_per_buffer
, channels
, effects
;
40 std::vector
<media::Point
> mic_positions
;
42 if (!ReadParam(m
, iter
, &format
) || !ReadParam(m
, iter
, &channel_layout
) ||
43 !ReadParam(m
, iter
, &sample_rate
) ||
44 !ReadParam(m
, iter
, &bits_per_sample
) ||
45 !ReadParam(m
, iter
, &frames_per_buffer
) ||
46 !ReadParam(m
, iter
, &channels
) || !ReadParam(m
, iter
, &effects
) ||
47 !ReadParam(m
, iter
, &mic_positions
)) {
51 AudioParameters
params(format
, channel_layout
, sample_rate
, bits_per_sample
,
53 params
.set_channels_for_discrete(channels
);
54 params
.set_effects(effects
);
55 params
.set_mic_positions(mic_positions
);
61 void ParamTraits
<AudioParameters
>::Log(const AudioParameters
& p
,
63 l
->append(base::StringPrintf("<AudioParameters>"));
66 void ParamTraits
<VideoCaptureFormat
>::Write(Message
* m
,
67 const VideoCaptureFormat
& p
) {
68 WriteParam(m
, p
.frame_size
);
69 WriteParam(m
, p
.frame_rate
);
70 WriteParam(m
, p
.pixel_format
);
71 WriteParam(m
, p
.pixel_storage
);
74 bool ParamTraits
<VideoCaptureFormat
>::Read(const Message
* m
,
75 base::PickleIterator
* iter
,
76 VideoCaptureFormat
* r
) {
77 if (!ReadParam(m
, iter
, &r
->frame_size
) ||
78 !ReadParam(m
, iter
, &r
->frame_rate
) ||
79 !ReadParam(m
, iter
, &r
->pixel_format
) ||
80 !ReadParam(m
, iter
, &r
->pixel_storage
)) {
86 void ParamTraits
<VideoCaptureFormat
>::Log(const VideoCaptureFormat
& p
,
88 l
->append(base::StringPrintf("<VideoCaptureFormat> %s",
89 media::VideoCaptureFormat::ToString(p
).c_str()));