1 /*
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 
11 #ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_INCLUDE_AUDIO_CODING_MODULE_H_
12 #define WEBRTC_MODULES_AUDIO_CODING_MAIN_INCLUDE_AUDIO_CODING_MODULE_H_
13 
14 #include <vector>
15 
16 #include "webrtc/base/maybe.h"
17 #include "webrtc/common_types.h"
18 #include "webrtc/modules/audio_coding/main/include/audio_coding_module_typedefs.h"
19 #include "webrtc/modules/audio_coding/neteq/include/neteq.h"
20 #include "webrtc/modules/include/module.h"
21 #include "webrtc/system_wrappers/include/clock.h"
22 #include "webrtc/typedefs.h"
23 
24 namespace webrtc {
25 
26 // forward declarations
27 struct CodecInst;
28 struct WebRtcRTPHeader;
29 class AudioDecoder;
30 class AudioEncoder;
31 class AudioFrame;
32 class RTPFragmentationHeader;
33 
34 #define WEBRTC_10MS_PCM_AUDIO 960  // 16 bits super wideband 48 kHz
35 
36 // Callback class used for sending data ready to be packetized
37 class AudioPacketizationCallback {
38  public:
~AudioPacketizationCallback()39   virtual ~AudioPacketizationCallback() {}
40 
41   virtual int32_t SendData(FrameType frame_type,
42                            uint8_t payload_type,
43                            uint32_t timestamp,
44                            const uint8_t* payload_data,
45                            size_t payload_len_bytes,
46                            const RTPFragmentationHeader* fragmentation) = 0;
47 };
48 
49 // Callback class used for reporting VAD decision
50 class ACMVADCallback {
51  public:
~ACMVADCallback()52   virtual ~ACMVADCallback() {}
53 
54   virtual int32_t InFrameType(FrameType frame_type) = 0;
55 };
56 
57 class AudioCodingModule {
58  protected:
AudioCodingModule()59   AudioCodingModule() {}
60 
61  public:
62   struct Config {
ConfigConfig63     Config() : id(0), neteq_config(), clock(Clock::GetRealTimeClock()) {
64       // Post-decode VAD is disabled by default in NetEq, however, Audio
65       // Conference Mixer relies on VAD decisions and fails without them.
66       neteq_config.enable_post_decode_vad = true;
67     }
68 
69     int id;
70     NetEq::Config neteq_config;
71     Clock* clock;
72   };
73 
74   ///////////////////////////////////////////////////////////////////////////
75   // Creation and destruction of a ACM.
76   //
77   // The second method is used for testing where a simulated clock can be
78   // injected into ACM. ACM will take the ownership of the object clock and
79   // delete it when destroyed.
80   //
81   static AudioCodingModule* Create(int id);
82   static AudioCodingModule* Create(int id, Clock* clock);
83   static AudioCodingModule* Create(const Config& config);
84   virtual ~AudioCodingModule() = default;
85 
86   ///////////////////////////////////////////////////////////////////////////
87   //   Utility functions
88   //
89 
90   ///////////////////////////////////////////////////////////////////////////
91   // uint8_t NumberOfCodecs()
92   // Returns number of supported codecs.
93   //
94   // Return value:
95   //   number of supported codecs.
96   ///
97   static int NumberOfCodecs();
98 
99   ///////////////////////////////////////////////////////////////////////////
100   // int32_t Codec()
101   // Get supported codec with list number.
102   //
103   // Input:
104   //   -list_id             : list number.
105   //
106   // Output:
107   //   -codec              : a structure where the parameters of the codec,
108   //                         given by list number is written to.
109   //
110   // Return value:
111   //   -1 if the list number (list_id) is invalid.
112   //    0 if succeeded.
113   //
114   static int Codec(int list_id, CodecInst* codec);
115 
116   ///////////////////////////////////////////////////////////////////////////
117   // int32_t Codec()
118   // Get supported codec with the given codec name, sampling frequency, and
119   // a given number of channels.
120   //
121   // Input:
122   //   -payload_name       : name of the codec.
123   //   -sampling_freq_hz   : sampling frequency of the codec. Note! for RED
124   //                         a sampling frequency of -1 is a valid input.
125   //   -channels           : number of channels ( 1 - mono, 2 - stereo).
126   //
127   // Output:
128   //   -codec              : a structure where the function returns the
129   //                         default parameters of the codec.
130   //
131   // Return value:
132   //   -1 if no codec matches the given parameters.
133   //    0 if succeeded.
134   //
135   static int Codec(const char* payload_name, CodecInst* codec,
136                        int sampling_freq_hz, int channels);
137 
138   ///////////////////////////////////////////////////////////////////////////
139   // int32_t Codec()
140   //
141   // Returns the list number of the given codec name, sampling frequency, and
142   // a given number of channels.
143   //
144   // Input:
145   //   -payload_name        : name of the codec.
146   //   -sampling_freq_hz    : sampling frequency of the codec. Note! for RED
147   //                          a sampling frequency of -1 is a valid input.
148   //   -channels            : number of channels ( 1 - mono, 2 - stereo).
149   //
150   // Return value:
151   //   if the codec is found, the index of the codec in the list,
152   //   -1 if the codec is not found.
153   //
154   static int Codec(const char* payload_name, int sampling_freq_hz,
155                              int channels);
156 
157   ///////////////////////////////////////////////////////////////////////////
158   // bool IsCodecValid()
159   // Checks the validity of the parameters of the given codec.
160   //
161   // Input:
162   //   -codec              : the structure which keeps the parameters of the
163   //                         codec.
164   //
165   // Return value:
166   //   true if the parameters are valid,
167   //   false if any parameter is not valid.
168   //
169   static bool IsCodecValid(const CodecInst& codec);
170 
171   ///////////////////////////////////////////////////////////////////////////
172   //   Sender
173   //
174 
175   ///////////////////////////////////////////////////////////////////////////
176   // int32_t RegisterSendCodec()
177   // Registers a codec, specified by |send_codec|, as sending codec.
178   // This API can be called multiple of times to register Codec. The last codec
179   // registered overwrites the previous ones.
180   // The API can also be used to change payload type for CNG and RED, which are
181   // registered by default to default payload types.
182   // Note that registering CNG and RED won't overwrite speech codecs.
183   // This API can be called to set/change the send payload-type, frame-size
184   // or encoding rate (if applicable for the codec).
185   //
186   // Note: If a stereo codec is registered as send codec, VAD/DTX will
187   // automatically be turned off, since it is not supported for stereo sending.
188   //
189   // Note: If a secondary encoder is already registered, and the new send-codec
190   // has a sampling rate that does not match the secondary encoder, the
191   // secondary encoder will be unregistered.
192   //
193   // Input:
194   //   -send_codec         : Parameters of the codec to be registered, c.f.
195   //                         common_types.h for the definition of
196   //                         CodecInst.
197   //
198   // Return value:
199   //   -1 if failed to initialize,
200   //    0 if succeeded.
201   //
202   virtual int32_t RegisterSendCodec(const CodecInst& send_codec) = 0;
203 
204   // Registers |external_speech_encoder| as encoder. The new encoder will
205   // replace any previously registered speech encoder (internal or external).
206   virtual void RegisterExternalSendCodec(
207       AudioEncoder* external_speech_encoder) = 0;
208 
209   ///////////////////////////////////////////////////////////////////////////
210   // int32_t SendCodec()
211   // Get parameters for the codec currently registered as send codec.
212   //
213   // Return value:
214   //   The send codec, or nothing if we don't have one
215   //
216   virtual rtc::Maybe<CodecInst> SendCodec() const = 0;
217 
218   ///////////////////////////////////////////////////////////////////////////
219   // int32_t SendFrequency()
220   // Get the sampling frequency of the current encoder in Hertz.
221   //
222   // Return value:
223   //   positive; sampling frequency [Hz] of the current encoder.
224   //   -1 if an error has happened.
225   //
226   virtual int32_t SendFrequency() const = 0;
227 
228   ///////////////////////////////////////////////////////////////////////////
229   // Sets the bitrate to the specified value in bits/sec. If the value is not
230   // supported by the codec, it will choose another appropriate value.
231   virtual void SetBitRate(int bitrate_bps) = 0;
232 
233   // int32_t RegisterTransportCallback()
234   // Register a transport callback which will be called to deliver
235   // the encoded buffers whenever Process() is called and a
236   // bit-stream is ready.
237   //
238   // Input:
239   //   -transport          : pointer to the callback class
240   //                         transport->SendData() is called whenever
241   //                         Process() is called and bit-stream is ready
242   //                         to deliver.
243   //
244   // Return value:
245   //   -1 if the transport callback could not be registered
246   //    0 if registration is successful.
247   //
248   virtual int32_t RegisterTransportCallback(
249       AudioPacketizationCallback* transport) = 0;
250 
251   ///////////////////////////////////////////////////////////////////////////
252   // int32_t Add10MsData()
253   // Add 10MS of raw (PCM) audio data and encode it. If the sampling
254   // frequency of the audio does not match the sampling frequency of the
255   // current encoder ACM will resample the audio. If an encoded packet was
256   // produced, it will be delivered via the callback object registered using
257   // RegisterTransportCallback, and the return value from this function will
258   // be the number of bytes encoded.
259   //
260   // Input:
261   //   -audio_frame        : the input audio frame, containing raw audio
262   //                         sampling frequency etc.,
263   //                         c.f. module_common_types.h for definition of
264   //                         AudioFrame.
265   //
266   // Return value:
267   //   >= 0   number of bytes encoded.
268   //     -1   some error occurred.
269   //
270   virtual int32_t Add10MsData(const AudioFrame& audio_frame) = 0;
271 
272   ///////////////////////////////////////////////////////////////////////////
273   // (RED) Redundant Coding
274   //
275 
276   ///////////////////////////////////////////////////////////////////////////
277   // int32_t SetREDStatus()
278   // configure RED status i.e. on/off.
279   //
280   // RFC 2198 describes a solution which has a single payload type which
281   // signifies a packet with redundancy. That packet then becomes a container,
282   // encapsulating multiple payloads into a single RTP packet.
283   // Such a scheme is flexible, since any amount of redundancy may be
284   // encapsulated within a single packet.  There is, however, a small overhead
285   // since each encapsulated payload must be preceded by a header indicating
286   // the type of data enclosed.
287   //
288   // Input:
289   //   -enable_red         : if true RED is enabled, otherwise RED is
290   //                         disabled.
291   //
292   // Return value:
293   //   -1 if failed to set RED status,
294   //    0 if succeeded.
295   //
296   virtual int32_t SetREDStatus(bool enable_red) = 0;
297 
298   ///////////////////////////////////////////////////////////////////////////
299   // bool REDStatus()
300   // Get RED status
301   //
302   // Return value:
303   //   true if RED is enabled,
304   //   false if RED is disabled.
305   //
306   virtual bool REDStatus() const = 0;
307 
308   ///////////////////////////////////////////////////////////////////////////
309   // (FEC) Forward Error Correction (codec internal)
310   //
311 
312   ///////////////////////////////////////////////////////////////////////////
313   // int32_t SetCodecFEC()
314   // Configures codec internal FEC status i.e. on/off. No effects on codecs that
315   // do not provide internal FEC.
316   //
317   // Input:
318   //   -enable_fec         : if true FEC will be enabled otherwise the FEC is
319   //                         disabled.
320   //
321   // Return value:
322   //   -1 if failed, or the codec does not support FEC
323   //    0 if succeeded.
324   //
325   virtual int SetCodecFEC(bool enable_codec_fec) = 0;
326 
327   ///////////////////////////////////////////////////////////////////////////
328   // bool CodecFEC()
329   // Gets status of codec internal FEC.
330   //
331   // Return value:
332   //   true if FEC is enabled,
333   //   false if FEC is disabled.
334   //
335   virtual bool CodecFEC() const = 0;
336 
337   ///////////////////////////////////////////////////////////////////////////
338   // int SetPacketLossRate()
339   // Sets expected packet loss rate for encoding. Some encoders provide packet
340   // loss gnostic encoding to make stream less sensitive to packet losses,
341   // through e.g., FEC. No effects on codecs that do not provide such encoding.
342   //
343   // Input:
344   //   -packet_loss_rate   : expected packet loss rate (0 -- 100 inclusive).
345   //
346   // Return value
347   //   -1 if failed to set packet loss rate,
348   //   0 if succeeded.
349   //
350   virtual int SetPacketLossRate(int packet_loss_rate) = 0;
351 
352   ///////////////////////////////////////////////////////////////////////////
353   //   (VAD) Voice Activity Detection
354   //
355 
356   ///////////////////////////////////////////////////////////////////////////
357   // int32_t SetVAD()
358   // If DTX is enabled & the codec does not have internal DTX/VAD
359   // WebRtc VAD will be automatically enabled and |enable_vad| is ignored.
360   //
361   // If DTX is disabled but VAD is enabled no DTX packets are send,
362   // regardless of whether the codec has internal DTX/VAD or not. In this
363   // case, WebRtc VAD is running to label frames as active/in-active.
364   //
365   // NOTE! VAD/DTX is not supported when sending stereo.
366   //
367   // Inputs:
368   //   -enable_dtx         : if true DTX is enabled,
369   //                         otherwise DTX is disabled.
370   //   -enable_vad         : if true VAD is enabled,
371   //                         otherwise VAD is disabled.
372   //   -vad_mode           : determines the aggressiveness of VAD. A more
373   //                         aggressive mode results in more frames labeled
374   //                         as in-active, c.f. definition of
375   //                         ACMVADMode in audio_coding_module_typedefs.h
376   //                         for valid values.
377   //
378   // Return value:
379   //   -1 if failed to set up VAD/DTX,
380   //    0 if succeeded.
381   //
382   virtual int32_t SetVAD(const bool enable_dtx = true,
383                                const bool enable_vad = false,
384                                const ACMVADMode vad_mode = VADNormal) = 0;
385 
386   ///////////////////////////////////////////////////////////////////////////
387   // int32_t VAD()
388   // Get VAD status.
389   //
390   // Outputs:
391   //   -dtx_enabled        : is set to true if DTX is enabled, otherwise
392   //                         is set to false.
393   //   -vad_enabled        : is set to true if VAD is enabled, otherwise
394   //                         is set to false.
395   //   -vad_mode            : is set to the current aggressiveness of VAD.
396   //
397   // Return value:
398   //   -1 if fails to retrieve the setting of DTX/VAD,
399   //    0 if succeeded.
400   //
401   virtual int32_t VAD(bool* dtx_enabled, bool* vad_enabled,
402                             ACMVADMode* vad_mode) const = 0;
403 
404   ///////////////////////////////////////////////////////////////////////////
405   // int32_t RegisterVADCallback()
406   // Call this method to register a callback function which is called
407   // any time that ACM encounters an empty frame. That is a frame which is
408   // recognized inactive. Depending on the codec WebRtc VAD or internal codec
409   // VAD is employed to identify a frame as active/inactive.
410   //
411   // Input:
412   //   -vad_callback        : pointer to a callback function.
413   //
414   // Return value:
415   //   -1 if failed to register the callback function.
416   //    0 if the callback function is registered successfully.
417   //
418   virtual int32_t RegisterVADCallback(ACMVADCallback* vad_callback) = 0;
419 
420   ///////////////////////////////////////////////////////////////////////////
421   //   Receiver
422   //
423 
424   ///////////////////////////////////////////////////////////////////////////
425   // int32_t InitializeReceiver()
426   // Any decoder-related state of ACM will be initialized to the
427   // same state when ACM is created. This will not interrupt or
428   // effect encoding functionality of ACM. ACM would lose all the
429   // decoding-related settings by calling this function.
430   // For instance, all registered codecs are deleted and have to be
431   // registered again.
432   //
433   // Return value:
434   //   -1 if failed to initialize,
435   //    0 if succeeded.
436   //
437   virtual int32_t InitializeReceiver() = 0;
438 
439   ///////////////////////////////////////////////////////////////////////////
440   // int32_t ReceiveFrequency()
441   // Get sampling frequency of the last received payload.
442   //
443   // Return value:
444   //   non-negative the sampling frequency in Hertz.
445   //   -1 if an error has occurred.
446   //
447   virtual int32_t ReceiveFrequency() const = 0;
448 
449   ///////////////////////////////////////////////////////////////////////////
450   // int32_t PlayoutFrequency()
451   // Get sampling frequency of audio played out.
452   //
453   // Return value:
454   //   the sampling frequency in Hertz.
455   //
456   virtual int32_t PlayoutFrequency() const = 0;
457 
458   ///////////////////////////////////////////////////////////////////////////
459   // int32_t RegisterReceiveCodec()
460   // Register possible decoders, can be called multiple times for
461   // codecs, CNG-NB, CNG-WB, CNG-SWB, AVT and RED.
462   //
463   // Input:
464   //   -receive_codec      : parameters of the codec to be registered, c.f.
465   //                         common_types.h for the definition of
466   //                         CodecInst.
467   //
468   // Return value:
469   //   -1 if failed to register the codec
470   //    0 if the codec registered successfully.
471   //
472   virtual int RegisterReceiveCodec(const CodecInst& receive_codec) = 0;
473 
474   virtual int RegisterExternalReceiveCodec(int rtp_payload_type,
475                                            AudioDecoder* external_decoder,
476                                            int sample_rate_hz,
477                                            int num_channels) = 0;
478 
479   ///////////////////////////////////////////////////////////////////////////
480   // int32_t UnregisterReceiveCodec()
481   // Unregister the codec currently registered with a specific payload type
482   // from the list of possible receive codecs.
483   //
484   // Input:
485   //   -payload_type        : The number representing the payload type to
486   //                         unregister.
487   //
488   // Output:
489   //   -1 if fails to unregister.
490   //    0 if the given codec is successfully unregistered.
491   //
492   virtual int UnregisterReceiveCodec(
493       uint8_t payload_type) = 0;
494 
495   ///////////////////////////////////////////////////////////////////////////
496   // int32_t ReceiveCodec()
497   // Get the codec associated with last received payload.
498   //
499   // Output:
500   //   -curr_receive_codec : parameters of the codec associated with the last
501   //                         received payload, c.f. common_types.h for
502   //                         the definition of CodecInst.
503   //
504   // Return value:
505   //   -1 if failed to retrieve the codec,
506   //    0 if the codec is successfully retrieved.
507   //
508   virtual int32_t ReceiveCodec(CodecInst* curr_receive_codec) const = 0;
509 
510   ///////////////////////////////////////////////////////////////////////////
511   // int32_t IncomingPacket()
512   // Call this function to insert a parsed RTP packet into ACM.
513   //
514   // Inputs:
515   //   -incoming_payload   : received payload.
516   //   -payload_len_bytes  : the length of payload in bytes.
517   //   -rtp_info           : the relevant information retrieved from RTP
518   //                         header.
519   //
520   // Return value:
521   //   -1 if failed to push in the payload
522   //    0 if payload is successfully pushed in.
523   //
524   virtual int32_t IncomingPacket(const uint8_t* incoming_payload,
525                                  const size_t payload_len_bytes,
526                                  const WebRtcRTPHeader& rtp_info) = 0;
527 
528   ///////////////////////////////////////////////////////////////////////////
529   // int32_t IncomingPayload()
530   // Call this API to push incoming payloads when there is no rtp-info.
531   // The rtp-info will be created in ACM. One usage for this API is when
532   // pre-encoded files are pushed in ACM
533   //
534   // Inputs:
535   //   -incoming_payload   : received payload.
536   //   -payload_len_byte   : the length, in bytes, of the received payload.
537   //   -payload_type       : the payload-type. This specifies which codec has
538   //                         to be used to decode the payload.
539   //   -timestamp          : send timestamp of the payload. ACM starts with
540   //                         a random value and increment it by the
541   //                         packet-size, which is given when the codec in
542   //                         question is registered by RegisterReceiveCodec().
543   //                         Therefore, it is essential to have the timestamp
544   //                         if the frame-size differ from the registered
545   //                         value or if the incoming payload contains DTX
546   //                         packets.
547   //
548   // Return value:
549   //   -1 if failed to push in the payload
550   //    0 if payload is successfully pushed in.
551   //
552   virtual int32_t IncomingPayload(const uint8_t* incoming_payload,
553                                   const size_t payload_len_byte,
554                                   const uint8_t payload_type,
555                                   const uint32_t timestamp = 0) = 0;
556 
557   ///////////////////////////////////////////////////////////////////////////
558   // int SetMinimumPlayoutDelay()
559   // Set a minimum for the playout delay, used for lip-sync. NetEq maintains
560   // such a delay unless channel condition yields to a higher delay.
561   //
562   // Input:
563   //   -time_ms            : minimum delay in milliseconds.
564   //
565   // Return value:
566   //   -1 if failed to set the delay,
567   //    0 if the minimum delay is set.
568   //
569   virtual int SetMinimumPlayoutDelay(int time_ms) = 0;
570 
571   ///////////////////////////////////////////////////////////////////////////
572   // int SetMaximumPlayoutDelay()
573   // Set a maximum for the playout delay
574   //
575   // Input:
576   //   -time_ms            : maximum delay in milliseconds.
577   //
578   // Return value:
579   //   -1 if failed to set the delay,
580   //    0 if the maximum delay is set.
581   //
582   virtual int SetMaximumPlayoutDelay(int time_ms) = 0;
583 
584   //
585   // The shortest latency, in milliseconds, required by jitter buffer. This
586   // is computed based on inter-arrival times and playout mode of NetEq. The
587   // actual delay is the maximum of least-required-delay and the minimum-delay
588   // specified by SetMinumumPlayoutDelay() API.
589   //
590   virtual int LeastRequiredDelayMs() const = 0;
591 
592   ///////////////////////////////////////////////////////////////////////////
593   // int32_t PlayoutTimestamp()
594   // The send timestamp of an RTP packet is associated with the decoded
595   // audio of the packet in question. This function returns the timestamp of
596   // the latest audio obtained by calling PlayoutData10ms().
597   //
598   // Input:
599   //   -timestamp          : a reference to a uint32_t to receive the
600   //                         timestamp.
601   // Return value:
602   //    0 if the output is a correct timestamp.
603   //   -1 if failed to output the correct timestamp.
604   //
605   // TODO(tlegrand): Change function to return the timestamp.
606   virtual int32_t PlayoutTimestamp(uint32_t* timestamp) = 0;
607 
608   ///////////////////////////////////////////////////////////////////////////
609   // int32_t PlayoutData10Ms(
610   // Get 10 milliseconds of raw audio data for playout, at the given sampling
611   // frequency. ACM will perform a resampling if required.
612   //
613   // Input:
614   //   -desired_freq_hz    : the desired sampling frequency, in Hertz, of the
615   //                         output audio. If set to -1, the function returns
616   //                         the audio at the current sampling frequency.
617   //
618   // Output:
619   //   -audio_frame        : output audio frame which contains raw audio data
620   //                         and other relevant parameters, c.f.
621   //                         module_common_types.h for the definition of
622   //                         AudioFrame.
623   //
624   // Return value:
625   //   -1 if the function fails,
626   //    0 if the function succeeds.
627   //
628   virtual int32_t PlayoutData10Ms(int32_t desired_freq_hz,
629                                         AudioFrame* audio_frame) = 0;
630 
631   ///////////////////////////////////////////////////////////////////////////
632   //   Codec specific
633   //
634 
635   ///////////////////////////////////////////////////////////////////////////
636   // int SetOpusApplication()
637   // Sets the intended application if current send codec is Opus. Opus uses this
638   // to optimize the encoding for applications like VOIP and music. Currently,
639   // two modes are supported: kVoip and kAudio.
640   //
641   // Input:
642   //   - application            : intended application.
643   //
644   // Return value:
645   //   -1 if current send codec is not Opus or error occurred in setting the
646   //      Opus application mode.
647   //    0 if the Opus application mode is successfully set.
648   //
649   virtual int SetOpusApplication(OpusApplicationMode application) = 0;
650 
651   ///////////////////////////////////////////////////////////////////////////
652   // int SetOpusMaxPlaybackRate()
653   // If current send codec is Opus, informs it about maximum playback rate the
654   // receiver will render. Opus can use this information to optimize the bit
655   // rate and increase the computation efficiency.
656   //
657   // Input:
658   //   -frequency_hz            : maximum playback rate in Hz.
659   //
660   // Return value:
661   //   -1 if current send codec is not Opus or
662   //      error occurred in setting the maximum playback rate,
663   //    0 if maximum bandwidth is set successfully.
664   //
665   virtual int SetOpusMaxPlaybackRate(int frequency_hz) = 0;
666 
667   ///////////////////////////////////////////////////////////////////////////
668   // EnableOpusDtx()
669   // Enable the DTX, if current send codec is Opus.
670   //
671   // Return value:
672   //   -1 if current send codec is not Opus or error occurred in enabling the
673   //      Opus DTX.
674   //    0 if Opus DTX is enabled successfully.
675   //
676   virtual int EnableOpusDtx() = 0;
677 
678   ///////////////////////////////////////////////////////////////////////////
679   // int DisableOpusDtx()
680   // If current send codec is Opus, disables its internal DTX.
681   //
682   // Return value:
683   //   -1 if current send codec is not Opus or error occurred in disabling DTX.
684   //    0 if Opus DTX is disabled successfully.
685   //
686   virtual int DisableOpusDtx() = 0;
687 
688   ///////////////////////////////////////////////////////////////////////////
689   //   statistics
690   //
691 
692   ///////////////////////////////////////////////////////////////////////////
693   // int32_t  GetNetworkStatistics()
694   // Get network statistics. Note that the internal statistics of NetEq are
695   // reset by this call.
696   //
697   // Input:
698   //   -network_statistics : a structure that contains network statistics.
699   //
700   // Return value:
701   //   -1 if failed to set the network statistics,
702   //    0 if statistics are set successfully.
703   //
704   virtual int32_t GetNetworkStatistics(
705       NetworkStatistics* network_statistics) = 0;
706 
707   //
708   // Enable NACK and set the maximum size of the NACK list. If NACK is already
709   // enable then the maximum NACK list size is modified accordingly.
710   //
711   // If the sequence number of last received packet is N, the sequence numbers
712   // of NACK list are in the range of [N - |max_nack_list_size|, N).
713   //
714   // |max_nack_list_size| should be positive (none zero) and less than or
715   // equal to |Nack::kNackListSizeLimit|. Otherwise, No change is applied and -1
716   // is returned. 0 is returned at success.
717   //
718   virtual int EnableNack(size_t max_nack_list_size) = 0;
719 
720   // Disable NACK.
721   virtual void DisableNack() = 0;
722 
723   //
724   // Get a list of packets to be retransmitted. |round_trip_time_ms| is an
725   // estimate of the round-trip-time (in milliseconds). Missing packets which
726   // will be playout in a shorter time than the round-trip-time (with respect
727   // to the time this API is called) will not be included in the list.
728   //
729   // Negative |round_trip_time_ms| results is an error message and empty list
730   // is returned.
731   //
732   virtual std::vector<uint16_t> GetNackList(
733       int64_t round_trip_time_ms) const = 0;
734 
735   virtual void GetDecodingCallStatistics(
736       AudioDecodingCallStats* call_stats) const = 0;
737 };
738 
739 }  // namespace webrtc
740 
741 #endif  // WEBRTC_MODULES_AUDIO_CODING_MAIN_INCLUDE_AUDIO_CODING_MODULE_H_
742