| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <unordered_map> | 11 #include <unordered_map> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "media/base/decryptor.h" | 16 #include "media/base/decryptor.h" |
| 17 #include "media/mojo/interfaces/decryptor.mojom.h" | 17 #include "media/mojo/interfaces/decryptor.mojom.h" |
| 18 #include "mojo/public/cpp/bindings/binding.h" | 18 #include "mojo/public/cpp/bindings/binding.h" |
| 19 #include "mojo/public/cpp/bindings/callback.h" | 19 #include "mojo/public/cpp/bindings/callback.h" |
| 20 #include "mojo/public/cpp/system/data_pipe.h" | 20 #include "mojo/public/cpp/system/data_pipe.h" |
| 21 | 21 |
| 22 namespace media { | 22 namespace media { |
| 23 | 23 |
| 24 class DecoderBuffer; | 24 class DecoderBuffer; |
| 25 class MediaKeys; | 25 class MediaKeys; |
| 26 | 26 |
| 27 // A interfaces::Decryptor implementation. This object is owned by the creator, | 27 // A mojom::Decryptor implementation. This object is owned by the creator, |
| 28 // and uses a weak binding across the mojo interface. | 28 // and uses a weak binding across the mojo interface. |
| 29 class MojoDecryptorService : public interfaces::Decryptor { | 29 class MojoDecryptorService : public mojom::Decryptor { |
| 30 public: | 30 public: |
| 31 // Constructs a MojoDecryptorService and binds it to the |request|. Keeps a | 31 // Constructs a MojoDecryptorService and binds it to the |request|. Keeps a |
| 32 // copy of |cdm| to prevent it from being deleted as long as it is needed. | 32 // copy of |cdm| to prevent it from being deleted as long as it is needed. |
| 33 // |error_handler| will be called if a connection error occurs. | 33 // |error_handler| will be called if a connection error occurs. |
| 34 MojoDecryptorService(const scoped_refptr<MediaKeys>& cdm, | 34 MojoDecryptorService(const scoped_refptr<MediaKeys>& cdm, |
| 35 mojo::InterfaceRequest<interfaces::Decryptor> request, | 35 mojo::InterfaceRequest<mojom::Decryptor> request, |
| 36 const mojo::Closure& error_handler); | 36 const mojo::Closure& error_handler); |
| 37 | 37 |
| 38 ~MojoDecryptorService() final; | 38 ~MojoDecryptorService() final; |
| 39 | 39 |
| 40 // interfaces::Decryptor implementation. | 40 // mojom::Decryptor implementation. |
| 41 void Initialize(mojo::ScopedDataPipeConsumerHandle receive_pipe, | 41 void Initialize(mojo::ScopedDataPipeConsumerHandle receive_pipe, |
| 42 mojo::ScopedDataPipeProducerHandle transmit_pipe) final; | 42 mojo::ScopedDataPipeProducerHandle transmit_pipe) final; |
| 43 void Decrypt(interfaces::DemuxerStream::Type stream_type, | 43 void Decrypt(mojom::DemuxerStream::Type stream_type, |
| 44 interfaces::DecoderBufferPtr encrypted, | 44 mojom::DecoderBufferPtr encrypted, |
| 45 const DecryptCallback& callback) final; | 45 const DecryptCallback& callback) final; |
| 46 void CancelDecrypt(interfaces::DemuxerStream::Type stream_type) final; | 46 void CancelDecrypt(mojom::DemuxerStream::Type stream_type) final; |
| 47 void InitializeAudioDecoder( | 47 void InitializeAudioDecoder( |
| 48 interfaces::AudioDecoderConfigPtr config, | 48 mojom::AudioDecoderConfigPtr config, |
| 49 const InitializeAudioDecoderCallback& callback) final; | 49 const InitializeAudioDecoderCallback& callback) final; |
| 50 void InitializeVideoDecoder( | 50 void InitializeVideoDecoder( |
| 51 interfaces::VideoDecoderConfigPtr config, | 51 mojom::VideoDecoderConfigPtr config, |
| 52 const InitializeVideoDecoderCallback& callback) final; | 52 const InitializeVideoDecoderCallback& callback) final; |
| 53 void DecryptAndDecodeAudio( | 53 void DecryptAndDecodeAudio( |
| 54 interfaces::DecoderBufferPtr encrypted, | 54 mojom::DecoderBufferPtr encrypted, |
| 55 const DecryptAndDecodeAudioCallback& callback) final; | 55 const DecryptAndDecodeAudioCallback& callback) final; |
| 56 void DecryptAndDecodeVideo( | 56 void DecryptAndDecodeVideo( |
| 57 interfaces::DecoderBufferPtr encrypted, | 57 mojom::DecoderBufferPtr encrypted, |
| 58 const DecryptAndDecodeVideoCallback& callback) final; | 58 const DecryptAndDecodeVideoCallback& callback) final; |
| 59 void ResetDecoder(interfaces::DemuxerStream::Type stream_type) final; | 59 void ResetDecoder(mojom::DemuxerStream::Type stream_type) final; |
| 60 void DeinitializeDecoder(interfaces::DemuxerStream::Type stream_type) final; | 60 void DeinitializeDecoder(mojom::DemuxerStream::Type stream_type) final; |
| 61 void ReleaseSharedBuffer(mojo::ScopedSharedBufferHandle buffer, | 61 void ReleaseSharedBuffer(mojo::ScopedSharedBufferHandle buffer, |
| 62 uint64_t buffer_size) final; | 62 uint64_t buffer_size) final; |
| 63 | 63 |
| 64 private: | 64 private: |
| 65 // Callback executed once Decrypt() is done. | 65 // Callback executed once Decrypt() is done. |
| 66 void OnDecryptDone(const DecryptCallback& callback, | 66 void OnDecryptDone(const DecryptCallback& callback, |
| 67 media::Decryptor::Status status, | 67 media::Decryptor::Status status, |
| 68 const scoped_refptr<DecoderBuffer>& buffer); | 68 const scoped_refptr<DecoderBuffer>& buffer); |
| 69 | 69 |
| 70 // Callbacks executed once decoder initialized. | 70 // Callbacks executed once decoder initialized. |
| 71 void OnAudioDecoderInitialized(const InitializeAudioDecoderCallback& callback, | 71 void OnAudioDecoderInitialized(const InitializeAudioDecoderCallback& callback, |
| 72 bool success); | 72 bool success); |
| 73 void OnVideoDecoderInitialized(const InitializeVideoDecoderCallback& callback, | 73 void OnVideoDecoderInitialized(const InitializeVideoDecoderCallback& callback, |
| 74 bool success); | 74 bool success); |
| 75 | 75 |
| 76 // Callbacks executed when DecryptAndDecode are done. | 76 // Callbacks executed when DecryptAndDecode are done. |
| 77 void OnAudioDecoded(const DecryptAndDecodeAudioCallback& callback, | 77 void OnAudioDecoded(const DecryptAndDecodeAudioCallback& callback, |
| 78 media::Decryptor::Status status, | 78 media::Decryptor::Status status, |
| 79 const media::Decryptor::AudioFrames& frames); | 79 const media::Decryptor::AudioFrames& frames); |
| 80 void OnVideoDecoded(const DecryptAndDecodeVideoCallback& callback, | 80 void OnVideoDecoded(const DecryptAndDecodeVideoCallback& callback, |
| 81 media::Decryptor::Status status, | 81 media::Decryptor::Status status, |
| 82 const scoped_refptr<VideoFrame>& frame); | 82 const scoped_refptr<VideoFrame>& frame); |
| 83 | 83 |
| 84 // Helper functions to write and read a DecoderBuffer. | 84 // Helper functions to write and read a DecoderBuffer. |
| 85 interfaces::DecoderBufferPtr TransferDecoderBuffer( | 85 mojom::DecoderBufferPtr TransferDecoderBuffer( |
| 86 const scoped_refptr<DecoderBuffer>& buffer); | 86 const scoped_refptr<DecoderBuffer>& buffer); |
| 87 scoped_refptr<DecoderBuffer> ReadDecoderBuffer( | 87 scoped_refptr<DecoderBuffer> ReadDecoderBuffer( |
| 88 interfaces::DecoderBufferPtr buffer); | 88 mojom::DecoderBufferPtr buffer); |
| 89 | 89 |
| 90 // A weak binding is used to connect to the MojoDecryptor. | 90 // A weak binding is used to connect to the MojoDecryptor. |
| 91 mojo::Binding<interfaces::Decryptor> binding_; | 91 mojo::Binding<mojom::Decryptor> binding_; |
| 92 | 92 |
| 93 // DataPipes for serializing the data section of DecoderBuffer into/from. | 93 // DataPipes for serializing the data section of DecoderBuffer into/from. |
| 94 mojo::ScopedDataPipeProducerHandle producer_handle_; | 94 mojo::ScopedDataPipeProducerHandle producer_handle_; |
| 95 mojo::ScopedDataPipeConsumerHandle consumer_handle_; | 95 mojo::ScopedDataPipeConsumerHandle consumer_handle_; |
| 96 | 96 |
| 97 // Keep ownership of |cdm_| while it is being used. |decryptor_| is the actual | 97 // Keep ownership of |cdm_| while it is being used. |decryptor_| is the actual |
| 98 // Decryptor referenced by |cdm_|. | 98 // Decryptor referenced by |cdm_|. |
| 99 scoped_refptr<MediaKeys> cdm_; | 99 scoped_refptr<MediaKeys> cdm_; |
| 100 media::Decryptor* decryptor_; | 100 media::Decryptor* decryptor_; |
| 101 | 101 |
| 102 // Keep a reference to VideoFrames until ReleaseSharedBuffer() is called | 102 // Keep a reference to VideoFrames until ReleaseSharedBuffer() is called |
| 103 // to release it. | 103 // to release it. |
| 104 std::unordered_map<MojoHandle, scoped_refptr<VideoFrame>> | 104 std::unordered_map<MojoHandle, scoped_refptr<VideoFrame>> |
| 105 in_use_video_frames_; | 105 in_use_video_frames_; |
| 106 | 106 |
| 107 base::WeakPtr<MojoDecryptorService> weak_this_; | 107 base::WeakPtr<MojoDecryptorService> weak_this_; |
| 108 base::WeakPtrFactory<MojoDecryptorService> weak_factory_; | 108 base::WeakPtrFactory<MojoDecryptorService> weak_factory_; |
| 109 | 109 |
| 110 DISALLOW_COPY_AND_ASSIGN(MojoDecryptorService); | 110 DISALLOW_COPY_AND_ASSIGN(MojoDecryptorService); |
| 111 }; | 111 }; |
| 112 | 112 |
| 113 } // namespace media | 113 } // namespace media |
| 114 | 114 |
| 115 #endif // MEDIA_MOJO_SERVICES_MOJO_DECRYPTOR_SERVICE_H_ | 115 #endif // MEDIA_MOJO_SERVICES_MOJO_DECRYPTOR_SERVICE_H_ |
| OLD | NEW |