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.

119 lines
3.8KB

  1. #ifndef _flv_header_h_
  2. #define _flv_header_h_
  3. #include <stdint.h>
  4. #include <stddef.h>
  5. #if defined(__cplusplus)
  6. extern "C" {
  7. #endif
  8. struct flv_header_t
  9. {
  10. uint8_t FLV[3];
  11. uint8_t version;
  12. uint8_t audio;
  13. uint8_t video;
  14. uint32_t offset; // data offset
  15. };
  16. struct flv_tag_header_t
  17. {
  18. uint8_t filter; // 0-No pre-processing required
  19. uint8_t type; // 8-audio, 9-video, 18-script data
  20. uint32_t size; // data size
  21. uint32_t timestamp;
  22. uint32_t streamId;
  23. };
  24. struct flv_audio_tag_header_t
  25. {
  26. uint8_t codecid; /// audio codec id: FLV_AUDIO_AAC
  27. uint8_t rate; /// audio sample frequence: 0-5.5 kHz, 1-11 kHz, 2-22 kHz, 3-44 kHz
  28. uint8_t bits; /// audio sample bits: 0-8 bit samples, 1-16-bit samples
  29. uint8_t channels; /// audio channel count: 0-Mono sound, 1-Stereo sound
  30. uint8_t avpacket; /// AAC only:FLV_SEQUENCE_HEADER/FLV_AVPACKET
  31. };
  32. struct flv_video_tag_header_t
  33. {
  34. uint8_t codecid; /// video codec id: FLV_VIDEO_H264
  35. uint8_t keyframe; /// video frame type: 1-key frame, 2-inter frame
  36. uint8_t avpacket; /// H.264/H.265/AV1 only:FLV_SEQUENCE_HEADER/FLV_AVPACKET/FLV_END_OF_SEQUENCE
  37. int32_t cts; /// video composition time(PTS - DTS), AVC/HEVC/AV1 only
  38. };
  39. /// Read FLV File Header
  40. /// @return >=0-header length in byte, <0-error
  41. int flv_header_read(struct flv_header_t* flv, const uint8_t* buf, size_t len);
  42. /// Write FLV File Header
  43. /// @param[in] audio 1-has audio, 0-don't have
  44. /// @param[in] video 1-has video, 0-don't have
  45. /// @param[out] buf flv header buffer
  46. /// @param[out] len flv header length
  47. /// @return >=0-header length in byte, <0-error
  48. int flv_header_write(int audio, int video, uint8_t* buf, size_t len);
  49. /// Read FLV Tag Header
  50. /// @return >=0-header length in byte, <0-error
  51. int flv_tag_header_read(struct flv_tag_header_t* tag, const uint8_t* buf, size_t len);
  52. /// Write FLV Tag Header
  53. /// @param[out] buf flv tag header buffer
  54. /// @param[out] len flv tag header length
  55. /// @return >=0-header length in byte, <0-error
  56. int flv_tag_header_write(const struct flv_tag_header_t* tag, uint8_t* buf, size_t len);
  57. /// Read FLV Audio Tag Header
  58. /// @param[out] audio flv audio parameter
  59. /// @param[in] buf flv audio tag header buffer
  60. /// @param[in] len flv audio tag header length
  61. /// @return >=0-header length in byte, <0-error
  62. int flv_audio_tag_header_read(struct flv_audio_tag_header_t* audio, const uint8_t* buf, size_t len);
  63. /// Write FLV Audio Tag Header
  64. /// @param[in] audio flv audio parameter
  65. /// @param[out] buf flv audio tag header buffer
  66. /// @param[out] len flv audio tag header length
  67. /// @return >=0-header length in byte, <0-error
  68. int flv_audio_tag_header_write(const struct flv_audio_tag_header_t* audio, uint8_t* buf, size_t len);
  69. /// Read FLV Video Tag Header
  70. /// @param[out] video flv video parameter
  71. /// @param[in] buf flv video tag header buffer
  72. /// @param[in] len flv video tag header length
  73. /// @return >=0-header length in byte, <0-error
  74. int flv_video_tag_header_read(struct flv_video_tag_header_t* video, const uint8_t* buf, size_t len);
  75. /// Write FLV Video Tag Header
  76. /// @param[in] video flv video parameter
  77. /// @param[out] buf flv video tag header buffer
  78. /// @param[out] len flv video tag header length
  79. /// @return >=0-header length in byte, <0-error
  80. int flv_video_tag_header_write(const struct flv_video_tag_header_t* video, uint8_t* buf, size_t len);
  81. /// Read FLV Data Tag Header
  82. /// @return >=0-header length in byte, <0-error
  83. int flv_data_tag_header_read(const uint8_t* buf, size_t len);
  84. /// Write FLV Data Tag Header
  85. /// @param[out] buf flv data tag header buffer
  86. /// @param[out] len flv data tag header length
  87. /// @return >=0-header length in byte, <0-error
  88. int flv_data_tag_header_write(uint8_t* buf, size_t len);
  89. /// Read/Write FLV previous tag size
  90. int flv_tag_size_read(const uint8_t* buf, size_t len, uint32_t* size);
  91. int flv_tag_size_write(uint8_t* buf, size_t len, uint32_t size);
  92. #if defined(__cplusplus)
  93. }
  94. #endif
  95. #endif /* !_flv_header_h_ */