OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_AUDIO_DECODER_SERVICE_H_ | 5 #ifndef MEDIA_MOJO_SERVICES_MOJO_AUDIO_DECODER_SERVICE_H_ |
6 #define MEDIA_MOJO_SERVICES_MOJO_AUDIO_DECODER_SERVICE_H_ | 6 #define MEDIA_MOJO_SERVICES_MOJO_AUDIO_DECODER_SERVICE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "media/base/audio_decoder.h" | 14 #include "media/base/audio_decoder.h" |
15 #include "media/mojo/interfaces/audio_decoder.mojom.h" | 15 #include "media/mojo/interfaces/audio_decoder.mojom.h" |
16 #include "mojo/public/cpp/bindings/strong_binding.h" | 16 #include "mojo/public/cpp/bindings/strong_binding.h" |
17 #include "mojo/public/cpp/system/data_pipe.h" | 17 #include "mojo/public/cpp/system/data_pipe.h" |
18 | 18 |
19 namespace media { | 19 namespace media { |
20 | 20 |
21 class MediaKeys; | 21 class MediaKeys; |
22 class MojoCdmServiceContext; | 22 class MojoCdmServiceContext; |
23 | 23 |
24 class MojoAudioDecoderService : public interfaces::AudioDecoder { | 24 class MojoAudioDecoderService : public mojom::AudioDecoder { |
25 public: | 25 public: |
26 MojoAudioDecoderService( | 26 MojoAudioDecoderService( |
27 base::WeakPtr<MojoCdmServiceContext> mojo_cdm_service_context, | 27 base::WeakPtr<MojoCdmServiceContext> mojo_cdm_service_context, |
28 std::unique_ptr<media::AudioDecoder> decoder, | 28 std::unique_ptr<media::AudioDecoder> decoder, |
29 mojo::InterfaceRequest<interfaces::AudioDecoder> request); | 29 mojo::InterfaceRequest<mojom::AudioDecoder> request); |
30 | 30 |
31 ~MojoAudioDecoderService() final; | 31 ~MojoAudioDecoderService() final; |
32 | 32 |
33 // interfaces::AudioDecoder implementation | 33 // mojom::AudioDecoder implementation |
34 void Initialize(interfaces::AudioDecoderClientPtr client, | 34 void Initialize(mojom::AudioDecoderClientPtr client, |
35 interfaces::AudioDecoderConfigPtr config, | 35 mojom::AudioDecoderConfigPtr config, |
36 int32_t cdm_id, | 36 int32_t cdm_id, |
37 const InitializeCallback& callback) final; | 37 const InitializeCallback& callback) final; |
38 | 38 |
39 void SetDataSource(mojo::ScopedDataPipeConsumerHandle receive_pipe) final; | 39 void SetDataSource(mojo::ScopedDataPipeConsumerHandle receive_pipe) final; |
40 | 40 |
41 void Decode(interfaces::DecoderBufferPtr buffer, | 41 void Decode(mojom::DecoderBufferPtr buffer, |
42 const DecodeCallback& callback) final; | 42 const DecodeCallback& callback) final; |
43 | 43 |
44 void Reset(const ResetCallback& callback) final; | 44 void Reset(const ResetCallback& callback) final; |
45 | 45 |
46 private: | 46 private: |
47 // Called by |decoder_| upon finishing initialization. | 47 // Called by |decoder_| upon finishing initialization. |
48 void OnInitialized(const InitializeCallback& callback, | 48 void OnInitialized(const InitializeCallback& callback, |
49 scoped_refptr<MediaKeys> cdm, | 49 scoped_refptr<MediaKeys> cdm, |
50 bool success); | 50 bool success); |
51 | 51 |
52 // Called by |decoder_| when DecoderBuffer is accepted or rejected. | 52 // Called by |decoder_| when DecoderBuffer is accepted or rejected. |
53 void OnDecodeStatus(const DecodeCallback& callback, | 53 void OnDecodeStatus(const DecodeCallback& callback, |
54 media::DecodeStatus status); | 54 media::DecodeStatus status); |
55 | 55 |
56 // Called by |decoder_| when reset sequence is finished. | 56 // Called by |decoder_| when reset sequence is finished. |
57 void OnResetDone(const ResetCallback& callback); | 57 void OnResetDone(const ResetCallback& callback); |
58 | 58 |
59 // Called by |decoder_| for each decoded buffer. | 59 // Called by |decoder_| for each decoded buffer. |
60 void OnAudioBufferReady(const scoped_refptr<AudioBuffer>& audio_buffer); | 60 void OnAudioBufferReady(const scoped_refptr<AudioBuffer>& audio_buffer); |
61 | 61 |
62 // A helper method to read and deserialize DecoderBuffer from data pipe. | 62 // A helper method to read and deserialize DecoderBuffer from data pipe. |
63 // Returns empty scoped_refptr in case of an error. | 63 // Returns empty scoped_refptr in case of an error. |
64 scoped_refptr<DecoderBuffer> ReadDecoderBuffer( | 64 scoped_refptr<DecoderBuffer> ReadDecoderBuffer( |
65 interfaces::DecoderBufferPtr buffer); | 65 mojom::DecoderBufferPtr buffer); |
66 | 66 |
67 // A binding represents the association between the service and the | 67 // A binding represents the association between the service and the |
68 // communication channel, i.e. the pipe. | 68 // communication channel, i.e. the pipe. |
69 mojo::StrongBinding<interfaces::AudioDecoder> binding_; | 69 mojo::StrongBinding<mojom::AudioDecoder> binding_; |
70 | 70 |
71 // DataPipe for serializing the data section of DecoderBuffer. | 71 // DataPipe for serializing the data section of DecoderBuffer. |
72 mojo::ScopedDataPipeConsumerHandle consumer_handle_; | 72 mojo::ScopedDataPipeConsumerHandle consumer_handle_; |
73 | 73 |
74 // A helper object required to get CDM from CDM id. | 74 // A helper object required to get CDM from CDM id. |
75 base::WeakPtr<MojoCdmServiceContext> mojo_cdm_service_context_; | 75 base::WeakPtr<MojoCdmServiceContext> mojo_cdm_service_context_; |
76 | 76 |
77 // The AudioDecoder that does actual decoding work. | 77 // The AudioDecoder that does actual decoding work. |
78 std::unique_ptr<media::AudioDecoder> decoder_; | 78 std::unique_ptr<media::AudioDecoder> decoder_; |
79 | 79 |
80 // The destination for the decoded buffers. | 80 // The destination for the decoded buffers. |
81 interfaces::AudioDecoderClientPtr client_; | 81 mojom::AudioDecoderClientPtr client_; |
82 | 82 |
83 // Hold a reference to the CDM to keep it alive for the lifetime of the | 83 // Hold a reference to the CDM to keep it alive for the lifetime of the |
84 // |decoder_|. The |cdm_| owns the CdmContext which is passed to |decoder_|. | 84 // |decoder_|. The |cdm_| owns the CdmContext which is passed to |decoder_|. |
85 scoped_refptr<MediaKeys> cdm_; | 85 scoped_refptr<MediaKeys> cdm_; |
86 | 86 |
87 base::WeakPtr<MojoAudioDecoderService> weak_this_; | 87 base::WeakPtr<MojoAudioDecoderService> weak_this_; |
88 base::WeakPtrFactory<MojoAudioDecoderService> weak_factory_; | 88 base::WeakPtrFactory<MojoAudioDecoderService> weak_factory_; |
89 | 89 |
90 DISALLOW_COPY_AND_ASSIGN(MojoAudioDecoderService); | 90 DISALLOW_COPY_AND_ASSIGN(MojoAudioDecoderService); |
91 }; | 91 }; |
92 | 92 |
93 } // namespace media | 93 } // namespace media |
94 | 94 |
95 #endif // MEDIA_MOJO_SERVICES_MOJO_AUDIO_DECODER_SERVICE_H_ | 95 #endif // MEDIA_MOJO_SERVICES_MOJO_AUDIO_DECODER_SERVICE_H_ |
OLD | NEW |