Home | History | Annotate | Download | only in audio_receiver
      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.
      4 
      5 #ifndef MEDIA_CAST_AUDIO_RECEIVER_AUDIO_DECODER_H_
      6 #define MEDIA_CAST_AUDIO_RECEIVER_AUDIO_DECODER_H_
      7 
      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"
     15 
     16 namespace webrtc {
     17 class AudioCodingModule;
     18 }
     19 
     20 namespace media {
     21 namespace cast {
     22 
     23 typedef std::map<uint32, uint32> FrameIdRtpTimestampMap;
     24 
     25 // Thread safe class.
     26 class AudioDecoder {
     27  public:
     28   AudioDecoder(scoped_refptr<CastEnvironment> cast_environment,
     29                const AudioReceiverConfig& audio_config,
     30                RtpPayloadFeedback* incoming_payload_feedback);
     31   virtual ~AudioDecoder();
     32 
     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
     36   // required.
     37   bool GetRawAudioFrame(int number_of_10ms_blocks,
     38                         int desired_frequency,
     39                         PcmAudioFrame* audio_frame,
     40                         uint32* rtp_timestamp);
     41 
     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,
     45                                size_t payload_size,
     46                                const RtpCastHeader& rtp_header);
     47 
     48   bool TimeToSendNextCastMessage(base::TimeTicks* time_to_send);
     49   void SendCastMessage();
     50 
     51  private:
     52   scoped_refptr<CastEnvironment> cast_environment_;
     53 
     54   // The webrtc AudioCodingModule is threadsafe.
     55   scoped_ptr<webrtc::AudioCodingModule> audio_decoder_;
     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 
     65   DISALLOW_COPY_AND_ASSIGN(AudioDecoder);
     66 };
     67 
     68 }  // namespace cast
     69 }  // namespace media
     70 
     71 #endif  // MEDIA_CAST_AUDIO_RECEIVER_AUDIO_DECODER_H_
     72