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.

142 líneas
4.0KB

  1. #include "rtp-payload.h"
  2. #include "rtp-profile.h"
  3. #include "rtp-header.h"
  4. extern "C" {
  5. #include "rtp-packet.h"
  6. }
  7. #include "rtp-ext.h"
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <assert.h>
  12. #if defined(_WIN32) || defined(_WIN64)
  13. #define strcasecmp _stricmp
  14. #endif
  15. struct rtp_header_ext_test_t
  16. {
  17. int payload;
  18. const char* encoding;
  19. FILE* frtp;
  20. FILE* fsource;
  21. FILE* frtp2;
  22. FILE* fsource2;
  23. void* encoder;
  24. void* decoder;
  25. size_t size;
  26. uint8_t packet[64 * 1024];
  27. };
  28. static void* rtp_alloc(void* /*param*/, int bytes)
  29. {
  30. static uint8_t buffer[2 * 1024 * 1024 + 4] = { 0, 0, 0, 1, };
  31. assert(bytes <= sizeof(buffer) - 4);
  32. return buffer + 4;
  33. }
  34. static void rtp_free(void* /*param*/, void* /*packet*/)
  35. {
  36. }
  37. static int rtp_encode_packet(void* param, const void* packet, int bytes, uint32_t /*timestamp*/, int /*flags*/)
  38. {
  39. struct rtp_payload_test_t* ctx = (struct rtp_payload_test_t*)param;
  40. //uint8_t size[2];
  41. //size[0] = (uint8_t)((uint32_t)bytes >> 8);
  42. //size[1] = (uint8_t)(uint32_t)bytes;
  43. //fwrite(size, 1, sizeof(size), ctx->frtp2);
  44. //fwrite(packet, 1, bytes, ctx->frtp2);
  45. return 0;
  46. }
  47. static int rtp_decode_packet(void* param, const void* packet, int bytes, uint32_t timestamp, int flags)
  48. {
  49. //memcpy(buffer + size, packet, bytes);
  50. //size += bytes;
  51. //// TODO:
  52. //// check media file
  53. //fwrite(buffer, 1, size, ctx->fsource2);
  54. //return rtp_payload_encode_input(ctx->encoder, buffer, size, timestamp);
  55. return 0;
  56. }
  57. void rtp_header_ext_test(const char* rtpfile)
  58. {
  59. struct rtp_header_ext_test_t ctx;
  60. ctx.frtp = fopen(rtpfile, "rb");
  61. rtp_packet_setsize(1456); // 1456(live555)
  62. //struct rtp_payload_t handler2;
  63. //handler2.alloc = rtp_alloc;
  64. //handler2.free = rtp_free;
  65. //handler2.packet = rtp_encode_packet;
  66. //ctx.encoder = rtp_payload_encode_create(payload, encoding, seq, ssrc, &handler2, &ctx);
  67. //struct rtp_payload_t handler1;
  68. //handler1.alloc = rtp_alloc;
  69. //handler1.free = rtp_free;
  70. //handler1.packet = rtp_decode_packet;
  71. //ctx.decoder = rtp_payload_decode_create(payload, encoding, &handler1, &ctx);
  72. const struct rtp_ext_uri_t* audio[5] = {
  73. NULL,
  74. rtp_ext_find_uri("urn:ietf:params:rtp-hdrext:ssrc-audio-level"),
  75. rtp_ext_find_uri("http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time"),
  76. rtp_ext_find_uri("http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01"),
  77. rtp_ext_find_uri("urn:ietf:params:rtp-hdrext:sdes:mid"),
  78. };
  79. const struct rtp_ext_uri_t* video[16] = {
  80. NULL,
  81. NULL,
  82. rtp_ext_find_uri("http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time"),
  83. rtp_ext_find_uri("http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01"),
  84. rtp_ext_find_uri("urn:ietf:params:rtp-hdrext:sdes:mid"),
  85. rtp_ext_find_uri("http://www.webrtc.org/experiments/rtp-hdrext/playout-delay"),
  86. rtp_ext_find_uri("http://www.webrtc.org/experiments/rtp-hdrext/video-content-type"),
  87. rtp_ext_find_uri("http://www.webrtc.org/experiments/rtp-hdrext/video-timing"),
  88. rtp_ext_find_uri("http://www.webrtc.org/experiments/rtp-hdrext/color-space"),
  89. NULL,
  90. rtp_ext_find_uri("urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id"),
  91. rtp_ext_find_uri("urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id"),
  92. NULL,
  93. rtp_ext_find_uri("urn:3gpp:video-orientation"),
  94. rtp_ext_find_uri("urn:ietf:params:rtp-hdrext:toffset"),
  95. };
  96. for (int i = 0; 1; i++)
  97. {
  98. uint8_t s2[2];
  99. if (2 != fread(s2, 1, 2, ctx.frtp))
  100. break;
  101. //ctx.size = (s2[0] << 8) | s2[1];
  102. ctx.size = (s2[1] << 8) | s2[0];
  103. //ctx.size -= 4;
  104. assert(ctx.size < sizeof(ctx.packet));
  105. if (ctx.size != (int)fread(ctx.packet, 1, ctx.size, ctx.frtp))
  106. break;
  107. rtp_packet_t pkt;
  108. rtp_packet_deserialize(&pkt, ctx.packet, ctx.size);
  109. printf("[%d] ssrc: 0x%04x, size: %d\n", i, pkt.rtp.ssrc, (int)ctx.size);
  110. if (pkt.extlen > 0)
  111. {
  112. struct rtp_ext_data_t data[256];
  113. rtp_ext_read(pkt.extprofile, (const uint8_t*)pkt.extension, pkt.extlen, data);
  114. }
  115. //rtp_payload_decode_input(ctx.decoder, ctx.packet, ctx.size);
  116. }
  117. fclose(ctx.frtp);
  118. //rtp_payload_decode_destroy(ctx.decoder);
  119. //rtp_payload_encode_destroy(ctx.encoder);
  120. }