summaryrefslogtreecommitdiffstats
path: root/chromecast/media/cma/ipc_streamer/encryption_scheme_marshaller.cc
blob: a88cfc5ce6ce6418314579cf6f24ce0c7fe15465 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chromecast/media/cma/ipc_streamer/encryption_scheme_marshaller.h"

#include <stdint.h>

#include "base/logging.h"
#include "chromecast/media/cma/ipc/media_message.h"

namespace chromecast {
namespace media {

namespace {

class PatternSpecMarshaller {
 public:
  static void Write(const ::media::EncryptionScheme::Pattern& pattern,
                    MediaMessage* msg) {
    CHECK(msg->WritePod(pattern.encrypt_blocks()));
    CHECK(msg->WritePod(pattern.skip_blocks()));
  }

  static ::media::EncryptionScheme::Pattern Read(MediaMessage* msg) {
    uint32_t encrypt_blocks;
    uint32_t skip_blocks;
    CHECK(msg->ReadPod(&encrypt_blocks));
    CHECK(msg->ReadPod(&skip_blocks));
    return ::media::EncryptionScheme::Pattern(encrypt_blocks, skip_blocks);
  }
};

}  // namespace

// static
void EncryptionSchemeMarshaller::Write(
    const ::media::EncryptionScheme& encryption_scheme,
    MediaMessage* msg) {
  CHECK(msg->WritePod(encryption_scheme.mode()));
  PatternSpecMarshaller::Write(encryption_scheme.pattern(), msg);
}

// static
::media::EncryptionScheme EncryptionSchemeMarshaller::Read(MediaMessage* msg) {
  ::media::EncryptionScheme::CipherMode mode;
  ::media::EncryptionScheme::Pattern pattern;
  CHECK(msg->ReadPod(&mode));
  pattern = PatternSpecMarshaller::Read(msg);
  return ::media::EncryptionScheme(mode, pattern);
}

}  // namespace media
}  // namespace chromecast