Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / common / media / media_param_traits.cc
blob5d5020c96544121434db4af0b5a6cf5a19feaae4
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;
20 namespace IPC {
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,
36 AudioParameters* r) {
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)) {
48 return false;
51 AudioParameters params(format, channel_layout, sample_rate, bits_per_sample,
52 frames_per_buffer);
53 params.set_channels_for_discrete(channels);
54 params.set_effects(effects);
55 params.set_mic_positions(mic_positions);
57 *r = params;
58 return r->IsValid();
61 void ParamTraits<AudioParameters>::Log(const AudioParameters& p,
62 std::string* l) {
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)) {
81 return false;
83 return r->IsValid();
86 void ParamTraits<VideoCaptureFormat>::Log(const VideoCaptureFormat& p,
87 std::string* l) {
88 l->append(base::StringPrintf("<VideoCaptureFormat> %s",
89 media::VideoCaptureFormat::ToString(p).c_str()));
92 } // namespace IPC