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_VIDEO_SENDER_VIDEO_SENDER_H_ | 5 #ifndef MEDIA_CAST_VIDEO_SENDER_VIDEO_SENDER_H_ |
6 #define MEDIA_CAST_VIDEO_SENDER_VIDEO_SENDER_H_ | 6 #define MEDIA_CAST_VIDEO_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" |
17 #include "media/cast/congestion_control/congestion_control.h" | 17 #include "media/cast/congestion_control/congestion_control.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/rtcp/rtcp.h" |
20 #include "media/cast/rtp_timestamp_helper.h" | 20 #include "media/cast/rtp_timestamp_helper.h" |
21 | 21 |
22 namespace media { | 22 namespace media { |
23 class VideoFrame; | 23 class VideoFrame; |
24 | 24 |
25 namespace cast { | 25 namespace cast { |
26 class LocalRtcpVideoSenderFeedback; | |
27 class LocalVideoEncoderCallback; | 26 class LocalVideoEncoderCallback; |
28 class VideoEncoder; | 27 class VideoEncoder; |
29 | 28 |
30 namespace transport { | 29 namespace transport { |
31 class CastTransportSender; | 30 class CastTransportSender; |
32 } | 31 } |
33 | 32 |
34 // Not thread safe. Only called from the main cast thread. | 33 // Not thread safe. Only called from the main cast thread. |
35 // 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 |
36 // packets, congestion control, video encoder, parsing and sending of | 35 // packets, congestion control, video encoder, parsing and sending of |
37 // RTCP packets. | 36 // RTCP packets. |
38 // 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 |
39 // timeouts. | 38 // timeouts. |
40 class VideoSender : public base::NonThreadSafe, | 39 class VideoSender : public RtcpSenderFeedback, |
| 40 public base::NonThreadSafe, |
41 public base::SupportsWeakPtr<VideoSender> { | 41 public base::SupportsWeakPtr<VideoSender> { |
42 public: | 42 public: |
43 VideoSender(scoped_refptr<CastEnvironment> cast_environment, | 43 VideoSender(scoped_refptr<CastEnvironment> cast_environment, |
44 const VideoSenderConfig& video_config, | 44 const VideoSenderConfig& video_config, |
45 const CreateVideoEncodeAcceleratorCallback& create_vea_cb, | 45 const CreateVideoEncodeAcceleratorCallback& create_vea_cb, |
46 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb, | 46 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb, |
47 const CastInitializationCallback& cast_initialization_cb, | 47 const CastInitializationCallback& cast_initialization_cb, |
48 transport::CastTransportSender* const transport_sender); | 48 transport::CastTransportSender* const transport_sender); |
49 | 49 |
50 virtual ~VideoSender(); | 50 virtual ~VideoSender(); |
51 | 51 |
52 // The video_frame must be valid until the closure callback is called. | 52 // The video_frame must be valid until the closure callback is called. |
53 // The closure callback is called from the video encoder thread as soon as | 53 // The closure callback is called from the video encoder thread as soon as |
54 // the encoder is done with the frame; it does not mean that the encoded frame | 54 // the encoder is done with the frame; it does not mean that the encoded frame |
55 // has been sent out. | 55 // has been sent out. |
56 void InsertRawVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame, | 56 void InsertRawVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame, |
57 const base::TimeTicks& capture_time); | 57 const base::TimeTicks& capture_time); |
58 | 58 |
59 // Only called from the main cast thread. | 59 // Only called from the main cast thread. |
60 void IncomingRtcpPacket(scoped_ptr<Packet> packet); | 60 void IncomingRtcpPacket(scoped_ptr<Packet> packet); |
61 | 61 |
62 protected: | 62 protected: |
63 // Protected for testability. | 63 // Protected for testability. |
64 void OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback); | 64 virtual void OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback) |
| 65 OVERRIDE; |
65 | 66 |
66 private: | 67 private: |
67 friend class LocalRtcpVideoSenderFeedback; | 68 friend class LocalRtcpVideoSenderFeedback; |
68 | 69 |
69 // Schedule when we should send the next RTPC report, | 70 // Schedule when we should send the next RTPC report, |
70 // via a PostDelayedTask to the main cast thread. | 71 // via a PostDelayedTask to the main cast thread. |
71 void ScheduleNextRtcpReport(); | 72 void ScheduleNextRtcpReport(); |
72 void SendRtcpReport(); | 73 void SendRtcpReport(bool schedule_future_reports); |
73 | 74 |
74 // Schedule when we should check that we have received an acknowledgment, or a | 75 // Schedule when we should check that we have received an acknowledgment, or a |
75 // loss report from our remote peer. If we have not heard back from our remote | 76 // loss report from our remote peer. If we have not heard back from our remote |
76 // peer we speculatively resend our oldest unacknowledged frame (the whole | 77 // peer we speculatively resend our oldest unacknowledged frame (the whole |
77 // frame). Note for this to happen we need to lose all pending packets (in | 78 // frame). Note for this to happen we need to lose all pending packets (in |
78 // normal operation 3 full frames), hence this is the last resort to prevent | 79 // normal operation 3 full frames), hence this is the last resort to prevent |
79 // us getting stuck after a long outage. | 80 // us getting stuck after a long outage. |
80 void ScheduleNextResendCheck(); | 81 void ScheduleNextResendCheck(); |
81 void ResendCheck(); | 82 void ResendCheck(); |
82 | 83 |
(...skipping 14 matching lines...) Expand all Loading... |
97 | 98 |
98 void UpdateBitrate(int32 new_bitrate); | 99 void UpdateBitrate(int32 new_bitrate); |
99 | 100 |
100 base::TimeDelta rtp_max_delay_; | 101 base::TimeDelta rtp_max_delay_; |
101 const int max_frame_rate_; | 102 const int max_frame_rate_; |
102 | 103 |
103 scoped_refptr<CastEnvironment> cast_environment_; | 104 scoped_refptr<CastEnvironment> cast_environment_; |
104 transport::CastTransportSender* const transport_sender_; | 105 transport::CastTransportSender* const transport_sender_; |
105 | 106 |
106 RtpTimestampHelper rtp_timestamp_helper_; | 107 RtpTimestampHelper rtp_timestamp_helper_; |
107 scoped_ptr<LocalRtcpVideoSenderFeedback> rtcp_feedback_; | |
108 scoped_ptr<VideoEncoder> video_encoder_; | 108 scoped_ptr<VideoEncoder> video_encoder_; |
109 scoped_ptr<Rtcp> rtcp_; | 109 scoped_ptr<Rtcp> rtcp_; |
| 110 int num_aggressive_rtcp_reports_sent_; |
110 uint8 max_unacked_frames_; | 111 uint8 max_unacked_frames_; |
111 int last_acked_frame_id_; | 112 int last_acked_frame_id_; |
112 int last_sent_frame_id_; | 113 int last_sent_frame_id_; |
113 int frames_in_encoder_; | 114 int frames_in_encoder_; |
114 int duplicate_ack_; | 115 int duplicate_ack_; |
115 base::TimeTicks last_send_time_; | 116 base::TimeTicks last_send_time_; |
116 base::TimeTicks last_checked_skip_count_time_; | 117 base::TimeTicks last_checked_skip_count_time_; |
117 int last_skip_count_; | 118 int last_skip_count_; |
118 int current_requested_bitrate_; | 119 int current_requested_bitrate_; |
119 // When we get close to the max number of un-acked frames, we set lower | 120 // When we get close to the max number of un-acked frames, we set lower |
(...skipping 16 matching lines...) Expand all Loading... |
136 // NOTE: Weak pointers must be invalidated before all other member variables. | 137 // NOTE: Weak pointers must be invalidated before all other member variables. |
137 base::WeakPtrFactory<VideoSender> weak_factory_; | 138 base::WeakPtrFactory<VideoSender> weak_factory_; |
138 | 139 |
139 DISALLOW_COPY_AND_ASSIGN(VideoSender); | 140 DISALLOW_COPY_AND_ASSIGN(VideoSender); |
140 }; | 141 }; |
141 | 142 |
142 } // namespace cast | 143 } // namespace cast |
143 } // namespace media | 144 } // namespace media |
144 | 145 |
145 #endif // MEDIA_CAST_VIDEO_SENDER_VIDEO_SENDER_H_ | 146 #endif // MEDIA_CAST_VIDEO_SENDER_VIDEO_SENDER_H_ |
OLD | NEW |