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/base/decrypt_context_impl.h"
6 
7 #include <memory>
8 #include <vector>
9 
10 #include "base/bind.h"
11 #include "base/check.h"
12 #include "chromecast/public/media/cast_decoder_buffer.h"
13 
14 namespace chromecast {
15 namespace media {
16 namespace {
BufferDecryptCB(bool * called,bool * ret,bool success)17 void BufferDecryptCB(bool* called, bool* ret, bool success) {
18   DCHECK(called);
19   DCHECK(ret);
20   *called = true;
21   *ret = success;
22 }
23 }
24 
DecryptContextImpl(CastKeySystem key_system)25 DecryptContextImpl::DecryptContextImpl(CastKeySystem key_system)
26     : key_system_(key_system) {}
27 
~DecryptContextImpl()28 DecryptContextImpl::~DecryptContextImpl() {}
29 
GetKeySystem()30 CastKeySystem DecryptContextImpl::GetKeySystem() {
31   return key_system_;
32 }
33 
Decrypt(CastDecoderBuffer * buffer,uint8_t * opaque_handle,size_t data_offset)34 bool DecryptContextImpl::Decrypt(CastDecoderBuffer* buffer,
35                                  uint8_t* opaque_handle,
36                                  size_t data_offset) {
37   bool called = false;
38   bool success = false;
39   DecryptAsync(buffer, opaque_handle, data_offset, false /* clear_output */,
40                base::BindOnce(&BufferDecryptCB, &called, &success));
41   CHECK(called) << "Sync Decrypt isn't supported";
42 
43   return success;
44 }
45 
DecryptAsync(CastDecoderBuffer * buffer,uint8_t * output_or_handle,size_t data_offset,bool clear_output,DecryptCB decrypt_cb)46 void DecryptContextImpl::DecryptAsync(CastDecoderBuffer* buffer,
47                                       uint8_t* output_or_handle,
48                                       size_t data_offset,
49                                       bool clear_output,
50                                       DecryptCB decrypt_cb) {
51   std::move(decrypt_cb).Run(false);
52 }
53 
GetOutputType() const54 DecryptContextImpl::OutputType DecryptContextImpl::GetOutputType() const {
55   return OutputType::kSecure;
56 }
57 
58 }  // namespace media
59 }  // namespace chromecast
60