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