Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: media/cast/sender/audio_sender.h

Issue 387933005: Cast: Refactor RTCP handling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: smaller diff Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_SENDER_AUDIO_SENDER_H_ 5 #ifndef MEDIA_CAST_SENDER_AUDIO_SENDER_H_
6 #define MEDIA_CAST_SENDER_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"
miu 2014/07/16 19:58:03 You can remove the following includes: cast_envir
Alpha Left Google 2014/07/17 01:01:46 Done.
18 #include "media/cast/logging/logging_defines.h" 18 #include "media/cast/logging/logging_defines.h"
19 #include "media/cast/net/rtcp/rtcp.h" 19 #include "media/cast/net/rtcp/rtcp.h"
20 #include "media/cast/sender/frame_sender.h"
20 #include "media/cast/sender/rtp_timestamp_helper.h" 21 #include "media/cast/sender/rtp_timestamp_helper.h"
21 22
22 namespace media { 23 namespace media {
23 namespace cast { 24 namespace cast {
24 25
25 class AudioEncoder; 26 class AudioEncoder;
26 27
27 // Not thread safe. Only called from the main cast thread. 28 // Not thread safe. Only called from the main cast thread.
28 // This class owns all objects related to sending audio, objects that create RTP 29 // This class owns all objects related to sending audio, objects that create RTP
29 // packets, congestion control, audio encoder, parsing and sending of 30 // packets, congestion control, audio encoder, parsing and sending of
30 // RTCP packets. 31 // RTCP packets.
31 // Additionally it posts a bunch of delayed tasks to the main thread for various 32 // Additionally it posts a bunch of delayed tasks to the main thread for various
32 // timeouts. 33 // timeouts.
33 class AudioSender : public RtcpSenderFeedback, 34 class AudioSender : public FrameSender,
34 public base::NonThreadSafe, 35 public base::NonThreadSafe,
35 public base::SupportsWeakPtr<AudioSender> { 36 public base::SupportsWeakPtr<AudioSender> {
36 public: 37 public:
37 AudioSender(scoped_refptr<CastEnvironment> cast_environment, 38 AudioSender(scoped_refptr<CastEnvironment> cast_environment,
38 const AudioSenderConfig& audio_config, 39 const AudioSenderConfig& audio_config,
39 CastTransportSender* const transport_sender); 40 CastTransportSender* const transport_sender);
40 41
41 virtual ~AudioSender(); 42 virtual ~AudioSender();
42 43
43 CastInitializationStatus InitializationResult() const { 44 CastInitializationStatus InitializationResult() const {
miu 2014/07/16 19:58:03 This is common to both AudioSender and VideoSender
Alpha Left Google 2014/07/17 01:01:46 Let's do the merge separately.
44 return cast_initialization_status_; 45 return cast_initialization_status_;
45 } 46 }
46 47
47 // Note: It is not guaranteed that |audio_frame| will actually be encoded and 48 // 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 49 // sent, if AudioSender detects too many frames in flight. Therefore, clients
49 // should be careful about the rate at which this method is called. 50 // should be careful about the rate at which this method is called.
50 // 51 //
51 // Note: It is invalid to call this method if InitializationResult() returns 52 // Note: It is invalid to call this method if InitializationResult() returns
52 // anything but STATUS_AUDIO_INITIALIZED. 53 // anything but STATUS_AUDIO_INITIALIZED.
53 void InsertAudio(scoped_ptr<AudioBus> audio_bus, 54 void InsertAudio(scoped_ptr<AudioBus> audio_bus,
54 const base::TimeTicks& recorded_time); 55 const base::TimeTicks& recorded_time);
55 56
56 // Only called from the main cast thread.
57 void IncomingRtcpPacket(scoped_ptr<Packet> packet);
58
59 protected: 57 protected:
60 // Protected for testability. 58 // Protected for testability.
61 virtual void OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback) 59 void OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback);
62 OVERRIDE;
63 60
64 private: 61 private:
65 // Schedule and execute periodic sending of RTCP report.
66 void ScheduleNextRtcpReport();
67 void SendRtcpReport(bool schedule_future_reports);
68
69 // Schedule and execute periodic checks for re-sending packets. If no 62 // Schedule and execute periodic checks for re-sending packets. If no
70 // acknowledgements have been received for "too long," AudioSender will 63 // acknowledgements have been received for "too long," AudioSender will
71 // speculatively re-send certain packets of an unacked frame to kick-start 64 // speculatively re-send certain packets of an unacked frame to kick-start
72 // re-transmission. This is a last resort tactic to prevent the session from 65 // re-transmission. This is a last resort tactic to prevent the session from
73 // getting stuck after a long outage. 66 // getting stuck after a long outage.
74 void ScheduleNextResendCheck(); 67 void ScheduleNextResendCheck();
75 void ResendCheck(); 68 void ResendCheck();
76 void ResendForKickstart(); 69 void ResendForKickstart();
77 70
78 // Returns true if there are too many frames in flight, as defined by the 71 // 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, 72 // configured target playout delay plus simple logic. When this is true,
80 // InsertAudio() will silenty drop frames instead of sending them to the audio 73 // InsertAudio() will silenty drop frames instead of sending them to the audio
81 // encoder. 74 // encoder.
82 bool AreTooManyFramesInFlight() const; 75 bool AreTooManyFramesInFlight() const;
83 76
84 // Called by the |audio_encoder_| with the next EncodedFrame to send. 77 // Called by the |audio_encoder_| with the next EncodedFrame to send.
85 void SendEncodedAudioFrame(scoped_ptr<EncodedFrame> audio_frame); 78 void SendEncodedAudioFrame(scoped_ptr<EncodedFrame> audio_frame);
86 79
87 const scoped_refptr<CastEnvironment> cast_environment_;
88
89 // The total amount of time between a frame's capture/recording on the sender 80 // 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 81 // 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, 82 // a value large enough to give the system sufficient time to encode,
92 // transmit/retransmit, receive, decode, and render; given its run-time 83 // transmit/retransmit, receive, decode, and render; given its run-time
93 // environment (sender/receiver hardware performance, network conditions, 84 // environment (sender/receiver hardware performance, network conditions,
94 // etc.). 85 // etc.).
95 const base::TimeDelta target_playout_delay_; 86 const base::TimeDelta target_playout_delay_;
96 87
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
99 // process to the browser process over IPC, with the browser process being
100 // responsible for "packetizing" the frames and pushing packets into the
101 // network layer.
102 CastTransportSender* const transport_sender_;
103
104 // Maximum number of outstanding frames before the encoding and sending of 88 // Maximum number of outstanding frames before the encoding and sending of
105 // new frames shall halt. 89 // new frames shall halt.
106 const int max_unacked_frames_; 90 const int max_unacked_frames_;
107 91
108 // Encodes AudioBuses into EncodedFrames. 92 // Encodes AudioBuses into EncodedFrames.
109 scoped_ptr<AudioEncoder> audio_encoder_; 93 scoped_ptr<AudioEncoder> audio_encoder_;
110 const int configured_encoder_bitrate_; 94 const int configured_encoder_bitrate_;
111 95
112 // Manages sending/receiving of RTCP packets, including sender/receiver
113 // reports.
114 Rtcp rtcp_;
115
116 // Records lip-sync (i.e., mapping of RTP <--> NTP timestamps), and
117 // extrapolates this mapping to any other point in time.
118 RtpTimestampHelper rtp_timestamp_helper_;
119
120 // Counts how many RTCP reports are being "aggressively" sent (i.e., one per 96 // Counts how many RTCP reports are being "aggressively" sent (i.e., one per
121 // frame) at the start of the session. Once a threshold is reached, RTCP 97 // frame) at the start of the session. Once a threshold is reached, RTCP
122 // reports are instead sent at the configured interval + random drift. 98 // reports are instead sent at the configured interval + random drift.
123 int num_aggressive_rtcp_reports_sent_; 99 int num_aggressive_rtcp_reports_sent_;
124 100
125 // This is "null" until the first frame is sent. Thereafter, this tracks the 101 // This is "null" until the first frame is sent. Thereafter, this tracks the
126 // last time any frame was sent or re-sent. 102 // last time any frame was sent or re-sent.
127 base::TimeTicks last_send_time_; 103 base::TimeTicks last_send_time_;
128 104
129 // The ID of the last frame sent. Logic throughout AudioSender assumes this 105 // The ID of the last frame sent. Logic throughout AudioSender assumes this
(...skipping 23 matching lines...) Expand all
153 // NOTE: Weak pointers must be invalidated before all other member variables. 129 // NOTE: Weak pointers must be invalidated before all other member variables.
154 base::WeakPtrFactory<AudioSender> weak_factory_; 130 base::WeakPtrFactory<AudioSender> weak_factory_;
155 131
156 DISALLOW_COPY_AND_ASSIGN(AudioSender); 132 DISALLOW_COPY_AND_ASSIGN(AudioSender);
157 }; 133 };
158 134
159 } // namespace cast 135 } // namespace cast
160 } // namespace media 136 } // namespace media
161 137
162 #endif // MEDIA_CAST_SENDER_AUDIO_SENDER_H_ 138 #endif // MEDIA_CAST_SENDER_AUDIO_SENDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698