| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_CAST_AUDIO_RECEIVER_AUDIO_DECODER_H_ | 5 #ifndef MEDIA_CAST_AUDIO_RECEIVER_AUDIO_DECODER_H_ |
| 6 #define MEDIA_CAST_AUDIO_RECEIVER_AUDIO_DECODER_H_ | 6 #define MEDIA_CAST_AUDIO_RECEIVER_AUDIO_DECODER_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/synchronization/lock.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "media/base/audio_bus.h" |
| 10 #include "media/cast/cast_config.h" | 11 #include "media/cast/cast_config.h" |
| 11 #include "media/cast/cast_environment.h" | 12 #include "media/cast/cast_environment.h" |
| 12 #include "media/cast/framer/cast_message_builder.h" | 13 #include "media/cast/transport/cast_transport_config.h" |
| 13 #include "media/cast/framer/frame_id_map.h" | |
| 14 #include "media/cast/rtp_receiver/rtp_receiver_defines.h" | |
| 15 | |
| 16 namespace webrtc { | |
| 17 class AudioCodingModule; | |
| 18 } | |
| 19 | 14 |
| 20 namespace media { | 15 namespace media { |
| 21 namespace cast { | 16 namespace cast { |
| 22 | 17 |
| 23 typedef std::map<uint32, uint32> FrameIdRtpTimestampMap; | |
| 24 | |
| 25 // Thread safe class. | |
| 26 class AudioDecoder { | 18 class AudioDecoder { |
| 27 public: | 19 public: |
| 28 AudioDecoder(scoped_refptr<CastEnvironment> cast_environment, | 20 // Callback passed to DecodeFrame, to deliver decoded audio data from the |
| 29 const AudioReceiverConfig& audio_config, | 21 // decoder. The number of samples in |audio_bus| may vary, and |audio_bus| |
| 30 RtpPayloadFeedback* incoming_payload_feedback); | 22 // can be NULL when errors occur. |is_continuous| is normally true, but will |
| 23 // be false if the decoder has detected a frame skip since the last decode |
| 24 // operation; and the client should take steps to smooth audio discontinuities |
| 25 // in this case. |
| 26 typedef base::Callback<void(scoped_ptr<AudioBus> audio_bus, |
| 27 bool is_continuous)> DecodeFrameCallback; |
| 28 |
| 29 AudioDecoder(const scoped_refptr<CastEnvironment>& cast_environment, |
| 30 const AudioReceiverConfig& audio_config); |
| 31 virtual ~AudioDecoder(); | 31 virtual ~AudioDecoder(); |
| 32 | 32 |
| 33 // Extract a raw audio frame from the decoder. | 33 // Returns STATUS_AUDIO_INITIALIZED if the decoder was successfully |
| 34 // Set the number of desired 10ms blocks and frequency. | 34 // constructed from the given AudioReceiverConfig. If this method returns any |
| 35 // Should be called from the cast audio decoder thread; however that is not | 35 // other value, calls to DecodeFrame() will not succeed. |
| 36 // required. | 36 CastInitializationStatus InitializationResult() const; |
| 37 bool GetRawAudioFrame(int number_of_10ms_blocks, | |
| 38 int desired_frequency, | |
| 39 PcmAudioFrame* audio_frame, | |
| 40 uint32* rtp_timestamp); | |
| 41 | 37 |
| 42 // Insert an RTP packet to the decoder. | 38 // Decode the payload in |encoded_frame| asynchronously. |callback| will be |
| 43 // Should be called from the main cast thread; however that is not required. | 39 // invoked on the CastEnvironment::MAIN thread with the result. |
| 44 void IncomingParsedRtpPacket(const uint8* payload_data, | 40 // |
| 45 size_t payload_size, | 41 // In the normal case, |encoded_frame->frame_id| will be |
| 46 const RtpCastHeader& rtp_header); | 42 // monotonically-increasing by 1 for each successive call to this method. |
| 47 | 43 // When it is not, the decoder will assume one or more frames have been |
| 48 bool TimeToSendNextCastMessage(base::TimeTicks* time_to_send); | 44 // dropped (e.g., due to packet loss), and will perform recovery actions. |
| 49 void SendCastMessage(); | 45 void DecodeFrame(scoped_ptr<transport::EncodedAudioFrame> encoded_frame, |
| 46 const DecodeFrameCallback& callback); |
| 50 | 47 |
| 51 private: | 48 private: |
| 52 scoped_refptr<CastEnvironment> cast_environment_; | 49 class ImplBase; |
| 50 class OpusImpl; |
| 51 class Pcm16Impl; |
| 53 | 52 |
| 54 // The webrtc AudioCodingModule is thread safe. | 53 const scoped_refptr<CastEnvironment> cast_environment_; |
| 55 scoped_ptr<webrtc::AudioCodingModule> audio_decoder_; | 54 scoped_refptr<ImplBase> impl_; |
| 56 | |
| 57 FrameIdMap frame_id_map_; | |
| 58 CastMessageBuilder cast_message_builder_; | |
| 59 | |
| 60 base::Lock lock_; | |
| 61 bool have_received_packets_; | |
| 62 FrameIdRtpTimestampMap frame_id_rtp_timestamp_map_; | |
| 63 uint32 last_played_out_timestamp_; | |
| 64 | 55 |
| 65 DISALLOW_COPY_AND_ASSIGN(AudioDecoder); | 56 DISALLOW_COPY_AND_ASSIGN(AudioDecoder); |
| 66 }; | 57 }; |
| 67 | 58 |
| 68 } // namespace cast | 59 } // namespace cast |
| 69 } // namespace media | 60 } // namespace media |
| 70 | 61 |
| 71 #endif // MEDIA_CAST_AUDIO_RECEIVER_AUDIO_DECODER_H_ | 62 #endif // MEDIA_CAST_AUDIO_RECEIVER_AUDIO_DECODER_H_ |
| OLD | NEW |