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