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 #include "media/cast/transport/utility/transport_encryption_handler.h" | |
21 | 22 |
22 namespace media { | 23 namespace media { |
23 class VideoFrame; | 24 class VideoFrame; |
24 | 25 |
25 namespace cast { | 26 namespace cast { |
26 class LocalVideoEncoderCallback; | 27 class LocalVideoEncoderCallback; |
27 class VideoEncoder; | 28 class VideoEncoder; |
28 | 29 |
29 namespace transport { | 30 namespace transport { |
30 class CastTransportSender; | 31 class CastTransportSender; |
31 } | 32 } |
32 | 33 |
33 // Not thread safe. Only called from the main cast thread. | 34 // Not thread safe. Only called from the main cast thread. |
34 // This class owns all objects related to sending video, objects that create RTP | 35 // This class owns all objects related to sending video, objects that create RTP |
35 // packets, congestion control, video encoder, parsing and sending of | 36 // packets, congestion control, video encoder, parsing and sending of |
36 // RTCP packets. | 37 // RTCP packets. |
37 // Additionally it posts a bunch of delayed tasks to the main thread for various | 38 // Additionally it posts a bunch of delayed tasks to the main thread for various |
38 // timeouts. | 39 // timeouts. |
39 class VideoSender : public RtcpSenderFeedback, | 40 class VideoSender : public RtcpSenderFeedback, |
40 public base::NonThreadSafe, | 41 public base::NonThreadSafe, |
41 public base::SupportsWeakPtr<VideoSender> { | 42 public base::SupportsWeakPtr<VideoSender> { |
42 public: | 43 public: |
43 VideoSender(scoped_refptr<CastEnvironment> cast_environment, | 44 VideoSender(scoped_refptr<CastEnvironment> cast_environment, |
44 const VideoSenderConfig& video_config, | 45 const VideoSenderConfig& video_config, |
45 const CreateVideoEncodeAcceleratorCallback& create_vea_cb, | 46 const CreateVideoEncodeAcceleratorCallback& create_vea_cb, |
46 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb, | 47 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_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 CastInitializationStatus InitializationResult() const { | |
53 return cast_initialization_status_; | |
54 } | |
55 | |
52 // The video_frame must be valid until the closure callback is called. | 56 // 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 | 57 // 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 | 58 // the encoder is done with the frame; it does not mean that the encoded frame |
55 // has been sent out. | 59 // has been sent out. |
60 // | |
61 // Note: It is invalid to call this method if InitializationResult() returns | |
62 // anything but STATUS_VIDEO_INITIALIZED. | |
56 void InsertRawVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame, | 63 void InsertRawVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame, |
57 const base::TimeTicks& capture_time); | 64 const base::TimeTicks& capture_time); |
58 | 65 |
59 // Only called from the main cast thread. | 66 // Only called from the main cast thread. |
60 void IncomingRtcpPacket(scoped_ptr<Packet> packet); | 67 void IncomingRtcpPacket(scoped_ptr<Packet> packet); |
61 | 68 |
62 protected: | 69 protected: |
63 // Protected for testability. | 70 // Protected for testability. |
64 virtual void OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback) | 71 virtual void OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback) |
65 OVERRIDE; | 72 OVERRIDE; |
(...skipping 17 matching lines...) Expand all Loading... | |
83 | 90 |
84 // Monitor how many frames that are silently dropped by the video sender | 91 // Monitor how many frames that are silently dropped by the video sender |
85 // per time unit. | 92 // per time unit. |
86 void ScheduleNextSkippedFramesCheck(); | 93 void ScheduleNextSkippedFramesCheck(); |
87 void SkippedFramesCheck(); | 94 void SkippedFramesCheck(); |
88 | 95 |
89 void ResendFrame(uint32 resend_frame_id); | 96 void ResendFrame(uint32 resend_frame_id); |
90 void ReceivedAck(uint32 acked_frame_id); | 97 void ReceivedAck(uint32 acked_frame_id); |
91 void UpdateFramesInFlight(); | 98 void UpdateFramesInFlight(); |
92 | 99 |
93 void SendEncodedVideoFrameMainThread( | 100 // Called by the |video_encoder_| with the next EncodeFrame to send. If |
94 int requested_bitrate_before_encode, | 101 // encryption is enabled, |encoded_frame->data| is encrypted before sending |
95 scoped_ptr<transport::EncodedFrame> encoded_frame); | 102 // using |transport_sender_|. |
103 void SendEncodedVideoFrame(int requested_bitrate_before_encode, | |
104 scoped_ptr<transport::EncodedFrame> encoded_frame); | |
96 | 105 |
97 void InitializeTimers(); | 106 void InitializeTimers(); |
98 | 107 |
99 void UpdateBitrate(int32 new_bitrate); | 108 void UpdateBitrate(int32 new_bitrate); |
100 | 109 |
101 base::TimeDelta rtp_max_delay_; | 110 base::TimeDelta rtp_max_delay_; |
102 const int max_frame_rate_; | 111 const int max_frame_rate_; |
103 | 112 |
104 scoped_refptr<CastEnvironment> cast_environment_; | 113 scoped_refptr<CastEnvironment> cast_environment_; |
105 transport::CastTransportSender* const transport_sender_; | 114 transport::CastTransportSender* const transport_sender_; |
106 | 115 |
107 RtpTimestampHelper rtp_timestamp_helper_; | 116 RtpTimestampHelper rtp_timestamp_helper_; |
108 scoped_ptr<VideoEncoder> video_encoder_; | 117 scoped_ptr<VideoEncoder> video_encoder_; |
109 scoped_ptr<Rtcp> rtcp_; | 118 scoped_ptr<Rtcp> rtcp_; |
110 int num_aggressive_rtcp_reports_sent_; | 119 int num_aggressive_rtcp_reports_sent_; |
111 uint8 max_unacked_frames_; | 120 uint8 max_unacked_frames_; |
112 int last_acked_frame_id_; | 121 int last_acked_frame_id_; |
113 int last_sent_frame_id_; | 122 int last_sent_frame_id_; |
114 int frames_in_encoder_; | 123 int frames_in_encoder_; |
115 int duplicate_ack_; | 124 int duplicate_ack_; |
116 base::TimeTicks last_send_time_; | 125 base::TimeTicks last_send_time_; |
117 base::TimeTicks last_checked_skip_count_time_; | 126 base::TimeTicks last_checked_skip_count_time_; |
118 int last_skip_count_; | 127 int last_skip_count_; |
119 int current_requested_bitrate_; | 128 int current_requested_bitrate_; |
120 // When we get close to the max number of un-acked frames, we set lower | 129 // When we get close to the max number of un-acked frames, we set lower |
121 // the bitrate drastically to ensure that we catch up. Without this we | 130 // the bitrate drastically to ensure that we catch up. Without this we |
122 // risk getting stuck in a catch-up state forever. | 131 // risk getting stuck in a catch-up state forever. |
123 CongestionControl congestion_control_; | 132 CongestionControl congestion_control_; |
124 | 133 |
134 // Encrypts data in EncodedFrames before they are sent. | |
135 transport::TransportEncryptionHandler encryptor_; | |
Alpha Left Google
2014/06/03 20:01:52
Same here. It is by design to perform encryption i
miu
2014/06/03 21:55:15
Done.
| |
136 | |
137 // If this sender is ready for use, this is STATUS_VIDEO_INITIALIZED. | |
138 CastInitializationStatus cast_initialization_status_; | |
139 | |
125 // This is a "good enough" mapping for finding the RTP timestamp associated | 140 // This is a "good enough" mapping for finding the RTP timestamp associated |
126 // with a video frame. The key is the lowest 8 bits of frame id (which is | 141 // with a video frame. The key is the lowest 8 bits of frame id (which is |
127 // what is sent via RTCP). This map is used for logging purposes. The only | 142 // what is sent via RTCP). This map is used for logging purposes. The only |
128 // time when this mapping will be incorrect is when it receives an ACK for a | 143 // time when this mapping will be incorrect is when it receives an ACK for a |
129 // old enough frame such that 8-bit wrap around has already occurred, which | 144 // old enough frame such that 8-bit wrap around has already occurred, which |
130 // should be pretty rare. | 145 // should be pretty rare. |
131 RtpTimestamp frame_id_to_rtp_timestamp_[256]; | 146 RtpTimestamp frame_id_to_rtp_timestamp_[256]; |
132 | 147 |
133 bool initialized_; | 148 bool initialized_; |
134 // Indicator for receiver acknowledgments. | 149 // Indicator for receiver acknowledgments. |
135 bool active_session_; | 150 bool active_session_; |
136 | 151 |
137 // NOTE: Weak pointers must be invalidated before all other member variables. | 152 // NOTE: Weak pointers must be invalidated before all other member variables. |
138 base::WeakPtrFactory<VideoSender> weak_factory_; | 153 base::WeakPtrFactory<VideoSender> weak_factory_; |
139 | 154 |
140 DISALLOW_COPY_AND_ASSIGN(VideoSender); | 155 DISALLOW_COPY_AND_ASSIGN(VideoSender); |
141 }; | 156 }; |
142 | 157 |
143 } // namespace cast | 158 } // namespace cast |
144 } // namespace media | 159 } // namespace media |
145 | 160 |
146 #endif // MEDIA_CAST_VIDEO_SENDER_VIDEO_SENDER_H_ | 161 #endif // MEDIA_CAST_VIDEO_SENDER_VIDEO_SENDER_H_ |
OLD | NEW |