| 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_CLIENTS_MOJO_AUDIO_DECODER_H_ | 5 #ifndef MEDIA_MOJO_CLIENTS_MOJO_AUDIO_DECODER_H_ |
| 6 #define MEDIA_MOJO_CLIENTS_MOJO_AUDIO_DECODER_H_ | 6 #define MEDIA_MOJO_CLIENTS_MOJO_AUDIO_DECODER_H_ |
| 7 | 7 |
| 8 #include <memory> |
| 9 |
| 8 #include "base/macros.h" | 10 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 10 #include "media/base/audio_decoder.h" | 12 #include "media/base/audio_decoder.h" |
| 11 #include "media/mojo/interfaces/audio_decoder.mojom.h" | 13 #include "media/mojo/interfaces/audio_decoder.mojom.h" |
| 12 #include "media/mojo/interfaces/media_types.mojom.h" | 14 #include "media/mojo/interfaces/media_types.mojom.h" |
| 13 #include "mojo/public/cpp/bindings/binding.h" | 15 #include "mojo/public/cpp/bindings/binding.h" |
| 14 #include "mojo/public/cpp/system/data_pipe.h" | |
| 15 | 16 |
| 16 namespace base { | 17 namespace base { |
| 17 class SingleThreadTaskRunner; | 18 class SingleThreadTaskRunner; |
| 18 } | 19 } |
| 19 | 20 |
| 20 namespace media { | 21 namespace media { |
| 21 | 22 |
| 23 class MojoDecoderBufferWriter; |
| 24 |
| 22 // An AudioDecoder that proxies to a mojom::AudioDecoder. | 25 // An AudioDecoder that proxies to a mojom::AudioDecoder. |
| 23 class MojoAudioDecoder : public AudioDecoder, public mojom::AudioDecoderClient { | 26 class MojoAudioDecoder : public AudioDecoder, public mojom::AudioDecoderClient { |
| 24 public: | 27 public: |
| 25 MojoAudioDecoder(scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 28 MojoAudioDecoder(scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 26 mojom::AudioDecoderPtr remote_decoder); | 29 mojom::AudioDecoderPtr remote_decoder); |
| 27 ~MojoAudioDecoder() final; | 30 ~MojoAudioDecoder() final; |
| 28 | 31 |
| 29 // AudioDecoder implementation. | 32 // AudioDecoder implementation. |
| 30 std::string GetDisplayName() const final; | 33 std::string GetDisplayName() const final; |
| 31 void Initialize(const AudioDecoderConfig& config, | 34 void Initialize(const AudioDecoderConfig& config, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 46 | 49 |
| 47 // Called when |remote_decoder_| finished initialization. | 50 // Called when |remote_decoder_| finished initialization. |
| 48 void OnInitialized(bool success, bool needs_bitstream_conversion); | 51 void OnInitialized(bool success, bool needs_bitstream_conversion); |
| 49 | 52 |
| 50 // Called when |remote_decoder_| accepted or rejected DecoderBuffer. | 53 // Called when |remote_decoder_| accepted or rejected DecoderBuffer. |
| 51 void OnDecodeStatus(mojom::DecodeStatus decode_status); | 54 void OnDecodeStatus(mojom::DecodeStatus decode_status); |
| 52 | 55 |
| 53 // called when |remote_decoder_| finished Reset() sequence. | 56 // called when |remote_decoder_| finished Reset() sequence. |
| 54 void OnResetDone(); | 57 void OnResetDone(); |
| 55 | 58 |
| 56 // A helper method that creates data pipe and sets the data connection to | |
| 57 // the service. | |
| 58 void CreateDataPipe(); | |
| 59 | |
| 60 // A helper method to serialize the data section of DecoderBuffer into pipe. | |
| 61 mojom::DecoderBufferPtr TransferDecoderBuffer( | |
| 62 const scoped_refptr<DecoderBuffer>& media_buffer); | |
| 63 | |
| 64 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 59 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 65 | 60 |
| 66 // This class is constructed on one thread and used exclusively on another | 61 // This class is constructed on one thread and used exclusively on another |
| 67 // thread. This member is used to safely pass the AudioDecoderPtr from one | 62 // thread. This member is used to safely pass the AudioDecoderPtr from one |
| 68 // thread to another. It is set in the constructor and is consumed in | 63 // thread to another. It is set in the constructor and is consumed in |
| 69 // Initialize(). | 64 // Initialize(). |
| 70 mojom::AudioDecoderPtrInfo remote_decoder_info_; | 65 mojom::AudioDecoderPtrInfo remote_decoder_info_; |
| 71 | 66 |
| 72 mojom::AudioDecoderPtr remote_decoder_; | 67 mojom::AudioDecoderPtr remote_decoder_; |
| 73 | 68 |
| 74 // DataPipe for serializing the data section of DecoderBuffer. | 69 std::unique_ptr<MojoDecoderBufferWriter> mojo_decoder_buffer_writer_; |
| 75 mojo::ScopedDataPipeProducerHandle producer_handle_; | |
| 76 | 70 |
| 77 // Binding for AudioDecoderClient, bound to the |task_runner_|. | 71 // Binding for AudioDecoderClient, bound to the |task_runner_|. |
| 78 mojo::Binding<AudioDecoderClient> binding_; | 72 mojo::Binding<AudioDecoderClient> binding_; |
| 79 | 73 |
| 80 // We call the following callbacks to pass the information to the pipeline. | 74 // We call the following callbacks to pass the information to the pipeline. |
| 81 // |output_cb_| is permanent while other three are called only once, | 75 // |output_cb_| is permanent while other three are called only once, |
| 82 // |decode_cb_| and |reset_cb_| are replaced by every by Decode() and Reset(). | 76 // |decode_cb_| and |reset_cb_| are replaced by every by Decode() and Reset(). |
| 83 InitCB init_cb_; | 77 InitCB init_cb_; |
| 84 OutputCB output_cb_; | 78 OutputCB output_cb_; |
| 85 DecodeCB decode_cb_; | 79 DecodeCB decode_cb_; |
| 86 base::Closure reset_cb_; | 80 base::Closure reset_cb_; |
| 87 | 81 |
| 88 // Flag that is set if we got connection error. Never cleared. | 82 // Flag that is set if we got connection error. Never cleared. |
| 89 bool has_connection_error_; | 83 bool has_connection_error_; |
| 90 | 84 |
| 91 // Flag telling whether this decoder requires bitstream conversion. | 85 // Flag telling whether this decoder requires bitstream conversion. |
| 92 // Passed from |remote_decoder_| as a result of its initialization. | 86 // Passed from |remote_decoder_| as a result of its initialization. |
| 93 bool needs_bitstream_conversion_; | 87 bool needs_bitstream_conversion_; |
| 94 | 88 |
| 95 DISALLOW_COPY_AND_ASSIGN(MojoAudioDecoder); | 89 DISALLOW_COPY_AND_ASSIGN(MojoAudioDecoder); |
| 96 }; | 90 }; |
| 97 | 91 |
| 98 } // namespace media | 92 } // namespace media |
| 99 | 93 |
| 100 #endif // MEDIA_MOJO_CLIENTS_MOJO_AUDIO_DECODER_H_ | 94 #endif // MEDIA_MOJO_CLIENTS_MOJO_AUDIO_DECODER_H_ |
| OLD | NEW |