blob: bddcc3a654110027ac8f24ace4e69dcd8d55b614 [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.org7ea4f242013-10-02 13:34:26 +000041 // TODO(hlundin): Remove the default implementation when possible.
henrik.lundin@webrtc.org9fe36032013-11-21 23:00:40 +000042 virtual void SuspendChange(int video_channel, bool is_suspended) {}
henrik.lundin@webrtc.org7ea4f242013-10-02 13:34:26 +000043
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000044 protected:
45 virtual ~ViEEncoderObserver() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000046};
47
niklase@google.com470e71d2011-07-07 08:21:25 +000048// This class declares an abstract interface for a user defined observer. It is
49// up to the VideoEngine user to implement a derived class which implements the
50// observer class. The observer is registered using RegisterDecoderObserver()
51// and deregistered using DeregisterDecoderObserver().
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000052class WEBRTC_DLLEXPORT ViEDecoderObserver {
53 public:
54 // This method is called when a new incoming stream is detected, normally
55 // triggered by a new incoming SSRC or payload type.
56 virtual void IncomingCodecChanged(const int video_channel,
57 const VideoCodec& video_codec) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000058
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000059 // This method is called once per second containing the frame rate and bit
60 // rate for the incoming stream
61 virtual void IncomingRate(const int video_channel,
62 const unsigned int framerate,
63 const unsigned int bitrate) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000064
fischman@webrtc.org37bb4972013-10-23 23:59:45 +000065 // Called periodically with decoder timing information. All values are
66 // "current" snapshots unless decorated with a min_/max_ prefix.
fischman@webrtc.org37bb4972013-10-23 23:59:45 +000067 virtual void DecoderTiming(int decode_ms,
68 int max_decode_ms,
69 int current_delay_ms,
70 int target_delay_ms,
71 int jitter_buffer_ms,
72 int min_playout_delay_ms,
fischman@webrtc.orgb7a17182013-10-28 17:36:59 +000073 int render_delay_ms) = 0;
fischman@webrtc.org37bb4972013-10-23 23:59:45 +000074
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000075 // This method is called when the decoder needs a new key frame from encoder
76 // on the sender.
77 virtual void RequestNewKeyFrame(const int video_channel) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000078
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000079 protected:
80 virtual ~ViEDecoderObserver() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000081};
82
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000083class WEBRTC_DLLEXPORT ViECodec {
84 public:
85 // Factory for the ViECodec sub‐API and increases an internal reference
86 // counter if successful. Returns NULL if the API is not supported or if
87 // construction fails.
88 static ViECodec* GetInterface(VideoEngine* video_engine);
niklase@google.com470e71d2011-07-07 08:21:25 +000089
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000090 // Releases the ViECodec sub-API and decreases an internal reference
91 // counter.
92 // Returns the new reference count. This value should be zero
93 // for all sub-API:s before the VideoEngine object can be safely deleted.
94 virtual int Release() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000095
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000096 // Gets the number of available codecs for the VideoEngine build.
97 virtual int NumberOfCodecs() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000098
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000099 // Gets a VideoCodec struct for a codec containing the default configuration
100 // for that codec type.
101 virtual int GetCodec(const unsigned char list_number,
102 VideoCodec& video_codec) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000103
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000104 // Sets the send codec to use for a specified channel.
105 virtual int SetSendCodec(const int video_channel,
106 const VideoCodec& video_codec) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000107
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000108 // Gets the current send codec settings.
109 virtual int GetSendCodec(const int video_channel,
110 VideoCodec& video_codec) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000111
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000112 // Prepares VideoEngine to receive a certain codec type and setting for a
113 // specified payload type.
114 virtual int SetReceiveCodec(const int video_channel,
115 const VideoCodec& video_codec) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000116
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000117 // Gets the current receive codec.
118 virtual int GetReceiveCodec(const int video_channel,
119 VideoCodec& video_codec) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000120
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000121 // This function is used to get codec configuration parameters to be
122 // signaled from the encoder to the decoder in the call setup.
123 virtual int GetCodecConfigParameters(
124 const int video_channel,
125 unsigned char config_parameters[kConfigParameterSize],
126 unsigned char& config_parameters_size) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000127
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000128 // Enables advanced scaling of the captured video stream if the stream
129 // differs from the send codec settings.
130 virtual int SetImageScaleStatus(const int video_channel,
131 const bool enable) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000132
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000133 // Gets the number of sent key frames and number of sent delta frames.
134 virtual int GetSendCodecStastistics(const int video_channel,
135 unsigned int& key_frames,
136 unsigned int& delta_frames) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000137
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000138 // Gets the number of decoded key frames and number of decoded delta frames.
139 virtual int GetReceiveCodecStastistics(const int video_channel,
140 unsigned int& key_frames,
141 unsigned int& delta_frames) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000142
mflodman@webrtc.org4aee6b62012-12-14 14:02:10 +0000143 // Estimate of the min required buffer time from the expected arrival time
144 // until rendering to get smooth playback.
145 virtual int GetReceiveSideDelay(const int video_channel,
146 int* delay_ms) const = 0;
147
stefan@webrtc.org439be292012-02-16 14:45:37 +0000148 // Gets the bitrate targeted by the video codec rate control in kbit/s.
149 virtual int GetCodecTargetBitrate(const int video_channel,
150 unsigned int* bitrate) const = 0;
151
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000152 // Gets the number of packets discarded by the jitter buffer because they
153 // arrived too late.
154 virtual unsigned int GetDiscardedPackets(const int video_channel) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000155
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000156 // Enables key frame request callback in ViEDecoderObserver.
157 virtual int SetKeyFrameRequestCallbackStatus(const int video_channel,
158 const bool enable) = 0;
stefan@webrtc.org791eec72011-10-11 07:53:43 +0000159
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000160 // Enables key frame requests for detected lost packets.
161 virtual int SetSignalKeyPacketLossStatus(
162 const int video_channel,
163 const bool enable,
164 const bool only_key_frames = false) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000165
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000166 // Registers an instance of a user implementation of the ViEEncoderObserver.
167 virtual int RegisterEncoderObserver(const int video_channel,
168 ViEEncoderObserver& observer) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000169
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000170 // Removes an already registered instance of ViEEncoderObserver.
171 virtual int DeregisterEncoderObserver(const int video_channel) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000172
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000173 // Registers an instance of a user implementation of the ViEDecoderObserver.
174 virtual int RegisterDecoderObserver(const int video_channel,
175 ViEDecoderObserver& observer) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000176
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000177 // Removes an already registered instance of ViEDecoderObserver.
178 virtual int DeregisterDecoderObserver(const int video_channel) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000179
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000180 // This function forces the next encoded frame to be a key frame. This is
181 // normally used when the remote endpoint only supports out‐band key frame
182 // request.
183 virtual int SendKeyFrame(const int video_channel) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000184
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000185 // This function makes the decoder wait for a key frame before starting to
186 // decode the incoming video stream.
187 virtual int WaitForFirstKeyFrame(const int video_channel,
188 const bool wait) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000189
mflodman@webrtc.org1c986e72013-06-26 09:12:49 +0000190 // Enables recording of debugging information.
191 virtual int StartDebugRecording(int video_channel,
192 const char* file_name_utf8) = 0;
193 // Disables recording of debugging information.
194 virtual int StopDebugRecording(int video_channel) = 0;
195
henrik.lundin@webrtc.orgce8e0932013-11-18 12:18:43 +0000196 // Lets the sender suspend video when the rate drops below
henrik.lundin@webrtc.org7ea4f242013-10-02 13:34:26 +0000197 // |threshold_bps|, and turns back on when the rate goes back up above
198 // |threshold_bps| + |window_bps|.
199 // This is under development; not tested.
henrik.lundin@webrtc.org70df3052013-10-03 13:38:59 +0000200 // TODO(hlundin): Remove the default implementation when possible.
henrik.lundin@webrtc.orgce8e0932013-11-18 12:18:43 +0000201 virtual void SuspendBelowMinBitrate(int video_channel) {}
henrik.lundin@webrtc.org7ea4f242013-10-02 13:34:26 +0000202
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000203 protected:
204 ViECodec() {}
205 virtual ~ViECodec() {}
niklase@google.com470e71d2011-07-07 08:21:25 +0000206};
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000207
208} // namespace webrtc
209
210#endif // WEBRTC_VIDEO_ENGINE_INCLUDE_VIE_CODEC_H_