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