blob: 840a719fa19b3c480be03343553f675448d5acce [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/function_view.h"
25#include "system_wrappers/include/clock.h"
kjellander3e6db232015-11-26 04:44:54 -080026
27namespace webrtc {
28
29// forward declarations
30struct CodecInst;
31struct WebRtcRTPHeader;
32class AudioDecoder;
33class AudioEncoder;
34class AudioFrame;
35class RTPFragmentationHeader;
36
37#define WEBRTC_10MS_PCM_AUDIO 960 // 16 bits super wideband 48 kHz
38
39// Callback class used for sending data ready to be packetized
40class AudioPacketizationCallback {
41 public:
42 virtual ~AudioPacketizationCallback() {}
43
44 virtual int32_t SendData(FrameType frame_type,
45 uint8_t payload_type,
46 uint32_t timestamp,
47 const uint8_t* payload_data,
48 size_t payload_len_bytes,
49 const RTPFragmentationHeader* fragmentation) = 0;
50};
51
52// Callback class used for reporting VAD decision
53class ACMVADCallback {
54 public:
55 virtual ~ACMVADCallback() {}
56
57 virtual int32_t InFrameType(FrameType frame_type) = 0;
58};
59
60class AudioCodingModule {
61 protected:
62 AudioCodingModule() {}
63
64 public:
65 struct Config {
Karl Wiberg5817d3d2018-04-06 10:06:42 +020066 explicit Config(
67 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory = nullptr);
kwiberg36a43882016-08-29 05:33:32 -070068 Config(const Config&);
69 ~Config();
kjellander3e6db232015-11-26 04:44:54 -080070
kjellander3e6db232015-11-26 04:44:54 -080071 NetEq::Config neteq_config;
72 Clock* clock;
ossue3525782016-05-25 07:37:43 -070073 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory;
kjellander3e6db232015-11-26 04:44:54 -080074 };
75
kjellander3e6db232015-11-26 04:44:54 -080076 static AudioCodingModule* Create(const Config& config);
77 virtual ~AudioCodingModule() = default;
78
79 ///////////////////////////////////////////////////////////////////////////
80 // Utility functions
81 //
82
83 ///////////////////////////////////////////////////////////////////////////
84 // uint8_t NumberOfCodecs()
85 // Returns number of supported codecs.
86 //
87 // Return value:
88 // number of supported codecs.
89 ///
90 static int NumberOfCodecs();
91
92 ///////////////////////////////////////////////////////////////////////////
93 // int32_t Codec()
94 // Get supported codec with list number.
95 //
96 // Input:
97 // -list_id : list number.
98 //
99 // Output:
100 // -codec : a structure where the parameters of the codec,
101 // given by list number is written to.
102 //
103 // Return value:
104 // -1 if the list number (list_id) is invalid.
105 // 0 if succeeded.
106 //
107 static int Codec(int list_id, CodecInst* codec);
108
109 ///////////////////////////////////////////////////////////////////////////
110 // int32_t Codec()
111 // Get supported codec with the given codec name, sampling frequency, and
112 // a given number of channels.
113 //
114 // Input:
115 // -payload_name : name of the codec.
116 // -sampling_freq_hz : sampling frequency of the codec. Note! for RED
117 // a sampling frequency of -1 is a valid input.
118 // -channels : number of channels ( 1 - mono, 2 - stereo).
119 //
120 // Output:
121 // -codec : a structure where the function returns the
122 // default parameters of the codec.
123 //
124 // Return value:
125 // -1 if no codec matches the given parameters.
126 // 0 if succeeded.
127 //
Yves Gerey665174f2018-06-19 15:03:05 +0200128 static int Codec(const char* payload_name,
129 CodecInst* codec,
130 int sampling_freq_hz,
131 size_t channels);
kjellander3e6db232015-11-26 04:44:54 -0800132
133 ///////////////////////////////////////////////////////////////////////////
134 // int32_t Codec()
135 //
136 // Returns the list number of the given codec name, sampling frequency, and
137 // a given number of channels.
138 //
139 // Input:
140 // -payload_name : name of the codec.
141 // -sampling_freq_hz : sampling frequency of the codec. Note! for RED
142 // a sampling frequency of -1 is a valid input.
143 // -channels : number of channels ( 1 - mono, 2 - stereo).
144 //
145 // Return value:
146 // if the codec is found, the index of the codec in the list,
147 // -1 if the codec is not found.
148 //
Yves Gerey665174f2018-06-19 15:03:05 +0200149 static int Codec(const char* payload_name,
150 int sampling_freq_hz,
Peter Kasting69558702016-01-12 16:26:35 -0800151 size_t channels);
kjellander3e6db232015-11-26 04:44:54 -0800152
153 ///////////////////////////////////////////////////////////////////////////
kjellander3e6db232015-11-26 04:44:54 -0800154 // Sender
155 //
156
157 ///////////////////////////////////////////////////////////////////////////
158 // int32_t RegisterSendCodec()
159 // Registers a codec, specified by |send_codec|, as sending codec.
160 // This API can be called multiple of times to register Codec. The last codec
161 // registered overwrites the previous ones.
162 // The API can also be used to change payload type for CNG and RED, which are
163 // registered by default to default payload types.
164 // Note that registering CNG and RED won't overwrite speech codecs.
165 // This API can be called to set/change the send payload-type, frame-size
166 // or encoding rate (if applicable for the codec).
167 //
168 // Note: If a stereo codec is registered as send codec, VAD/DTX will
169 // automatically be turned off, since it is not supported for stereo sending.
170 //
171 // Note: If a secondary encoder is already registered, and the new send-codec
172 // has a sampling rate that does not match the secondary encoder, the
173 // secondary encoder will be unregistered.
174 //
175 // Input:
176 // -send_codec : Parameters of the codec to be registered, c.f.
177 // common_types.h for the definition of
178 // CodecInst.
179 //
180 // Return value:
181 // -1 if failed to initialize,
182 // 0 if succeeded.
183 //
184 virtual int32_t RegisterSendCodec(const CodecInst& send_codec) = 0;
185
186 // Registers |external_speech_encoder| as encoder. The new encoder will
187 // replace any previously registered speech encoder (internal or external).
188 virtual void RegisterExternalSendCodec(
189 AudioEncoder* external_speech_encoder) = 0;
190
kwiberg4cdbd572016-03-30 03:10:05 -0700191 // |modifier| is called exactly once with one argument: a pointer to the
192 // unique_ptr that holds the current encoder (which is null if there is no
193 // current encoder). For the duration of the call, |modifier| has exclusive
194 // access to the unique_ptr; it may call the encoder, steal the encoder and
195 // replace it with another encoder or with nullptr, etc.
196 virtual void ModifyEncoder(
kwiberg24c7c122016-09-28 11:57:10 -0700197 rtc::FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier) = 0;
kwiberg4cdbd572016-03-30 03:10:05 -0700198
199 // Utility method for simply replacing the existing encoder with a new one.
200 void SetEncoder(std::unique_ptr<AudioEncoder> new_encoder) {
201 ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) {
202 *encoder = std::move(new_encoder);
203 });
204 }
205
kjellander3e6db232015-11-26 04:44:54 -0800206 ///////////////////////////////////////////////////////////////////////////
207 // int32_t SendCodec()
208 // Get parameters for the codec currently registered as send codec.
209 //
210 // Return value:
211 // The send codec, or nothing if we don't have one
212 //
Danil Chapovalovb6021232018-06-19 13:26:36 +0200213 virtual absl::optional<CodecInst> SendCodec() const = 0;
kjellander3e6db232015-11-26 04:44:54 -0800214
215 ///////////////////////////////////////////////////////////////////////////
kjellander3e6db232015-11-26 04:44:54 -0800216 // Sets the bitrate to the specified value in bits/sec. If the value is not
217 // supported by the codec, it will choose another appropriate value.
minyue7e304322016-10-12 05:00:55 -0700218 //
219 // This is only used in test code that rely on old ACM APIs.
220 // TODO(minyue): Remove it when possible.
kjellander3e6db232015-11-26 04:44:54 -0800221 virtual void SetBitRate(int bitrate_bps) = 0;
222
223 // int32_t RegisterTransportCallback()
224 // Register a transport callback which will be called to deliver
225 // the encoded buffers whenever Process() is called and a
226 // bit-stream is ready.
227 //
228 // Input:
229 // -transport : pointer to the callback class
230 // transport->SendData() is called whenever
231 // Process() is called and bit-stream is ready
232 // to deliver.
233 //
234 // Return value:
235 // -1 if the transport callback could not be registered
236 // 0 if registration is successful.
237 //
238 virtual int32_t RegisterTransportCallback(
239 AudioPacketizationCallback* transport) = 0;
240
241 ///////////////////////////////////////////////////////////////////////////
242 // int32_t Add10MsData()
243 // Add 10MS of raw (PCM) audio data and encode it. If the sampling
244 // frequency of the audio does not match the sampling frequency of the
245 // current encoder ACM will resample the audio. If an encoded packet was
246 // produced, it will be delivered via the callback object registered using
247 // RegisterTransportCallback, and the return value from this function will
248 // be the number of bytes encoded.
249 //
250 // Input:
251 // -audio_frame : the input audio frame, containing raw audio
Fredrik Solenbergbbf21a32018-04-12 22:44:09 +0200252 // sampling frequency etc.
kjellander3e6db232015-11-26 04:44:54 -0800253 //
254 // Return value:
255 // >= 0 number of bytes encoded.
256 // -1 some error occurred.
257 //
258 virtual int32_t Add10MsData(const AudioFrame& audio_frame) = 0;
259
260 ///////////////////////////////////////////////////////////////////////////
261 // (RED) Redundant Coding
262 //
263
264 ///////////////////////////////////////////////////////////////////////////
265 // int32_t SetREDStatus()
266 // configure RED status i.e. on/off.
267 //
268 // RFC 2198 describes a solution which has a single payload type which
269 // signifies a packet with redundancy. That packet then becomes a container,
270 // encapsulating multiple payloads into a single RTP packet.
271 // Such a scheme is flexible, since any amount of redundancy may be
272 // encapsulated within a single packet. There is, however, a small overhead
273 // since each encapsulated payload must be preceded by a header indicating
274 // the type of data enclosed.
275 //
276 // Input:
277 // -enable_red : if true RED is enabled, otherwise RED is
278 // disabled.
279 //
280 // Return value:
281 // -1 if failed to set RED status,
282 // 0 if succeeded.
283 //
284 virtual int32_t SetREDStatus(bool enable_red) = 0;
285
286 ///////////////////////////////////////////////////////////////////////////
287 // bool REDStatus()
288 // Get RED status
289 //
290 // Return value:
291 // true if RED is enabled,
292 // false if RED is disabled.
293 //
294 virtual bool REDStatus() const = 0;
295
296 ///////////////////////////////////////////////////////////////////////////
297 // (FEC) Forward Error Correction (codec internal)
298 //
299
300 ///////////////////////////////////////////////////////////////////////////
301 // int32_t SetCodecFEC()
302 // Configures codec internal FEC status i.e. on/off. No effects on codecs that
303 // do not provide internal FEC.
304 //
305 // Input:
306 // -enable_fec : if true FEC will be enabled otherwise the FEC is
307 // disabled.
308 //
309 // Return value:
310 // -1 if failed, or the codec does not support FEC
311 // 0 if succeeded.
312 //
313 virtual int SetCodecFEC(bool enable_codec_fec) = 0;
314
315 ///////////////////////////////////////////////////////////////////////////
316 // bool CodecFEC()
317 // Gets status of codec internal FEC.
318 //
319 // Return value:
320 // true if FEC is enabled,
321 // false if FEC is disabled.
322 //
323 virtual bool CodecFEC() const = 0;
324
325 ///////////////////////////////////////////////////////////////////////////
326 // int SetPacketLossRate()
327 // Sets expected packet loss rate for encoding. Some encoders provide packet
328 // loss gnostic encoding to make stream less sensitive to packet losses,
329 // through e.g., FEC. No effects on codecs that do not provide such encoding.
330 //
331 // Input:
332 // -packet_loss_rate : expected packet loss rate (0 -- 100 inclusive).
333 //
334 // Return value
335 // -1 if failed to set packet loss rate,
336 // 0 if succeeded.
337 //
minyue7e304322016-10-12 05:00:55 -0700338 // This is only used in test code that rely on old ACM APIs.
339 // TODO(minyue): Remove it when possible.
kjellander3e6db232015-11-26 04:44:54 -0800340 virtual int SetPacketLossRate(int packet_loss_rate) = 0;
341
342 ///////////////////////////////////////////////////////////////////////////
343 // (VAD) Voice Activity Detection
344 //
345
346 ///////////////////////////////////////////////////////////////////////////
347 // int32_t SetVAD()
348 // If DTX is enabled & the codec does not have internal DTX/VAD
349 // WebRtc VAD will be automatically enabled and |enable_vad| is ignored.
350 //
351 // If DTX is disabled but VAD is enabled no DTX packets are send,
352 // regardless of whether the codec has internal DTX/VAD or not. In this
353 // case, WebRtc VAD is running to label frames as active/in-active.
354 //
355 // NOTE! VAD/DTX is not supported when sending stereo.
356 //
357 // Inputs:
358 // -enable_dtx : if true DTX is enabled,
359 // otherwise DTX is disabled.
360 // -enable_vad : if true VAD is enabled,
361 // otherwise VAD is disabled.
362 // -vad_mode : determines the aggressiveness of VAD. A more
363 // aggressive mode results in more frames labeled
364 // as in-active, c.f. definition of
365 // ACMVADMode in audio_coding_module_typedefs.h
366 // for valid values.
367 //
368 // Return value:
369 // -1 if failed to set up VAD/DTX,
370 // 0 if succeeded.
371 //
372 virtual int32_t SetVAD(const bool enable_dtx = true,
Yves Gerey665174f2018-06-19 15:03:05 +0200373 const bool enable_vad = false,
374 const ACMVADMode vad_mode = VADNormal) = 0;
kjellander3e6db232015-11-26 04:44:54 -0800375
376 ///////////////////////////////////////////////////////////////////////////
377 // int32_t VAD()
378 // Get VAD status.
379 //
380 // Outputs:
381 // -dtx_enabled : is set to true if DTX is enabled, otherwise
382 // is set to false.
383 // -vad_enabled : is set to true if VAD is enabled, otherwise
384 // is set to false.
385 // -vad_mode : is set to the current aggressiveness of VAD.
386 //
387 // Return value:
388 // -1 if fails to retrieve the setting of DTX/VAD,
389 // 0 if succeeded.
390 //
Yves Gerey665174f2018-06-19 15:03:05 +0200391 virtual int32_t VAD(bool* dtx_enabled,
392 bool* vad_enabled,
393 ACMVADMode* vad_mode) const = 0;
kjellander3e6db232015-11-26 04:44:54 -0800394
395 ///////////////////////////////////////////////////////////////////////////
396 // int32_t RegisterVADCallback()
397 // Call this method to register a callback function which is called
398 // any time that ACM encounters an empty frame. That is a frame which is
399 // recognized inactive. Depending on the codec WebRtc VAD or internal codec
400 // VAD is employed to identify a frame as active/inactive.
401 //
402 // Input:
403 // -vad_callback : pointer to a callback function.
404 //
405 // Return value:
406 // -1 if failed to register the callback function.
407 // 0 if the callback function is registered successfully.
408 //
409 virtual int32_t RegisterVADCallback(ACMVADCallback* vad_callback) = 0;
410
411 ///////////////////////////////////////////////////////////////////////////
412 // Receiver
413 //
414
415 ///////////////////////////////////////////////////////////////////////////
416 // int32_t InitializeReceiver()
417 // Any decoder-related state of ACM will be initialized to the
418 // same state when ACM is created. This will not interrupt or
419 // effect encoding functionality of ACM. ACM would lose all the
420 // decoding-related settings by calling this function.
421 // For instance, all registered codecs are deleted and have to be
422 // registered again.
423 //
424 // Return value:
425 // -1 if failed to initialize,
426 // 0 if succeeded.
427 //
428 virtual int32_t InitializeReceiver() = 0;
429
430 ///////////////////////////////////////////////////////////////////////////
431 // int32_t ReceiveFrequency()
432 // Get sampling frequency of the last received payload.
433 //
434 // Return value:
435 // non-negative the sampling frequency in Hertz.
436 // -1 if an error has occurred.
437 //
438 virtual int32_t ReceiveFrequency() const = 0;
439
440 ///////////////////////////////////////////////////////////////////////////
441 // int32_t PlayoutFrequency()
442 // Get sampling frequency of audio played out.
443 //
444 // Return value:
445 // the sampling frequency in Hertz.
446 //
447 virtual int32_t PlayoutFrequency() const = 0;
448
kwiberg1c07c702017-03-27 07:15:49 -0700449 // Replace any existing decoders with the given payload type -> decoder map.
450 virtual void SetReceiveCodecs(
451 const std::map<int, SdpAudioFormat>& codecs) = 0;
452
kwiberg5adaf732016-10-04 09:33:27 -0700453 // Registers a decoder for the given payload type. Returns true iff
454 // successful.
455 virtual bool RegisterReceiveCodec(int rtp_payload_type,
456 const SdpAudioFormat& audio_format) = 0;
457
kjellander3e6db232015-11-26 04:44:54 -0800458 ///////////////////////////////////////////////////////////////////////////
459 // int32_t RegisterReceiveCodec()
460 // Register possible decoders, can be called multiple times for
461 // codecs, CNG-NB, CNG-WB, CNG-SWB, AVT and RED.
462 //
463 // Input:
464 // -receive_codec : parameters of the codec to be registered, c.f.
465 // common_types.h for the definition of
466 // CodecInst.
467 //
468 // Return value:
469 // -1 if failed to register the codec
470 // 0 if the codec registered successfully.
471 //
472 virtual int RegisterReceiveCodec(const CodecInst& receive_codec) = 0;
473
kwiberg4cdbd572016-03-30 03:10:05 -0700474 // Register a decoder; call repeatedly to register multiple decoders. |df| is
475 // a decoder factory that returns an iSAC decoder; it will be called once if
476 // the decoder being registered is iSAC.
477 virtual int RegisterReceiveCodec(
478 const CodecInst& receive_codec,
kwiberg24c7c122016-09-28 11:57:10 -0700479 rtc::FunctionView<std::unique_ptr<AudioDecoder>()> isac_factory) = 0;
kwiberg4cdbd572016-03-30 03:10:05 -0700480
henrik.lundin4cf61dd2015-12-09 06:20:58 -0800481 // Registers an external decoder. The name is only used to provide information
482 // back to the caller about the decoder. Hence, the name is arbitrary, and may
483 // be empty.
kjellander3e6db232015-11-26 04:44:54 -0800484 virtual int RegisterExternalReceiveCodec(int rtp_payload_type,
485 AudioDecoder* external_decoder,
486 int sample_rate_hz,
henrik.lundin4cf61dd2015-12-09 06:20:58 -0800487 int num_channels,
488 const std::string& name) = 0;
kjellander3e6db232015-11-26 04:44:54 -0800489
490 ///////////////////////////////////////////////////////////////////////////
491 // int32_t UnregisterReceiveCodec()
492 // Unregister the codec currently registered with a specific payload type
493 // from the list of possible receive codecs.
494 //
495 // Input:
496 // -payload_type : The number representing the payload type to
497 // unregister.
498 //
499 // Output:
500 // -1 if fails to unregister.
501 // 0 if the given codec is successfully unregistered.
502 //
Yves Gerey665174f2018-06-19 15:03:05 +0200503 virtual int UnregisterReceiveCodec(uint8_t payload_type) = 0;
kjellander3e6db232015-11-26 04:44:54 -0800504
505 ///////////////////////////////////////////////////////////////////////////
506 // int32_t ReceiveCodec()
507 // Get the codec associated with last received payload.
508 //
509 // Output:
510 // -curr_receive_codec : parameters of the codec associated with the last
511 // received payload, c.f. common_types.h for
512 // the definition of CodecInst.
513 //
514 // Return value:
515 // -1 if failed to retrieve the codec,
516 // 0 if the codec is successfully retrieved.
517 //
518 virtual int32_t ReceiveCodec(CodecInst* curr_receive_codec) const = 0;
519
520 ///////////////////////////////////////////////////////////////////////////
Danil Chapovalovb6021232018-06-19 13:26:36 +0200521 // absl::optional<SdpAudioFormat> ReceiveFormat()
ossue280cde2016-10-12 11:04:10 -0700522 // Get the format associated with last received payload.
523 //
524 // Return value:
525 // An SdpAudioFormat describing the format associated with the last
526 // received payload.
527 // An empty Optional if no payload has yet been received.
528 //
Danil Chapovalovb6021232018-06-19 13:26:36 +0200529 virtual absl::optional<SdpAudioFormat> ReceiveFormat() const = 0;
ossue280cde2016-10-12 11:04:10 -0700530
531 ///////////////////////////////////////////////////////////////////////////
kjellander3e6db232015-11-26 04:44:54 -0800532 // int32_t IncomingPacket()
533 // Call this function to insert a parsed RTP packet into ACM.
534 //
535 // Inputs:
536 // -incoming_payload : received payload.
537 // -payload_len_bytes : the length of payload in bytes.
538 // -rtp_info : the relevant information retrieved from RTP
539 // header.
540 //
541 // Return value:
542 // -1 if failed to push in the payload
543 // 0 if payload is successfully pushed in.
544 //
545 virtual int32_t IncomingPacket(const uint8_t* incoming_payload,
546 const size_t payload_len_bytes,
547 const WebRtcRTPHeader& rtp_info) = 0;
548
549 ///////////////////////////////////////////////////////////////////////////
kjellander3e6db232015-11-26 04:44:54 -0800550 // int SetMinimumPlayoutDelay()
551 // Set a minimum for the playout delay, used for lip-sync. NetEq maintains
552 // such a delay unless channel condition yields to a higher delay.
553 //
554 // Input:
555 // -time_ms : minimum delay in milliseconds.
556 //
557 // Return value:
558 // -1 if failed to set the delay,
559 // 0 if the minimum delay is set.
560 //
561 virtual int SetMinimumPlayoutDelay(int time_ms) = 0;
562
563 ///////////////////////////////////////////////////////////////////////////
564 // int SetMaximumPlayoutDelay()
565 // Set a maximum for the playout delay
566 //
567 // Input:
568 // -time_ms : maximum delay in milliseconds.
569 //
570 // Return value:
571 // -1 if failed to set the delay,
572 // 0 if the maximum delay is set.
573 //
574 virtual int SetMaximumPlayoutDelay(int time_ms) = 0;
575
henrik.lundin9a410dd2016-04-06 01:39:22 -0700576 ///////////////////////////////////////////////////////////////////////////
577 // int32_t PlayoutTimestamp()
578 // The send timestamp of an RTP packet is associated with the decoded
579 // audio of the packet in question. This function returns the timestamp of
580 // the latest audio obtained by calling PlayoutData10ms(), or empty if no
581 // valid timestamp is available.
582 //
Danil Chapovalovb6021232018-06-19 13:26:36 +0200583 virtual absl::optional<uint32_t> PlayoutTimestamp() = 0;
kjellander3e6db232015-11-26 04:44:54 -0800584
585 ///////////////////////////////////////////////////////////////////////////
henrik.lundinb3f1c5d2016-08-22 15:39:53 -0700586 // int FilteredCurrentDelayMs()
587 // Returns the current total delay from NetEq (packet buffer and sync buffer)
588 // in ms, with smoothing applied to even out short-time fluctuations due to
589 // jitter. The packet buffer part of the delay is not updated during DTX/CNG
590 // periods.
591 //
592 virtual int FilteredCurrentDelayMs() const = 0;
593
594 ///////////////////////////////////////////////////////////////////////////
Henrik Lundinabbff892017-11-29 09:14:04 +0100595 // int FilteredCurrentDelayMs()
596 // Returns the current target delay for NetEq in ms.
597 //
598 virtual int TargetDelayMs() const = 0;
599
600 ///////////////////////////////////////////////////////////////////////////
kjellander3e6db232015-11-26 04:44:54 -0800601 // int32_t PlayoutData10Ms(
602 // Get 10 milliseconds of raw audio data for playout, at the given sampling
603 // frequency. ACM will perform a resampling if required.
604 //
605 // Input:
606 // -desired_freq_hz : the desired sampling frequency, in Hertz, of the
607 // output audio. If set to -1, the function returns
608 // the audio at the current sampling frequency.
609 //
610 // Output:
611 // -audio_frame : output audio frame which contains raw audio data
Fredrik Solenbergbbf21a32018-04-12 22:44:09 +0200612 // and other relevant parameters.
henrik.lundin834a6ea2016-05-13 03:45:24 -0700613 // -muted : if true, the sample data in audio_frame is not
614 // populated, and must be interpreted as all zero.
kjellander3e6db232015-11-26 04:44:54 -0800615 //
616 // Return value:
617 // -1 if the function fails,
618 // 0 if the function succeeds.
619 //
620 virtual int32_t PlayoutData10Ms(int32_t desired_freq_hz,
henrik.lundin834a6ea2016-05-13 03:45:24 -0700621 AudioFrame* audio_frame,
622 bool* muted) = 0;
623
kjellander3e6db232015-11-26 04:44:54 -0800624 ///////////////////////////////////////////////////////////////////////////
625 // Codec specific
626 //
627
628 ///////////////////////////////////////////////////////////////////////////
629 // int SetOpusApplication()
630 // Sets the intended application if current send codec is Opus. Opus uses this
631 // to optimize the encoding for applications like VOIP and music. Currently,
632 // two modes are supported: kVoip and kAudio.
633 //
634 // Input:
635 // - application : intended application.
636 //
637 // Return value:
638 // -1 if current send codec is not Opus or error occurred in setting the
639 // Opus application mode.
640 // 0 if the Opus application mode is successfully set.
641 //
642 virtual int SetOpusApplication(OpusApplicationMode application) = 0;
643
644 ///////////////////////////////////////////////////////////////////////////
645 // int SetOpusMaxPlaybackRate()
646 // If current send codec is Opus, informs it about maximum playback rate the
647 // receiver will render. Opus can use this information to optimize the bit
648 // rate and increase the computation efficiency.
649 //
650 // Input:
651 // -frequency_hz : maximum playback rate in Hz.
652 //
653 // Return value:
654 // -1 if current send codec is not Opus or
655 // error occurred in setting the maximum playback rate,
656 // 0 if maximum bandwidth is set successfully.
657 //
658 virtual int SetOpusMaxPlaybackRate(int frequency_hz) = 0;
659
660 ///////////////////////////////////////////////////////////////////////////
661 // EnableOpusDtx()
662 // Enable the DTX, if current send codec is Opus.
663 //
664 // Return value:
665 // -1 if current send codec is not Opus or error occurred in enabling the
666 // Opus DTX.
667 // 0 if Opus DTX is enabled successfully.
668 //
669 virtual int EnableOpusDtx() = 0;
670
671 ///////////////////////////////////////////////////////////////////////////
672 // int DisableOpusDtx()
673 // If current send codec is Opus, disables its internal DTX.
674 //
675 // Return value:
676 // -1 if current send codec is not Opus or error occurred in disabling DTX.
677 // 0 if Opus DTX is disabled successfully.
678 //
679 virtual int DisableOpusDtx() = 0;
680
681 ///////////////////////////////////////////////////////////////////////////
682 // statistics
683 //
684
685 ///////////////////////////////////////////////////////////////////////////
686 // int32_t GetNetworkStatistics()
687 // Get network statistics. Note that the internal statistics of NetEq are
688 // reset by this call.
689 //
690 // Input:
691 // -network_statistics : a structure that contains network statistics.
692 //
693 // Return value:
694 // -1 if failed to set the network statistics,
695 // 0 if statistics are set successfully.
696 //
697 virtual int32_t GetNetworkStatistics(
698 NetworkStatistics* network_statistics) = 0;
699
700 //
701 // Enable NACK and set the maximum size of the NACK list. If NACK is already
702 // enable then the maximum NACK list size is modified accordingly.
703 //
704 // If the sequence number of last received packet is N, the sequence numbers
705 // of NACK list are in the range of [N - |max_nack_list_size|, N).
706 //
707 // |max_nack_list_size| should be positive (none zero) and less than or
708 // equal to |Nack::kNackListSizeLimit|. Otherwise, No change is applied and -1
709 // is returned. 0 is returned at success.
710 //
711 virtual int EnableNack(size_t max_nack_list_size) = 0;
712
713 // Disable NACK.
714 virtual void DisableNack() = 0;
715
716 //
717 // Get a list of packets to be retransmitted. |round_trip_time_ms| is an
718 // estimate of the round-trip-time (in milliseconds). Missing packets which
719 // will be playout in a shorter time than the round-trip-time (with respect
720 // to the time this API is called) will not be included in the list.
721 //
722 // Negative |round_trip_time_ms| results is an error message and empty list
723 // is returned.
724 //
725 virtual std::vector<uint16_t> GetNackList(
726 int64_t round_trip_time_ms) const = 0;
727
728 virtual void GetDecodingCallStatistics(
729 AudioDecodingCallStats* call_stats) const = 0;
ivoce1198e02017-09-08 08:13:19 -0700730
731 virtual ANAStats GetANAStats() const = 0;
kjellander3e6db232015-11-26 04:44:54 -0800732};
733
734} // namespace webrtc
735
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200736#endif // MODULES_AUDIO_CODING_INCLUDE_AUDIO_CODING_MODULE_H_