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
3 // found in the LICENSE file.
5 #ifndef MEDIA_CAST_AUDIO_RECEIVER_AUDIO_DECODER_H_
6 #define MEDIA_CAST_AUDIO_RECEIVER_AUDIO_DECODER_H_
8 #include "base/callback.h"
9 #include "base/synchronization/lock.h"
10 #include "media/cast/cast_config.h"
11 #include "media/cast/cast_environment.h"
12 #include "media/cast/framer/cast_message_builder.h"
13 #include "media/cast/framer/frame_id_map.h"
14 #include "media/cast/rtp_receiver/rtp_receiver_defines.h"
17 class AudioCodingModule;
23 typedef std::map<uint32, uint32> FrameIdRtpTimestampMap;
28 AudioDecoder(scoped_refptr<CastEnvironment> cast_environment,
29 const AudioReceiverConfig& audio_config,
30 RtpPayloadFeedback* incoming_payload_feedback);
31 virtual ~AudioDecoder();
33 // Extract a raw audio frame from the decoder.
34 // Set the number of desired 10ms blocks and frequency.
35 // Should be called from the cast audio decoder thread; however that is not
37 bool GetRawAudioFrame(int number_of_10ms_blocks,
38 int desired_frequency,
39 PcmAudioFrame* audio_frame,
40 uint32* rtp_timestamp);
42 // Insert an RTP packet to the decoder.
43 // Should be called from the main cast thread; however that is not required.
44 void IncomingParsedRtpPacket(const uint8* payload_data,
46 const RtpCastHeader& rtp_header);
48 bool TimeToSendNextCastMessage(base::TimeTicks* time_to_send);
49 void SendCastMessage();
52 scoped_refptr<CastEnvironment> cast_environment_;
54 // The webrtc AudioCodingModule is thread safe.
55 scoped_ptr<webrtc::AudioCodingModule> audio_decoder_;
57 FrameIdMap frame_id_map_;
58 CastMessageBuilder cast_message_builder_;
61 bool have_received_packets_;
62 FrameIdRtpTimestampMap frame_id_rtp_timestamp_map_;
63 uint32 last_played_out_timestamp_;
65 DISALLOW_COPY_AND_ASSIGN(AudioDecoder);
71 #endif // MEDIA_CAST_AUDIO_RECEIVER_AUDIO_DECODER_H_