Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

158 rindas
6.6KB

  1. #ifndef _rtsp_payloads_h_
  2. #define _rtsp_payloads_h_
  3. #include "flv-proto.h"
  4. #include "mov-format.h"
  5. #include "mkv-format.h"
  6. #include "rtp-profile.h"
  7. #include "mpeg-proto.h"
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #if defined(OS_WINDOWS)
  11. #if !defined(strcasecmp)
  12. #define strcasecmp _stricmp
  13. #endif
  14. #endif
  15. #ifdef _avcodecid_h_
  16. #define CODEC(avcodec, mov, mkv, flv, mpeg2, rtp, rate, encoding, name) { avcodec, flv, mov, mpeg2, rtp, encoding, mkv, rate, name }
  17. #else
  18. #define CODEC(avcodec, mov, mkv, flv, mpeg2, rtp, rate, encoding, name) { flv, mov, mpeg2, rtp, encoding, mkv, rate, name }
  19. #endif
  20. static struct
  21. {
  22. #ifdef _avcodecid_h_
  23. AVPACKET_CODEC_ID codecid;
  24. #endif
  25. uint16_t flv; // flv codec id
  26. uint8_t mov; // mov object id
  27. uint8_t mpeg2; // mpeg2 codecid
  28. uint8_t payload; // rtp payload id
  29. const char* encoding; // rtp encoding
  30. enum mkv_codec_t mkv; // mkv codec id
  31. int frequency;
  32. const char* name; // describe
  33. } s_payloads[] = {
  34. // video
  35. CODEC(AVCODEC_VIDEO_H264, MOV_OBJECT_H264, MKV_CODEC_VIDEO_H264, FLV_VIDEO_H264, PSI_STREAM_H264, RTP_PAYLOAD_H264, 90000, "H264", "H264"),
  36. CODEC(AVCODEC_VIDEO_H265, MOV_OBJECT_H265, MKV_CODEC_VIDEO_H265, FLV_VIDEO_H265, PSI_STREAM_H265, RTP_PAYLOAD_H265, 90000, "H265", "H265"),
  37. CODEC(AVCODEC_VIDEO_H265, MOV_OBJECT_H265, MKV_CODEC_VIDEO_H265, FLV_VIDEO_H265, PSI_STREAM_H265, RTP_PAYLOAD_H265, 90000, "HEVC", "H265"),
  38. CODEC(AVCODEC_VIDEO_MPEG4, MOV_OBJECT_MP4V, MKV_CODEC_VIDEO_MPEG4, 0, PSI_STREAM_MPEG4, RTP_PAYLOAD_MP4V, 90000, "MP4V-ES", "MPEG4"),
  39. CODEC(AVCODEC_VIDEO_MPEG4, MOV_OBJECT_MP4V, MKV_CODEC_VIDEO_MPEG4, 0, PSI_STREAM_MPEG4, RTP_PAYLOAD_MP4V, 90000, "MPEG4", "MPEG4"),
  40. CODEC(AVCODEC_VIDEO_VP8, MOV_OBJECT_VP8, MKV_CODEC_VIDEO_VP8, 0, PSI_STREAM_VP8, RTP_PAYLOAD_VP8, 90000, "VP8", "VP8"),
  41. CODEC(AVCODEC_VIDEO_VP9, MOV_OBJECT_VP9, MKV_CODEC_VIDEO_VP9, 0, PSI_STREAM_VP9, RTP_PAYLOAD_VP9, 90000, "VP9", "VP9"),
  42. CODEC(AVCODEC_VIDEO_AV1, MOV_OBJECT_AV1, MKV_CODEC_VIDEO_AV1, FLV_VIDEO_AV1, PSI_STREAM_AV1, RTP_PAYLOAD_AV1, 90000, "AV1", "AV1"),
  43. CODEC(AVCODEC_VIDEO_AV1, MOV_OBJECT_AV1, MKV_CODEC_VIDEO_AV1, FLV_VIDEO_AV1, PSI_STREAM_AV1, RTP_PAYLOAD_AV1X, 90000, "AV1X", "AV1"), // https://bugs.chromium.org/p/webrtc/issues/detail?id=11042
  44. // audio
  45. CODEC(AVCODEC_AUDIO_AAC, MOV_OBJECT_AAC, MKV_CODEC_AUDIO_AAC, FLV_AUDIO_AAC, PSI_STREAM_AAC, RTP_PAYLOAD_LATM, 44100, "MP4A-LATM","AAC"),
  46. CODEC(AVCODEC_AUDIO_AAC, MOV_OBJECT_AAC, MKV_CODEC_AUDIO_AAC, FLV_AUDIO_AAC, PSI_STREAM_AAC, RTP_PAYLOAD_MP4A, 44100, "mpeg4-generic", "AAC"),
  47. CODEC(AVCODEC_AUDIO_OPUS, MOV_OBJECT_OPUS, MKV_CODEC_AUDIO_OPUS, FLV_AUDIO_OPUS, PSI_STREAM_AUDIO_OPUS, RTP_PAYLOAD_OPUS, 48000, "opus", "opus"),
  48. CODEC(AVCODEC_AUDIO_MP3, MOV_OBJECT_MP3, MKV_CODEC_AUDIO_MP3, FLV_AUDIO_MP3, PSI_STREAM_MP3, RTP_PAYLOAD_MP3, 16000, "mp3", "mp3"), // rtp standard payload id
  49. CODEC(AVCODEC_AUDIO_G711A, MOV_OBJECT_G711a, MKV_CODEC_UNKNOWN, FLV_AUDIO_G711A, PSI_STREAM_AUDIO_G711A, RTP_PAYLOAD_PCMA, 8000, "pcma", "g711a"), // rtp standard payload id
  50. CODEC(AVCODEC_AUDIO_G711U, MOV_OBJECT_G711u, MKV_CODEC_UNKNOWN, FLV_AUDIO_G711U, PSI_STREAM_AUDIO_G711U, RTP_PAYLOAD_PCMU, 8000, "pcmu", "g711u"), // rtp standard payload id
  51. // data
  52. CODEC(AVCODEC_DATA_RAW, MOV_OBJECT_NONE, MKV_CODEC_UNKNOWN, FLV_SCRIPT_METADATA, PSI_STREAM_RESERVED, RTP_PAYLOAD_DYNAMIC,0, "raw", "raw"),
  53. CODEC(AVCODEC_DATA_MP2P, MOV_OBJECT_NONE, MKV_CODEC_UNKNOWN, 0, PSI_STREAM_RESERVED, RTP_PAYLOAD_MP2P, 90000, "MP2P", "PS"),
  54. // PS/TS
  55. CODEC(AVCODEC_NONE, MOV_OBJECT_NONE, MKV_CODEC_UNKNOWN, 0, PSI_STREAM_RESERVED, RTP_PAYLOAD_MP2T, 90000, "TS", "TS"), // rtp standard payload id
  56. CODEC(AVCODEC_NONE, MOV_OBJECT_NONE, MKV_CODEC_UNKNOWN, 0, PSI_STREAM_RESERVED, RTP_PAYLOAD_MP2P, 90000, "MP2P", "PS"),
  57. CODEC(AVCODEC_NONE, MOV_OBJECT_NONE, MKV_CODEC_UNKNOWN, 0, PSI_STREAM_RESERVED, RTP_PAYLOAD_MP2P, 90000, "PS", "PS"), // GB28181
  58. };
  59. #ifdef _avcodecid_h_
  60. static inline int avcodecid_find_by_codecid(AVPACKET_CODEC_ID codecid)
  61. {
  62. size_t i;
  63. for (i = 0; i < sizeof(s_payloads) / sizeof(s_payloads[0]); i++)
  64. {
  65. if (s_payloads[i].codecid == codecid && AVCODEC_NONE != s_payloads[i].codecid)
  66. return (int)i;
  67. }
  68. return -1;
  69. }
  70. #endif
  71. static inline int avpayload_find_by_flv(int flv)
  72. {
  73. size_t i;
  74. for (i = 0; i < sizeof(s_payloads) / sizeof(s_payloads[0]); i++)
  75. {
  76. if ((int)s_payloads[i].flv == flv && flv != 0)
  77. return (int)i;
  78. }
  79. return -1;
  80. }
  81. static inline int avpayload_find_by_mov(uint8_t object)
  82. {
  83. size_t i;
  84. for (i = 0; i < sizeof(s_payloads) / sizeof(s_payloads[0]); i++)
  85. {
  86. if (s_payloads[i].mov == object && MOV_OBJECT_NONE != object)
  87. return (int)i;
  88. }
  89. return -1;
  90. }
  91. static inline int avpayload_find_by_mkv(enum mkv_codec_t codec)
  92. {
  93. size_t i;
  94. for (i = 0; i < sizeof(s_payloads) / sizeof(s_payloads[0]); i++)
  95. {
  96. if (s_payloads[i].mkv == codec && MKV_CODEC_UNKNOWN != codec)
  97. return (int)i;
  98. }
  99. return -1;
  100. }
  101. static inline int avpayload_find_by_mpeg2(uint8_t mpeg2)
  102. {
  103. size_t i;
  104. for (i = 0; i < sizeof(s_payloads) / sizeof(s_payloads[0]); i++)
  105. {
  106. if (s_payloads[i].mpeg2 == mpeg2 && PSI_STREAM_RESERVED != mpeg2)
  107. return (int)i;
  108. }
  109. return -1;
  110. }
  111. // for rtp encoding
  112. static inline int avpayload_find_by_payload(uint8_t payload)
  113. {
  114. size_t i;
  115. for (i = 0; i < sizeof(s_payloads) / sizeof(s_payloads[0]); i++)
  116. {
  117. if (s_payloads[i].payload == payload)
  118. return (int)i;
  119. }
  120. return -1;
  121. }
  122. // for rtp decoding
  123. static inline int avpayload_find_by_rtp(uint8_t payload, const char* encoding)
  124. {
  125. size_t i;
  126. for (i = 0; i < sizeof(s_payloads) / sizeof(s_payloads[0]); i++)
  127. {
  128. if ( (payload < RTP_PAYLOAD_DYNAMIC || !encoding || !*encoding) && s_payloads[i].payload == payload)
  129. return (int)i;
  130. else if (payload >= RTP_PAYLOAD_DYNAMIC && encoding && 0 == strcasecmp(encoding, s_payloads[i].encoding))
  131. return (int)i;
  132. }
  133. return -1;
  134. }
  135. #endif /* !_rtsp_payloads_h_ */