blob: 54631185a2d390dfed6b24bce907330484bbb4a6 [file] [log] [blame]
Niels Möller0327c2d2018-05-21 14:09:31 +02001/*
2 * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef API_VIDEO_VIDEO_STREAM_ENCODER_INTERFACE_H_
12#define API_VIDEO_VIDEO_STREAM_ENCODER_INTERFACE_H_
13
14#include <vector>
15
Steve Anton10542f22019-01-11 09:11:00 -080016#include "api/rtp_parameters.h" // For DegradationPreference.
Erik Språng610c7632019-03-06 15:37:33 +010017#include "api/units/data_rate.h"
Niels Möllerefd70342019-01-22 10:35:42 +010018#include "api/video/video_bitrate_allocator.h"
Niels Möller0327c2d2018-05-21 14:09:31 +020019#include "api/video/video_sink_interface.h"
20#include "api/video/video_source_interface.h"
21#include "api/video_codecs/video_encoder.h"
22#include "api/video_codecs/video_encoder_config.h"
23
24namespace webrtc {
25
Niels Möller0327c2d2018-05-21 14:09:31 +020026// This interface represents a class responsible for creating and driving the
27// encoder(s) for a single video stream. It is also responsible for adaptation
28// decisions related to video quality, requesting reduced frame rate or
29// resolution from the VideoSource when needed.
30// TODO(bugs.webrtc.org/8830): This interface is under development. Changes
31// under consideration include:
32//
33// 1. Taking out responsibility for adaptation decisions, instead only reporting
34// per-frame measurements to the decision maker.
35//
36// 2. Moving responsibility for simulcast and for software fallback into this
37// class.
38class VideoStreamEncoderInterface : public rtc::VideoSinkInterface<VideoFrame> {
39 public:
40 // Interface for receiving encoded video frames and notifications about
41 // configuration changes.
42 class EncoderSink : public EncodedImageCallback {
43 public:
44 virtual void OnEncoderConfigurationChanged(
45 std::vector<VideoStream> streams,
Rasmus Brandtc402dbe2019-02-04 11:09:46 +010046 VideoEncoderConfig::ContentType content_type,
Niels Möller0327c2d2018-05-21 14:09:31 +020047 int min_transmit_bitrate_bps) = 0;
48 };
49
Niels Möller0327c2d2018-05-21 14:09:31 +020050 // Sets the source that will provide video frames to the VideoStreamEncoder's
51 // OnFrame method. |degradation_preference| control whether or not resolution
52 // or frame rate may be reduced. The VideoStreamEncoder registers itself with
53 // |source|, and signals adaptation decisions to the source in the form of
54 // VideoSinkWants.
55 // TODO(nisse): When adaptation logic is extracted from this class,
56 // it no longer needs to know the source.
57 virtual void SetSource(
58 rtc::VideoSourceInterface<VideoFrame>* source,
59 const DegradationPreference& degradation_preference) = 0;
60
61 // Sets the |sink| that gets the encoded frames. |rotation_applied| means
62 // that the source must support rotation. Only set |rotation_applied| if the
63 // remote side does not support the rotation extension.
64 virtual void SetSink(EncoderSink* sink, bool rotation_applied) = 0;
65
66 // Sets an initial bitrate, later overriden by OnBitrateUpdated. Mainly
67 // affects the resolution of the initial key frame: If incoming frames are
68 // larger than reasonable for the start bitrate, and scaling is enabled,
69 // VideoStreamEncoder asks the source to scale down and drops a few initial
70 // frames.
71 // TODO(nisse): This is a poor interface, and mixes bandwidth estimation and
72 // codec configuration in an undesired way. For the actual send bandwidth, we
73 // should always be somewhat conservative, but we may nevertheless want to let
74 // the application configure a more optimistic quality for the initial
75 // resolution. Should be replaced by a construction time setting.
76 virtual void SetStartBitrate(int start_bitrate_bps) = 0;
77
78 // Request a key frame. Used for signalling from the remote receiver.
79 virtual void SendKeyFrame() = 0;
80
Erik Språng4c6ca302019-04-08 15:14:01 +020081 // Set the currently estimated network properties. A |target_bitrate|
Niels Möller0327c2d2018-05-21 14:09:31 +020082 // of zero pauses the encoder.
Erik Språng4c6ca302019-04-08 15:14:01 +020083 // |link_allocation| is the bandwidth available for this video stream on the
84 // network link. It is always at least |target_bitrate| but may be higher
85 // if we are not network constrained.
Erik Språng610c7632019-03-06 15:37:33 +010086 virtual void OnBitrateUpdated(DataRate target_bitrate,
Erik Språng4c6ca302019-04-08 15:14:01 +020087 DataRate link_allocation,
Niels Möller0327c2d2018-05-21 14:09:31 +020088 uint8_t fraction_lost,
89 int64_t round_trip_time_ms) = 0;
90
91 // Register observer for the bitrate allocation between the temporal
92 // and spatial layers.
93 virtual void SetBitrateAllocationObserver(
94 VideoBitrateAllocationObserver* bitrate_observer) = 0;
95
96 // Creates and configures an encoder with the given |config|. The
97 // |max_data_payload_length| is used to support single NAL unit
98 // packetization for H.264.
99 virtual void ConfigureEncoder(VideoEncoderConfig config,
100 size_t max_data_payload_length) = 0;
101
102 // Permanently stop encoding. After this method has returned, it is
103 // guaranteed that no encoded frames will be delivered to the sink.
104 virtual void Stop() = 0;
105};
106
107} // namespace webrtc
108
109#endif // API_VIDEO_VIDEO_STREAM_ENCODER_INTERFACE_H_