blob: aaf017d2bab8c803f8f5f39feaf8935dbd172db5 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
stefan@webrtc.org439be292012-02-16 14:45:37 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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// This sub-API supports the following functionalities:
12// - Setting send and receive codecs.
13// - Codec specific settings.
14// - Key frame signaling.
15// - Stream management settings.
16
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000017#ifndef WEBRTC_VIDEO_ENGINE_INCLUDE_VIE_CODEC_H_
18#define WEBRTC_VIDEO_ENGINE_INCLUDE_VIE_CODEC_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000019
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000020#include "webrtc/common_types.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000021
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000022namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000023
24class VideoEngine;
25struct VideoCodec;
26
niklase@google.com470e71d2011-07-07 08:21:25 +000027// This class declares an abstract interface for a user defined observer. It is
28// up to the VideoEngine user to implement a derived class which implements the
29// observer class. The observer is registered using RegisterEncoderObserver()
30// and deregistered using DeregisterEncoderObserver().
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000031class WEBRTC_DLLEXPORT ViEEncoderObserver {
32 public:
33 // This method is called once per second with the current encoded frame rate
34 // and bit rate.
35 virtual void OutgoingRate(const int video_channel,
36 const unsigned int framerate,
37 const unsigned int bitrate) = 0;
henrik.lundin@webrtc.org7ea4f242013-10-02 13:34:26 +000038
henrik.lundin@webrtc.orgce8e0932013-11-18 12:18:43 +000039 // This method is called whenever the state of the SuspendBelowMinBitrate
40 // changes, i.e., when |is_suspended| toggles.
henrik.lundin@webrtc.org245037d2013-12-05 12:01:45 +000041 virtual void SuspendChange(int video_channel, bool is_suspended) = 0;
henrik.lundin@webrtc.org7ea4f242013-10-02 13:34:26 +000042
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000043 protected:
44 virtual ~ViEEncoderObserver() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000045};
46
niklase@google.com470e71d2011-07-07 08:21:25 +000047// This class declares an abstract interface for a user defined observer. It is
48// up to the VideoEngine user to implement a derived class which implements the
49// observer class. The observer is registered using RegisterDecoderObserver()
50// and deregistered using DeregisterDecoderObserver().
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000051class WEBRTC_DLLEXPORT ViEDecoderObserver {
52 public:
53 // This method is called when a new incoming stream is detected, normally
54 // triggered by a new incoming SSRC or payload type.
55 virtual void IncomingCodecChanged(const int video_channel,
56 const VideoCodec& video_codec) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000057
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000058 // This method is called once per second containing the frame rate and bit
59 // rate for the incoming stream
60 virtual void IncomingRate(const int video_channel,
61 const unsigned int framerate,
62 const unsigned int bitrate) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000063
fischman@webrtc.org37bb4972013-10-23 23:59:45 +000064 // Called periodically with decoder timing information. All values are
65 // "current" snapshots unless decorated with a min_/max_ prefix.
fischman@webrtc.org37bb4972013-10-23 23:59:45 +000066 virtual void DecoderTiming(int decode_ms,
67 int max_decode_ms,
68 int current_delay_ms,
69 int target_delay_ms,
70 int jitter_buffer_ms,
71 int min_playout_delay_ms,
fischman@webrtc.orgb7a17182013-10-28 17:36:59 +000072 int render_delay_ms) = 0;
fischman@webrtc.org37bb4972013-10-23 23:59:45 +000073
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000074 // This method is called when the decoder needs a new key frame from encoder
75 // on the sender.
76 virtual void RequestNewKeyFrame(const int video_channel) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000077
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000078 protected:
79 virtual ~ViEDecoderObserver() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000080};
81
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000082class WEBRTC_DLLEXPORT ViECodec {
83 public:
84 // Factory for the ViECodec sub‐API and increases an internal reference
85 // counter if successful. Returns NULL if the API is not supported or if
86 // construction fails.
87 static ViECodec* GetInterface(VideoEngine* video_engine);
niklase@google.com470e71d2011-07-07 08:21:25 +000088
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000089 // Releases the ViECodec sub-API and decreases an internal reference
90 // counter.
91 // Returns the new reference count. This value should be zero
92 // for all sub-API:s before the VideoEngine object can be safely deleted.
93 virtual int Release() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000094
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000095 // Gets the number of available codecs for the VideoEngine build.
96 virtual int NumberOfCodecs() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000097
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000098 // Gets a VideoCodec struct for a codec containing the default configuration
99 // for that codec type.
100 virtual int GetCodec(const unsigned char list_number,
101 VideoCodec& video_codec) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000102
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000103 // Sets the send codec to use for a specified channel.
104 virtual int SetSendCodec(const int video_channel,
105 const VideoCodec& video_codec) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000106
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000107 // Gets the current send codec settings.
108 virtual int GetSendCodec(const int video_channel,
109 VideoCodec& video_codec) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000110
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000111 // Prepares VideoEngine to receive a certain codec type and setting for a
112 // specified payload type.
113 virtual int SetReceiveCodec(const int video_channel,
114 const VideoCodec& video_codec) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000115
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000116 // Gets the current receive codec.
117 virtual int GetReceiveCodec(const int video_channel,
118 VideoCodec& video_codec) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000119
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000120 // This function is used to get codec configuration parameters to be
121 // signaled from the encoder to the decoder in the call setup.
122 virtual int GetCodecConfigParameters(
123 const int video_channel,
124 unsigned char config_parameters[kConfigParameterSize],
125 unsigned char& config_parameters_size) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000126
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000127 // Enables advanced scaling of the captured video stream if the stream
128 // differs from the send codec settings.
129 virtual int SetImageScaleStatus(const int video_channel,
130 const bool enable) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000131
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000132 // Gets the number of sent key frames and number of sent delta frames.
133 virtual int GetSendCodecStastistics(const int video_channel,
134 unsigned int& key_frames,
135 unsigned int& delta_frames) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000136
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000137 // Gets the number of decoded key frames and number of decoded delta frames.
138 virtual int GetReceiveCodecStastistics(const int video_channel,
139 unsigned int& key_frames,
140 unsigned int& delta_frames) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000141
mflodman@webrtc.org4aee6b62012-12-14 14:02:10 +0000142 // Estimate of the min required buffer time from the expected arrival time
143 // until rendering to get smooth playback.
144 virtual int GetReceiveSideDelay(const int video_channel,
145 int* delay_ms) const = 0;
146
stefan@webrtc.org439be292012-02-16 14:45:37 +0000147 // Gets the bitrate targeted by the video codec rate control in kbit/s.
148 virtual int GetCodecTargetBitrate(const int video_channel,
149 unsigned int* bitrate) const = 0;
150
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000151 // Gets the number of packets discarded by the jitter buffer because they
152 // arrived too late.
153 virtual unsigned int GetDiscardedPackets(const int video_channel) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000154
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000155 // Enables key frame request callback in ViEDecoderObserver.
156 virtual int SetKeyFrameRequestCallbackStatus(const int video_channel,
157 const bool enable) = 0;
stefan@webrtc.org791eec72011-10-11 07:53:43 +0000158
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000159 // Enables key frame requests for detected lost packets.
160 virtual int SetSignalKeyPacketLossStatus(
161 const int video_channel,
162 const bool enable,
163 const bool only_key_frames = false) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000164
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000165 // Registers an instance of a user implementation of the ViEEncoderObserver.
166 virtual int RegisterEncoderObserver(const int video_channel,
167 ViEEncoderObserver& observer) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000168
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000169 // Removes an already registered instance of ViEEncoderObserver.
170 virtual int DeregisterEncoderObserver(const int video_channel) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000171
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000172 // Registers an instance of a user implementation of the ViEDecoderObserver.
173 virtual int RegisterDecoderObserver(const int video_channel,
174 ViEDecoderObserver& observer) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000175
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000176 // Removes an already registered instance of ViEDecoderObserver.
177 virtual int DeregisterDecoderObserver(const int video_channel) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000178
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000179 // This function forces the next encoded frame to be a key frame. This is
180 // normally used when the remote endpoint only supports out‐band key frame
181 // request.
182 virtual int SendKeyFrame(const int video_channel) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000183
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000184 // This function makes the decoder wait for a key frame before starting to
185 // decode the incoming video stream.
186 virtual int WaitForFirstKeyFrame(const int video_channel,
187 const bool wait) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000188
mflodman@webrtc.org1c986e72013-06-26 09:12:49 +0000189 // Enables recording of debugging information.
190 virtual int StartDebugRecording(int video_channel,
191 const char* file_name_utf8) = 0;
192 // Disables recording of debugging information.
193 virtual int StopDebugRecording(int video_channel) = 0;
194
henrik.lundin@webrtc.orgce8e0932013-11-18 12:18:43 +0000195 // Lets the sender suspend video when the rate drops below
henrik.lundin@webrtc.org7ea4f242013-10-02 13:34:26 +0000196 // |threshold_bps|, and turns back on when the rate goes back up above
197 // |threshold_bps| + |window_bps|.
198 // This is under development; not tested.
henrik.lundin@webrtc.org245037d2013-12-05 12:01:45 +0000199 virtual void SuspendBelowMinBitrate(int video_channel) = 0;
henrik.lundin@webrtc.org7ea4f242013-10-02 13:34:26 +0000200
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000201 protected:
202 ViECodec() {}
203 virtual ~ViECodec() {}
niklase@google.com470e71d2011-07-07 08:21:25 +0000204};
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000205
206} // namespace webrtc
207
208#endif // WEBRTC_VIDEO_ENGINE_INCLUDE_VIE_CODEC_H_