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 <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 class VideoFrameFactory; | 31 class VideoFrameFactory; |
32 | 32 |
33 typedef base::Callback<void(base::TimeDelta)> PlayoutDelayChangeCB; | 33 typedef base::Callback<void(base::TimeDelta)> PlayoutDelayChangeCB; |
34 | 34 |
35 // Not thread safe. Only called from the main cast thread. | 35 // Not thread safe. Only called from the main cast thread. |
36 // This class owns all objects related to sending video, objects that create RTP | 36 // This class owns all objects related to sending video, objects that create RTP |
37 // packets, congestion control, video encoder, parsing and sending of | 37 // packets, congestion control, video encoder, parsing and sending of |
38 // RTCP packets. | 38 // RTCP packets. |
39 // Additionally it posts a bunch of delayed tasks to the main thread for various | 39 // Additionally it posts a bunch of delayed tasks to the main thread for various |
40 // timeouts. | 40 // timeouts. |
41 class VideoSender : public FrameSender, | 41 class VideoSender : public FrameSender, public base::NonThreadSafe { |
42 public base::NonThreadSafe, | |
43 public base::SupportsWeakPtr<VideoSender> { | |
44 public: | 42 public: |
45 VideoSender(scoped_refptr<CastEnvironment> cast_environment, | 43 VideoSender(scoped_refptr<CastEnvironment> cast_environment, |
46 const FrameSenderConfig& video_config, | 44 const FrameSenderConfig& video_config, |
47 const StatusChangeCallback& status_change_cb, | 45 const StatusChangeCallback& status_change_cb, |
48 const CreateVideoEncodeAcceleratorCallback& create_vea_cb, | 46 const CreateVideoEncodeAcceleratorCallback& create_vea_cb, |
49 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb, | 47 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb, |
50 CastTransport* const transport_sender, | 48 CastTransport* const transport_sender, |
51 const PlayoutDelayChangeCB& playout_delay_change_cb); | 49 const PlayoutDelayChangeCB& playout_delay_change_cb); |
52 | 50 |
53 ~VideoSender() override; | 51 ~VideoSender() override; |
54 | 52 |
55 // Note: It is not guaranteed that |video_frame| will actually be encoded and | 53 // Note: It is not guaranteed that |video_frame| will actually be encoded and |
56 // sent, if VideoSender detects too many frames in flight. Therefore, clients | 54 // sent, if VideoSender detects too many frames in flight. Therefore, clients |
57 // should be careful about the rate at which this method is called. | 55 // should be careful about the rate at which this method is called. |
58 void InsertRawVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame, | 56 void InsertRawVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame, |
59 const base::TimeTicks& reference_time); | 57 const base::TimeTicks& reference_time); |
60 | 58 |
61 // Creates a |VideoFrameFactory| object to vend |VideoFrame| object with | 59 // Creates a |VideoFrameFactory| object to vend |VideoFrame| object with |
62 // encoder affinity (defined as offering some sort of performance benefit). If | 60 // encoder affinity (defined as offering some sort of performance benefit). If |
63 // the encoder does not have any such capability, returns null. | 61 // the encoder does not have any such capability, returns null. |
64 std::unique_ptr<VideoFrameFactory> CreateVideoFrameFactory(); | 62 std::unique_ptr<VideoFrameFactory> CreateVideoFrameFactory(); |
65 | 63 |
| 64 base::WeakPtr<VideoSender> AsWeakPtr(); |
| 65 |
66 protected: | 66 protected: |
67 int GetNumberOfFramesInEncoder() const final; | 67 int GetNumberOfFramesInEncoder() const final; |
68 base::TimeDelta GetInFlightMediaDuration() const final; | 68 base::TimeDelta GetInFlightMediaDuration() const final; |
69 | 69 |
70 private: | 70 private: |
71 // Called by the |video_encoder_| with the next EncodedFrame to send. | 71 // Called by the |video_encoder_| with the next EncodedFrame to send. |
72 void OnEncodedVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame, | 72 void OnEncodedVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame, |
73 int encoder_bitrate, | 73 int encoder_bitrate, |
74 std::unique_ptr<SenderEncodedFrame> encoded_frame); | 74 std::unique_ptr<SenderEncodedFrame> encoded_frame); |
75 | 75 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 // NOTE: Weak pointers must be invalidated before all other member variables. | 113 // NOTE: Weak pointers must be invalidated before all other member variables. |
114 base::WeakPtrFactory<VideoSender> weak_factory_; | 114 base::WeakPtrFactory<VideoSender> weak_factory_; |
115 | 115 |
116 DISALLOW_COPY_AND_ASSIGN(VideoSender); | 116 DISALLOW_COPY_AND_ASSIGN(VideoSender); |
117 }; | 117 }; |
118 | 118 |
119 } // namespace cast | 119 } // namespace cast |
120 } // namespace media | 120 } // namespace media |
121 | 121 |
122 #endif // MEDIA_CAST_SENDER_VIDEO_SENDER_H_ | 122 #endif // MEDIA_CAST_SENDER_VIDEO_SENDER_H_ |
OLD | NEW |