| 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 "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "media/base/audio_decoder.h" | 11 #include "media/base/audio_decoder.h" |
| 12 #include "media/mojo/interfaces/audio_decoder.mojom.h" | 12 #include "media/mojo/interfaces/audio_decoder.mojom.h" |
| 13 #include "mojo/public/cpp/bindings/strong_binding.h" | 13 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 14 #include "mojo/public/cpp/system/data_pipe.h" |
| 14 | 15 |
| 15 namespace media { | 16 namespace media { |
| 16 | 17 |
| 17 class MojoAudioDecoderService : public interfaces::AudioDecoder { | 18 class MojoAudioDecoderService : public interfaces::AudioDecoder { |
| 18 public: | 19 public: |
| 19 MojoAudioDecoderService( | 20 MojoAudioDecoderService( |
| 20 scoped_ptr<media::AudioDecoder> decoder, | 21 scoped_ptr<media::AudioDecoder> decoder, |
| 21 mojo::InterfaceRequest<interfaces::AudioDecoder> request); | 22 mojo::InterfaceRequest<interfaces::AudioDecoder> request); |
| 22 | 23 |
| 23 ~MojoAudioDecoderService() final; | 24 ~MojoAudioDecoderService() final; |
| 24 | 25 |
| 25 // interfaces::AudioDecoder implementation | 26 // interfaces::AudioDecoder implementation |
| 26 void Initialize(interfaces::AudioDecoderClientPtr client, | 27 void Initialize(interfaces::AudioDecoderClientPtr client, |
| 27 interfaces::AudioDecoderConfigPtr config, | 28 interfaces::AudioDecoderConfigPtr config, |
| 28 int32_t cdm_id, | 29 int32_t cdm_id, |
| 29 const InitializeCallback& callback) final; | 30 const InitializeCallback& callback) final; |
| 30 | 31 |
| 32 void SetDataSource(mojo::ScopedDataPipeConsumerHandle receive_pipe) final; |
| 33 |
| 31 void Decode(interfaces::DecoderBufferPtr buffer, | 34 void Decode(interfaces::DecoderBufferPtr buffer, |
| 32 const DecodeCallback& callback) final; | 35 const DecodeCallback& callback) final; |
| 33 | 36 |
| 34 void Reset(const ResetCallback& callback) final; | 37 void Reset(const ResetCallback& callback) final; |
| 35 | 38 |
| 36 private: | 39 private: |
| 37 // Called by |decoder_| upon finishing initialization. | 40 // Called by |decoder_| upon finishing initialization. |
| 38 void OnInitialized(const InitializeCallback& callback, bool success); | 41 void OnInitialized(const InitializeCallback& callback, bool success); |
| 39 | 42 |
| 40 // Called by |decoder_| when DecoderBuffer is accepted or rejected. | 43 // Called by |decoder_| when DecoderBuffer is accepted or rejected. |
| 41 void OnDecodeStatus(const DecodeCallback& callback, | 44 void OnDecodeStatus(const DecodeCallback& callback, |
| 42 media::AudioDecoder::Status status); | 45 media::AudioDecoder::Status status); |
| 43 | 46 |
| 44 // Called by |decoder_| when reset sequence is finished. | 47 // Called by |decoder_| when reset sequence is finished. |
| 45 void OnResetDone(const ResetCallback& callback); | 48 void OnResetDone(const ResetCallback& callback); |
| 46 | 49 |
| 47 // Called by |decoder_| for each decoded buffer. | 50 // Called by |decoder_| for each decoded buffer. |
| 48 void OnAudioBufferReady(const scoped_refptr<AudioBuffer>& audio_buffer); | 51 void OnAudioBufferReady(const scoped_refptr<AudioBuffer>& audio_buffer); |
| 49 | 52 |
| 50 // A helper method to read and deserialize DecoderBuffer from data pipe. | 53 // A helper method to read and deserialize DecoderBuffer from data pipe. |
| 51 scoped_refptr<DecoderBuffer> ReadDecoderBuffer( | 54 scoped_refptr<DecoderBuffer> ReadDecoderBuffer( |
| 52 interfaces::DecoderBufferPtr buffer); | 55 interfaces::DecoderBufferPtr buffer); |
| 53 | 56 |
| 54 // A binding represents the association between the service and the | 57 // A binding represents the association between the service and the |
| 55 // communication channel, i.e. the pipe. | 58 // communication channel, i.e. the pipe. |
| 56 mojo::StrongBinding<interfaces::AudioDecoder> binding_; | 59 mojo::StrongBinding<interfaces::AudioDecoder> binding_; |
| 57 | 60 |
| 61 // DataPipe for serializing the data section of DecoderBuffer. |
| 62 mojo::ScopedDataPipeConsumerHandle consumer_handle_; |
| 63 |
| 58 // The AudioDecoder that does actual decoding work. | 64 // The AudioDecoder that does actual decoding work. |
| 59 scoped_ptr<media::AudioDecoder> decoder_; | 65 scoped_ptr<media::AudioDecoder> decoder_; |
| 60 | 66 |
| 61 // The destination for the decoded buffers. | 67 // The destination for the decoded buffers. |
| 62 interfaces::AudioDecoderClientPtr client_; | 68 interfaces::AudioDecoderClientPtr client_; |
| 63 | 69 |
| 64 base::WeakPtr<MojoAudioDecoderService> weak_this_; | 70 base::WeakPtr<MojoAudioDecoderService> weak_this_; |
| 65 base::WeakPtrFactory<MojoAudioDecoderService> weak_factory_; | 71 base::WeakPtrFactory<MojoAudioDecoderService> weak_factory_; |
| 66 | 72 |
| 67 DISALLOW_COPY_AND_ASSIGN(MojoAudioDecoderService); | 73 DISALLOW_COPY_AND_ASSIGN(MojoAudioDecoderService); |
| 68 }; | 74 }; |
| 69 | 75 |
| 70 } // namespace media | 76 } // namespace media |
| 71 | 77 |
| 72 #endif // MEDIA_MOJO_SERVICES_MOJO_AUDIO_DECODER_SERVICE_H_ | 78 #endif // MEDIA_MOJO_SERVICES_MOJO_AUDIO_DECODER_SERVICE_H_ |
| OLD | NEW |