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