blob: 41745abc7b3501ca347631c6e6c3afb30f618b0f [file] [log] [blame]
kjellander3e6db232015-11-26 04:44:54 -08001/*
2 * Copyright (c) 2012 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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_CODING_INCLUDE_AUDIO_CODING_MODULE_H_
12#define MODULES_AUDIO_CODING_INCLUDE_AUDIO_CODING_MODULE_H_
kjellander3e6db232015-11-26 04:44:54 -080013
kwiberg84be5112016-04-27 01:19:58 -070014#include <memory>
henrik.lundin4cf61dd2015-12-09 06:20:58 -080015#include <string>
kjellander3e6db232015-11-26 04:44:54 -080016#include <vector>
17
Danil Chapovalovb6021232018-06-19 13:26:36 +020018#include "absl/types/optional.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "api/audio_codecs/audio_decoder_factory.h"
20#include "api/audio_codecs/audio_encoder.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020021#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "modules/audio_coding/include/audio_coding_module_typedefs.h"
23#include "modules/audio_coding/neteq/include/neteq.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "rtc_base/deprecation.h"
25#include "rtc_base/function_view.h"
26#include "system_wrappers/include/clock.h"
kjellander3e6db232015-11-26 04:44:54 -080027
28namespace webrtc {
29
30// forward declarations
31struct CodecInst;
32struct WebRtcRTPHeader;
33class AudioDecoder;
34class AudioEncoder;
35class AudioFrame;
36class RTPFragmentationHeader;
37
38#define WEBRTC_10MS_PCM_AUDIO 960 // 16 bits super wideband 48 kHz
39
40// Callback class used for sending data ready to be packetized
41class AudioPacketizationCallback {
42 public:
43 virtual ~AudioPacketizationCallback() {}
44
45 virtual int32_t SendData(FrameType frame_type,
46 uint8_t payload_type,
47 uint32_t timestamp,
48 const uint8_t* payload_data,
49 size_t payload_len_bytes,
50 const RTPFragmentationHeader* fragmentation) = 0;
51};
52
53// Callback class used for reporting VAD decision
54class ACMVADCallback {
55 public:
56 virtual ~ACMVADCallback() {}
57
58 virtual int32_t InFrameType(FrameType frame_type) = 0;
59};
60
61class AudioCodingModule {
62 protected:
63 AudioCodingModule() {}
64
65 public:
66 struct Config {
Karl Wiberg5817d3d2018-04-06 10:06:42 +020067 explicit Config(
68 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory = nullptr);
kwiberg36a43882016-08-29 05:33:32 -070069 Config(const Config&);
70 ~Config();
kjellander3e6db232015-11-26 04:44:54 -080071
kjellander3e6db232015-11-26 04:44:54 -080072 NetEq::Config neteq_config;
73 Clock* clock;
ossue3525782016-05-25 07:37:43 -070074 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory;
kjellander3e6db232015-11-26 04:44:54 -080075 };
76
kjellander3e6db232015-11-26 04:44:54 -080077 static AudioCodingModule* Create(const Config& config);
78 virtual ~AudioCodingModule() = default;
79
80 ///////////////////////////////////////////////////////////////////////////
81 // Utility functions
82 //
83
84 ///////////////////////////////////////////////////////////////////////////
85 // uint8_t NumberOfCodecs()
86 // Returns number of supported codecs.
87 //
88 // Return value:
89 // number of supported codecs.
90 ///
91 static int NumberOfCodecs();
92
93 ///////////////////////////////////////////////////////////////////////////
94 // int32_t Codec()
95 // Get supported codec with list number.
96 //
97 // Input:
98 // -list_id : list number.
99 //
100 // Output:
101 // -codec : a structure where the parameters of the codec,
102 // given by list number is written to.
103 //
104 // Return value:
105 // -1 if the list number (list_id) is invalid.
106 // 0 if succeeded.
107 //
108 static int Codec(int list_id, CodecInst* codec);
109
110 ///////////////////////////////////////////////////////////////////////////
111 // int32_t Codec()
112 // Get supported codec with the given codec name, sampling frequency, and
113 // a given number of channels.
114 //
115 // Input:
116 // -payload_name : name of the codec.
117 // -sampling_freq_hz : sampling frequency of the codec. Note! for RED
118 // a sampling frequency of -1 is a valid input.
119 // -channels : number of channels ( 1 - mono, 2 - stereo).
120 //
121 // Output:
122 // -codec : a structure where the function returns the
123 // default parameters of the codec.
124 //
125 // Return value:
126 // -1 if no codec matches the given parameters.
127 // 0 if succeeded.
128 //
Yves Gerey665174f2018-06-19 15:03:05 +0200129 static int Codec(const char* payload_name,
130 CodecInst* codec,
131 int sampling_freq_hz,
132 size_t channels);
kjellander3e6db232015-11-26 04:44:54 -0800133
134 ///////////////////////////////////////////////////////////////////////////
135 // int32_t Codec()
136 //
137 // Returns the list number of the given codec name, sampling frequency, and
138 // a given number of channels.
139 //
140 // Input:
141 // -payload_name : name of the codec.
142 // -sampling_freq_hz : sampling frequency of the codec. Note! for RED
143 // a sampling frequency of -1 is a valid input.
144 // -channels : number of channels ( 1 - mono, 2 - stereo).
145 //
146 // Return value:
147 // if the codec is found, the index of the codec in the list,
148 // -1 if the codec is not found.
149 //
Yves Gerey665174f2018-06-19 15:03:05 +0200150 static int Codec(const char* payload_name,
151 int sampling_freq_hz,
Peter Kasting69558702016-01-12 16:26:35 -0800152 size_t channels);
kjellander3e6db232015-11-26 04:44:54 -0800153
154 ///////////////////////////////////////////////////////////////////////////
155 // bool IsCodecValid()
156 // Checks the validity of the parameters of the given codec.
157 //
158 // Input:
159 // -codec : the structure which keeps the parameters of the
160 // codec.
161 //
162 // Return value:
163 // true if the parameters are valid,
164 // false if any parameter is not valid.
165 //
166 static bool IsCodecValid(const CodecInst& codec);
167
168 ///////////////////////////////////////////////////////////////////////////
169 // Sender
170 //
171
172 ///////////////////////////////////////////////////////////////////////////
173 // int32_t RegisterSendCodec()
174 // Registers a codec, specified by |send_codec|, as sending codec.
175 // This API can be called multiple of times to register Codec. The last codec
176 // registered overwrites the previous ones.
177 // The API can also be used to change payload type for CNG and RED, which are
178 // registered by default to default payload types.
179 // Note that registering CNG and RED won't overwrite speech codecs.
180 // This API can be called to set/change the send payload-type, frame-size
181 // or encoding rate (if applicable for the codec).
182 //
183 // Note: If a stereo codec is registered as send codec, VAD/DTX will
184 // automatically be turned off, since it is not supported for stereo sending.
185 //
186 // Note: If a secondary encoder is already registered, and the new send-codec
187 // has a sampling rate that does not match the secondary encoder, the
188 // secondary encoder will be unregistered.
189 //
190 // Input:
191 // -send_codec : Parameters of the codec to be registered, c.f.
192 // common_types.h for the definition of
193 // CodecInst.
194 //
195 // Return value:
196 // -1 if failed to initialize,
197 // 0 if succeeded.
198 //
199 virtual int32_t RegisterSendCodec(const CodecInst& send_codec) = 0;
200
201 // Registers |external_speech_encoder| as encoder. The new encoder will
202 // replace any previously registered speech encoder (internal or external).
203 virtual void RegisterExternalSendCodec(
204 AudioEncoder* external_speech_encoder) = 0;
205
kwiberg4cdbd572016-03-30 03:10:05 -0700206 // |modifier| is called exactly once with one argument: a pointer to the
207 // unique_ptr that holds the current encoder (which is null if there is no
208 // current encoder). For the duration of the call, |modifier| has exclusive
209 // access to the unique_ptr; it may call the encoder, steal the encoder and
210 // replace it with another encoder or with nullptr, etc.
211 virtual void ModifyEncoder(
kwiberg24c7c122016-09-28 11:57:10 -0700212 rtc::FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier) = 0;
kwiberg4cdbd572016-03-30 03:10:05 -0700213
ivoc85228d62016-07-27 04:53:47 -0700214 // |modifier| is called exactly once with one argument: a const pointer to the
215 // current encoder (which is null if there is no current encoder).
kwiberg24c7c122016-09-28 11:57:10 -0700216 virtual void QueryEncoder(
217 rtc::FunctionView<void(AudioEncoder const*)> query) = 0;
ivoc85228d62016-07-27 04:53:47 -0700218
kwiberg4cdbd572016-03-30 03:10:05 -0700219 // Utility method for simply replacing the existing encoder with a new one.
220 void SetEncoder(std::unique_ptr<AudioEncoder> new_encoder) {
221 ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) {
222 *encoder = std::move(new_encoder);
223 });
224 }
225
kjellander3e6db232015-11-26 04:44:54 -0800226 ///////////////////////////////////////////////////////////////////////////
227 // int32_t SendCodec()
228 // Get parameters for the codec currently registered as send codec.
229 //
230 // Return value:
231 // The send codec, or nothing if we don't have one
232 //
Danil Chapovalovb6021232018-06-19 13:26:36 +0200233 virtual absl::optional<CodecInst> SendCodec() const = 0;
kjellander3e6db232015-11-26 04:44:54 -0800234
235 ///////////////////////////////////////////////////////////////////////////
236 // int32_t SendFrequency()
237 // Get the sampling frequency of the current encoder in Hertz.
238 //
239 // Return value:
240 // positive; sampling frequency [Hz] of the current encoder.
241 // -1 if an error has happened.
242 //
243 virtual int32_t SendFrequency() const = 0;
244
245 ///////////////////////////////////////////////////////////////////////////
246 // Sets the bitrate to the specified value in bits/sec. If the value is not
247 // supported by the codec, it will choose another appropriate value.
minyue7e304322016-10-12 05:00:55 -0700248 //
249 // This is only used in test code that rely on old ACM APIs.
250 // TODO(minyue): Remove it when possible.
kjellander3e6db232015-11-26 04:44:54 -0800251 virtual void SetBitRate(int bitrate_bps) = 0;
252
253 // int32_t RegisterTransportCallback()
254 // Register a transport callback which will be called to deliver
255 // the encoded buffers whenever Process() is called and a
256 // bit-stream is ready.
257 //
258 // Input:
259 // -transport : pointer to the callback class
260 // transport->SendData() is called whenever
261 // Process() is called and bit-stream is ready
262 // to deliver.
263 //
264 // Return value:
265 // -1 if the transport callback could not be registered
266 // 0 if registration is successful.
267 //
268 virtual int32_t RegisterTransportCallback(
269 AudioPacketizationCallback* transport) = 0;
270
271 ///////////////////////////////////////////////////////////////////////////
272 // int32_t Add10MsData()
273 // Add 10MS of raw (PCM) audio data and encode it. If the sampling
274 // frequency of the audio does not match the sampling frequency of the
275 // current encoder ACM will resample the audio. If an encoded packet was
276 // produced, it will be delivered via the callback object registered using
277 // RegisterTransportCallback, and the return value from this function will
278 // be the number of bytes encoded.
279 //
280 // Input:
281 // -audio_frame : the input audio frame, containing raw audio
Fredrik Solenbergbbf21a32018-04-12 22:44:09 +0200282 // sampling frequency etc.
kjellander3e6db232015-11-26 04:44:54 -0800283 //
284 // Return value:
285 // >= 0 number of bytes encoded.
286 // -1 some error occurred.
287 //
288 virtual int32_t Add10MsData(const AudioFrame& audio_frame) = 0;
289
290 ///////////////////////////////////////////////////////////////////////////
291 // (RED) Redundant Coding
292 //
293
294 ///////////////////////////////////////////////////////////////////////////
295 // int32_t SetREDStatus()
296 // configure RED status i.e. on/off.
297 //
298 // RFC 2198 describes a solution which has a single payload type which
299 // signifies a packet with redundancy. That packet then becomes a container,
300 // encapsulating multiple payloads into a single RTP packet.
301 // Such a scheme is flexible, since any amount of redundancy may be
302 // encapsulated within a single packet. There is, however, a small overhead
303 // since each encapsulated payload must be preceded by a header indicating
304 // the type of data enclosed.
305 //
306 // Input:
307 // -enable_red : if true RED is enabled, otherwise RED is
308 // disabled.
309 //
310 // Return value:
311 // -1 if failed to set RED status,
312 // 0 if succeeded.
313 //
314 virtual int32_t SetREDStatus(bool enable_red) = 0;
315
316 ///////////////////////////////////////////////////////////////////////////
317 // bool REDStatus()
318 // Get RED status
319 //
320 // Return value:
321 // true if RED is enabled,
322 // false if RED is disabled.
323 //
324 virtual bool REDStatus() const = 0;
325
326 ///////////////////////////////////////////////////////////////////////////
327 // (FEC) Forward Error Correction (codec internal)
328 //
329
330 ///////////////////////////////////////////////////////////////////////////
331 // int32_t SetCodecFEC()
332 // Configures codec internal FEC status i.e. on/off. No effects on codecs that
333 // do not provide internal FEC.
334 //
335 // Input:
336 // -enable_fec : if true FEC will be enabled otherwise the FEC is
337 // disabled.
338 //
339 // Return value:
340 // -1 if failed, or the codec does not support FEC
341 // 0 if succeeded.
342 //
343 virtual int SetCodecFEC(bool enable_codec_fec) = 0;
344
345 ///////////////////////////////////////////////////////////////////////////
346 // bool CodecFEC()
347 // Gets status of codec internal FEC.
348 //
349 // Return value:
350 // true if FEC is enabled,
351 // false if FEC is disabled.
352 //
353 virtual bool CodecFEC() const = 0;
354
355 ///////////////////////////////////////////////////////////////////////////
356 // int SetPacketLossRate()
357 // Sets expected packet loss rate for encoding. Some encoders provide packet
358 // loss gnostic encoding to make stream less sensitive to packet losses,
359 // through e.g., FEC. No effects on codecs that do not provide such encoding.
360 //
361 // Input:
362 // -packet_loss_rate : expected packet loss rate (0 -- 100 inclusive).
363 //
364 // Return value
365 // -1 if failed to set packet loss rate,
366 // 0 if succeeded.
367 //
minyue7e304322016-10-12 05:00:55 -0700368 // This is only used in test code that rely on old ACM APIs.
369 // TODO(minyue): Remove it when possible.
kjellander3e6db232015-11-26 04:44:54 -0800370 virtual int SetPacketLossRate(int packet_loss_rate) = 0;
371
372 ///////////////////////////////////////////////////////////////////////////
373 // (VAD) Voice Activity Detection
374 //
375
376 ///////////////////////////////////////////////////////////////////////////
377 // int32_t SetVAD()
378 // If DTX is enabled & the codec does not have internal DTX/VAD
379 // WebRtc VAD will be automatically enabled and |enable_vad| is ignored.
380 //
381 // If DTX is disabled but VAD is enabled no DTX packets are send,
382 // regardless of whether the codec has internal DTX/VAD or not. In this
383 // case, WebRtc VAD is running to label frames as active/in-active.
384 //
385 // NOTE! VAD/DTX is not supported when sending stereo.
386 //
387 // Inputs:
388 // -enable_dtx : if true DTX is enabled,
389 // otherwise DTX is disabled.
390 // -enable_vad : if true VAD is enabled,
391 // otherwise VAD is disabled.
392 // -vad_mode : determines the aggressiveness of VAD. A more
393 // aggressive mode results in more frames labeled
394 // as in-active, c.f. definition of
395 // ACMVADMode in audio_coding_module_typedefs.h
396 // for valid values.
397 //
398 // Return value:
399 // -1 if failed to set up VAD/DTX,
400 // 0 if succeeded.
401 //
402 virtual int32_t SetVAD(const bool enable_dtx = true,
Yves Gerey665174f2018-06-19 15:03:05 +0200403 const bool enable_vad = false,
404 const ACMVADMode vad_mode = VADNormal) = 0;
kjellander3e6db232015-11-26 04:44:54 -0800405
406 ///////////////////////////////////////////////////////////////////////////
407 // int32_t VAD()
408 // Get VAD status.
409 //
410 // Outputs:
411 // -dtx_enabled : is set to true if DTX is enabled, otherwise
412 // is set to false.
413 // -vad_enabled : is set to true if VAD is enabled, otherwise
414 // is set to false.
415 // -vad_mode : is set to the current aggressiveness of VAD.
416 //
417 // Return value:
418 // -1 if fails to retrieve the setting of DTX/VAD,
419 // 0 if succeeded.
420 //
Yves Gerey665174f2018-06-19 15:03:05 +0200421 virtual int32_t VAD(bool* dtx_enabled,
422 bool* vad_enabled,
423 ACMVADMode* vad_mode) const = 0;
kjellander3e6db232015-11-26 04:44:54 -0800424
425 ///////////////////////////////////////////////////////////////////////////
426 // int32_t RegisterVADCallback()
427 // Call this method to register a callback function which is called
428 // any time that ACM encounters an empty frame. That is a frame which is
429 // recognized inactive. Depending on the codec WebRtc VAD or internal codec
430 // VAD is employed to identify a frame as active/inactive.
431 //
432 // Input:
433 // -vad_callback : pointer to a callback function.
434 //
435 // Return value:
436 // -1 if failed to register the callback function.
437 // 0 if the callback function is registered successfully.
438 //
439 virtual int32_t RegisterVADCallback(ACMVADCallback* vad_callback) = 0;
440
441 ///////////////////////////////////////////////////////////////////////////
442 // Receiver
443 //
444
445 ///////////////////////////////////////////////////////////////////////////
446 // int32_t InitializeReceiver()
447 // Any decoder-related state of ACM will be initialized to the
448 // same state when ACM is created. This will not interrupt or
449 // effect encoding functionality of ACM. ACM would lose all the
450 // decoding-related settings by calling this function.
451 // For instance, all registered codecs are deleted and have to be
452 // registered again.
453 //
454 // Return value:
455 // -1 if failed to initialize,
456 // 0 if succeeded.
457 //
458 virtual int32_t InitializeReceiver() = 0;
459
460 ///////////////////////////////////////////////////////////////////////////
461 // int32_t ReceiveFrequency()
462 // Get sampling frequency of the last received payload.
463 //
464 // Return value:
465 // non-negative the sampling frequency in Hertz.
466 // -1 if an error has occurred.
467 //
468 virtual int32_t ReceiveFrequency() const = 0;
469
470 ///////////////////////////////////////////////////////////////////////////
471 // int32_t PlayoutFrequency()
472 // Get sampling frequency of audio played out.
473 //
474 // Return value:
475 // the sampling frequency in Hertz.
476 //
477 virtual int32_t PlayoutFrequency() const = 0;
478
kwiberg1c07c702017-03-27 07:15:49 -0700479 // Replace any existing decoders with the given payload type -> decoder map.
480 virtual void SetReceiveCodecs(
481 const std::map<int, SdpAudioFormat>& codecs) = 0;
482
kwiberg5adaf732016-10-04 09:33:27 -0700483 // Registers a decoder for the given payload type. Returns true iff
484 // successful.
485 virtual bool RegisterReceiveCodec(int rtp_payload_type,
486 const SdpAudioFormat& audio_format) = 0;
487
kjellander3e6db232015-11-26 04:44:54 -0800488 ///////////////////////////////////////////////////////////////////////////
489 // int32_t RegisterReceiveCodec()
490 // Register possible decoders, can be called multiple times for
491 // codecs, CNG-NB, CNG-WB, CNG-SWB, AVT and RED.
492 //
493 // Input:
494 // -receive_codec : parameters of the codec to be registered, c.f.
495 // common_types.h for the definition of
496 // CodecInst.
497 //
498 // Return value:
499 // -1 if failed to register the codec
500 // 0 if the codec registered successfully.
501 //
502 virtual int RegisterReceiveCodec(const CodecInst& receive_codec) = 0;
503
kwiberg4cdbd572016-03-30 03:10:05 -0700504 // Register a decoder; call repeatedly to register multiple decoders. |df| is
505 // a decoder factory that returns an iSAC decoder; it will be called once if
506 // the decoder being registered is iSAC.
507 virtual int RegisterReceiveCodec(
508 const CodecInst& receive_codec,
kwiberg24c7c122016-09-28 11:57:10 -0700509 rtc::FunctionView<std::unique_ptr<AudioDecoder>()> isac_factory) = 0;
kwiberg4cdbd572016-03-30 03:10:05 -0700510
henrik.lundin4cf61dd2015-12-09 06:20:58 -0800511 // Registers an external decoder. The name is only used to provide information
512 // back to the caller about the decoder. Hence, the name is arbitrary, and may
513 // be empty.
kjellander3e6db232015-11-26 04:44:54 -0800514 virtual int RegisterExternalReceiveCodec(int rtp_payload_type,
515 AudioDecoder* external_decoder,
516 int sample_rate_hz,
henrik.lundin4cf61dd2015-12-09 06:20:58 -0800517 int num_channels,
518 const std::string& name) = 0;
kjellander3e6db232015-11-26 04:44:54 -0800519
520 ///////////////////////////////////////////////////////////////////////////
521 // int32_t UnregisterReceiveCodec()
522 // Unregister the codec currently registered with a specific payload type
523 // from the list of possible receive codecs.
524 //
525 // Input:
526 // -payload_type : The number representing the payload type to
527 // unregister.
528 //
529 // Output:
530 // -1 if fails to unregister.
531 // 0 if the given codec is successfully unregistered.
532 //
Yves Gerey665174f2018-06-19 15:03:05 +0200533 virtual int UnregisterReceiveCodec(uint8_t payload_type) = 0;
kjellander3e6db232015-11-26 04:44:54 -0800534
535 ///////////////////////////////////////////////////////////////////////////
536 // int32_t ReceiveCodec()
537 // Get the codec associated with last received payload.
538 //
539 // Output:
540 // -curr_receive_codec : parameters of the codec associated with the last
541 // received payload, c.f. common_types.h for
542 // the definition of CodecInst.
543 //
544 // Return value:
545 // -1 if failed to retrieve the codec,
546 // 0 if the codec is successfully retrieved.
547 //
548 virtual int32_t ReceiveCodec(CodecInst* curr_receive_codec) const = 0;
549
550 ///////////////////////////////////////////////////////////////////////////
Danil Chapovalovb6021232018-06-19 13:26:36 +0200551 // absl::optional<SdpAudioFormat> ReceiveFormat()
ossue280cde2016-10-12 11:04:10 -0700552 // Get the format associated with last received payload.
553 //
554 // Return value:
555 // An SdpAudioFormat describing the format associated with the last
556 // received payload.
557 // An empty Optional if no payload has yet been received.
558 //
Danil Chapovalovb6021232018-06-19 13:26:36 +0200559 virtual absl::optional<SdpAudioFormat> ReceiveFormat() const = 0;
ossue280cde2016-10-12 11:04:10 -0700560
561 ///////////////////////////////////////////////////////////////////////////
kjellander3e6db232015-11-26 04:44:54 -0800562 // int32_t IncomingPacket()
563 // Call this function to insert a parsed RTP packet into ACM.
564 //
565 // Inputs:
566 // -incoming_payload : received payload.
567 // -payload_len_bytes : the length of payload in bytes.
568 // -rtp_info : the relevant information retrieved from RTP
569 // header.
570 //
571 // Return value:
572 // -1 if failed to push in the payload
573 // 0 if payload is successfully pushed in.
574 //
575 virtual int32_t IncomingPacket(const uint8_t* incoming_payload,
576 const size_t payload_len_bytes,
577 const WebRtcRTPHeader& rtp_info) = 0;
578
579 ///////////////////////////////////////////////////////////////////////////
kjellander3e6db232015-11-26 04:44:54 -0800580 // int SetMinimumPlayoutDelay()
581 // Set a minimum for the playout delay, used for lip-sync. NetEq maintains
582 // such a delay unless channel condition yields to a higher delay.
583 //
584 // Input:
585 // -time_ms : minimum delay in milliseconds.
586 //
587 // Return value:
588 // -1 if failed to set the delay,
589 // 0 if the minimum delay is set.
590 //
591 virtual int SetMinimumPlayoutDelay(int time_ms) = 0;
592
593 ///////////////////////////////////////////////////////////////////////////
594 // int SetMaximumPlayoutDelay()
595 // Set a maximum for the playout delay
596 //
597 // Input:
598 // -time_ms : maximum delay in milliseconds.
599 //
600 // Return value:
601 // -1 if failed to set the delay,
602 // 0 if the maximum delay is set.
603 //
604 virtual int SetMaximumPlayoutDelay(int time_ms) = 0;
605
solenberg08b19df2017-02-15 00:42:31 -0800606 // TODO(kwiberg): Consider if this is needed anymore, now that voe::Channel
607 // doesn't use it.
kjellander3e6db232015-11-26 04:44:54 -0800608 // The shortest latency, in milliseconds, required by jitter buffer. This
609 // is computed based on inter-arrival times and playout mode of NetEq. The
610 // actual delay is the maximum of least-required-delay and the minimum-delay
611 // specified by SetMinumumPlayoutDelay() API.
612 //
613 virtual int LeastRequiredDelayMs() const = 0;
614
kjellander3e6db232015-11-26 04:44:54 -0800615 // int32_t PlayoutTimestamp()
616 // The send timestamp of an RTP packet is associated with the decoded
617 // audio of the packet in question. This function returns the timestamp of
618 // the latest audio obtained by calling PlayoutData10ms().
619 //
620 // Input:
621 // -timestamp : a reference to a uint32_t to receive the
622 // timestamp.
623 // Return value:
624 // 0 if the output is a correct timestamp.
625 // -1 if failed to output the correct timestamp.
626 //
henrik.lundin9a410dd2016-04-06 01:39:22 -0700627 RTC_DEPRECATED virtual int32_t PlayoutTimestamp(uint32_t* timestamp) = 0;
628
629 ///////////////////////////////////////////////////////////////////////////
630 // int32_t PlayoutTimestamp()
631 // The send timestamp of an RTP packet is associated with the decoded
632 // audio of the packet in question. This function returns the timestamp of
633 // the latest audio obtained by calling PlayoutData10ms(), or empty if no
634 // valid timestamp is available.
635 //
Danil Chapovalovb6021232018-06-19 13:26:36 +0200636 virtual absl::optional<uint32_t> PlayoutTimestamp() = 0;
kjellander3e6db232015-11-26 04:44:54 -0800637
638 ///////////////////////////////////////////////////////////////////////////
henrik.lundinb3f1c5d2016-08-22 15:39:53 -0700639 // int FilteredCurrentDelayMs()
640 // Returns the current total delay from NetEq (packet buffer and sync buffer)
641 // in ms, with smoothing applied to even out short-time fluctuations due to
642 // jitter. The packet buffer part of the delay is not updated during DTX/CNG
643 // periods.
644 //
645 virtual int FilteredCurrentDelayMs() const = 0;
646
647 ///////////////////////////////////////////////////////////////////////////
Henrik Lundinabbff892017-11-29 09:14:04 +0100648 // int FilteredCurrentDelayMs()
649 // Returns the current target delay for NetEq in ms.
650 //
651 virtual int TargetDelayMs() const = 0;
652
653 ///////////////////////////////////////////////////////////////////////////
kjellander3e6db232015-11-26 04:44:54 -0800654 // int32_t PlayoutData10Ms(
655 // Get 10 milliseconds of raw audio data for playout, at the given sampling
656 // frequency. ACM will perform a resampling if required.
657 //
658 // Input:
659 // -desired_freq_hz : the desired sampling frequency, in Hertz, of the
660 // output audio. If set to -1, the function returns
661 // the audio at the current sampling frequency.
662 //
663 // Output:
664 // -audio_frame : output audio frame which contains raw audio data
Fredrik Solenbergbbf21a32018-04-12 22:44:09 +0200665 // and other relevant parameters.
henrik.lundin834a6ea2016-05-13 03:45:24 -0700666 // -muted : if true, the sample data in audio_frame is not
667 // populated, and must be interpreted as all zero.
kjellander3e6db232015-11-26 04:44:54 -0800668 //
669 // Return value:
670 // -1 if the function fails,
671 // 0 if the function succeeds.
672 //
673 virtual int32_t PlayoutData10Ms(int32_t desired_freq_hz,
henrik.lundin834a6ea2016-05-13 03:45:24 -0700674 AudioFrame* audio_frame,
675 bool* muted) = 0;
676
677 /////////////////////////////////////////////////////////////////////////////
678 // Same as above, but without the muted parameter. This methods should not be
679 // used if enable_fast_accelerate was set to true in NetEq::Config.
680 // TODO(henrik.lundin) Remove this method when downstream dependencies are
681 // ready.
682 virtual int32_t PlayoutData10Ms(int32_t desired_freq_hz,
683 AudioFrame* audio_frame) = 0;
kjellander3e6db232015-11-26 04:44:54 -0800684
685 ///////////////////////////////////////////////////////////////////////////
686 // Codec specific
687 //
688
689 ///////////////////////////////////////////////////////////////////////////
690 // int SetOpusApplication()
691 // Sets the intended application if current send codec is Opus. Opus uses this
692 // to optimize the encoding for applications like VOIP and music. Currently,
693 // two modes are supported: kVoip and kAudio.
694 //
695 // Input:
696 // - application : intended application.
697 //
698 // Return value:
699 // -1 if current send codec is not Opus or error occurred in setting the
700 // Opus application mode.
701 // 0 if the Opus application mode is successfully set.
702 //
703 virtual int SetOpusApplication(OpusApplicationMode application) = 0;
704
705 ///////////////////////////////////////////////////////////////////////////
706 // int SetOpusMaxPlaybackRate()
707 // If current send codec is Opus, informs it about maximum playback rate the
708 // receiver will render. Opus can use this information to optimize the bit
709 // rate and increase the computation efficiency.
710 //
711 // Input:
712 // -frequency_hz : maximum playback rate in Hz.
713 //
714 // Return value:
715 // -1 if current send codec is not Opus or
716 // error occurred in setting the maximum playback rate,
717 // 0 if maximum bandwidth is set successfully.
718 //
719 virtual int SetOpusMaxPlaybackRate(int frequency_hz) = 0;
720
721 ///////////////////////////////////////////////////////////////////////////
722 // EnableOpusDtx()
723 // Enable the DTX, if current send codec is Opus.
724 //
725 // Return value:
726 // -1 if current send codec is not Opus or error occurred in enabling the
727 // Opus DTX.
728 // 0 if Opus DTX is enabled successfully.
729 //
730 virtual int EnableOpusDtx() = 0;
731
732 ///////////////////////////////////////////////////////////////////////////
733 // int DisableOpusDtx()
734 // If current send codec is Opus, disables its internal DTX.
735 //
736 // Return value:
737 // -1 if current send codec is not Opus or error occurred in disabling DTX.
738 // 0 if Opus DTX is disabled successfully.
739 //
740 virtual int DisableOpusDtx() = 0;
741
742 ///////////////////////////////////////////////////////////////////////////
743 // statistics
744 //
745
746 ///////////////////////////////////////////////////////////////////////////
747 // int32_t GetNetworkStatistics()
748 // Get network statistics. Note that the internal statistics of NetEq are
749 // reset by this call.
750 //
751 // Input:
752 // -network_statistics : a structure that contains network statistics.
753 //
754 // Return value:
755 // -1 if failed to set the network statistics,
756 // 0 if statistics are set successfully.
757 //
758 virtual int32_t GetNetworkStatistics(
759 NetworkStatistics* network_statistics) = 0;
760
761 //
762 // Enable NACK and set the maximum size of the NACK list. If NACK is already
763 // enable then the maximum NACK list size is modified accordingly.
764 //
765 // If the sequence number of last received packet is N, the sequence numbers
766 // of NACK list are in the range of [N - |max_nack_list_size|, N).
767 //
768 // |max_nack_list_size| should be positive (none zero) and less than or
769 // equal to |Nack::kNackListSizeLimit|. Otherwise, No change is applied and -1
770 // is returned. 0 is returned at success.
771 //
772 virtual int EnableNack(size_t max_nack_list_size) = 0;
773
774 // Disable NACK.
775 virtual void DisableNack() = 0;
776
777 //
778 // Get a list of packets to be retransmitted. |round_trip_time_ms| is an
779 // estimate of the round-trip-time (in milliseconds). Missing packets which
780 // will be playout in a shorter time than the round-trip-time (with respect
781 // to the time this API is called) will not be included in the list.
782 //
783 // Negative |round_trip_time_ms| results is an error message and empty list
784 // is returned.
785 //
786 virtual std::vector<uint16_t> GetNackList(
787 int64_t round_trip_time_ms) const = 0;
788
789 virtual void GetDecodingCallStatistics(
790 AudioDecodingCallStats* call_stats) const = 0;
ivoce1198e02017-09-08 08:13:19 -0700791
792 virtual ANAStats GetANAStats() const = 0;
kjellander3e6db232015-11-26 04:44:54 -0800793};
794
795} // namespace webrtc
796
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200797#endif // MODULES_AUDIO_CODING_INCLUDE_AUDIO_CODING_MODULE_H_