25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.2KB

  1. /// RFC3016 RTP Payload Format for MPEG-4 Audio/Visual Streams
  2. /// RFC6416 RTP Payload Format for MPEG-4 Audio/Visual Streams
  3. #include "rtp-packet.h"
  4. #include "rtp-profile.h"
  5. #include "rtp-payload-helper.h"
  6. #include "rtp-payload-internal.h"
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <assert.h>
  10. #include <errno.h>
  11. #include <errno.h>
  12. static int rtp_decode_mp4a_latm(void* p, const void* packet, int bytes)
  13. {
  14. int len;
  15. const uint8_t *ptr, *pend;
  16. struct rtp_packet_t pkt;
  17. struct rtp_payload_helper_t *helper;
  18. helper = (struct rtp_payload_helper_t *)p;
  19. if (!helper || 0 != rtp_packet_deserialize(&pkt, packet, bytes) || pkt.payloadlen < 4)
  20. return -EINVAL;
  21. rtp_payload_check(helper, &pkt);
  22. // save payload
  23. if (0 == helper->size)
  24. {
  25. ptr = (const uint8_t *)pkt.payload;
  26. for (pend = ptr + pkt.payloadlen; ptr < pend; ptr += len)
  27. {
  28. // ISO/IEC 14496-3:200X(E)
  29. // Table 1.44 - Syntax of PayloadLengthInfo() (p84)
  30. // Table 1.45 - Syntax of PayloadMux()
  31. for (len = 0; ptr < pend; ptr++)
  32. {
  33. len += *ptr;
  34. if (255 != *ptr)
  35. {
  36. ++ptr;
  37. break;
  38. }
  39. }
  40. if (ptr + len > pend)
  41. {
  42. assert(0);
  43. //helper->size = 0;
  44. helper->lost = 1;
  45. //helper->flags |= RTP_PAYLOAD_FLAG_PACKET_LOST;
  46. return -1; // invalid packet
  47. }
  48. // TODO: add ADTS/ASC ???
  49. pkt.payload = ptr;
  50. pkt.payloadlen = len;
  51. rtp_payload_write(helper, &pkt);
  52. if (ptr + len < pend || pkt.rtp.m)
  53. {
  54. rtp_payload_onframe(helper);
  55. }
  56. }
  57. }
  58. else
  59. {
  60. // RFC6416 6.3. Fragmentation of MPEG-4 Audio Bitstream (p17)
  61. // It is RECOMMENDED to put one audioMuxElement in each RTP packet. If
  62. // the size of an audioMuxElement can be kept small enough that the size
  63. // of the RTP packet containing it does not exceed the size of the Path
  64. // MTU, this will be no problem.If it cannot, the audioMuxElement
  65. // SHALL be fragmented and spread across multiple packets.
  66. rtp_payload_write(helper, &pkt);
  67. if (pkt.rtp.m)
  68. {
  69. rtp_payload_onframe(helper);
  70. }
  71. }
  72. return helper->lost ? 0 : 1; // packet handled
  73. }
  74. struct rtp_payload_decode_t *rtp_mp4a_latm_decode()
  75. {
  76. static struct rtp_payload_decode_t unpacker = {
  77. rtp_payload_helper_create,
  78. rtp_payload_helper_destroy,
  79. rtp_decode_mp4a_latm,
  80. };
  81. return &unpacker;
  82. }