blob: 0cd9ddcead6d1c134d5bf642b1d4ed1eae70a99d [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.
Niels Möllerefd70342019-01-22 10:35:42 +010017#include "api/video/video_bitrate_allocator.h"
Niels Möller0327c2d2018-05-21 14:09:31 +020018#include "api/video/video_sink_interface.h"
19#include "api/video/video_source_interface.h"
20#include "api/video_codecs/video_encoder.h"
21#include "api/video_codecs/video_encoder_config.h"
22
23namespace webrtc {
24
Niels Möller0327c2d2018-05-21 14:09:31 +020025// This interface represents a class responsible for creating and driving the
26// encoder(s) for a single video stream. It is also responsible for adaptation
27// decisions related to video quality, requesting reduced frame rate or
28// resolution from the VideoSource when needed.
29// TODO(bugs.webrtc.org/8830): This interface is under development. Changes
30// under consideration include:
31//
32// 1. Taking out responsibility for adaptation decisions, instead only reporting
33// per-frame measurements to the decision maker.
34//
35// 2. Moving responsibility for simulcast and for software fallback into this
36// class.
37class VideoStreamEncoderInterface : public rtc::VideoSinkInterface<VideoFrame> {
38 public:
39 // Interface for receiving encoded video frames and notifications about
40 // configuration changes.
41 class EncoderSink : public EncodedImageCallback {
42 public:
43 virtual void OnEncoderConfigurationChanged(
44 std::vector<VideoStream> streams,
45 int min_transmit_bitrate_bps) = 0;
46 };
47
Niels Möller0327c2d2018-05-21 14:09:31 +020048 // Sets the source that will provide video frames to the VideoStreamEncoder's
49 // OnFrame method. |degradation_preference| control whether or not resolution
50 // or frame rate may be reduced. The VideoStreamEncoder registers itself with
51 // |source|, and signals adaptation decisions to the source in the form of
52 // VideoSinkWants.
53 // TODO(nisse): When adaptation logic is extracted from this class,
54 // it no longer needs to know the source.
55 virtual void SetSource(
56 rtc::VideoSourceInterface<VideoFrame>* source,
57 const DegradationPreference& degradation_preference) = 0;
58
59 // Sets the |sink| that gets the encoded frames. |rotation_applied| means
60 // that the source must support rotation. Only set |rotation_applied| if the
61 // remote side does not support the rotation extension.
62 virtual void SetSink(EncoderSink* sink, bool rotation_applied) = 0;
63
64 // Sets an initial bitrate, later overriden by OnBitrateUpdated. Mainly
65 // affects the resolution of the initial key frame: If incoming frames are
66 // larger than reasonable for the start bitrate, and scaling is enabled,
67 // VideoStreamEncoder asks the source to scale down and drops a few initial
68 // frames.
69 // TODO(nisse): This is a poor interface, and mixes bandwidth estimation and
70 // codec configuration in an undesired way. For the actual send bandwidth, we
71 // should always be somewhat conservative, but we may nevertheless want to let
72 // the application configure a more optimistic quality for the initial
73 // resolution. Should be replaced by a construction time setting.
74 virtual void SetStartBitrate(int start_bitrate_bps) = 0;
75
76 // Request a key frame. Used for signalling from the remote receiver.
77 virtual void SendKeyFrame() = 0;
78
79 // Set the currently estimated network properties. A |bitrate_bps|
80 // of zero pauses the encoder.
81 virtual void OnBitrateUpdated(uint32_t bitrate_bps,
82 uint8_t fraction_lost,
83 int64_t round_trip_time_ms) = 0;
84
85 // Register observer for the bitrate allocation between the temporal
86 // and spatial layers.
87 virtual void SetBitrateAllocationObserver(
88 VideoBitrateAllocationObserver* bitrate_observer) = 0;
89
90 // Creates and configures an encoder with the given |config|. The
91 // |max_data_payload_length| is used to support single NAL unit
92 // packetization for H.264.
93 virtual void ConfigureEncoder(VideoEncoderConfig config,
94 size_t max_data_payload_length) = 0;
95
96 // Permanently stop encoding. After this method has returned, it is
97 // guaranteed that no encoded frames will be delivered to the sink.
98 virtual void Stop() = 0;
99};
100
101} // namespace webrtc
102
103#endif // API_VIDEO_VIDEO_STREAM_ENCODER_INTERFACE_H_