| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef MEDIA_MOJO_SERVICES_MOJO_DECRYPTOR_SERVICE_H_ | 5 #ifndef MEDIA_MOJO_SERVICES_MOJO_DECRYPTOR_SERVICE_H_ |
| 6 #define MEDIA_MOJO_SERVICES_MOJO_DECRYPTOR_SERVICE_H_ | 6 #define MEDIA_MOJO_SERVICES_MOJO_DECRYPTOR_SERVICE_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "media/base/decryptor.h" | 11 #include "media/base/decryptor.h" |
| 12 #include "media/mojo/interfaces/decryptor.mojom.h" | 12 #include "media/mojo/interfaces/decryptor.mojom.h" |
| 13 #include "mojo/public/cpp/bindings/binding.h" | 13 #include "mojo/public/cpp/bindings/binding.h" |
| 14 #include "mojo/public/cpp/bindings/callback.h" | 14 #include "mojo/public/cpp/bindings/callback.h" |
| 15 #include "mojo/public/cpp/system/data_pipe.h" |
| 15 | 16 |
| 16 namespace media { | 17 namespace media { |
| 17 | 18 |
| 18 class DecoderBuffer; | 19 class DecoderBuffer; |
| 19 class MediaKeys; | 20 class MediaKeys; |
| 20 | 21 |
| 21 // A interfaces::Decryptor implementation. This object is owned by the creator, | 22 // A interfaces::Decryptor implementation. This object is owned by the creator, |
| 22 // and uses a weak binding across the mojo interface. | 23 // and uses a weak binding across the mojo interface. |
| 23 class MojoDecryptorService : public interfaces::Decryptor { | 24 class MojoDecryptorService : public interfaces::Decryptor { |
| 24 public: | 25 public: |
| 25 // Constructs a MojoDecryptorService and binds it to the |request|. Keeps a | 26 // Constructs a MojoDecryptorService and binds it to the |request|. Keeps a |
| 26 // copy of |cdm| to prevent it from being deleted as long as it is needed. | 27 // copy of |cdm| to prevent it from being deleted as long as it is needed. |
| 27 // |error_handler| will be called if a connection error occurs. | 28 // |error_handler| will be called if a connection error occurs. |
| 28 MojoDecryptorService(const scoped_refptr<MediaKeys>& cdm, | 29 MojoDecryptorService(const scoped_refptr<MediaKeys>& cdm, |
| 29 mojo::InterfaceRequest<interfaces::Decryptor> request, | 30 mojo::InterfaceRequest<interfaces::Decryptor> request, |
| 30 const mojo::Closure& error_handler); | 31 const mojo::Closure& error_handler); |
| 31 | 32 |
| 32 ~MojoDecryptorService() final; | 33 ~MojoDecryptorService() final; |
| 33 | 34 |
| 34 // interfaces::Decryptor implementation. | 35 // interfaces::Decryptor implementation. |
| 36 void Initialize(mojo::ScopedDataPipeConsumerHandle receive_pipe, |
| 37 mojo::ScopedDataPipeProducerHandle transmit_pipe) final; |
| 35 void Decrypt(interfaces::DemuxerStream::Type stream_type, | 38 void Decrypt(interfaces::DemuxerStream::Type stream_type, |
| 36 interfaces::DecoderBufferPtr encrypted, | 39 interfaces::DecoderBufferPtr encrypted, |
| 37 const DecryptCallback& callback) final; | 40 const DecryptCallback& callback) final; |
| 38 void CancelDecrypt(interfaces::DemuxerStream::Type stream_type) final; | 41 void CancelDecrypt(interfaces::DemuxerStream::Type stream_type) final; |
| 39 void InitializeAudioDecoder( | 42 void InitializeAudioDecoder( |
| 40 interfaces::AudioDecoderConfigPtr config, | 43 interfaces::AudioDecoderConfigPtr config, |
| 41 const InitializeAudioDecoderCallback& callback) final; | 44 const InitializeAudioDecoderCallback& callback) final; |
| 42 void InitializeVideoDecoder( | 45 void InitializeVideoDecoder( |
| 43 interfaces::VideoDecoderConfigPtr config, | 46 interfaces::VideoDecoderConfigPtr config, |
| 44 const InitializeVideoDecoderCallback& callback) final; | 47 const InitializeVideoDecoderCallback& callback) final; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 64 bool success); | 67 bool success); |
| 65 | 68 |
| 66 // Callbacks executed when DecryptAndDecode are done. | 69 // Callbacks executed when DecryptAndDecode are done. |
| 67 void OnAudioDecoded(const DecryptAndDecodeAudioCallback& callback, | 70 void OnAudioDecoded(const DecryptAndDecodeAudioCallback& callback, |
| 68 media::Decryptor::Status status, | 71 media::Decryptor::Status status, |
| 69 const media::Decryptor::AudioFrames& frames); | 72 const media::Decryptor::AudioFrames& frames); |
| 70 void OnVideoDecoded(const DecryptAndDecodeVideoCallback& callback, | 73 void OnVideoDecoded(const DecryptAndDecodeVideoCallback& callback, |
| 71 media::Decryptor::Status status, | 74 media::Decryptor::Status status, |
| 72 const scoped_refptr<VideoFrame>& frame); | 75 const scoped_refptr<VideoFrame>& frame); |
| 73 | 76 |
| 77 // Helper functions to write and read a DecoderBuffer. |
| 78 interfaces::DecoderBufferPtr TransferDecoderBuffer( |
| 79 const scoped_refptr<DecoderBuffer>& buffer); |
| 80 scoped_refptr<DecoderBuffer> ReadDecoderBuffer( |
| 81 interfaces::DecoderBufferPtr buffer); |
| 82 |
| 74 // A weak binding is used to connect to the MojoDecryptor. | 83 // A weak binding is used to connect to the MojoDecryptor. |
| 75 mojo::Binding<interfaces::Decryptor> binding_; | 84 mojo::Binding<interfaces::Decryptor> binding_; |
| 76 | 85 |
| 86 // DataPipes for serializing the data section of DecoderBuffer into/from. |
| 87 mojo::ScopedDataPipeProducerHandle producer_handle_; |
| 88 mojo::ScopedDataPipeConsumerHandle consumer_handle_; |
| 89 |
| 77 // Keep ownership of |cdm_| while it is being used. |decryptor_| is the actual | 90 // Keep ownership of |cdm_| while it is being used. |decryptor_| is the actual |
| 78 // Decryptor referenced by |cdm_|. | 91 // Decryptor referenced by |cdm_|. |
| 79 scoped_refptr<MediaKeys> cdm_; | 92 scoped_refptr<MediaKeys> cdm_; |
| 80 media::Decryptor* decryptor_; | 93 media::Decryptor* decryptor_; |
| 81 | 94 |
| 82 base::WeakPtr<MojoDecryptorService> weak_this_; | 95 base::WeakPtr<MojoDecryptorService> weak_this_; |
| 83 base::WeakPtrFactory<MojoDecryptorService> weak_factory_; | 96 base::WeakPtrFactory<MojoDecryptorService> weak_factory_; |
| 84 | 97 |
| 85 DISALLOW_COPY_AND_ASSIGN(MojoDecryptorService); | 98 DISALLOW_COPY_AND_ASSIGN(MojoDecryptorService); |
| 86 }; | 99 }; |
| 87 | 100 |
| 88 } // namespace media | 101 } // namespace media |
| 89 | 102 |
| 90 #endif // MEDIA_MOJO_SERVICES_MOJO_DECRYPTOR_SERVICE_H_ | 103 #endif // MEDIA_MOJO_SERVICES_MOJO_DECRYPTOR_SERVICE_H_ |
| OLD | NEW |