Chromecast: sets chromium_code=1 in chromecast/media/.
[chromium-blink-merge.git] / chromecast / media / cma / ipc_streamer / decrypt_config_marshaller.cc
blob72eacd6e9ce0474eea21de21226f26b58c43f958
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/decrypt_config_marshaller.h"
7 #include "base/logging.h"
8 #include "chromecast/media/cma/ipc/media_message.h"
9 #include "media/base/decrypt_config.h"
11 namespace chromecast {
12 namespace media {
14 namespace {
15 const size_t kMaxKeyIdSize = 256;
16 const size_t kMaxIvSize = 256;
17 const size_t kMaxSubsampleCount = 1024;
20 // static
21 void DecryptConfigMarshaller::Write(
22 const ::media::DecryptConfig& config, MediaMessage* msg) {
23 CHECK_GT(config.key_id().size(), 0u);
24 CHECK_GT(config.iv().size(), 0u);
25 CHECK_GT(config.subsamples().size(), 0u);
27 CHECK(msg->WritePod(config.key_id().size()));
28 CHECK(msg->WriteBuffer(config.key_id().data(), config.key_id().size()));
29 CHECK(msg->WritePod(config.iv().size()));
30 CHECK(msg->WriteBuffer(config.iv().data(), config.iv().size()));
31 CHECK(msg->WritePod(config.subsamples().size()));
32 for (size_t k = 0; k < config.subsamples().size(); k++) {
33 CHECK(msg->WritePod(config.subsamples()[k].clear_bytes));
34 CHECK(msg->WritePod(config.subsamples()[k].cypher_bytes));
38 // static
39 scoped_ptr< ::media::DecryptConfig> DecryptConfigMarshaller::Read(
40 MediaMessage* msg) {
41 size_t key_id_size = 0;
42 CHECK(msg->ReadPod(&key_id_size));
43 CHECK_GT(key_id_size, 0u);
44 CHECK_LT(key_id_size, kMaxKeyIdSize);
45 scoped_ptr<char[]> key_id(new char[key_id_size]);
46 CHECK(msg->ReadBuffer(key_id.get(), key_id_size));
48 size_t iv_size = 0;
49 CHECK(msg->ReadPod(&iv_size));
50 CHECK_GT(iv_size, 0u);
51 CHECK_LT(iv_size, kMaxIvSize);
52 scoped_ptr<char[]> iv(new char[iv_size]);
53 CHECK(msg->ReadBuffer(iv.get(), iv_size));
55 size_t subsample_count = 0;
56 CHECK(msg->ReadPod(&subsample_count));
57 CHECK_GT(subsample_count, 0u);
58 CHECK_LT(subsample_count, kMaxSubsampleCount);
59 std::vector< ::media::SubsampleEntry> subsamples(subsample_count);
60 for (size_t k = 0; k < subsample_count; k++) {
61 subsamples[k].clear_bytes = 0;
62 subsamples[k].cypher_bytes = 0;
63 CHECK(msg->ReadPod(&subsamples[k].clear_bytes));
64 CHECK(msg->ReadPod(&subsamples[k].cypher_bytes));
67 return scoped_ptr< ::media::DecryptConfig>(
68 new ::media::DecryptConfig(
69 std::string(key_id.get(), key_id_size),
70 std::string(iv.get(), iv_size),
71 subsamples));
74 } // namespace media
75 } // namespace chromecast