OLD | NEW |
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" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 // 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 |
51 // sent, if VideoSender detects too many frames in flight. Therefore, clients | 51 // sent, if VideoSender detects too many frames in flight. Therefore, clients |
52 // 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. |
53 // | 53 // |
54 // Note: It is invalid to call this method if InitializationResult() returns | 54 // Note: It is invalid to call this method if InitializationResult() returns |
55 // anything but STATUS_VIDEO_INITIALIZED. | 55 // anything but STATUS_VIDEO_INITIALIZED. |
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 protected: | 59 protected: |
60 // Protected for testability. | 60 virtual void OnAck(uint32 frame_id) OVERRIDE; |
61 void OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback); | |
62 | 61 |
63 private: | 62 private: |
64 // Returns true if there are too many frames in flight, or if the media | |
65 // duration of the frames in flight would be too high by sending the next | |
66 // frame. The latter metric is determined from the given |capture_time| | |
67 // for the next frame to be encoded and sent. | |
68 bool ShouldDropNextFrame(base::TimeTicks capture_time) const; | |
69 | |
70 // Called by the |video_encoder_| with the next EncodeFrame to send. | |
71 void SendEncodedVideoFrame(int requested_bitrate_before_encode, | |
72 scoped_ptr<EncodedFrame> encoded_frame); | |
73 // If this value is non zero then a fixed value is used for bitrate. | |
74 // If external video encoder is used then bitrate will be fixed to | |
75 // (min_bitrate + max_bitrate) / 2. | |
76 const size_t fixed_bitrate_; | |
77 | |
78 // Encodes media::VideoFrame images into EncodedFrames. Per configuration, | 63 // Encodes media::VideoFrame images into EncodedFrames. Per configuration, |
79 // this will point to either the internal software-based encoder or a proxy to | 64 // this will point to either the internal software-based encoder or a proxy to |
80 // a hardware-based encoder. | 65 // a hardware-based encoder. |
81 scoped_ptr<VideoEncoder> video_encoder_; | 66 scoped_ptr<VideoEncoder> video_encoder_; |
82 | 67 |
83 // The number of frames currently being processed in |video_encoder_|. | 68 // Remember what we set the bitrate to before, no need to set it again if |
84 int frames_in_encoder_; | 69 // we get the same value. |
85 | 70 uint32 last_bitrate_; |
86 // When we get close to the max number of un-acked frames, we set lower | |
87 // the bitrate drastically to ensure that we catch up. Without this we | |
88 // risk getting stuck in a catch-up state forever. | |
89 CongestionControl congestion_control_; | |
90 | 71 |
91 // NOTE: Weak pointers must be invalidated before all other member variables. | 72 // NOTE: Weak pointers must be invalidated before all other member variables. |
92 base::WeakPtrFactory<VideoSender> weak_factory_; | 73 base::WeakPtrFactory<VideoSender> weak_factory_; |
93 | 74 |
94 DISALLOW_COPY_AND_ASSIGN(VideoSender); | 75 DISALLOW_COPY_AND_ASSIGN(VideoSender); |
95 }; | 76 }; |
96 | 77 |
97 } // namespace cast | 78 } // namespace cast |
98 } // namespace media | 79 } // namespace media |
99 | 80 |
100 #endif // MEDIA_CAST_SENDER_VIDEO_SENDER_H_ | 81 #endif // MEDIA_CAST_SENDER_VIDEO_SENDER_H_ |
OLD | NEW |