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.

39 lines
1.2KB

  1. #ifndef _rtmp_chunk_header_h_
  2. #define _rtmp_chunk_header_h_
  3. #include <stdint.h>
  4. #include <stddef.h>
  5. enum rtmp_chunk_type_t
  6. {
  7. RTMP_CHUNK_TYPE_0 = 0, // 11-bytes: timestamp(3) + length(3) + stream type(1) + stream id(4)
  8. RTMP_CHUNK_TYPE_1 = 1, // 7-bytes: delta(3) + length(3) + stream type(1)
  9. RTMP_CHUNK_TYPE_2 = 2, // 3-bytes: delta(3)
  10. RTMP_CHUNK_TYPE_3 = 3, // 0-byte
  11. };
  12. struct rtmp_chunk_header_t
  13. {
  14. uint8_t fmt; // RTMP_CHUNK_TYPE_XXX
  15. uint32_t cid; // chunk stream id(22-bits)
  16. uint32_t timestamp; // delta(24-bits) / extended timestamp(32-bits)
  17. uint32_t length; // message length (24-bits)
  18. uint8_t type; // message type id
  19. uint32_t stream_id; // message stream id
  20. };
  21. /// @return read bytes
  22. int rtmp_chunk_basic_header_read(const uint8_t* data, uint8_t* fmt, uint32_t* cid);
  23. int rtmp_chunk_message_header_read(const uint8_t* data, struct rtmp_chunk_header_t* header);
  24. int rtmp_chunk_extended_timestamp_read(const uint8_t* out, uint32_t* timestamp);
  25. /// @return write bytes
  26. int rtmp_chunk_basic_header_write(uint8_t* out, uint8_t fmt, uint32_t id);
  27. int rtmp_chunk_message_header_write(uint8_t* out, const struct rtmp_chunk_header_t* header);
  28. int rtmp_chunk_extended_timestamp_write(uint8_t* out, uint32_t timestamp);
  29. #endif /* !_rtmp_chunk_header_h_ */