Remove INJECT_EVENTS permissions from test APKs.
[chromium-blink-merge.git] / media / cast / sender / video_sender.h
blobac5d6d06dcdad676bd65567c8388b0d34d8f95b2
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 private:
68 // Called by the |video_encoder_| with the next EncodedFrame to send.
69 void OnEncodedVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame,
70 int encoder_bitrate,
71 scoped_ptr<SenderEncodedFrame> encoded_frame);
73 // Encodes media::VideoFrame images into EncodedFrames. Per configuration,
74 // this will point to either the internal software-based encoder or a proxy to
75 // a hardware-based encoder.
76 scoped_ptr<VideoEncoder> video_encoder_;
78 // The number of frames queued for encoding, but not yet sent.
79 int frames_in_encoder_;
81 // The duration of video queued for encoding, but not yet sent.
82 base::TimeDelta duration_in_encoder_;
84 // The timestamp of the frame that was last enqueued in |video_encoder_|.
85 RtpTimestamp last_enqueued_frame_rtp_timestamp_;
86 base::TimeTicks last_enqueued_frame_reference_time_;
88 // Remember what we set the bitrate to before, no need to set it again if
89 // we get the same value.
90 uint32 last_bitrate_;
92 PlayoutDelayChangeCB playout_delay_change_cb_;
94 // The video encoder's performance metrics as of the last call to
95 // OnEncodedVideoFrame(). See header file comments for SenderEncodedFrame for
96 // an explanation of these values.
97 double last_reported_deadline_utilization_;
98 double last_reported_lossy_utilization_;
100 // NOTE: Weak pointers must be invalidated before all other member variables.
101 base::WeakPtrFactory<VideoSender> weak_factory_;
103 DISALLOW_COPY_AND_ASSIGN(VideoSender);
106 } // namespace cast
107 } // namespace media
109 #endif // MEDIA_CAST_SENDER_VIDEO_SENDER_H_