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.

70 lines
2.2KB

  1. /// RFC2250 2. Encapsulation of MPEG System and Transport Streams (p3)
  2. #include "rtp-packet.h"
  3. #include "rtp-payload-helper.h"
  4. #include "rtp-payload-internal.h"
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <assert.h>
  9. #include <errno.h>
  10. // Pack start code
  11. static const uint8_t s_mpeg2_packet_start[] = {0x00, 0x00, 0x01, 0xBA};
  12. static int rtp_decode_ps(void* p, const void* packet, int bytes)
  13. {
  14. struct rtp_packet_t pkt;
  15. struct rtp_payload_helper_t *helper;
  16. helper = (struct rtp_payload_helper_t *)p;
  17. if (!helper || 0 != rtp_packet_deserialize(&pkt, packet, bytes))
  18. return -EINVAL;
  19. // if(-1 == helper->flags)
  20. // {
  21. // if(pkt.payloadlen < sizeof(s_mpeg2_packet_start) + 2 || 0 != memcmp(s_mpeg2_packet_start, pkt.payload, sizeof(s_mpeg2_packet_start)))
  22. // return 0; // packet discard, wait for first packet
  23. // }
  24. // 2.1 RTP header usage(p4)
  25. // M bit: Set to 1 whenever the timestamp is discontinuous. (such as
  26. // might happen when a sender switches from one data
  27. // source to another).This allows the receiver and any
  28. // intervening RTP mixers or translators that are synchronizing
  29. // to the flow to ignore the difference between this timestamp
  30. // and any previous timestamp in their clock phase detectors.
  31. // if (pkt.rtp.m)
  32. // {
  33. // //TODO: test
  34. // // new frame start
  35. // helper->size = 0; // discard previous packets
  36. // helper->lost = 0;
  37. // helper->flags |= RTP_PAYLOAD_FLAG_PACKET_LOST; // notify source changed
  38. // helper->seq = (uint16_t)pkt.rtp.seq;
  39. // helper->timestamp = pkt.rtp.timestamp;
  40. // }
  41. // else
  42. {
  43. rtp_payload_check(helper, &pkt);
  44. }
  45. // ignore RTP M bit
  46. if (pkt.payloadlen > sizeof(s_mpeg2_packet_start) && 0 == memcmp(s_mpeg2_packet_start, pkt.payload, sizeof(s_mpeg2_packet_start)))
  47. rtp_payload_onframe(helper); // new frame/access start
  48. rtp_payload_write(helper, &pkt);
  49. return helper->lost ? 0 : 1; // packet handled
  50. }
  51. struct rtp_payload_decode_t *rtp_ps_decode(void)
  52. {
  53. static struct rtp_payload_decode_t decode = {
  54. rtp_payload_helper_create,
  55. rtp_payload_helper_destroy,
  56. rtp_decode_ps,
  57. };
  58. return &decode;
  59. }