Process Alt-Svc headers.
[chromium-blink-merge.git] / content / common / media / media_param_traits.cc
blob19c3b87975badff70e7cce7c8eeb4aa5b63b443a
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, channels, sample_rate,
48 bits_per_sample, frames_per_buffer, effects);
49 *r = params;
50 return r->IsValid();
53 void ParamTraits<AudioParameters>::Log(const AudioParameters& p,
54 std::string* l) {
55 l->append(base::StringPrintf("<AudioParameters>"));
58 void ParamTraits<VideoCaptureFormat>::Write(Message* m,
59 const VideoCaptureFormat& p) {
60 WriteParam(m, p.frame_size);
61 WriteParam(m, p.frame_rate);
62 WriteParam(m, p.pixel_format);
63 WriteParam(m, p.pixel_storage);
66 bool ParamTraits<VideoCaptureFormat>::Read(const Message* m,
67 base::PickleIterator* iter,
68 VideoCaptureFormat* r) {
69 if (!ReadParam(m, iter, &r->frame_size) ||
70 !ReadParam(m, iter, &r->frame_rate) ||
71 !ReadParam(m, iter, &r->pixel_format) ||
72 !ReadParam(m, iter, &r->pixel_storage)) {
73 return false;
75 return r->IsValid();
78 void ParamTraits<VideoCaptureFormat>::Log(const VideoCaptureFormat& p,
79 std::string* l) {
80 l->append(base::StringPrintf("<VideoCaptureFormat> %s",
81 media::VideoCaptureFormat::ToString(p).c_str()));