1 // Copyright 2019 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 "media/fuchsia/cdm/fuchsia_decryptor.h"
6 
7 #include "base/check.h"
8 #include "base/fuchsia/fuchsia_logging.h"
9 #include "base/location.h"
10 #include "base/notreached.h"
11 #include "base/threading/thread_task_runner_handle.h"
12 #include "media/base/decoder_buffer.h"
13 #include "media/base/video_frame.h"
14 #include "media/fuchsia/cdm/fuchsia_cdm_context.h"
15 #include "media/fuchsia/cdm/fuchsia_stream_decryptor.h"
16 
17 namespace media {
18 
FuchsiaDecryptor(FuchsiaCdmContext * cdm_context)19 FuchsiaDecryptor::FuchsiaDecryptor(FuchsiaCdmContext* cdm_context)
20     : cdm_context_(cdm_context) {
21   DCHECK(cdm_context_);
22 }
23 
~FuchsiaDecryptor()24 FuchsiaDecryptor::~FuchsiaDecryptor() {
25   if (audio_decryptor_) {
26     audio_decryptor_task_runner_->DeleteSoon(FROM_HERE,
27                                              std::move(audio_decryptor_));
28   }
29 }
30 
Decrypt(StreamType stream_type,scoped_refptr<DecoderBuffer> encrypted,DecryptCB decrypt_cb)31 void FuchsiaDecryptor::Decrypt(StreamType stream_type,
32                                scoped_refptr<DecoderBuffer> encrypted,
33                                DecryptCB decrypt_cb) {
34   if (stream_type != StreamType::kAudio) {
35     std::move(decrypt_cb).Run(Status::kError, nullptr);
36     return;
37   }
38 
39   if (!audio_decryptor_) {
40     audio_decryptor_task_runner_ = base::ThreadTaskRunnerHandle::Get();
41     audio_decryptor_ = cdm_context_->CreateAudioDecryptor();
42   }
43 
44   audio_decryptor_->Decrypt(std::move(encrypted), std::move(decrypt_cb));
45 }
46 
CancelDecrypt(StreamType stream_type)47 void FuchsiaDecryptor::CancelDecrypt(StreamType stream_type) {
48   if (stream_type == StreamType::kAudio && audio_decryptor_) {
49     audio_decryptor_->CancelDecrypt();
50   }
51 }
52 
InitializeAudioDecoder(const AudioDecoderConfig & config,DecoderInitCB init_cb)53 void FuchsiaDecryptor::InitializeAudioDecoder(const AudioDecoderConfig& config,
54                                               DecoderInitCB init_cb) {
55   // Only decryption is supported.
56   std::move(init_cb).Run(false);
57 }
58 
InitializeVideoDecoder(const VideoDecoderConfig & config,DecoderInitCB init_cb)59 void FuchsiaDecryptor::InitializeVideoDecoder(const VideoDecoderConfig& config,
60                                               DecoderInitCB init_cb) {
61   // Only decryption is supported.
62   std::move(init_cb).Run(false);
63 }
64 
DecryptAndDecodeAudio(scoped_refptr<DecoderBuffer> encrypted,const AudioDecodeCB & audio_decode_cb)65 void FuchsiaDecryptor::DecryptAndDecodeAudio(
66     scoped_refptr<DecoderBuffer> encrypted,
67     const AudioDecodeCB& audio_decode_cb) {
68   NOTREACHED();
69   audio_decode_cb.Run(Status::kError, AudioFrames());
70 }
71 
DecryptAndDecodeVideo(scoped_refptr<DecoderBuffer> encrypted,const VideoDecodeCB & video_decode_cb)72 void FuchsiaDecryptor::DecryptAndDecodeVideo(
73     scoped_refptr<DecoderBuffer> encrypted,
74     const VideoDecodeCB& video_decode_cb) {
75   NOTREACHED();
76   video_decode_cb.Run(Status::kError, nullptr);
77 }
78 
ResetDecoder(StreamType stream_type)79 void FuchsiaDecryptor::ResetDecoder(StreamType stream_type) {
80   NOTREACHED();
81 }
82 
DeinitializeDecoder(StreamType stream_type)83 void FuchsiaDecryptor::DeinitializeDecoder(StreamType stream_type) {
84   NOTREACHED();
85 }
86 
CanAlwaysDecrypt()87 bool FuchsiaDecryptor::CanAlwaysDecrypt() {
88   return false;
89 }
90 
91 }  // namespace media
92