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

Side by Side Diff: media/cast/sender/video_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_VIDEO_SENDER_H_ 5 #ifndef MEDIA_CAST_SENDER_VIDEO_SENDER_H_
6 #define MEDIA_CAST_SENDER_VIDEO_SENDER_H_ 6 #define MEDIA_CAST_SENDER_VIDEO_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/cast/cast_config.h" 15 #include "media/cast/cast_config.h"
16 #include "media/cast/cast_environment.h" 16 #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:47 Done.
17 #include "media/cast/logging/logging_defines.h" 17 #include "media/cast/logging/logging_defines.h"
18 #include "media/cast/net/rtcp/rtcp.h" 18 #include "media/cast/net/rtcp/rtcp.h"
19 #include "media/cast/sender/congestion_control.h" 19 #include "media/cast/sender/congestion_control.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 24
24 class VideoFrame; 25 class VideoFrame;
25 26
26 namespace cast { 27 namespace cast {
27 28
28 class CastTransportSender; 29 class CastTransportSender;
miu 2014/07/16 19:58:03 Remove this forward decl.
Alpha Left Google 2014/07/17 01:01:47 Done.
29 class LocalVideoEncoderCallback; 30 class LocalVideoEncoderCallback;
30 class VideoEncoder; 31 class VideoEncoder;
31 32
32 // Not thread safe. Only called from the main cast thread. 33 // Not thread safe. Only called from the main cast thread.
33 // This class owns all objects related to sending video, objects that create RTP 34 // This class owns all objects related to sending video, objects that create RTP
34 // packets, congestion control, video encoder, parsing and sending of 35 // packets, congestion control, video encoder, parsing and sending of
35 // RTCP packets. 36 // RTCP packets.
36 // Additionally it posts a bunch of delayed tasks to the main thread for various 37 // Additionally it posts a bunch of delayed tasks to the main thread for various
37 // timeouts. 38 // timeouts.
38 class VideoSender : public RtcpSenderFeedback, 39 class VideoSender : public FrameSender,
39 public base::NonThreadSafe, 40 public base::NonThreadSafe,
40 public base::SupportsWeakPtr<VideoSender> { 41 public base::SupportsWeakPtr<VideoSender> {
41 public: 42 public:
42 VideoSender(scoped_refptr<CastEnvironment> cast_environment, 43 VideoSender(scoped_refptr<CastEnvironment> cast_environment,
43 const VideoSenderConfig& video_config, 44 const VideoSenderConfig& video_config,
44 const CreateVideoEncodeAcceleratorCallback& create_vea_cb, 45 const CreateVideoEncodeAcceleratorCallback& create_vea_cb,
45 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb, 46 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb,
46 CastTransportSender* const transport_sender); 47 CastTransportSender* const transport_sender);
47 48
48 virtual ~VideoSender(); 49 virtual ~VideoSender();
49 50
50 CastInitializationStatus InitializationResult() const { 51 CastInitializationStatus InitializationResult() const {
miu 2014/07/16 19:58:03 ditto: Can be moved to FrameSender.
Alpha Left Google 2014/07/17 01:01:47 Let's do the merge for RTCP-unrelated items later.
51 return cast_initialization_status_; 52 return cast_initialization_status_;
52 } 53 }
53 54
54 // Note: It is not guaranteed that |video_frame| will actually be encoded and 55 // Note: It is not guaranteed that |video_frame| will actually be encoded and
55 // sent, if VideoSender detects too many frames in flight. Therefore, clients 56 // sent, if VideoSender detects too many frames in flight. Therefore, clients
56 // should be careful about the rate at which this method is called. 57 // should be careful about the rate at which this method is called.
57 // 58 //
58 // Note: It is invalid to call this method if InitializationResult() returns 59 // Note: It is invalid to call this method if InitializationResult() returns
59 // anything but STATUS_VIDEO_INITIALIZED. 60 // anything but STATUS_VIDEO_INITIALIZED.
60 void InsertRawVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame, 61 void InsertRawVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame,
61 const base::TimeTicks& capture_time); 62 const base::TimeTicks& capture_time);
62 63
63 // Only called from the main cast thread.
64 void IncomingRtcpPacket(scoped_ptr<Packet> packet);
65
66 protected: 64 protected:
67 // Protected for testability. 65 // Protected for testability.
68 virtual void OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback) 66 void OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback);
69 OVERRIDE;
70 67
71 private: 68 private:
72 // Schedule and execute periodic sending of RTCP report.
73 void ScheduleNextRtcpReport();
74 void SendRtcpReport(bool schedule_future_reports);
75
76 // Schedule and execute periodic checks for re-sending packets. If no 69 // Schedule and execute periodic checks for re-sending packets. If no
77 // acknowledgements have been received for "too long," VideoSender will 70 // acknowledgements have been received for "too long," VideoSender will
78 // speculatively re-send certain packets of an unacked frame to kick-start 71 // speculatively re-send certain packets of an unacked frame to kick-start
79 // re-transmission. This is a last resort tactic to prevent the session from 72 // re-transmission. This is a last resort tactic to prevent the session from
80 // getting stuck after a long outage. 73 // getting stuck after a long outage.
81 void ScheduleNextResendCheck(); 74 void ScheduleNextResendCheck();
82 void ResendCheck(); 75 void ResendCheck();
83 void ResendForKickstart(); 76 void ResendForKickstart();
84 77
85 // 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
86 // configured target playout delay plus simple logic. When this is true, 79 // configured target playout delay plus simple logic. When this is true,
87 // InsertRawVideoFrame() will silenty drop frames instead of sending them to 80 // InsertRawVideoFrame() will silenty drop frames instead of sending them to
88 // the video encoder. 81 // the video encoder.
89 bool AreTooManyFramesInFlight() const; 82 bool AreTooManyFramesInFlight() const;
90 83
91 // Called by the |video_encoder_| with the next EncodeFrame to send. 84 // Called by the |video_encoder_| with the next EncodeFrame to send.
92 void SendEncodedVideoFrame(int requested_bitrate_before_encode, 85 void SendEncodedVideoFrame(int requested_bitrate_before_encode,
93 scoped_ptr<EncodedFrame> encoded_frame); 86 scoped_ptr<EncodedFrame> encoded_frame);
94 87
95 const scoped_refptr<CastEnvironment> cast_environment_;
96
97 // The total amount of time between a frame's capture/recording on the sender 88 // The total amount of time between a frame's capture/recording on the sender
98 // and its playback on the receiver (i.e., shown to a user). This is fixed as 89 // and its playback on the receiver (i.e., shown to a user). This is fixed as
99 // a value large enough to give the system sufficient time to encode, 90 // a value large enough to give the system sufficient time to encode,
100 // transmit/retransmit, receive, decode, and render; given its run-time 91 // transmit/retransmit, receive, decode, and render; given its run-time
101 // environment (sender/receiver hardware performance, network conditions, 92 // environment (sender/receiver hardware performance, network conditions,
102 // etc.). 93 // etc.).
103 const base::TimeDelta target_playout_delay_; 94 const base::TimeDelta target_playout_delay_;
104 95
105 // Sends encoded frames over the configured transport (e.g., UDP). In
106 // Chromium, this could be a proxy that first sends the frames from a renderer
107 // process to the browser process over IPC, with the browser process being
108 // responsible for "packetizing" the frames and pushing packets into the
109 // network layer.
110 CastTransportSender* const transport_sender_;
111
112 // Maximum number of outstanding frames before the encoding and sending of 96 // Maximum number of outstanding frames before the encoding and sending of
113 // new frames shall halt. 97 // new frames shall halt.
114 const int max_unacked_frames_; 98 const int max_unacked_frames_;
115 99
116 // Encodes media::VideoFrame images into EncodedFrames. Per configuration, 100 // Encodes media::VideoFrame images into EncodedFrames. Per configuration,
117 // this will point to either the internal software-based encoder or a proxy to 101 // this will point to either the internal software-based encoder or a proxy to
118 // a hardware-based encoder. 102 // a hardware-based encoder.
119 scoped_ptr<VideoEncoder> video_encoder_; 103 scoped_ptr<VideoEncoder> video_encoder_;
120 104
121 // Manages sending/receiving of RTCP packets, including sender/receiver
122 // reports.
123 Rtcp rtcp_;
124
125 // Records lip-sync (i.e., mapping of RTP <--> NTP timestamps), and
126 // extrapolates this mapping to any other point in time.
127 RtpTimestampHelper rtp_timestamp_helper_;
128
129 // Counts how many RTCP reports are being "aggressively" sent (i.e., one per 105 // Counts how many RTCP reports are being "aggressively" sent (i.e., one per
130 // frame) at the start of the session. Once a threshold is reached, RTCP 106 // frame) at the start of the session. Once a threshold is reached, RTCP
131 // reports are instead sent at the configured interval + random drift. 107 // reports are instead sent at the configured interval + random drift.
132 int num_aggressive_rtcp_reports_sent_; 108 int num_aggressive_rtcp_reports_sent_;
133 109
134 // The number of frames currently being processed in |video_encoder_|. 110 // The number of frames currently being processed in |video_encoder_|.
135 int frames_in_encoder_; 111 int frames_in_encoder_;
136 112
137 // This is "null" until the first frame is sent. Thereafter, this tracks the 113 // This is "null" until the first frame is sent. Thereafter, this tracks the
138 // last time any frame was sent or re-sent. 114 // last time any frame was sent or re-sent.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 // NOTE: Weak pointers must be invalidated before all other member variables. 146 // NOTE: Weak pointers must be invalidated before all other member variables.
171 base::WeakPtrFactory<VideoSender> weak_factory_; 147 base::WeakPtrFactory<VideoSender> weak_factory_;
172 148
173 DISALLOW_COPY_AND_ASSIGN(VideoSender); 149 DISALLOW_COPY_AND_ASSIGN(VideoSender);
174 }; 150 };
175 151
176 } // namespace cast 152 } // namespace cast
177 } // namespace media 153 } // namespace media
178 154
179 #endif // MEDIA_CAST_SENDER_VIDEO_SENDER_H_ 155 #endif // MEDIA_CAST_SENDER_VIDEO_SENDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698