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