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 "media/audio/audio_parameters.h"
9 #include "media/base/limits.h"
10 #include "media/video/capture/video_capture_types.h"
12 using media::AudioParameters;
13 using media::ChannelLayout;
14 using media::VideoCaptureFormat;
15 using media::VideoCaptureSessionId;
19 void ParamTraits<AudioParameters>::Write(Message* m,
20 const AudioParameters& p) {
21 m->WriteInt(static_cast<int>(p.format()));
22 m->WriteInt(static_cast<int>(p.channel_layout()));
23 m->WriteInt(p.sample_rate());
24 m->WriteInt(p.bits_per_sample());
25 m->WriteInt(p.frames_per_buffer());
26 m->WriteInt(p.channels());
27 m->WriteInt(p.input_channels());
30 bool ParamTraits<AudioParameters>::Read(const Message* m,
33 int format, channel_layout, sample_rate, bits_per_sample,
34 frames_per_buffer, channels, input_channels;
36 if (!m->ReadInt(iter, &format) ||
37 !m->ReadInt(iter, &channel_layout) ||
38 !m->ReadInt(iter, &sample_rate) ||
39 !m->ReadInt(iter, &bits_per_sample) ||
40 !m->ReadInt(iter, &frames_per_buffer) ||
41 !m->ReadInt(iter, &channels) ||
42 !m->ReadInt(iter, &input_channels))
44 r->Reset(static_cast<AudioParameters::Format>(format),
45 static_cast<ChannelLayout>(channel_layout), channels,
46 input_channels, sample_rate, bits_per_sample, frames_per_buffer);
52 void ParamTraits<AudioParameters>::Log(const AudioParameters& p,
54 l->append(base::StringPrintf("<AudioParameters>"));
57 void ParamTraits<VideoCaptureFormat>::Write(Message* m,
58 const VideoCaptureFormat& p) {
60 m->WriteInt(p.height);
61 m->WriteInt(p.frame_rate);
62 m->WriteInt(static_cast<int>(p.frame_size_type));
65 bool ParamTraits<VideoCaptureFormat>::Read(const Message* m,
67 VideoCaptureFormat* r) {
69 if (!m->ReadInt(iter, &r->width) ||
70 !m->ReadInt(iter, &r->height) ||
71 !m->ReadInt(iter, &r->frame_rate) ||
72 !m->ReadInt(iter, &frame_size_type))
76 static_cast<media::VideoCaptureResolutionType>(
83 void ParamTraits<VideoCaptureFormat>::Log(const VideoCaptureFormat& p,
85 l->append(base::StringPrintf("<VideoCaptureFormat>"));