blob: 7181143c0598ec9ad32ac496c96a35ba7a7535e3 [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,
Rasmus Brandtc402dbe2019-02-04 11:09:46 +010045 VideoEncoderConfig::ContentType content_type,
Niels Möller0327c2d2018-05-21 14:09:31 +020046 int min_transmit_bitrate_bps) = 0;
47 };
48
Niels Möller0327c2d2018-05-21 14:09:31 +020049 // Sets the source that will provide video frames to the VideoStreamEncoder's
50 // OnFrame method. |degradation_preference| control whether or not resolution
51 // or frame rate may be reduced. The VideoStreamEncoder registers itself with
52 // |source|, and signals adaptation decisions to the source in the form of
53 // VideoSinkWants.
54 // TODO(nisse): When adaptation logic is extracted from this class,
55 // it no longer needs to know the source.
56 virtual void SetSource(
57 rtc::VideoSourceInterface<VideoFrame>* source,
58 const DegradationPreference& degradation_preference) = 0;
59
60 // Sets the |sink| that gets the encoded frames. |rotation_applied| means
61 // that the source must support rotation. Only set |rotation_applied| if the
62 // remote side does not support the rotation extension.
63 virtual void SetSink(EncoderSink* sink, bool rotation_applied) = 0;
64
65 // Sets an initial bitrate, later overriden by OnBitrateUpdated. Mainly
66 // affects the resolution of the initial key frame: If incoming frames are
67 // larger than reasonable for the start bitrate, and scaling is enabled,
68 // VideoStreamEncoder asks the source to scale down and drops a few initial
69 // frames.
70 // TODO(nisse): This is a poor interface, and mixes bandwidth estimation and
71 // codec configuration in an undesired way. For the actual send bandwidth, we
72 // should always be somewhat conservative, but we may nevertheless want to let
73 // the application configure a more optimistic quality for the initial
74 // resolution. Should be replaced by a construction time setting.
75 virtual void SetStartBitrate(int start_bitrate_bps) = 0;
76
77 // Request a key frame. Used for signalling from the remote receiver.
78 virtual void SendKeyFrame() = 0;
79
80 // Set the currently estimated network properties. A |bitrate_bps|
81 // of zero pauses the encoder.
82 virtual void OnBitrateUpdated(uint32_t bitrate_bps,
83 uint8_t fraction_lost,
84 int64_t round_trip_time_ms) = 0;
85
86 // Register observer for the bitrate allocation between the temporal
87 // and spatial layers.
88 virtual void SetBitrateAllocationObserver(
89 VideoBitrateAllocationObserver* bitrate_observer) = 0;
90
91 // Creates and configures an encoder with the given |config|. The
92 // |max_data_payload_length| is used to support single NAL unit
93 // packetization for H.264.
94 virtual void ConfigureEncoder(VideoEncoderConfig config,
95 size_t max_data_payload_length) = 0;
96
97 // Permanently stop encoding. After this method has returned, it is
98 // guaranteed that no encoded frames will be delivered to the sink.
99 virtual void Stop() = 0;
100};
101
102} // namespace webrtc
103
104#endif // API_VIDEO_VIDEO_STREAM_ENCODER_INTERFACE_H_