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