blob: 3c193a41fe52dddabf8b137b2c3eab0b497ffe7d [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "api/audio_codecs/audio_decoder_factory.h"
19#include "api/audio_codecs/audio_encoder.h"
20#include "api/optional.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 //
130 static int Codec(const char* payload_name, CodecInst* codec,
Peter Kasting69558702016-01-12 16:26:35 -0800131 int sampling_freq_hz, 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 //
149 static int Codec(const char* payload_name, int sampling_freq_hz,
Peter Kasting69558702016-01-12 16:26:35 -0800150 size_t channels);
kjellander3e6db232015-11-26 04:44:54 -0800151
152 ///////////////////////////////////////////////////////////////////////////
153 // bool IsCodecValid()
154 // Checks the validity of the parameters of the given codec.
155 //
156 // Input:
157 // -codec : the structure which keeps the parameters of the
158 // codec.
159 //
160 // Return value:
161 // true if the parameters are valid,
162 // false if any parameter is not valid.
163 //
164 static bool IsCodecValid(const CodecInst& codec);
165
166 ///////////////////////////////////////////////////////////////////////////
167 // Sender
168 //
169
170 ///////////////////////////////////////////////////////////////////////////
171 // int32_t RegisterSendCodec()
172 // Registers a codec, specified by |send_codec|, as sending codec.
173 // This API can be called multiple of times to register Codec. The last codec
174 // registered overwrites the previous ones.
175 // The API can also be used to change payload type for CNG and RED, which are
176 // registered by default to default payload types.
177 // Note that registering CNG and RED won't overwrite speech codecs.
178 // This API can be called to set/change the send payload-type, frame-size
179 // or encoding rate (if applicable for the codec).
180 //
181 // Note: If a stereo codec is registered as send codec, VAD/DTX will
182 // automatically be turned off, since it is not supported for stereo sending.
183 //
184 // Note: If a secondary encoder is already registered, and the new send-codec
185 // has a sampling rate that does not match the secondary encoder, the
186 // secondary encoder will be unregistered.
187 //
188 // Input:
189 // -send_codec : Parameters of the codec to be registered, c.f.
190 // common_types.h for the definition of
191 // CodecInst.
192 //
193 // Return value:
194 // -1 if failed to initialize,
195 // 0 if succeeded.
196 //
197 virtual int32_t RegisterSendCodec(const CodecInst& send_codec) = 0;
198
199 // Registers |external_speech_encoder| as encoder. The new encoder will
200 // replace any previously registered speech encoder (internal or external).
201 virtual void RegisterExternalSendCodec(
202 AudioEncoder* external_speech_encoder) = 0;
203
kwiberg4cdbd572016-03-30 03:10:05 -0700204 // |modifier| is called exactly once with one argument: a pointer to the
205 // unique_ptr that holds the current encoder (which is null if there is no
206 // current encoder). For the duration of the call, |modifier| has exclusive
207 // access to the unique_ptr; it may call the encoder, steal the encoder and
208 // replace it with another encoder or with nullptr, etc.
209 virtual void ModifyEncoder(
kwiberg24c7c122016-09-28 11:57:10 -0700210 rtc::FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier) = 0;
kwiberg4cdbd572016-03-30 03:10:05 -0700211
ivoc85228d62016-07-27 04:53:47 -0700212 // |modifier| is called exactly once with one argument: a const pointer to the
213 // current encoder (which is null if there is no current encoder).
kwiberg24c7c122016-09-28 11:57:10 -0700214 virtual void QueryEncoder(
215 rtc::FunctionView<void(AudioEncoder const*)> query) = 0;
ivoc85228d62016-07-27 04:53:47 -0700216
kwiberg4cdbd572016-03-30 03:10:05 -0700217 // Utility method for simply replacing the existing encoder with a new one.
218 void SetEncoder(std::unique_ptr<AudioEncoder> new_encoder) {
219 ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) {
220 *encoder = std::move(new_encoder);
221 });
222 }
223
kjellander3e6db232015-11-26 04:44:54 -0800224 ///////////////////////////////////////////////////////////////////////////
225 // int32_t SendCodec()
226 // Get parameters for the codec currently registered as send codec.
227 //
228 // Return value:
229 // The send codec, or nothing if we don't have one
230 //
231 virtual rtc::Optional<CodecInst> SendCodec() const = 0;
232
233 ///////////////////////////////////////////////////////////////////////////
234 // int32_t SendFrequency()
235 // Get the sampling frequency of the current encoder in Hertz.
236 //
237 // Return value:
238 // positive; sampling frequency [Hz] of the current encoder.
239 // -1 if an error has happened.
240 //
241 virtual int32_t SendFrequency() const = 0;
242
243 ///////////////////////////////////////////////////////////////////////////
244 // Sets the bitrate to the specified value in bits/sec. If the value is not
245 // supported by the codec, it will choose another appropriate value.
minyue7e304322016-10-12 05:00:55 -0700246 //
247 // This is only used in test code that rely on old ACM APIs.
248 // TODO(minyue): Remove it when possible.
kjellander3e6db232015-11-26 04:44:54 -0800249 virtual void SetBitRate(int bitrate_bps) = 0;
250
251 // int32_t RegisterTransportCallback()
252 // Register a transport callback which will be called to deliver
253 // the encoded buffers whenever Process() is called and a
254 // bit-stream is ready.
255 //
256 // Input:
257 // -transport : pointer to the callback class
258 // transport->SendData() is called whenever
259 // Process() is called and bit-stream is ready
260 // to deliver.
261 //
262 // Return value:
263 // -1 if the transport callback could not be registered
264 // 0 if registration is successful.
265 //
266 virtual int32_t RegisterTransportCallback(
267 AudioPacketizationCallback* transport) = 0;
268
269 ///////////////////////////////////////////////////////////////////////////
270 // int32_t Add10MsData()
271 // Add 10MS of raw (PCM) audio data and encode it. If the sampling
272 // frequency of the audio does not match the sampling frequency of the
273 // current encoder ACM will resample the audio. If an encoded packet was
274 // produced, it will be delivered via the callback object registered using
275 // RegisterTransportCallback, and the return value from this function will
276 // be the number of bytes encoded.
277 //
278 // Input:
279 // -audio_frame : the input audio frame, containing raw audio
Fredrik Solenbergbbf21a32018-04-12 22:44:09 +0200280 // sampling frequency etc.
kjellander3e6db232015-11-26 04:44:54 -0800281 //
282 // Return value:
283 // >= 0 number of bytes encoded.
284 // -1 some error occurred.
285 //
286 virtual int32_t Add10MsData(const AudioFrame& audio_frame) = 0;
287
288 ///////////////////////////////////////////////////////////////////////////
289 // (RED) Redundant Coding
290 //
291
292 ///////////////////////////////////////////////////////////////////////////
293 // int32_t SetREDStatus()
294 // configure RED status i.e. on/off.
295 //
296 // RFC 2198 describes a solution which has a single payload type which
297 // signifies a packet with redundancy. That packet then becomes a container,
298 // encapsulating multiple payloads into a single RTP packet.
299 // Such a scheme is flexible, since any amount of redundancy may be
300 // encapsulated within a single packet. There is, however, a small overhead
301 // since each encapsulated payload must be preceded by a header indicating
302 // the type of data enclosed.
303 //
304 // Input:
305 // -enable_red : if true RED is enabled, otherwise RED is
306 // disabled.
307 //
308 // Return value:
309 // -1 if failed to set RED status,
310 // 0 if succeeded.
311 //
312 virtual int32_t SetREDStatus(bool enable_red) = 0;
313
314 ///////////////////////////////////////////////////////////////////////////
315 // bool REDStatus()
316 // Get RED status
317 //
318 // Return value:
319 // true if RED is enabled,
320 // false if RED is disabled.
321 //
322 virtual bool REDStatus() const = 0;
323
324 ///////////////////////////////////////////////////////////////////////////
325 // (FEC) Forward Error Correction (codec internal)
326 //
327
328 ///////////////////////////////////////////////////////////////////////////
329 // int32_t SetCodecFEC()
330 // Configures codec internal FEC status i.e. on/off. No effects on codecs that
331 // do not provide internal FEC.
332 //
333 // Input:
334 // -enable_fec : if true FEC will be enabled otherwise the FEC is
335 // disabled.
336 //
337 // Return value:
338 // -1 if failed, or the codec does not support FEC
339 // 0 if succeeded.
340 //
341 virtual int SetCodecFEC(bool enable_codec_fec) = 0;
342
343 ///////////////////////////////////////////////////////////////////////////
344 // bool CodecFEC()
345 // Gets status of codec internal FEC.
346 //
347 // Return value:
348 // true if FEC is enabled,
349 // false if FEC is disabled.
350 //
351 virtual bool CodecFEC() const = 0;
352
353 ///////////////////////////////////////////////////////////////////////////
354 // int SetPacketLossRate()
355 // Sets expected packet loss rate for encoding. Some encoders provide packet
356 // loss gnostic encoding to make stream less sensitive to packet losses,
357 // through e.g., FEC. No effects on codecs that do not provide such encoding.
358 //
359 // Input:
360 // -packet_loss_rate : expected packet loss rate (0 -- 100 inclusive).
361 //
362 // Return value
363 // -1 if failed to set packet loss rate,
364 // 0 if succeeded.
365 //
minyue7e304322016-10-12 05:00:55 -0700366 // This is only used in test code that rely on old ACM APIs.
367 // TODO(minyue): Remove it when possible.
kjellander3e6db232015-11-26 04:44:54 -0800368 virtual int SetPacketLossRate(int packet_loss_rate) = 0;
369
370 ///////////////////////////////////////////////////////////////////////////
371 // (VAD) Voice Activity Detection
372 //
373
374 ///////////////////////////////////////////////////////////////////////////
375 // int32_t SetVAD()
376 // If DTX is enabled & the codec does not have internal DTX/VAD
377 // WebRtc VAD will be automatically enabled and |enable_vad| is ignored.
378 //
379 // If DTX is disabled but VAD is enabled no DTX packets are send,
380 // regardless of whether the codec has internal DTX/VAD or not. In this
381 // case, WebRtc VAD is running to label frames as active/in-active.
382 //
383 // NOTE! VAD/DTX is not supported when sending stereo.
384 //
385 // Inputs:
386 // -enable_dtx : if true DTX is enabled,
387 // otherwise DTX is disabled.
388 // -enable_vad : if true VAD is enabled,
389 // otherwise VAD is disabled.
390 // -vad_mode : determines the aggressiveness of VAD. A more
391 // aggressive mode results in more frames labeled
392 // as in-active, c.f. definition of
393 // ACMVADMode in audio_coding_module_typedefs.h
394 // for valid values.
395 //
396 // Return value:
397 // -1 if failed to set up VAD/DTX,
398 // 0 if succeeded.
399 //
400 virtual int32_t SetVAD(const bool enable_dtx = true,
401 const bool enable_vad = false,
402 const ACMVADMode vad_mode = VADNormal) = 0;
403
404 ///////////////////////////////////////////////////////////////////////////
405 // int32_t VAD()
406 // Get VAD status.
407 //
408 // Outputs:
409 // -dtx_enabled : is set to true if DTX is enabled, otherwise
410 // is set to false.
411 // -vad_enabled : is set to true if VAD is enabled, otherwise
412 // is set to false.
413 // -vad_mode : is set to the current aggressiveness of VAD.
414 //
415 // Return value:
416 // -1 if fails to retrieve the setting of DTX/VAD,
417 // 0 if succeeded.
418 //
419 virtual int32_t VAD(bool* dtx_enabled, bool* vad_enabled,
420 ACMVADMode* vad_mode) const = 0;
421
422 ///////////////////////////////////////////////////////////////////////////
423 // int32_t RegisterVADCallback()
424 // Call this method to register a callback function which is called
425 // any time that ACM encounters an empty frame. That is a frame which is
426 // recognized inactive. Depending on the codec WebRtc VAD or internal codec
427 // VAD is employed to identify a frame as active/inactive.
428 //
429 // Input:
430 // -vad_callback : pointer to a callback function.
431 //
432 // Return value:
433 // -1 if failed to register the callback function.
434 // 0 if the callback function is registered successfully.
435 //
436 virtual int32_t RegisterVADCallback(ACMVADCallback* vad_callback) = 0;
437
438 ///////////////////////////////////////////////////////////////////////////
439 // Receiver
440 //
441
442 ///////////////////////////////////////////////////////////////////////////
443 // int32_t InitializeReceiver()
444 // Any decoder-related state of ACM will be initialized to the
445 // same state when ACM is created. This will not interrupt or
446 // effect encoding functionality of ACM. ACM would lose all the
447 // decoding-related settings by calling this function.
448 // For instance, all registered codecs are deleted and have to be
449 // registered again.
450 //
451 // Return value:
452 // -1 if failed to initialize,
453 // 0 if succeeded.
454 //
455 virtual int32_t InitializeReceiver() = 0;
456
457 ///////////////////////////////////////////////////////////////////////////
458 // int32_t ReceiveFrequency()
459 // Get sampling frequency of the last received payload.
460 //
461 // Return value:
462 // non-negative the sampling frequency in Hertz.
463 // -1 if an error has occurred.
464 //
465 virtual int32_t ReceiveFrequency() const = 0;
466
467 ///////////////////////////////////////////////////////////////////////////
468 // int32_t PlayoutFrequency()
469 // Get sampling frequency of audio played out.
470 //
471 // Return value:
472 // the sampling frequency in Hertz.
473 //
474 virtual int32_t PlayoutFrequency() const = 0;
475
kwiberg1c07c702017-03-27 07:15:49 -0700476 // Replace any existing decoders with the given payload type -> decoder map.
477 virtual void SetReceiveCodecs(
478 const std::map<int, SdpAudioFormat>& codecs) = 0;
479
kwiberg5adaf732016-10-04 09:33:27 -0700480 // Registers a decoder for the given payload type. Returns true iff
481 // successful.
482 virtual bool RegisterReceiveCodec(int rtp_payload_type,
483 const SdpAudioFormat& audio_format) = 0;
484
kjellander3e6db232015-11-26 04:44:54 -0800485 ///////////////////////////////////////////////////////////////////////////
486 // int32_t RegisterReceiveCodec()
487 // Register possible decoders, can be called multiple times for
488 // codecs, CNG-NB, CNG-WB, CNG-SWB, AVT and RED.
489 //
490 // Input:
491 // -receive_codec : parameters of the codec to be registered, c.f.
492 // common_types.h for the definition of
493 // CodecInst.
494 //
495 // Return value:
496 // -1 if failed to register the codec
497 // 0 if the codec registered successfully.
498 //
499 virtual int RegisterReceiveCodec(const CodecInst& receive_codec) = 0;
500
kwiberg4cdbd572016-03-30 03:10:05 -0700501 // Register a decoder; call repeatedly to register multiple decoders. |df| is
502 // a decoder factory that returns an iSAC decoder; it will be called once if
503 // the decoder being registered is iSAC.
504 virtual int RegisterReceiveCodec(
505 const CodecInst& receive_codec,
kwiberg24c7c122016-09-28 11:57:10 -0700506 rtc::FunctionView<std::unique_ptr<AudioDecoder>()> isac_factory) = 0;
kwiberg4cdbd572016-03-30 03:10:05 -0700507
henrik.lundin4cf61dd2015-12-09 06:20:58 -0800508 // Registers an external decoder. The name is only used to provide information
509 // back to the caller about the decoder. Hence, the name is arbitrary, and may
510 // be empty.
kjellander3e6db232015-11-26 04:44:54 -0800511 virtual int RegisterExternalReceiveCodec(int rtp_payload_type,
512 AudioDecoder* external_decoder,
513 int sample_rate_hz,
henrik.lundin4cf61dd2015-12-09 06:20:58 -0800514 int num_channels,
515 const std::string& name) = 0;
kjellander3e6db232015-11-26 04:44:54 -0800516
517 ///////////////////////////////////////////////////////////////////////////
518 // int32_t UnregisterReceiveCodec()
519 // Unregister the codec currently registered with a specific payload type
520 // from the list of possible receive codecs.
521 //
522 // Input:
523 // -payload_type : The number representing the payload type to
524 // unregister.
525 //
526 // Output:
527 // -1 if fails to unregister.
528 // 0 if the given codec is successfully unregistered.
529 //
530 virtual int UnregisterReceiveCodec(
531 uint8_t payload_type) = 0;
532
533 ///////////////////////////////////////////////////////////////////////////
534 // int32_t ReceiveCodec()
535 // Get the codec associated with last received payload.
536 //
537 // Output:
538 // -curr_receive_codec : parameters of the codec associated with the last
539 // received payload, c.f. common_types.h for
540 // the definition of CodecInst.
541 //
542 // Return value:
543 // -1 if failed to retrieve the codec,
544 // 0 if the codec is successfully retrieved.
545 //
546 virtual int32_t ReceiveCodec(CodecInst* curr_receive_codec) const = 0;
547
548 ///////////////////////////////////////////////////////////////////////////
ossue280cde2016-10-12 11:04:10 -0700549 // rtc::Optional<SdpAudioFormat> ReceiveFormat()
550 // Get the format associated with last received payload.
551 //
552 // Return value:
553 // An SdpAudioFormat describing the format associated with the last
554 // received payload.
555 // An empty Optional if no payload has yet been received.
556 //
557 virtual rtc::Optional<SdpAudioFormat> ReceiveFormat() const = 0;
558
559 ///////////////////////////////////////////////////////////////////////////
kjellander3e6db232015-11-26 04:44:54 -0800560 // int32_t IncomingPacket()
561 // Call this function to insert a parsed RTP packet into ACM.
562 //
563 // Inputs:
564 // -incoming_payload : received payload.
565 // -payload_len_bytes : the length of payload in bytes.
566 // -rtp_info : the relevant information retrieved from RTP
567 // header.
568 //
569 // Return value:
570 // -1 if failed to push in the payload
571 // 0 if payload is successfully pushed in.
572 //
573 virtual int32_t IncomingPacket(const uint8_t* incoming_payload,
574 const size_t payload_len_bytes,
575 const WebRtcRTPHeader& rtp_info) = 0;
576
577 ///////////////////////////////////////////////////////////////////////////
kjellander3e6db232015-11-26 04:44:54 -0800578 // int SetMinimumPlayoutDelay()
579 // Set a minimum for the playout delay, used for lip-sync. NetEq maintains
580 // such a delay unless channel condition yields to a higher delay.
581 //
582 // Input:
583 // -time_ms : minimum delay in milliseconds.
584 //
585 // Return value:
586 // -1 if failed to set the delay,
587 // 0 if the minimum delay is set.
588 //
589 virtual int SetMinimumPlayoutDelay(int time_ms) = 0;
590
591 ///////////////////////////////////////////////////////////////////////////
592 // int SetMaximumPlayoutDelay()
593 // Set a maximum for the playout delay
594 //
595 // Input:
596 // -time_ms : maximum delay in milliseconds.
597 //
598 // Return value:
599 // -1 if failed to set the delay,
600 // 0 if the maximum delay is set.
601 //
602 virtual int SetMaximumPlayoutDelay(int time_ms) = 0;
603
solenberg08b19df2017-02-15 00:42:31 -0800604 // TODO(kwiberg): Consider if this is needed anymore, now that voe::Channel
605 // doesn't use it.
kjellander3e6db232015-11-26 04:44:54 -0800606 // The shortest latency, in milliseconds, required by jitter buffer. This
607 // is computed based on inter-arrival times and playout mode of NetEq. The
608 // actual delay is the maximum of least-required-delay and the minimum-delay
609 // specified by SetMinumumPlayoutDelay() API.
610 //
611 virtual int LeastRequiredDelayMs() const = 0;
612
kjellander3e6db232015-11-26 04:44:54 -0800613 // int32_t PlayoutTimestamp()
614 // The send timestamp of an RTP packet is associated with the decoded
615 // audio of the packet in question. This function returns the timestamp of
616 // the latest audio obtained by calling PlayoutData10ms().
617 //
618 // Input:
619 // -timestamp : a reference to a uint32_t to receive the
620 // timestamp.
621 // Return value:
622 // 0 if the output is a correct timestamp.
623 // -1 if failed to output the correct timestamp.
624 //
henrik.lundin9a410dd2016-04-06 01:39:22 -0700625 RTC_DEPRECATED virtual int32_t PlayoutTimestamp(uint32_t* timestamp) = 0;
626
627 ///////////////////////////////////////////////////////////////////////////
628 // int32_t PlayoutTimestamp()
629 // The send timestamp of an RTP packet is associated with the decoded
630 // audio of the packet in question. This function returns the timestamp of
631 // the latest audio obtained by calling PlayoutData10ms(), or empty if no
632 // valid timestamp is available.
633 //
634 virtual rtc::Optional<uint32_t> PlayoutTimestamp() = 0;
kjellander3e6db232015-11-26 04:44:54 -0800635
636 ///////////////////////////////////////////////////////////////////////////
henrik.lundinb3f1c5d2016-08-22 15:39:53 -0700637 // int FilteredCurrentDelayMs()
638 // Returns the current total delay from NetEq (packet buffer and sync buffer)
639 // in ms, with smoothing applied to even out short-time fluctuations due to
640 // jitter. The packet buffer part of the delay is not updated during DTX/CNG
641 // periods.
642 //
643 virtual int FilteredCurrentDelayMs() const = 0;
644
645 ///////////////////////////////////////////////////////////////////////////
Henrik Lundinabbff892017-11-29 09:14:04 +0100646 // int FilteredCurrentDelayMs()
647 // Returns the current target delay for NetEq in ms.
648 //
649 virtual int TargetDelayMs() const = 0;
650
651 ///////////////////////////////////////////////////////////////////////////
kjellander3e6db232015-11-26 04:44:54 -0800652 // int32_t PlayoutData10Ms(
653 // Get 10 milliseconds of raw audio data for playout, at the given sampling
654 // frequency. ACM will perform a resampling if required.
655 //
656 // Input:
657 // -desired_freq_hz : the desired sampling frequency, in Hertz, of the
658 // output audio. If set to -1, the function returns
659 // the audio at the current sampling frequency.
660 //
661 // Output:
662 // -audio_frame : output audio frame which contains raw audio data
Fredrik Solenbergbbf21a32018-04-12 22:44:09 +0200663 // and other relevant parameters.
henrik.lundin834a6ea2016-05-13 03:45:24 -0700664 // -muted : if true, the sample data in audio_frame is not
665 // populated, and must be interpreted as all zero.
kjellander3e6db232015-11-26 04:44:54 -0800666 //
667 // Return value:
668 // -1 if the function fails,
669 // 0 if the function succeeds.
670 //
671 virtual int32_t PlayoutData10Ms(int32_t desired_freq_hz,
henrik.lundin834a6ea2016-05-13 03:45:24 -0700672 AudioFrame* audio_frame,
673 bool* muted) = 0;
674
675 /////////////////////////////////////////////////////////////////////////////
676 // Same as above, but without the muted parameter. This methods should not be
677 // used if enable_fast_accelerate was set to true in NetEq::Config.
678 // TODO(henrik.lundin) Remove this method when downstream dependencies are
679 // ready.
680 virtual int32_t PlayoutData10Ms(int32_t desired_freq_hz,
681 AudioFrame* audio_frame) = 0;
kjellander3e6db232015-11-26 04:44:54 -0800682
683 ///////////////////////////////////////////////////////////////////////////
684 // Codec specific
685 //
686
687 ///////////////////////////////////////////////////////////////////////////
688 // int SetOpusApplication()
689 // Sets the intended application if current send codec is Opus. Opus uses this
690 // to optimize the encoding for applications like VOIP and music. Currently,
691 // two modes are supported: kVoip and kAudio.
692 //
693 // Input:
694 // - application : intended application.
695 //
696 // Return value:
697 // -1 if current send codec is not Opus or error occurred in setting the
698 // Opus application mode.
699 // 0 if the Opus application mode is successfully set.
700 //
701 virtual int SetOpusApplication(OpusApplicationMode application) = 0;
702
703 ///////////////////////////////////////////////////////////////////////////
704 // int SetOpusMaxPlaybackRate()
705 // If current send codec is Opus, informs it about maximum playback rate the
706 // receiver will render. Opus can use this information to optimize the bit
707 // rate and increase the computation efficiency.
708 //
709 // Input:
710 // -frequency_hz : maximum playback rate in Hz.
711 //
712 // Return value:
713 // -1 if current send codec is not Opus or
714 // error occurred in setting the maximum playback rate,
715 // 0 if maximum bandwidth is set successfully.
716 //
717 virtual int SetOpusMaxPlaybackRate(int frequency_hz) = 0;
718
719 ///////////////////////////////////////////////////////////////////////////
720 // EnableOpusDtx()
721 // Enable the DTX, if current send codec is Opus.
722 //
723 // Return value:
724 // -1 if current send codec is not Opus or error occurred in enabling the
725 // Opus DTX.
726 // 0 if Opus DTX is enabled successfully.
727 //
728 virtual int EnableOpusDtx() = 0;
729
730 ///////////////////////////////////////////////////////////////////////////
731 // int DisableOpusDtx()
732 // If current send codec is Opus, disables its internal DTX.
733 //
734 // Return value:
735 // -1 if current send codec is not Opus or error occurred in disabling DTX.
736 // 0 if Opus DTX is disabled successfully.
737 //
738 virtual int DisableOpusDtx() = 0;
739
740 ///////////////////////////////////////////////////////////////////////////
741 // statistics
742 //
743
744 ///////////////////////////////////////////////////////////////////////////
745 // int32_t GetNetworkStatistics()
746 // Get network statistics. Note that the internal statistics of NetEq are
747 // reset by this call.
748 //
749 // Input:
750 // -network_statistics : a structure that contains network statistics.
751 //
752 // Return value:
753 // -1 if failed to set the network statistics,
754 // 0 if statistics are set successfully.
755 //
756 virtual int32_t GetNetworkStatistics(
757 NetworkStatistics* network_statistics) = 0;
758
759 //
760 // Enable NACK and set the maximum size of the NACK list. If NACK is already
761 // enable then the maximum NACK list size is modified accordingly.
762 //
763 // If the sequence number of last received packet is N, the sequence numbers
764 // of NACK list are in the range of [N - |max_nack_list_size|, N).
765 //
766 // |max_nack_list_size| should be positive (none zero) and less than or
767 // equal to |Nack::kNackListSizeLimit|. Otherwise, No change is applied and -1
768 // is returned. 0 is returned at success.
769 //
770 virtual int EnableNack(size_t max_nack_list_size) = 0;
771
772 // Disable NACK.
773 virtual void DisableNack() = 0;
774
775 //
776 // Get a list of packets to be retransmitted. |round_trip_time_ms| is an
777 // estimate of the round-trip-time (in milliseconds). Missing packets which
778 // will be playout in a shorter time than the round-trip-time (with respect
779 // to the time this API is called) will not be included in the list.
780 //
781 // Negative |round_trip_time_ms| results is an error message and empty list
782 // is returned.
783 //
784 virtual std::vector<uint16_t> GetNackList(
785 int64_t round_trip_time_ms) const = 0;
786
787 virtual void GetDecodingCallStatistics(
788 AudioDecodingCallStats* call_stats) const = 0;
ivoce1198e02017-09-08 08:13:19 -0700789
790 virtual ANAStats GetANAStats() const = 0;
kjellander3e6db232015-11-26 04:44:54 -0800791};
792
793} // namespace webrtc
794
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200795#endif // MODULES_AUDIO_CODING_INCLUDE_AUDIO_CODING_MODULE_H_