niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
stefan@webrtc.org | 439be29 | 2012-02-16 14:45:37 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | // 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.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 17 | #ifndef WEBRTC_VIDEO_ENGINE_INCLUDE_VIE_CODEC_H_ |
| 18 | #define WEBRTC_VIDEO_ENGINE_INCLUDE_VIE_CODEC_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 19 | |
pbos@webrtc.org | f5d4cb1 | 2013-05-17 13:44:48 +0000 | [diff] [blame] | 20 | #include "webrtc/common_types.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 22 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
| 24 | class VideoEngine; |
| 25 | struct VideoCodec; |
| 26 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 27 | // 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.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 31 | class 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.org | 7ea4f24 | 2013-10-02 13:34:26 +0000 | [diff] [blame] | 38 | |
henrik.lundin@webrtc.org | ce8e093 | 2013-11-18 12:18:43 +0000 | [diff] [blame] | 39 | // This method is called whenever the state of the SuspendBelowMinBitrate |
| 40 | // changes, i.e., when |is_suspended| toggles. |
henrik.lundin@webrtc.org | 7ea4f24 | 2013-10-02 13:34:26 +0000 | [diff] [blame] | 41 | // TODO(hlundin): Remove the default implementation when possible. |
henrik.lundin@webrtc.org | 9fe3603 | 2013-11-21 23:00:40 +0000 | [diff] [blame] | 42 | virtual void SuspendChange(int video_channel, bool is_suspended) {} |
henrik.lundin@webrtc.org | 7ea4f24 | 2013-10-02 13:34:26 +0000 | [diff] [blame] | 43 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 44 | protected: |
| 45 | virtual ~ViEEncoderObserver() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 46 | }; |
| 47 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 48 | // 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.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 52 | class 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 58 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 59 | // 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 64 | |
fischman@webrtc.org | 37bb497 | 2013-10-23 23:59:45 +0000 | [diff] [blame] | 65 | // Called periodically with decoder timing information. All values are |
| 66 | // "current" snapshots unless decorated with a min_/max_ prefix. |
fischman@webrtc.org | 37bb497 | 2013-10-23 23:59:45 +0000 | [diff] [blame] | 67 | 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.org | b7a1718 | 2013-10-28 17:36:59 +0000 | [diff] [blame] | 73 | int render_delay_ms) = 0; |
fischman@webrtc.org | 37bb497 | 2013-10-23 23:59:45 +0000 | [diff] [blame] | 74 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 75 | // 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 78 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 79 | protected: |
| 80 | virtual ~ViEDecoderObserver() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 81 | }; |
| 82 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 83 | class 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 90 | // 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 95 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 96 | // Gets the number of available codecs for the VideoEngine build. |
| 97 | virtual int NumberOfCodecs() const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 98 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 99 | // 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 103 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 104 | // 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 107 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 108 | // Gets the current send codec settings. |
| 109 | virtual int GetSendCodec(const int video_channel, |
| 110 | VideoCodec& video_codec) const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 111 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 112 | // 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 116 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 117 | // Gets the current receive codec. |
| 118 | virtual int GetReceiveCodec(const int video_channel, |
| 119 | VideoCodec& video_codec) const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 120 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 121 | // 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 127 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 128 | // 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 132 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 133 | // 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 137 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 138 | // 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 142 | |
mflodman@webrtc.org | 4aee6b6 | 2012-12-14 14:02:10 +0000 | [diff] [blame] | 143 | // 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.org | 439be29 | 2012-02-16 14:45:37 +0000 | [diff] [blame] | 148 | // 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.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 152 | // 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 155 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 156 | // Enables key frame request callback in ViEDecoderObserver. |
| 157 | virtual int SetKeyFrameRequestCallbackStatus(const int video_channel, |
| 158 | const bool enable) = 0; |
stefan@webrtc.org | 791eec7 | 2011-10-11 07:53:43 +0000 | [diff] [blame] | 159 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 160 | // 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 165 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 166 | // Registers an instance of a user implementation of the ViEEncoderObserver. |
| 167 | virtual int RegisterEncoderObserver(const int video_channel, |
| 168 | ViEEncoderObserver& observer) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 169 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 170 | // Removes an already registered instance of ViEEncoderObserver. |
| 171 | virtual int DeregisterEncoderObserver(const int video_channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 172 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 173 | // Registers an instance of a user implementation of the ViEDecoderObserver. |
| 174 | virtual int RegisterDecoderObserver(const int video_channel, |
| 175 | ViEDecoderObserver& observer) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 176 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 177 | // Removes an already registered instance of ViEDecoderObserver. |
| 178 | virtual int DeregisterDecoderObserver(const int video_channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 179 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 180 | // 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 184 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 185 | // 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 189 | |
mflodman@webrtc.org | 1c986e7 | 2013-06-26 09:12:49 +0000 | [diff] [blame] | 190 | // 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.org | ce8e093 | 2013-11-18 12:18:43 +0000 | [diff] [blame] | 196 | // Lets the sender suspend video when the rate drops below |
henrik.lundin@webrtc.org | 7ea4f24 | 2013-10-02 13:34:26 +0000 | [diff] [blame] | 197 | // |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.org | 70df305 | 2013-10-03 13:38:59 +0000 | [diff] [blame] | 200 | // TODO(hlundin): Remove the default implementation when possible. |
henrik.lundin@webrtc.org | ce8e093 | 2013-11-18 12:18:43 +0000 | [diff] [blame] | 201 | virtual void SuspendBelowMinBitrate(int video_channel) {} |
henrik.lundin@webrtc.org | 7ea4f24 | 2013-10-02 13:34:26 +0000 | [diff] [blame] | 202 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 203 | protected: |
| 204 | ViECodec() {} |
| 205 | virtual ~ViECodec() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 206 | }; |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 207 | |
| 208 | } // namespace webrtc |
| 209 | |
| 210 | #endif // WEBRTC_VIDEO_ENGINE_INCLUDE_VIE_CODEC_H_ |