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
{
16 const size_t kMaxExtraDataSize
= 16 * 1024;
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()));
33 ::media::AudioDecoderConfig
AudioDecoderConfigMarshaller::Read(
35 ::media::AudioCodec codec
;
36 ::media::SampleFormat sample_format
;
37 ::media::ChannelLayout channel_layout
;
38 int samples_per_second
;
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(
64 channel_layout
, samples_per_second
,
65 extra_data
.get(), extra_data_size
,
70 } // namespace chromecast