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" | |
20 | 19 |
21 namespace media { | 20 namespace media { |
22 namespace cast { | 21 namespace cast { |
23 | 22 |
24 class AudioEncoder; | 23 class AudioEncoder; |
25 | 24 |
26 // This class is not thread safe. | 25 // This class is not thread safe. |
27 // It's only called from the main cast thread. | 26 // It's only called from the main cast thread. |
28 class AudioSender : public RtcpSenderFeedback, | 27 class AudioSender : public RtcpSenderFeedback, |
29 public base::NonThreadSafe, | 28 public base::NonThreadSafe, |
30 public base::SupportsWeakPtr<AudioSender> { | 29 public base::SupportsWeakPtr<AudioSender> { |
31 public: | 30 public: |
32 AudioSender(scoped_refptr<CastEnvironment> cast_environment, | 31 AudioSender(scoped_refptr<CastEnvironment> cast_environment, |
33 const AudioSenderConfig& audio_config, | 32 const AudioSenderConfig& audio_config, |
34 transport::CastTransportSender* const transport_sender); | 33 transport::CastTransportSender* const transport_sender); |
35 | 34 |
36 virtual ~AudioSender(); | 35 virtual ~AudioSender(); |
37 | 36 |
38 CastInitializationStatus InitializationResult() const { | 37 CastInitializationStatus InitializationResult() const { |
39 return cast_initialization_cb_; | 38 return cast_initialization_status_; |
40 } | 39 } |
41 | 40 |
| 41 // Note: It is invalid to call this method if InitializationResult() returns |
| 42 // anything but STATUS_AUDIO_INITIALIZED. |
42 void InsertAudio(scoped_ptr<AudioBus> audio_bus, | 43 void InsertAudio(scoped_ptr<AudioBus> audio_bus, |
43 const base::TimeTicks& recorded_time); | 44 const base::TimeTicks& recorded_time); |
44 | 45 |
45 // Only called from the main cast thread. | 46 // Only called from the main cast thread. |
46 void IncomingRtcpPacket(scoped_ptr<Packet> packet); | 47 void IncomingRtcpPacket(scoped_ptr<Packet> packet); |
47 | 48 |
48 protected: | |
49 void SendEncodedAudioFrame(scoped_ptr<transport::EncodedFrame> audio_frame); | |
50 | |
51 private: | 49 private: |
52 void ResendPackets( | 50 void ResendPackets( |
53 const MissingFramesAndPacketsMap& missing_frames_and_packets); | 51 const MissingFramesAndPacketsMap& missing_frames_and_packets); |
54 | 52 |
55 void ScheduleNextRtcpReport(); | 53 void ScheduleNextRtcpReport(); |
56 void SendRtcpReport(bool schedule_future_reports); | 54 void SendRtcpReport(bool schedule_future_reports); |
57 | 55 |
| 56 // Called by the |audio_encoder_| with the next EncodedFrame to send. |
| 57 void SendEncodedAudioFrame(scoped_ptr<transport::EncodedFrame> audio_frame); |
| 58 |
58 virtual void OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback) | 59 virtual void OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback) |
59 OVERRIDE; | 60 OVERRIDE; |
60 | 61 |
61 scoped_refptr<CastEnvironment> cast_environment_; | 62 scoped_refptr<CastEnvironment> cast_environment_; |
62 transport::CastTransportSender* const transport_sender_; | 63 transport::CastTransportSender* const transport_sender_; |
63 scoped_ptr<AudioEncoder> audio_encoder_; | 64 scoped_ptr<AudioEncoder> audio_encoder_; |
64 RtpTimestampHelper rtp_timestamp_helper_; | 65 RtpTimestampHelper rtp_timestamp_helper_; |
65 Rtcp rtcp_; | 66 Rtcp rtcp_; |
66 int num_aggressive_rtcp_reports_sent_; | 67 int num_aggressive_rtcp_reports_sent_; |
67 CastInitializationStatus cast_initialization_cb_; | 68 |
| 69 // If this sender is ready for use, this is STATUS_AUDIO_INITIALIZED. |
| 70 CastInitializationStatus cast_initialization_status_; |
68 | 71 |
69 // Used to map the lower 8 bits of the frame id to a RTP timestamp. This is | 72 // Used to map the lower 8 bits of the frame id to a RTP timestamp. This is |
70 // good enough as we only use it for logging. | 73 // good enough as we only use it for logging. |
71 RtpTimestamp frame_id_to_rtp_timestamp_[256]; | 74 RtpTimestamp frame_id_to_rtp_timestamp_[256]; |
72 | 75 |
73 // NOTE: Weak pointers must be invalidated before all other member variables. | 76 // NOTE: Weak pointers must be invalidated before all other member variables. |
74 base::WeakPtrFactory<AudioSender> weak_factory_; | 77 base::WeakPtrFactory<AudioSender> weak_factory_; |
75 | 78 |
76 DISALLOW_COPY_AND_ASSIGN(AudioSender); | 79 DISALLOW_COPY_AND_ASSIGN(AudioSender); |
77 }; | 80 }; |
78 | 81 |
79 } // namespace cast | 82 } // namespace cast |
80 } // namespace media | 83 } // namespace media |
81 | 84 |
82 #endif // MEDIA_CAST_AUDIO_SENDER_H_ | 85 #endif // MEDIA_CAST_AUDIO_SENDER_H_ |
OLD | NEW |