You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.2KB

  1. // RFC3640 RTP Payload Format for Transport of MPEG-4 Elementary Streams
  2. #include "rtp-packet.h"
  3. #include "rtp-profile.h"
  4. #include "rtp-payload-helper.h"
  5. #include "rtp-payload-internal.h"
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <assert.h>
  9. #include <errno.h>
  10. #include <errno.h>
  11. static int rtp_decode_mpeg4_generic(void* p, const void* packet, int bytes)
  12. {
  13. int i, size;
  14. int au_size;
  15. int au_numbers;
  16. int au_header_length;
  17. const uint8_t *ptr, *pau, *pend;
  18. struct rtp_packet_t pkt;
  19. struct rtp_payload_helper_t *helper;
  20. helper = (struct rtp_payload_helper_t *)p;
  21. if (!helper || 0 != rtp_packet_deserialize(&pkt, packet, bytes) || pkt.payloadlen < 4)
  22. return -EINVAL;
  23. rtp_payload_check(helper, &pkt);
  24. // save payload
  25. ptr = (const uint8_t *)pkt.payload;
  26. pend = ptr + pkt.payloadlen;
  27. // AU-headers-length
  28. au_header_length = (ptr[0] << 8) + ptr[1];
  29. au_header_length = (au_header_length + 7) / 8; // bit -> byte
  30. if (ptr + au_header_length /*AU-size*/ > pend || au_header_length < 2)
  31. {
  32. assert(0);
  33. //helper->size = 0;
  34. helper->lost = 1;
  35. //helper->flags |= RTP_PAYLOAD_FLAG_PACKET_LOST;
  36. return -1; // invalid packet
  37. }
  38. // 3.3.6. High Bit-rate AAC
  39. // SDP fmtp: sizeLength=13; indexLength=3; indexDeltaLength=3;
  40. au_size = 2; // only AU-size
  41. au_numbers = au_header_length / au_size;
  42. assert(0 == au_header_length % au_size);
  43. ptr += 2; // skip AU headers length section 2-bytes
  44. pau = ptr + au_header_length; // point to Access Unit
  45. for (i = 0; i < au_numbers; i++)
  46. {
  47. size = (ptr[0] << 8) | (ptr[1] & 0xF8);
  48. size = size >> 3; // bit -> byte
  49. if (pau + size > pend)
  50. {
  51. assert(0);
  52. //helper->size = 0;
  53. helper->lost = 1;
  54. //helper->flags |= RTP_PAYLOAD_FLAG_PACKET_LOST;
  55. return -1; // invalid packet
  56. }
  57. // TODO: add ADTS/ASC ???
  58. pkt.payload = pau;
  59. pkt.payloadlen = size;
  60. rtp_payload_write(helper, &pkt);
  61. ptr += au_size;
  62. pau += size;
  63. if (au_numbers > 1 || pkt.rtp.m)
  64. {
  65. rtp_payload_onframe(helper);
  66. }
  67. }
  68. return helper->lost ? 0 : 1; // packet handled
  69. }
  70. struct rtp_payload_decode_t *rtp_mpeg4_generic_decode()
  71. {
  72. static struct rtp_payload_decode_t unpacker = {
  73. rtp_payload_helper_create,
  74. rtp_payload_helper_destroy,
  75. rtp_decode_mpeg4_generic,
  76. };
  77. return &unpacker;
  78. }