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

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

Issue 1257013003: Load CMA backend from shared library (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 4 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chromecast/media/cma/ipc_streamer/decrypt_config_marshaller.h" 5 #include "chromecast/media/cma/ipc_streamer/decrypt_config_marshaller.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chromecast/media/cma/base/cast_decrypt_config_impl.h"
8 #include "chromecast/media/cma/ipc/media_message.h" 9 #include "chromecast/media/cma/ipc/media_message.h"
9 #include "media/base/decrypt_config.h" 10 #include "chromecast/public/media/cast_decrypt_config.h"
10 11
11 namespace chromecast { 12 namespace chromecast {
12 namespace media { 13 namespace media {
13 14
14 namespace { 15 namespace {
15 const size_t kMaxKeyIdSize = 256; 16 const size_t kMaxKeyIdSize = 256;
16 const size_t kMaxIvSize = 256; 17 const size_t kMaxIvSize = 256;
17 const size_t kMaxSubsampleCount = 1024; 18 const size_t kMaxSubsampleCount = 1024;
18 } 19 }
19 20
20 // static 21 // static
21 void DecryptConfigMarshaller::Write( 22 void DecryptConfigMarshaller::Write(const CastDecryptConfig& config,
22 const ::media::DecryptConfig& config, MediaMessage* msg) { 23 MediaMessage* msg) {
23 CHECK_GT(config.key_id().size(), 0u); 24 CHECK_GT(config.key_id().size(), 0u);
24 CHECK_GT(config.iv().size(), 0u); 25 CHECK_GT(config.iv().size(), 0u);
25 CHECK_GT(config.subsamples().size(), 0u); 26 CHECK_GT(config.subsamples().size(), 0u);
26 27
27 CHECK(msg->WritePod(config.key_id().size())); 28 CHECK(msg->WritePod(config.key_id().size()));
28 CHECK(msg->WriteBuffer(config.key_id().data(), config.key_id().size())); 29 CHECK(msg->WriteBuffer(config.key_id().data(), config.key_id().size()));
29 CHECK(msg->WritePod(config.iv().size())); 30 CHECK(msg->WritePod(config.iv().size()));
30 CHECK(msg->WriteBuffer(config.iv().data(), config.iv().size())); 31 CHECK(msg->WriteBuffer(config.iv().data(), config.iv().size()));
31 CHECK(msg->WritePod(config.subsamples().size())); 32 CHECK(msg->WritePod(config.subsamples().size()));
32 for (size_t k = 0; k < config.subsamples().size(); k++) { 33 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].clear_bytes));
34 CHECK(msg->WritePod(config.subsamples()[k].cypher_bytes)); 35 CHECK(msg->WritePod(config.subsamples()[k].cypher_bytes));
35 } 36 }
36 } 37 }
37 38
38 // static 39 // static
39 scoped_ptr< ::media::DecryptConfig> DecryptConfigMarshaller::Read( 40 scoped_ptr<CastDecryptConfig> DecryptConfigMarshaller::Read(MediaMessage* msg) {
40 MediaMessage* msg) {
41 size_t key_id_size = 0; 41 size_t key_id_size = 0;
42 CHECK(msg->ReadPod(&key_id_size)); 42 CHECK(msg->ReadPod(&key_id_size));
43 CHECK_GT(key_id_size, 0u); 43 CHECK_GT(key_id_size, 0u);
44 CHECK_LT(key_id_size, kMaxKeyIdSize); 44 CHECK_LT(key_id_size, kMaxKeyIdSize);
45 scoped_ptr<char[]> key_id(new char[key_id_size]); 45 scoped_ptr<char[]> key_id(new char[key_id_size]);
46 CHECK(msg->ReadBuffer(key_id.get(), key_id_size)); 46 CHECK(msg->ReadBuffer(key_id.get(), key_id_size));
47 47
48 size_t iv_size = 0; 48 size_t iv_size = 0;
49 CHECK(msg->ReadPod(&iv_size)); 49 CHECK(msg->ReadPod(&iv_size));
50 CHECK_GT(iv_size, 0u); 50 CHECK_GT(iv_size, 0u);
51 CHECK_LT(iv_size, kMaxIvSize); 51 CHECK_LT(iv_size, kMaxIvSize);
52 scoped_ptr<char[]> iv(new char[iv_size]); 52 scoped_ptr<char[]> iv(new char[iv_size]);
53 CHECK(msg->ReadBuffer(iv.get(), iv_size)); 53 CHECK(msg->ReadBuffer(iv.get(), iv_size));
54 54
55 size_t subsample_count = 0; 55 size_t subsample_count = 0;
56 CHECK(msg->ReadPod(&subsample_count)); 56 CHECK(msg->ReadPod(&subsample_count));
57 CHECK_GT(subsample_count, 0u); 57 CHECK_GT(subsample_count, 0u);
58 CHECK_LT(subsample_count, kMaxSubsampleCount); 58 CHECK_LT(subsample_count, kMaxSubsampleCount);
59 std::vector< ::media::SubsampleEntry> subsamples(subsample_count); 59 std::vector<SubsampleEntry> subsamples(subsample_count);
60 for (size_t k = 0; k < subsample_count; k++) { 60 for (size_t k = 0; k < subsample_count; k++) {
61 subsamples[k].clear_bytes = 0; 61 subsamples[k].clear_bytes = 0;
62 subsamples[k].cypher_bytes = 0; 62 subsamples[k].cypher_bytes = 0;
63 CHECK(msg->ReadPod(&subsamples[k].clear_bytes)); 63 CHECK(msg->ReadPod(&subsamples[k].clear_bytes));
64 CHECK(msg->ReadPod(&subsamples[k].cypher_bytes)); 64 CHECK(msg->ReadPod(&subsamples[k].cypher_bytes));
65 } 65 }
66 66
67 return scoped_ptr< ::media::DecryptConfig>( 67 return scoped_ptr<CastDecryptConfig>(
68 new ::media::DecryptConfig( 68 new CastDecryptConfigImpl(std::string(key_id.get(), key_id_size),
69 std::string(key_id.get(), key_id_size), 69 std::string(iv.get(), iv_size), subsamples));
70 std::string(iv.get(), iv_size),
71 subsamples));
72 } 70 }
73 71
74 } // namespace media 72 } // namespace media
75 } // namespace chromecast 73 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698