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_H_ | 5 #ifndef MEDIA_MOJO_SERVICES_MOJO_DECRYPTOR_H_ |
6 #define MEDIA_MOJO_SERVICES_MOJO_DECRYPTOR_H_ | 6 #define MEDIA_MOJO_SERVICES_MOJO_DECRYPTOR_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "base/threading/thread_checker.h" | 10 #include "base/threading/thread_checker.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/system/data_pipe.h" | 14 #include "mojo/public/cpp/system/data_pipe.h" |
15 | 15 |
16 namespace media { | 16 namespace media { |
17 | 17 |
18 // A Decryptor implementation based on interfaces::DecryptorPtr. | 18 // A Decryptor implementation based on mojom::DecryptorPtr. |
19 // This class is single threaded. The |remote_decryptor| is connected before | 19 // This class is single threaded. The |remote_decryptor| is connected before |
20 // being passed to MojoDecryptor, but it is bound to the thread MojoDecryptor | 20 // being passed to MojoDecryptor, but it is bound to the thread MojoDecryptor |
21 // lives on the first time it is used in this class. | 21 // lives on the first time it is used in this class. |
22 class MojoDecryptor : public Decryptor { | 22 class MojoDecryptor : public Decryptor { |
23 public: | 23 public: |
24 explicit MojoDecryptor(interfaces::DecryptorPtr remote_decryptor); | 24 explicit MojoDecryptor(mojom::DecryptorPtr remote_decryptor); |
25 ~MojoDecryptor() final; | 25 ~MojoDecryptor() final; |
26 | 26 |
27 // Decryptor implementation. | 27 // Decryptor implementation. |
28 void RegisterNewKeyCB(StreamType stream_type, | 28 void RegisterNewKeyCB(StreamType stream_type, |
29 const NewKeyCB& key_added_cb) final; | 29 const NewKeyCB& key_added_cb) final; |
30 void Decrypt(StreamType stream_type, | 30 void Decrypt(StreamType stream_type, |
31 const scoped_refptr<DecoderBuffer>& encrypted, | 31 const scoped_refptr<DecoderBuffer>& encrypted, |
32 const DecryptCB& decrypt_cb) final; | 32 const DecryptCB& decrypt_cb) final; |
33 void CancelDecrypt(StreamType stream_type) final; | 33 void CancelDecrypt(StreamType stream_type) final; |
34 void InitializeAudioDecoder(const AudioDecoderConfig& config, | 34 void InitializeAudioDecoder(const AudioDecoderConfig& config, |
35 const DecoderInitCB& init_cb) final; | 35 const DecoderInitCB& init_cb) final; |
36 void InitializeVideoDecoder(const VideoDecoderConfig& config, | 36 void InitializeVideoDecoder(const VideoDecoderConfig& config, |
37 const DecoderInitCB& init_cb) final; | 37 const DecoderInitCB& init_cb) final; |
38 void DecryptAndDecodeAudio(const scoped_refptr<DecoderBuffer>& encrypted, | 38 void DecryptAndDecodeAudio(const scoped_refptr<DecoderBuffer>& encrypted, |
39 const AudioDecodeCB& audio_decode_cb) final; | 39 const AudioDecodeCB& audio_decode_cb) final; |
40 void DecryptAndDecodeVideo(const scoped_refptr<DecoderBuffer>& encrypted, | 40 void DecryptAndDecodeVideo(const scoped_refptr<DecoderBuffer>& encrypted, |
41 const VideoDecodeCB& video_decode_cb) final; | 41 const VideoDecodeCB& video_decode_cb) final; |
42 void ResetDecoder(StreamType stream_type) final; | 42 void ResetDecoder(StreamType stream_type) final; |
43 void DeinitializeDecoder(StreamType stream_type) final; | 43 void DeinitializeDecoder(StreamType stream_type) final; |
44 | 44 |
45 // Called when keys have changed and an additional key is available. | 45 // Called when keys have changed and an additional key is available. |
46 void OnKeyAdded(); | 46 void OnKeyAdded(); |
47 | 47 |
48 private: | 48 private: |
49 // Called when a buffer is decrypted. | 49 // Called when a buffer is decrypted. |
50 void OnBufferDecrypted(const DecryptCB& decrypt_cb, | 50 void OnBufferDecrypted(const DecryptCB& decrypt_cb, |
51 interfaces::Decryptor::Status status, | 51 mojom::Decryptor::Status status, |
52 interfaces::DecoderBufferPtr buffer); | 52 mojom::DecoderBufferPtr buffer); |
53 void OnAudioDecoded(const AudioDecodeCB& audio_decode_cb, | 53 void OnAudioDecoded(const AudioDecodeCB& audio_decode_cb, |
54 interfaces::Decryptor::Status status, | 54 mojom::Decryptor::Status status, |
55 mojo::Array<interfaces::AudioBufferPtr> audio_buffers); | 55 mojo::Array<mojom::AudioBufferPtr> audio_buffers); |
56 void OnVideoDecoded(const VideoDecodeCB& video_decode_cb, | 56 void OnVideoDecoded(const VideoDecodeCB& video_decode_cb, |
57 interfaces::Decryptor::Status status, | 57 mojom::Decryptor::Status status, |
58 interfaces::VideoFramePtr video_frame); | 58 mojom::VideoFramePtr video_frame); |
59 | 59 |
60 // Called when done with a VideoFrame in order to reuse the shared memory. | 60 // Called when done with a VideoFrame in order to reuse the shared memory. |
61 void ReleaseSharedBuffer(mojo::ScopedSharedBufferHandle buffer, | 61 void ReleaseSharedBuffer(mojo::ScopedSharedBufferHandle buffer, |
62 size_t buffer_size); | 62 size_t buffer_size); |
63 | 63 |
64 // To pass DecoderBuffers to and from the MojoDecryptorService, 2 data pipes | 64 // To pass DecoderBuffers to and from the MojoDecryptorService, 2 data pipes |
65 // are required (one each way). At initialization both pipes are created, | 65 // are required (one each way). At initialization both pipes are created, |
66 // and then the handles are passed to the MojoDecryptorService. | 66 // and then the handles are passed to the MojoDecryptorService. |
67 void CreateDataPipes(); | 67 void CreateDataPipes(); |
68 | 68 |
69 // Helper functions to write and read a DecoderBuffer. | 69 // Helper functions to write and read a DecoderBuffer. |
70 interfaces::DecoderBufferPtr TransferDecoderBuffer( | 70 mojom::DecoderBufferPtr TransferDecoderBuffer( |
71 const scoped_refptr<DecoderBuffer>& buffer); | 71 const scoped_refptr<DecoderBuffer>& buffer); |
72 scoped_refptr<DecoderBuffer> ReadDecoderBuffer( | 72 scoped_refptr<DecoderBuffer> ReadDecoderBuffer( |
73 interfaces::DecoderBufferPtr buffer); | 73 mojom::DecoderBufferPtr buffer); |
74 | 74 |
75 base::ThreadChecker thread_checker_; | 75 base::ThreadChecker thread_checker_; |
76 | 76 |
77 interfaces::DecryptorPtr remote_decryptor_; | 77 mojom::DecryptorPtr remote_decryptor_; |
78 | 78 |
79 // DataPipes for serializing the data section of DecoderBuffer into/from. | 79 // DataPipes for serializing the data section of DecoderBuffer into/from. |
80 mojo::ScopedDataPipeProducerHandle producer_handle_; | 80 mojo::ScopedDataPipeProducerHandle producer_handle_; |
81 mojo::ScopedDataPipeConsumerHandle consumer_handle_; | 81 mojo::ScopedDataPipeConsumerHandle consumer_handle_; |
82 | 82 |
83 NewKeyCB new_audio_key_cb_; | 83 NewKeyCB new_audio_key_cb_; |
84 NewKeyCB new_video_key_cb_; | 84 NewKeyCB new_video_key_cb_; |
85 | 85 |
86 base::WeakPtrFactory<MojoDecryptor> weak_factory_; | 86 base::WeakPtrFactory<MojoDecryptor> weak_factory_; |
87 | 87 |
88 DISALLOW_COPY_AND_ASSIGN(MojoDecryptor); | 88 DISALLOW_COPY_AND_ASSIGN(MojoDecryptor); |
89 }; | 89 }; |
90 | 90 |
91 } // namespace media | 91 } // namespace media |
92 | 92 |
93 #endif // MEDIA_MOJO_SERVICES_MOJO_DECRYPTOR_H_ | 93 #endif // MEDIA_MOJO_SERVICES_MOJO_DECRYPTOR_H_ |
OLD | NEW |