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_SENDER_H_ | 5 #ifndef MEDIA_CAST_AUDIO_SENDER_H_ |
6 #define MEDIA_CAST_AUDIO_SENDER_H_ | 6 #define MEDIA_CAST_AUDIO_SENDER_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "base/threading/non_thread_safe.h" | 12 #include "base/threading/non_thread_safe.h" |
13 #include "base/time/tick_clock.h" | 13 #include "base/time/tick_clock.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "media/base/audio_bus.h" | 15 #include "media/base/audio_bus.h" |
16 #include "media/cast/cast_config.h" | 16 #include "media/cast/cast_config.h" |
17 #include "media/cast/rtcp/rtcp.h" | 17 #include "media/cast/rtcp/rtcp.h" |
18 #include "media/cast/rtp_timestamp_helper.h" | 18 #include "media/cast/rtp_timestamp_helper.h" |
19 #include "media/cast/transport/rtp_sender/rtp_sender.h" | 19 #include "media/cast/transport/rtp_sender/rtp_sender.h" |
20 | 20 |
21 namespace media { | 21 namespace media { |
22 namespace cast { | 22 namespace cast { |
23 | 23 |
24 class AudioEncoder; | 24 class AudioEncoder; |
25 class LocalRtcpAudioSenderFeedback; | |
26 | 25 |
27 // This class is not thread safe. | 26 // This class is not thread safe. |
28 // It's only called from the main cast thread. | 27 // It's only called from the main cast thread. |
29 class AudioSender : public base::NonThreadSafe, | 28 class AudioSender : public RtcpSenderFeedback, |
| 29 public base::NonThreadSafe, |
30 public base::SupportsWeakPtr<AudioSender> { | 30 public base::SupportsWeakPtr<AudioSender> { |
31 public: | 31 public: |
32 AudioSender(scoped_refptr<CastEnvironment> cast_environment, | 32 AudioSender(scoped_refptr<CastEnvironment> cast_environment, |
33 const AudioSenderConfig& audio_config, | 33 const AudioSenderConfig& audio_config, |
34 transport::CastTransportSender* const transport_sender); | 34 transport::CastTransportSender* const transport_sender); |
35 | 35 |
36 virtual ~AudioSender(); | 36 virtual ~AudioSender(); |
37 | 37 |
38 CastInitializationStatus InitializationResult() const { | 38 CastInitializationStatus InitializationResult() const { |
39 return cast_initialization_cb_; | 39 return cast_initialization_cb_; |
40 } | 40 } |
41 | 41 |
42 void InsertAudio(scoped_ptr<AudioBus> audio_bus, | 42 void InsertAudio(scoped_ptr<AudioBus> audio_bus, |
43 const base::TimeTicks& recorded_time); | 43 const base::TimeTicks& recorded_time); |
44 | 44 |
45 // Only called from the main cast thread. | 45 // Only called from the main cast thread. |
46 void IncomingRtcpPacket(scoped_ptr<Packet> packet); | 46 void IncomingRtcpPacket(scoped_ptr<Packet> packet); |
47 | 47 |
48 protected: | 48 protected: |
49 void SendEncodedAudioFrame(scoped_ptr<transport::EncodedFrame> audio_frame); | 49 void SendEncodedAudioFrame(scoped_ptr<transport::EncodedFrame> audio_frame); |
50 | 50 |
51 private: | 51 private: |
52 friend class LocalRtcpAudioSenderFeedback; | |
53 | |
54 void ResendPackets( | 52 void ResendPackets( |
55 const MissingFramesAndPacketsMap& missing_frames_and_packets); | 53 const MissingFramesAndPacketsMap& missing_frames_and_packets); |
56 | 54 |
57 void ScheduleNextRtcpReport(); | 55 void ScheduleNextRtcpReport(); |
58 void SendRtcpReport(); | 56 void SendRtcpReport(bool schedule_future_reports); |
59 | 57 |
60 void InitializeTimers(); | 58 virtual void OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback) |
| 59 OVERRIDE; |
61 | 60 |
62 scoped_refptr<CastEnvironment> cast_environment_; | 61 scoped_refptr<CastEnvironment> cast_environment_; |
63 transport::CastTransportSender* const transport_sender_; | 62 transport::CastTransportSender* const transport_sender_; |
64 scoped_ptr<AudioEncoder> audio_encoder_; | 63 scoped_ptr<AudioEncoder> audio_encoder_; |
65 RtpTimestampHelper rtp_timestamp_helper_; | 64 RtpTimestampHelper rtp_timestamp_helper_; |
66 scoped_ptr<LocalRtcpAudioSenderFeedback> rtcp_feedback_; | |
67 Rtcp rtcp_; | 65 Rtcp rtcp_; |
68 bool timers_initialized_; | 66 int num_aggressive_rtcp_reports_sent_; |
69 CastInitializationStatus cast_initialization_cb_; | 67 CastInitializationStatus cast_initialization_cb_; |
70 | 68 |
71 // NOTE: Weak pointers must be invalidated before all other member variables. | 69 // NOTE: Weak pointers must be invalidated before all other member variables. |
72 base::WeakPtrFactory<AudioSender> weak_factory_; | 70 base::WeakPtrFactory<AudioSender> weak_factory_; |
73 | 71 |
74 DISALLOW_COPY_AND_ASSIGN(AudioSender); | 72 DISALLOW_COPY_AND_ASSIGN(AudioSender); |
75 }; | 73 }; |
76 | 74 |
77 } // namespace cast | 75 } // namespace cast |
78 } // namespace media | 76 } // namespace media |
79 | 77 |
80 #endif // MEDIA_CAST_AUDIO_SENDER_H_ | 78 #endif // MEDIA_CAST_AUDIO_SENDER_H_ |
OLD | NEW |