Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(386)

Side by Side Diff: chromecast/media/cma/ipc_streamer/decrypt_config_marshaller.cc

Issue 2300993003: CmaRenderer is dead. Long live MojoRenderer. (Closed)
Patch Set: update OWNERS file Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "chromecast/media/cma/ipc_streamer/decrypt_config_marshaller.h"
6
7 #include <stddef.h>
8
9 #include "base/logging.h"
10 #include "chromecast/media/cma/base/cast_decrypt_config_impl.h"
11 #include "chromecast/media/cma/ipc/media_message.h"
12 #include "chromecast/public/media/cast_decrypt_config.h"
13
14 namespace chromecast {
15 namespace media {
16
17 namespace {
18 const size_t kMaxKeyIdSize = 256;
19 const size_t kMaxIvSize = 256;
20 const size_t kMaxSubsampleCount = 1024;
21 }
22
23 // static
24 void DecryptConfigMarshaller::Write(const CastDecryptConfig& config,
25 MediaMessage* msg) {
26 CHECK_GT(config.key_id().size(), 0u);
27 CHECK_GT(config.iv().size(), 0u);
28 CHECK_GT(config.subsamples().size(), 0u);
29
30 CHECK(msg->WritePod(config.key_id().size()));
31 CHECK(msg->WriteBuffer(config.key_id().data(), config.key_id().size()));
32 CHECK(msg->WritePod(config.iv().size()));
33 CHECK(msg->WriteBuffer(config.iv().data(), config.iv().size()));
34 CHECK(msg->WritePod(config.subsamples().size()));
35 for (size_t k = 0; k < config.subsamples().size(); k++) {
36 CHECK(msg->WritePod(config.subsamples()[k].clear_bytes));
37 CHECK(msg->WritePod(config.subsamples()[k].cypher_bytes));
38 }
39 }
40
41 // static
42 std::unique_ptr<CastDecryptConfig> DecryptConfigMarshaller::Read(
43 MediaMessage* msg) {
44 size_t key_id_size = 0;
45 CHECK(msg->ReadPod(&key_id_size));
46 CHECK_GT(key_id_size, 0u);
47 CHECK_LT(key_id_size, kMaxKeyIdSize);
48 std::unique_ptr<char[]> key_id(new char[key_id_size]);
49 CHECK(msg->ReadBuffer(key_id.get(), key_id_size));
50
51 size_t iv_size = 0;
52 CHECK(msg->ReadPod(&iv_size));
53 CHECK_GT(iv_size, 0u);
54 CHECK_LT(iv_size, kMaxIvSize);
55 std::unique_ptr<char[]> iv(new char[iv_size]);
56 CHECK(msg->ReadBuffer(iv.get(), iv_size));
57
58 size_t subsample_count = 0;
59 CHECK(msg->ReadPod(&subsample_count));
60 CHECK_GT(subsample_count, 0u);
61 CHECK_LT(subsample_count, kMaxSubsampleCount);
62 std::vector<SubsampleEntry> subsamples(subsample_count);
63 for (size_t k = 0; k < subsample_count; k++) {
64 subsamples[k].clear_bytes = 0;
65 subsamples[k].cypher_bytes = 0;
66 CHECK(msg->ReadPod(&subsamples[k].clear_bytes));
67 CHECK(msg->ReadPod(&subsamples[k].cypher_bytes));
68 }
69
70 return std::unique_ptr<CastDecryptConfig>(
71 new CastDecryptConfigImpl(std::string(key_id.get(), key_id_size),
72 std::string(iv.get(), iv_size), subsamples));
73 }
74
75 } // namespace media
76 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698