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_SENDER_AUDIO_SENDER_H_ |
6 #define MEDIA_CAST_AUDIO_SENDER_H_ | 6 #define MEDIA_CAST_SENDER_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/cast_environment.h" | 17 #include "media/cast/cast_environment.h" |
18 #include "media/cast/logging/logging_defines.h" | 18 #include "media/cast/logging/logging_defines.h" |
19 #include "media/cast/rtcp/rtcp.h" | 19 #include "media/cast/net/rtcp/rtcp.h" |
20 #include "media/cast/rtp_timestamp_helper.h" | 20 #include "media/cast/sender/rtp_timestamp_helper.h" |
21 | 21 |
22 namespace media { | 22 namespace media { |
23 namespace cast { | 23 namespace cast { |
24 | 24 |
25 class AudioEncoder; | 25 class AudioEncoder; |
26 | 26 |
27 // Not thread safe. Only called from the main cast thread. | 27 // Not thread safe. Only called from the main cast thread. |
28 // This class owns all objects related to sending audio, objects that create RTP | 28 // This class owns all objects related to sending audio, objects that create RTP |
29 // packets, congestion control, audio encoder, parsing and sending of | 29 // packets, congestion control, audio encoder, parsing and sending of |
30 // RTCP packets. | 30 // RTCP packets. |
31 // Additionally it posts a bunch of delayed tasks to the main thread for various | 31 // Additionally it posts a bunch of delayed tasks to the main thread for various |
32 // timeouts. | 32 // timeouts. |
33 class AudioSender : public RtcpSenderFeedback, | 33 class AudioSender : public RtcpSenderFeedback, |
34 public base::NonThreadSafe, | 34 public base::NonThreadSafe, |
35 public base::SupportsWeakPtr<AudioSender> { | 35 public base::SupportsWeakPtr<AudioSender> { |
36 public: | 36 public: |
37 AudioSender(scoped_refptr<CastEnvironment> cast_environment, | 37 AudioSender(scoped_refptr<CastEnvironment> cast_environment, |
38 const AudioSenderConfig& audio_config, | 38 const AudioSenderConfig& audio_config, |
39 transport::CastTransportSender* const transport_sender); | 39 CastTransportSender* const transport_sender); |
40 | 40 |
41 virtual ~AudioSender(); | 41 virtual ~AudioSender(); |
42 | 42 |
43 CastInitializationStatus InitializationResult() const { | 43 CastInitializationStatus InitializationResult() const { |
44 return cast_initialization_status_; | 44 return cast_initialization_status_; |
45 } | 45 } |
46 | 46 |
47 // Note: It is not guaranteed that |audio_frame| will actually be encoded and | 47 // Note: It is not guaranteed that |audio_frame| will actually be encoded and |
48 // sent, if AudioSender detects too many frames in flight. Therefore, clients | 48 // sent, if AudioSender detects too many frames in flight. Therefore, clients |
49 // should be careful about the rate at which this method is called. | 49 // should be careful about the rate at which this method is called. |
(...skipping 25 matching lines...) Expand all Loading... |
75 void ResendCheck(); | 75 void ResendCheck(); |
76 void ResendForKickstart(); | 76 void ResendForKickstart(); |
77 | 77 |
78 // Returns true if there are too many frames in flight, as defined by the | 78 // Returns true if there are too many frames in flight, as defined by the |
79 // configured target playout delay plus simple logic. When this is true, | 79 // configured target playout delay plus simple logic. When this is true, |
80 // InsertAudio() will silenty drop frames instead of sending them to the audio | 80 // InsertAudio() will silenty drop frames instead of sending them to the audio |
81 // encoder. | 81 // encoder. |
82 bool AreTooManyFramesInFlight() const; | 82 bool AreTooManyFramesInFlight() const; |
83 | 83 |
84 // Called by the |audio_encoder_| with the next EncodedFrame to send. | 84 // Called by the |audio_encoder_| with the next EncodedFrame to send. |
85 void SendEncodedAudioFrame(scoped_ptr<transport::EncodedFrame> audio_frame); | 85 void SendEncodedAudioFrame(scoped_ptr<EncodedFrame> audio_frame); |
86 | 86 |
87 const scoped_refptr<CastEnvironment> cast_environment_; | 87 const scoped_refptr<CastEnvironment> cast_environment_; |
88 | 88 |
89 // The total amount of time between a frame's capture/recording on the sender | 89 // The total amount of time between a frame's capture/recording on the sender |
90 // and its playback on the receiver (i.e., shown to a user). This is fixed as | 90 // and its playback on the receiver (i.e., shown to a user). This is fixed as |
91 // a value large enough to give the system sufficient time to encode, | 91 // a value large enough to give the system sufficient time to encode, |
92 // transmit/retransmit, receive, decode, and render; given its run-time | 92 // transmit/retransmit, receive, decode, and render; given its run-time |
93 // environment (sender/receiver hardware performance, network conditions, | 93 // environment (sender/receiver hardware performance, network conditions, |
94 // etc.). | 94 // etc.). |
95 const base::TimeDelta target_playout_delay_; | 95 const base::TimeDelta target_playout_delay_; |
96 | 96 |
97 // Sends encoded frames over the configured transport (e.g., UDP). In | 97 // Sends encoded frames over the configured transport (e.g., UDP). In |
98 // Chromium, this could be a proxy that first sends the frames from a renderer | 98 // Chromium, this could be a proxy that first sends the frames from a renderer |
99 // process to the browser process over IPC, with the browser process being | 99 // process to the browser process over IPC, with the browser process being |
100 // responsible for "packetizing" the frames and pushing packets into the | 100 // responsible for "packetizing" the frames and pushing packets into the |
101 // network layer. | 101 // network layer. |
102 transport::CastTransportSender* const transport_sender_; | 102 CastTransportSender* const transport_sender_; |
103 | 103 |
104 // Maximum number of outstanding frames before the encoding and sending of | 104 // Maximum number of outstanding frames before the encoding and sending of |
105 // new frames shall halt. | 105 // new frames shall halt. |
106 const int max_unacked_frames_; | 106 const int max_unacked_frames_; |
107 | 107 |
108 // Encodes AudioBuses into EncodedFrames. | 108 // Encodes AudioBuses into EncodedFrames. |
109 scoped_ptr<AudioEncoder> audio_encoder_; | 109 scoped_ptr<AudioEncoder> audio_encoder_; |
110 const int configured_encoder_bitrate_; | 110 const int configured_encoder_bitrate_; |
111 | 111 |
112 // Manages sending/receiving of RTCP packets, including sender/receiver | 112 // Manages sending/receiving of RTCP packets, including sender/receiver |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 152 |
153 // NOTE: Weak pointers must be invalidated before all other member variables. | 153 // NOTE: Weak pointers must be invalidated before all other member variables. |
154 base::WeakPtrFactory<AudioSender> weak_factory_; | 154 base::WeakPtrFactory<AudioSender> weak_factory_; |
155 | 155 |
156 DISALLOW_COPY_AND_ASSIGN(AudioSender); | 156 DISALLOW_COPY_AND_ASSIGN(AudioSender); |
157 }; | 157 }; |
158 | 158 |
159 } // namespace cast | 159 } // namespace cast |
160 } // namespace media | 160 } // namespace media |
161 | 161 |
162 #endif // MEDIA_CAST_AUDIO_SENDER_H_ | 162 #endif // MEDIA_CAST_SENDER_AUDIO_SENDER_H_ |
OLD | NEW |