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

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: fix test 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
« no previous file with comments | « media/cast/sender/frame_sender.cc ('k') | media/cast/sender/video_sender.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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"
17 #include "media/cast/logging/logging_defines.h"
18 #include "media/cast/net/rtcp/rtcp.h"
19 #include "media/cast/sender/congestion_control.h" 16 #include "media/cast/sender/congestion_control.h"
20 #include "media/cast/sender/rtp_timestamp_helper.h" 17 #include "media/cast/sender/frame_sender.h"
21 18
22 namespace media { 19 namespace media {
23 20
24 class VideoFrame; 21 class VideoFrame;
25 22
26 namespace cast { 23 namespace cast {
27 24
28 class CastTransportSender; 25 class CastTransportSender;
29 class LocalVideoEncoderCallback;
30 class VideoEncoder; 26 class VideoEncoder;
31 27
32 // Not thread safe. Only called from the main cast thread. 28 // Not thread safe. Only called from the main cast thread.
33 // This class owns all objects related to sending video, objects that create RTP 29 // This class owns all objects related to sending video, objects that create RTP
34 // packets, congestion control, video encoder, parsing and sending of 30 // packets, congestion control, video encoder, parsing and sending of
35 // RTCP packets. 31 // RTCP packets.
36 // 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
37 // timeouts. 33 // timeouts.
38 class VideoSender : public RtcpSenderFeedback, 34 class VideoSender : public FrameSender,
39 public base::NonThreadSafe, 35 public base::NonThreadSafe,
40 public base::SupportsWeakPtr<VideoSender> { 36 public base::SupportsWeakPtr<VideoSender> {
41 public: 37 public:
42 VideoSender(scoped_refptr<CastEnvironment> cast_environment, 38 VideoSender(scoped_refptr<CastEnvironment> cast_environment,
43 const VideoSenderConfig& video_config, 39 const VideoSenderConfig& video_config,
44 const CreateVideoEncodeAcceleratorCallback& create_vea_cb, 40 const CreateVideoEncodeAcceleratorCallback& create_vea_cb,
45 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb, 41 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb,
46 CastTransportSender* const transport_sender); 42 CastTransportSender* const transport_sender);
47 43
48 virtual ~VideoSender(); 44 virtual ~VideoSender();
49 45
50 CastInitializationStatus InitializationResult() const { 46 CastInitializationStatus InitializationResult() const {
51 return cast_initialization_status_; 47 return cast_initialization_status_;
52 } 48 }
53 49
54 // Note: It is not guaranteed that |video_frame| will actually be encoded and 50 // 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 51 // sent, if VideoSender detects too many frames in flight. Therefore, clients
56 // should be careful about the rate at which this method is called. 52 // should be careful about the rate at which this method is called.
57 // 53 //
58 // Note: It is invalid to call this method if InitializationResult() returns 54 // Note: It is invalid to call this method if InitializationResult() returns
59 // anything but STATUS_VIDEO_INITIALIZED. 55 // anything but STATUS_VIDEO_INITIALIZED.
60 void InsertRawVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame, 56 void InsertRawVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame,
61 const base::TimeTicks& capture_time); 57 const base::TimeTicks& capture_time);
62 58
63 // Only called from the main cast thread.
64 void IncomingRtcpPacket(scoped_ptr<Packet> packet);
65
66 protected: 59 protected:
67 // Protected for testability. 60 // Protected for testability.
68 virtual void OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback) 61 void OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback);
69 OVERRIDE;
70 62
71 private: 63 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 64 // Schedule and execute periodic checks for re-sending packets. If no
77 // acknowledgements have been received for "too long," VideoSender will 65 // acknowledgements have been received for "too long," VideoSender will
78 // speculatively re-send certain packets of an unacked frame to kick-start 66 // 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 67 // re-transmission. This is a last resort tactic to prevent the session from
80 // getting stuck after a long outage. 68 // getting stuck after a long outage.
81 void ScheduleNextResendCheck(); 69 void ScheduleNextResendCheck();
82 void ResendCheck(); 70 void ResendCheck();
83 void ResendForKickstart(); 71 void ResendForKickstart();
84 72
85 // Returns true if there are too many frames in flight, as defined by the 73 // 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, 74 // configured target playout delay plus simple logic. When this is true,
87 // InsertRawVideoFrame() will silenty drop frames instead of sending them to 75 // InsertRawVideoFrame() will silenty drop frames instead of sending them to
88 // the video encoder. 76 // the video encoder.
89 bool AreTooManyFramesInFlight() const; 77 bool AreTooManyFramesInFlight() const;
90 78
91 // Called by the |video_encoder_| with the next EncodeFrame to send. 79 // Called by the |video_encoder_| with the next EncodeFrame to send.
92 void SendEncodedVideoFrame(int requested_bitrate_before_encode, 80 void SendEncodedVideoFrame(int requested_bitrate_before_encode,
93 scoped_ptr<EncodedFrame> encoded_frame); 81 scoped_ptr<EncodedFrame> encoded_frame);
94 82
95 const scoped_refptr<CastEnvironment> cast_environment_;
96
97 // The total amount of time between a frame's capture/recording on the sender 83 // 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 84 // 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, 85 // a value large enough to give the system sufficient time to encode,
100 // transmit/retransmit, receive, decode, and render; given its run-time 86 // transmit/retransmit, receive, decode, and render; given its run-time
101 // environment (sender/receiver hardware performance, network conditions, 87 // environment (sender/receiver hardware performance, network conditions,
102 // etc.). 88 // etc.).
103 const base::TimeDelta target_playout_delay_; 89 const base::TimeDelta target_playout_delay_;
104 90
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 91 // Maximum number of outstanding frames before the encoding and sending of
113 // new frames shall halt. 92 // new frames shall halt.
114 const int max_unacked_frames_; 93 const int max_unacked_frames_;
115 94
116 // Encodes media::VideoFrame images into EncodedFrames. Per configuration, 95 // Encodes media::VideoFrame images into EncodedFrames. Per configuration,
117 // this will point to either the internal software-based encoder or a proxy to 96 // this will point to either the internal software-based encoder or a proxy to
118 // a hardware-based encoder. 97 // a hardware-based encoder.
119 scoped_ptr<VideoEncoder> video_encoder_; 98 scoped_ptr<VideoEncoder> video_encoder_;
120 99
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 100 // 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 101 // frame) at the start of the session. Once a threshold is reached, RTCP
131 // reports are instead sent at the configured interval + random drift. 102 // reports are instead sent at the configured interval + random drift.
132 int num_aggressive_rtcp_reports_sent_; 103 int num_aggressive_rtcp_reports_sent_;
133 104
134 // The number of frames currently being processed in |video_encoder_|. 105 // The number of frames currently being processed in |video_encoder_|.
135 int frames_in_encoder_; 106 int frames_in_encoder_;
136 107
137 // This is "null" until the first frame is sent. Thereafter, this tracks the 108 // This is "null" until the first frame is sent. Thereafter, this tracks the
138 // last time any frame was sent or re-sent. 109 // 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. 141 // NOTE: Weak pointers must be invalidated before all other member variables.
171 base::WeakPtrFactory<VideoSender> weak_factory_; 142 base::WeakPtrFactory<VideoSender> weak_factory_;
172 143
173 DISALLOW_COPY_AND_ASSIGN(VideoSender); 144 DISALLOW_COPY_AND_ASSIGN(VideoSender);
174 }; 145 };
175 146
176 } // namespace cast 147 } // namespace cast
177 } // namespace media 148 } // namespace media
178 149
179 #endif // MEDIA_CAST_SENDER_VIDEO_SENDER_H_ 150 #endif // MEDIA_CAST_SENDER_VIDEO_SENDER_H_
OLDNEW
« no previous file with comments | « media/cast/sender/frame_sender.cc ('k') | media/cast/sender/video_sender.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698