[MacViews] Show comboboxes with a native NSMenu
[chromium-blink-merge.git] / content / common / media / media_param_traits.cc
blob7b3edcd8528cc2e8c0898316788a0ac253c7c7ee
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/base/limits.h"
13 #include "ui/gfx/ipc/gfx_param_traits.h"
15 using media::AudioParameters;
16 using media::ChannelLayout;
17 using media::VideoCaptureFormat;
19 namespace IPC {
21 void ParamTraits<AudioParameters>::Write(Message* m,
22 const AudioParameters& p) {
23 WriteParam(m, p.format());
24 WriteParam(m, p.channel_layout());
25 WriteParam(m, p.sample_rate());
26 WriteParam(m, p.bits_per_sample());
27 WriteParam(m, p.frames_per_buffer());
28 WriteParam(m, p.channels());
29 WriteParam(m, p.effects());
32 bool ParamTraits<AudioParameters>::Read(const Message* m,
33 base::PickleIterator* iter,
34 AudioParameters* r) {
35 AudioParameters::Format format;
36 ChannelLayout channel_layout;
37 int sample_rate, bits_per_sample, frames_per_buffer, channels, effects;
39 if (!ReadParam(m, iter, &format) || !ReadParam(m, iter, &channel_layout) ||
40 !ReadParam(m, iter, &sample_rate) ||
41 !ReadParam(m, iter, &bits_per_sample) ||
42 !ReadParam(m, iter, &frames_per_buffer) ||
43 !ReadParam(m, iter, &channels) || !ReadParam(m, iter, &effects)) {
44 return false;
47 AudioParameters params(format, channel_layout, sample_rate, bits_per_sample,
48 frames_per_buffer);
49 params.set_channels_for_discrete(channels);
50 params.set_effects(effects);
52 *r = params;
53 return r->IsValid();
56 void ParamTraits<AudioParameters>::Log(const AudioParameters& p,
57 std::string* l) {
58 l->append(base::StringPrintf("<AudioParameters>"));
61 void ParamTraits<VideoCaptureFormat>::Write(Message* m,
62 const VideoCaptureFormat& p) {
63 WriteParam(m, p.frame_size);
64 WriteParam(m, p.frame_rate);
65 WriteParam(m, p.pixel_format);
66 WriteParam(m, p.pixel_storage);
69 bool ParamTraits<VideoCaptureFormat>::Read(const Message* m,
70 base::PickleIterator* iter,
71 VideoCaptureFormat* r) {
72 if (!ReadParam(m, iter, &r->frame_size) ||
73 !ReadParam(m, iter, &r->frame_rate) ||
74 !ReadParam(m, iter, &r->pixel_format) ||
75 !ReadParam(m, iter, &r->pixel_storage)) {
76 return false;
78 return r->IsValid();
81 void ParamTraits<VideoCaptureFormat>::Log(const VideoCaptureFormat& p,
82 std::string* l) {
83 l->append(base::StringPrintf("<VideoCaptureFormat> %s",
84 media::VideoCaptureFormat::ToString(p).c_str()));
87 } // namespace IPC