| 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_SENDER_VIDEO_SENDER_H_ |
| 6 #define MEDIA_CAST_VIDEO_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" |
| 17 #include "media/cast/congestion_control/congestion_control.h" | |
| 18 #include "media/cast/logging/logging_defines.h" | 17 #include "media/cast/logging/logging_defines.h" |
| 19 #include "media/cast/rtcp/rtcp.h" | 18 #include "media/cast/net/rtcp/rtcp.h" |
| 20 #include "media/cast/rtp_timestamp_helper.h" | 19 #include "media/cast/sender/congestion_control.h" |
| 20 #include "media/cast/sender/rtp_timestamp_helper.h" |
| 21 | 21 |
| 22 namespace media { | 22 namespace media { |
| 23 | 23 |
| 24 class VideoFrame; | 24 class VideoFrame; |
| 25 | 25 |
| 26 namespace cast { | 26 namespace cast { |
| 27 | 27 |
| 28 class CastTransportSender; |
| 28 class LocalVideoEncoderCallback; | 29 class LocalVideoEncoderCallback; |
| 29 class VideoEncoder; | 30 class VideoEncoder; |
| 30 | 31 |
| 31 namespace transport { | |
| 32 class CastTransportSender; | |
| 33 } | |
| 34 | |
| 35 // Not thread safe. Only called from the main cast thread. | 32 // Not thread safe. Only called from the main cast thread. |
| 36 // This class owns all objects related to sending video, objects that create RTP | 33 // This class owns all objects related to sending video, objects that create RTP |
| 37 // packets, congestion control, video encoder, parsing and sending of | 34 // packets, congestion control, video encoder, parsing and sending of |
| 38 // RTCP packets. | 35 // RTCP packets. |
| 39 // Additionally it posts a bunch of delayed tasks to the main thread for various | 36 // Additionally it posts a bunch of delayed tasks to the main thread for various |
| 40 // timeouts. | 37 // timeouts. |
| 41 class VideoSender : public RtcpSenderFeedback, | 38 class VideoSender : public RtcpSenderFeedback, |
| 42 public base::NonThreadSafe, | 39 public base::NonThreadSafe, |
| 43 public base::SupportsWeakPtr<VideoSender> { | 40 public base::SupportsWeakPtr<VideoSender> { |
| 44 public: | 41 public: |
| 45 VideoSender(scoped_refptr<CastEnvironment> cast_environment, | 42 VideoSender(scoped_refptr<CastEnvironment> cast_environment, |
| 46 const VideoSenderConfig& video_config, | 43 const VideoSenderConfig& video_config, |
| 47 const CreateVideoEncodeAcceleratorCallback& create_vea_cb, | 44 const CreateVideoEncodeAcceleratorCallback& create_vea_cb, |
| 48 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb, | 45 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb, |
| 49 transport::CastTransportSender* const transport_sender); | 46 CastTransportSender* const transport_sender); |
| 50 | 47 |
| 51 virtual ~VideoSender(); | 48 virtual ~VideoSender(); |
| 52 | 49 |
| 53 CastInitializationStatus InitializationResult() const { | 50 CastInitializationStatus InitializationResult() const { |
| 54 return cast_initialization_status_; | 51 return cast_initialization_status_; |
| 55 } | 52 } |
| 56 | 53 |
| 57 // Note: It is not guaranteed that |video_frame| will actually be encoded and | 54 // Note: It is not guaranteed that |video_frame| will actually be encoded and |
| 58 // sent, if VideoSender detects too many frames in flight. Therefore, clients | 55 // sent, if VideoSender detects too many frames in flight. Therefore, clients |
| 59 // should be careful about the rate at which this method is called. | 56 // should be careful about the rate at which this method is called. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 86 void ResendForKickstart(); | 83 void ResendForKickstart(); |
| 87 | 84 |
| 88 // Returns true if there are too many frames in flight, as defined by the | 85 // Returns true if there are too many frames in flight, as defined by the |
| 89 // configured target playout delay plus simple logic. When this is true, | 86 // configured target playout delay plus simple logic. When this is true, |
| 90 // InsertRawVideoFrame() will silenty drop frames instead of sending them to | 87 // InsertRawVideoFrame() will silenty drop frames instead of sending them to |
| 91 // the video encoder. | 88 // the video encoder. |
| 92 bool AreTooManyFramesInFlight() const; | 89 bool AreTooManyFramesInFlight() const; |
| 93 | 90 |
| 94 // Called by the |video_encoder_| with the next EncodeFrame to send. | 91 // Called by the |video_encoder_| with the next EncodeFrame to send. |
| 95 void SendEncodedVideoFrame(int requested_bitrate_before_encode, | 92 void SendEncodedVideoFrame(int requested_bitrate_before_encode, |
| 96 scoped_ptr<transport::EncodedFrame> encoded_frame); | 93 scoped_ptr<EncodedFrame> encoded_frame); |
| 97 | 94 |
| 98 const scoped_refptr<CastEnvironment> cast_environment_; | 95 const scoped_refptr<CastEnvironment> cast_environment_; |
| 99 | 96 |
| 100 // The total amount of time between a frame's capture/recording on the sender | 97 // The total amount of time between a frame's capture/recording on the sender |
| 101 // and its playback on the receiver (i.e., shown to a user). This is fixed as | 98 // and its playback on the receiver (i.e., shown to a user). This is fixed as |
| 102 // a value large enough to give the system sufficient time to encode, | 99 // a value large enough to give the system sufficient time to encode, |
| 103 // transmit/retransmit, receive, decode, and render; given its run-time | 100 // transmit/retransmit, receive, decode, and render; given its run-time |
| 104 // environment (sender/receiver hardware performance, network conditions, | 101 // environment (sender/receiver hardware performance, network conditions, |
| 105 // etc.). | 102 // etc.). |
| 106 const base::TimeDelta target_playout_delay_; | 103 const base::TimeDelta target_playout_delay_; |
| 107 | 104 |
| 108 // Sends encoded frames over the configured transport (e.g., UDP). In | 105 // Sends encoded frames over the configured transport (e.g., UDP). In |
| 109 // Chromium, this could be a proxy that first sends the frames from a renderer | 106 // Chromium, this could be a proxy that first sends the frames from a renderer |
| 110 // process to the browser process over IPC, with the browser process being | 107 // process to the browser process over IPC, with the browser process being |
| 111 // responsible for "packetizing" the frames and pushing packets into the | 108 // responsible for "packetizing" the frames and pushing packets into the |
| 112 // network layer. | 109 // network layer. |
| 113 transport::CastTransportSender* const transport_sender_; | 110 CastTransportSender* const transport_sender_; |
| 114 | 111 |
| 115 // Maximum number of outstanding frames before the encoding and sending of | 112 // Maximum number of outstanding frames before the encoding and sending of |
| 116 // new frames shall halt. | 113 // new frames shall halt. |
| 117 const int max_unacked_frames_; | 114 const int max_unacked_frames_; |
| 118 | 115 |
| 119 // Encodes media::VideoFrame images into EncodedFrames. Per configuration, | 116 // Encodes media::VideoFrame images into EncodedFrames. Per configuration, |
| 120 // this will point to either the internal software-based encoder or a proxy to | 117 // this will point to either the internal software-based encoder or a proxy to |
| 121 // a hardware-based encoder. | 118 // a hardware-based encoder. |
| 122 scoped_ptr<VideoEncoder> video_encoder_; | 119 scoped_ptr<VideoEncoder> video_encoder_; |
| 123 | 120 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 169 |
| 173 // NOTE: Weak pointers must be invalidated before all other member variables. | 170 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 174 base::WeakPtrFactory<VideoSender> weak_factory_; | 171 base::WeakPtrFactory<VideoSender> weak_factory_; |
| 175 | 172 |
| 176 DISALLOW_COPY_AND_ASSIGN(VideoSender); | 173 DISALLOW_COPY_AND_ASSIGN(VideoSender); |
| 177 }; | 174 }; |
| 178 | 175 |
| 179 } // namespace cast | 176 } // namespace cast |
| 180 } // namespace media | 177 } // namespace media |
| 181 | 178 |
| 182 #endif // MEDIA_CAST_VIDEO_SENDER_VIDEO_SENDER_H_ | 179 #endif // MEDIA_CAST_SENDER_VIDEO_SENDER_H_ |
| OLD | NEW |