Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / media / cast / sender / video_sender.h
blob826321cf5b3d211577c36ec98c374701d37971f9
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
3 // found in the LICENSE file.
5 #ifndef MEDIA_CAST_SENDER_VIDEO_SENDER_H_
6 #define MEDIA_CAST_SENDER_VIDEO_SENDER_H_
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/threading/non_thread_safe.h"
13 #include "base/time/tick_clock.h"
14 #include "base/time/time.h"
15 #include "media/cast/cast_config.h"
16 #include "media/cast/sender/congestion_control.h"
17 #include "media/cast/sender/frame_sender.h"
19 namespace media {
21 class VideoFrame;
23 namespace cast {
25 class CastTransportSender;
26 class VideoEncoder;
27 class VideoFrameFactory;
29 typedef base::Callback<void(base::TimeDelta)> PlayoutDelayChangeCB;
31 // Not thread safe. Only called from the main cast thread.
32 // This class owns all objects related to sending video, objects that create RTP
33 // packets, congestion control, video encoder, parsing and sending of
34 // RTCP packets.
35 // Additionally it posts a bunch of delayed tasks to the main thread for various
36 // timeouts.
37 class VideoSender : public FrameSender,
38 public base::NonThreadSafe,
39 public base::SupportsWeakPtr<VideoSender> {
40 public:
41 VideoSender(scoped_refptr<CastEnvironment> cast_environment,
42 const VideoSenderConfig& video_config,
43 const StatusChangeCallback& status_change_cb,
44 const CreateVideoEncodeAcceleratorCallback& create_vea_cb,
45 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb,
46 CastTransportSender* const transport_sender,
47 const PlayoutDelayChangeCB& playout_delay_change_cb);
49 ~VideoSender() override;
51 // Note: It is not guaranteed that |video_frame| will actually be encoded and
52 // sent, if VideoSender detects too many frames in flight. Therefore, clients
53 // should be careful about the rate at which this method is called.
54 void InsertRawVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame,
55 const base::TimeTicks& reference_time);
57 // Creates a |VideoFrameFactory| object to vend |VideoFrame| object with
58 // encoder affinity (defined as offering some sort of performance benefit). If
59 // the encoder does not have any such capability, returns null.
60 scoped_ptr<VideoFrameFactory> CreateVideoFrameFactory();
62 protected:
63 int GetNumberOfFramesInEncoder() const final;
64 base::TimeDelta GetInFlightMediaDuration() const final;
65 void OnAck(uint32 frame_id) final;
67 // Return the maximum target bitrate that should be used for the given video
68 // |frame|. This will be provided to CongestionControl as a soft maximum
69 // limit, and should be interpreted as "the point above which the extra
70 // encoder CPU time + network bandwidth usage isn't warranted for the amount
71 // of further quality improvement to be gained."
72 static int GetMaximumTargetBitrateForFrame(const media::VideoFrame& frame);
74 private:
75 // Called by the |video_encoder_| with the next EncodedFrame to send.
76 void OnEncodedVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame,
77 int encoder_bitrate,
78 scoped_ptr<SenderEncodedFrame> encoded_frame);
80 // Encodes media::VideoFrame images into EncodedFrames. Per configuration,
81 // this will point to either the internal software-based encoder or a proxy to
82 // a hardware-based encoder.
83 scoped_ptr<VideoEncoder> video_encoder_;
85 // The number of frames queued for encoding, but not yet sent.
86 int frames_in_encoder_;
88 // The duration of video queued for encoding, but not yet sent.
89 base::TimeDelta duration_in_encoder_;
91 // The timestamp of the frame that was last enqueued in |video_encoder_|.
92 RtpTimestamp last_enqueued_frame_rtp_timestamp_;
93 base::TimeTicks last_enqueued_frame_reference_time_;
95 // Remember what we set the bitrate to before, no need to set it again if
96 // we get the same value.
97 int last_bitrate_;
99 PlayoutDelayChangeCB playout_delay_change_cb_;
101 // The video encoder's performance metrics as of the last call to
102 // OnEncodedVideoFrame(). See header file comments for SenderEncodedFrame for
103 // an explanation of these values.
104 double last_reported_deadline_utilization_;
105 double last_reported_lossy_utilization_;
107 // NOTE: Weak pointers must be invalidated before all other member variables.
108 base::WeakPtrFactory<VideoSender> weak_factory_;
110 DISALLOW_COPY_AND_ASSIGN(VideoSender);
113 } // namespace cast
114 } // namespace media
116 #endif // MEDIA_CAST_SENDER_VIDEO_SENDER_H_