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_SENDER_H_
6 #define MEDIA_CAST_AUDIO_SENDER_H_
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/threading/non_thread_safe.h"
13 #include "base/time/tick_clock.h"
14 #include "base/time/time.h"
15 #include "media/cast/cast_config.h"
16 #include "media/cast/cast_environment.h"
17 #include "media/cast/rtcp/rtcp.h"
18 #include "media/cast/rtp_sender/rtp_sender.h"
24 class LocalRtcpAudioSenderFeedback;
25 class LocalRtpSenderStatistics;
26 class PacedPacketSender;
28 // This class is not thread safe.
29 // It's only called from the main cast thread.
30 class AudioSender : public base::NonThreadSafe,
31 public base::SupportsWeakPtr<AudioSender> {
33 AudioSender(scoped_refptr<CastEnvironment> cast_environment,
34 const AudioSenderConfig& audio_config,
35 PacedPacketSender* const paced_packet_sender);
37 virtual ~AudioSender();
39 // The audio_frame must be valid until the closure callback is called.
40 // The closure callback is called from the main cast thread as soon as
41 // the encoder is done with the frame; it does not mean that the encoded frame
43 void InsertRawAudioFrame(const PcmAudioFrame* audio_frame,
44 const base::TimeTicks& recorded_time,
45 const base::Closure callback);
47 // The audio_frame must be valid until the closure callback is called.
48 // The closure callback is called from the main cast thread as soon as
49 // the cast sender is done with the frame; it does not mean that the encoded
50 // frame has been sent out.
51 void InsertCodedAudioFrame(const EncodedAudioFrame* audio_frame,
52 const base::TimeTicks& recorded_time,
53 const base::Closure callback);
55 // Only called from the main cast thread.
56 void IncomingRtcpPacket(const uint8* packet, size_t length,
57 const base::Closure callback);
60 void SendEncodedAudioFrame(scoped_ptr<EncodedAudioFrame> audio_frame,
61 const base::TimeTicks& recorded_time);
64 friend class LocalRtcpAudioSenderFeedback;
67 const MissingFramesAndPacketsMap& missing_frames_and_packets);
69 void ScheduleNextRtcpReport();
70 void SendRtcpReport();
72 base::WeakPtrFactory<AudioSender> weak_factory_;
74 const uint32 incoming_feedback_ssrc_;
75 scoped_refptr<CastEnvironment> cast_environment_;
76 scoped_refptr<AudioEncoder> audio_encoder_;
77 RtpSender rtp_sender_;
78 scoped_ptr<LocalRtpSenderStatistics> rtp_audio_sender_statistics_;
79 scoped_ptr<LocalRtcpAudioSenderFeedback> rtcp_feedback_;
82 DISALLOW_COPY_AND_ASSIGN(AudioSender);
88 #endif // MEDIA_CAST_AUDIO_SENDER_H_