| 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/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "media/base/decryptor.h" | 17 #include "media/base/decryptor.h" |
| 18 #include "media/mojo/interfaces/decryptor.mojom.h" | 18 #include "media/mojo/interfaces/decryptor.mojom.h" |
| 19 #include "mojo/public/cpp/bindings/binding.h" | 19 #include "mojo/public/cpp/bindings/binding.h" |
| 20 #include "mojo/public/cpp/system/data_pipe.h" | |
| 21 | 20 |
| 22 namespace media { | 21 namespace media { |
| 23 | 22 |
| 24 class DecoderBuffer; | 23 class DecoderBuffer; |
| 25 class MediaKeys; | 24 class MediaKeys; |
| 25 class MojoDecoderBufferReader; |
| 26 class MojoDecoderBufferWriter; |
| 26 | 27 |
| 27 // A mojom::Decryptor implementation. This object is owned by the creator, | 28 // A mojom::Decryptor implementation. This object is owned by the creator, |
| 28 // and uses a weak binding across the mojo interface. | 29 // and uses a weak binding across the mojo interface. |
| 29 class MojoDecryptorService : public mojom::Decryptor { | 30 class MojoDecryptorService : public mojom::Decryptor { |
| 30 public: | 31 public: |
| 31 // Constructs a MojoDecryptorService and binds it to the |request|. Keeps a | 32 // 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. | 33 // 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. | 34 // |error_handler| will be called if a connection error occurs. |
| 34 MojoDecryptorService(const scoped_refptr<MediaKeys>& cdm, | 35 MojoDecryptorService(const scoped_refptr<MediaKeys>& cdm, |
| 35 mojo::InterfaceRequest<mojom::Decryptor> request, | 36 mojo::InterfaceRequest<mojom::Decryptor> request, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 bool success); | 75 bool success); |
| 75 | 76 |
| 76 // Callbacks executed when DecryptAndDecode are done. | 77 // Callbacks executed when DecryptAndDecode are done. |
| 77 void OnAudioDecoded(const DecryptAndDecodeAudioCallback& callback, | 78 void OnAudioDecoded(const DecryptAndDecodeAudioCallback& callback, |
| 78 media::Decryptor::Status status, | 79 media::Decryptor::Status status, |
| 79 const media::Decryptor::AudioFrames& frames); | 80 const media::Decryptor::AudioFrames& frames); |
| 80 void OnVideoDecoded(const DecryptAndDecodeVideoCallback& callback, | 81 void OnVideoDecoded(const DecryptAndDecodeVideoCallback& callback, |
| 81 media::Decryptor::Status status, | 82 media::Decryptor::Status status, |
| 82 const scoped_refptr<VideoFrame>& frame); | 83 const scoped_refptr<VideoFrame>& frame); |
| 83 | 84 |
| 84 // Helper functions to write and read a DecoderBuffer. | |
| 85 mojom::DecoderBufferPtr TransferDecoderBuffer( | |
| 86 const scoped_refptr<DecoderBuffer>& buffer); | |
| 87 scoped_refptr<DecoderBuffer> ReadDecoderBuffer( | |
| 88 mojom::DecoderBufferPtr buffer); | |
| 89 | |
| 90 // A weak binding is used to connect to the MojoDecryptor. | 85 // A weak binding is used to connect to the MojoDecryptor. |
| 91 mojo::Binding<mojom::Decryptor> binding_; | 86 mojo::Binding<mojom::Decryptor> binding_; |
| 92 | 87 |
| 93 // DataPipes for serializing the data section of DecoderBuffer into/from. | 88 // Helper class to send decrypted DecoderBuffer to the client. |
| 94 mojo::ScopedDataPipeProducerHandle producer_handle_; | 89 std::unique_ptr<MojoDecoderBufferWriter> mojo_decoder_buffer_writer_; |
| 95 mojo::ScopedDataPipeConsumerHandle consumer_handle_; | 90 |
| 91 // Helper class to receive encrypted DecoderBuffer from the client. |
| 92 std::unique_ptr<MojoDecoderBufferReader> mojo_decoder_buffer_reader_; |
| 96 | 93 |
| 97 // Keep ownership of |cdm_| while it is being used. |decryptor_| is the actual | 94 // Keep ownership of |cdm_| while it is being used. |decryptor_| is the actual |
| 98 // Decryptor referenced by |cdm_|. | 95 // Decryptor referenced by |cdm_|. |
| 99 scoped_refptr<MediaKeys> cdm_; | 96 scoped_refptr<MediaKeys> cdm_; |
| 100 media::Decryptor* decryptor_; | 97 media::Decryptor* decryptor_; |
| 101 | 98 |
| 102 // Keep a reference to VideoFrames until ReleaseSharedBuffer() is called | 99 // Keep a reference to VideoFrames until ReleaseSharedBuffer() is called |
| 103 // to release it. | 100 // to release it. |
| 104 std::unordered_map<MojoHandle, scoped_refptr<VideoFrame>> | 101 std::unordered_map<MojoHandle, scoped_refptr<VideoFrame>> |
| 105 in_use_video_frames_; | 102 in_use_video_frames_; |
| 106 | 103 |
| 107 base::WeakPtr<MojoDecryptorService> weak_this_; | 104 base::WeakPtr<MojoDecryptorService> weak_this_; |
| 108 base::WeakPtrFactory<MojoDecryptorService> weak_factory_; | 105 base::WeakPtrFactory<MojoDecryptorService> weak_factory_; |
| 109 | 106 |
| 110 DISALLOW_COPY_AND_ASSIGN(MojoDecryptorService); | 107 DISALLOW_COPY_AND_ASSIGN(MojoDecryptorService); |
| 111 }; | 108 }; |
| 112 | 109 |
| 113 } // namespace media | 110 } // namespace media |
| 114 | 111 |
| 115 #endif // MEDIA_MOJO_SERVICES_MOJO_DECRYPTOR_SERVICE_H_ | 112 #endif // MEDIA_MOJO_SERVICES_MOJO_DECRYPTOR_SERVICE_H_ |
| OLD | NEW |