No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

68 líneas
3.8KB

  1. #include "rtp-ext.h"
  2. #include <inttypes.h>
  3. #include <stdint.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <assert.h>
  7. #include <stdio.h>
  8. // https://webrtc.googlesource.com/src/+/refs/heads/main/docs/native-code/rtp-hdrext/inband-cn/
  9. /*
  10. Introduction
  11. Comfort noise (CN) is widely used in real time communication, as it significantly reduces the frequency of RTP packets, and thus saves the network bandwidth, when participants in the communication are constantly actively speaking.
  12. One way of deploying CN is through [RFC 3389]. It defines CN as a special payload, which needs to be encoded and decoded independently from the codec(s) applied to active speech signals. This deployment is referred to as outband CN in this context.
  13. Some codecs, for example RFC 6716: Definition of the Opus Audio Codec, implement their own CN schemes. Basically, the encoder can notify that a CN packet is issued and/or no packet needs to be transmitted.
  14. Since CN packets have their particularities, cloud and client may need to identify them and treat them differently. Special treatments on CN packets include but are not limited to
  15. Upon receiving multiple streams of CN packets, choose only one to relay or mix.
  16. Adapt jitter buffer wisely according to the discontinuous transmission nature of CN packets.
  17. While RTP packets that contain outband CN can be easily identified as they bear a different payload type, inband CN cannot. Some codecs may be able to extract the information by decoding the packet, but that depends on codec implementation, not even mentioning that decoding packets is not always feasible. This document proposes using an RTP header extension to signal the inband CN.
  18. RTP header extension format
  19. The inband CN extension can be encoded using either the one-byte or two-byte header defined in [RFC 5285]. Figures 1 and 2 show encodings with each of these header formats.
  20. 0 1
  21. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
  22. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  23. | ID | len=0 |N| noise level |
  24. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  25. Figure 1. Encoding Using the One-Byte Header Format
  26. 0 1 2
  27. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
  28. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  29. | ID | len=1 |N| noise level |
  30. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  31. Figure 2. Encoding Using the Two-Byte Header Format
  32. Noise level is an optional data. The bit ¡°N¡± being 1 indicates that there is a noise level. The noise level is defined the same way as the audio level in [RFC 6464] and therefore can be used to avoid the Audio Level Header Extension on the same RTP packet. This also means that this level is defined the same as the noise level in [RFC 3389] and therfore can be compared against outband CN.
  33. Further details
  34. The existence of this header extension in an RTP packet indicates that it has inband CN, and therefore it will be used sparsely, and results in very small transmission cost.
  35. The end receiver can utilize this RTP header extension to get notified about an upcoming discontinuous transmission. This can be useful for its jitter buffer management. This RTP header extension signals comfort noise, it can also be used by audio mixer to mix streams wisely. As an example, it can avoid mixing multiple comfort noises together.
  36. Cloud may have the benefits of this RTP header extension as an end receiver, if it does transcoding. It may also utilize this RTP header extension to prioritize RTP packets if it does packet filtering. In both cases, this RTP header extension should not be encrypted.
  37. */
  38. int rtp_ext_inband_cn_parse(const uint8_t* data, int bytes, uint8_t *level)
  39. {
  40. assert(1 == bytes);
  41. if (1 != bytes)
  42. return -1;
  43. *level = data[0] & 0x7f;
  44. return 0;
  45. }
  46. int rtp_ext_inband_cn_write(uint8_t* data, int bytes, uint8_t level)
  47. {
  48. if (bytes < 1)
  49. return -1;
  50. data[0] = level & 0x7f;
  51. return 1;
  52. }