ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chromecast / media / cma / ipc_streamer / audio_decoder_config_marshaller.cc
blobd595bdaac3de361915c3a1dc1554605dde61c2ca
1 // Copyright 2014 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 "chromecast/media/cma/ipc_streamer/audio_decoder_config_marshaller.h"
7 #include "base/basictypes.h"
8 #include "base/logging.h"
9 #include "chromecast/media/cma/ipc/media_message.h"
10 #include "media/base/audio_decoder_config.h"
12 namespace chromecast {
13 namespace media {
15 namespace {
16 const size_t kMaxExtraDataSize = 16 * 1024;
19 // static
20 void AudioDecoderConfigMarshaller::Write(
21 const ::media::AudioDecoderConfig& config, MediaMessage* msg) {
22 CHECK(msg->WritePod(config.codec()));
23 CHECK(msg->WritePod(config.channel_layout()));
24 CHECK(msg->WritePod(config.samples_per_second()));
25 CHECK(msg->WritePod(config.sample_format()));
26 CHECK(msg->WritePod(config.is_encrypted()));
27 CHECK(msg->WritePod(config.extra_data_size()));
28 if (config.extra_data_size() > 0)
29 CHECK(msg->WriteBuffer(config.extra_data(), config.extra_data_size()));
32 // static
33 ::media::AudioDecoderConfig AudioDecoderConfigMarshaller::Read(
34 MediaMessage* msg) {
35 ::media::AudioCodec codec;
36 ::media::SampleFormat sample_format;
37 ::media::ChannelLayout channel_layout;
38 int samples_per_second;
39 bool is_encrypted;
40 size_t extra_data_size;
41 scoped_ptr<uint8[]> extra_data;
43 CHECK(msg->ReadPod(&codec));
44 CHECK(msg->ReadPod(&channel_layout));
45 CHECK(msg->ReadPod(&samples_per_second));
46 CHECK(msg->ReadPod(&sample_format));
47 CHECK(msg->ReadPod(&is_encrypted));
48 CHECK(msg->ReadPod(&extra_data_size));
50 CHECK_GE(codec, ::media::kUnknownAudioCodec);
51 CHECK_LE(codec, ::media::kAudioCodecMax);
52 CHECK_GE(channel_layout, ::media::CHANNEL_LAYOUT_NONE);
53 CHECK_LE(channel_layout, ::media::CHANNEL_LAYOUT_MAX);
54 CHECK_GE(sample_format, ::media::kUnknownSampleFormat);
55 CHECK_LE(sample_format, ::media::kSampleFormatMax);
56 CHECK_LT(extra_data_size, kMaxExtraDataSize);
57 if (extra_data_size > 0) {
58 extra_data.reset(new uint8[extra_data_size]);
59 CHECK(msg->ReadBuffer(extra_data.get(), extra_data_size));
62 return ::media::AudioDecoderConfig(
63 codec, sample_format,
64 channel_layout, samples_per_second,
65 extra_data.get(), extra_data_size,
66 is_encrypted);
69 } // namespace media
70 } // namespace chromecast