av.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. package av
  2. import (
  3. "fmt"
  4. "io"
  5. )
  6. const (
  7. TAG_AUDIO = 8
  8. TAG_VIDEO = 9
  9. TAG_SCRIPTDATAAMF0 = 18
  10. TAG_SCRIPTDATAAMF3 = 0xf
  11. )
  12. const (
  13. MetadatAMF0 = 0x12
  14. MetadataAMF3 = 0xf
  15. )
  16. const (
  17. SOUND_MP3 = 2
  18. SOUND_NELLYMOSER_16KHZ_MONO = 4
  19. SOUND_NELLYMOSER_8KHZ_MONO = 5
  20. SOUND_NELLYMOSER = 6
  21. SOUND_ALAW = 7
  22. SOUND_MULAW = 8
  23. SOUND_AAC = 10
  24. SOUND_SPEEX = 11
  25. SOUND_5_5Khz = 0
  26. SOUND_11Khz = 1
  27. SOUND_22Khz = 2
  28. SOUND_44Khz = 3
  29. SOUND_8BIT = 0
  30. SOUND_16BIT = 1
  31. SOUND_MONO = 0
  32. SOUND_STEREO = 1
  33. AAC_SEQHDR = 0
  34. AAC_RAW = 1
  35. )
  36. const (
  37. AVC_SEQHDR = 0
  38. AVC_NALU = 1
  39. AVC_EOS = 2
  40. FRAME_KEY = 1
  41. FRAME_INTER = 2
  42. VIDEO_H264 = 7
  43. )
  44. var (
  45. PUBLISH = "publish"
  46. PLAY = "play"
  47. )
  48. // Header can be converted to AudioHeaderInfo or VideoHeaderInfo
  49. type Packet struct {
  50. IsAudio bool
  51. IsVideo bool
  52. IsMetadata bool
  53. TimeStamp uint32 // dts
  54. StreamID uint32
  55. Header PacketHeader
  56. Data []byte
  57. }
  58. type PacketHeader interface {
  59. }
  60. type AudioPacketHeader interface {
  61. PacketHeader
  62. SoundFormat() uint8
  63. AACPacketType() uint8
  64. }
  65. type VideoPacketHeader interface {
  66. PacketHeader
  67. IsKeyFrame() bool
  68. IsSeq() bool
  69. CodecID() uint8
  70. CompositionTime() int32
  71. }
  72. type Demuxer interface {
  73. Demux(*Packet) (ret *Packet, err error)
  74. }
  75. type Muxer interface {
  76. Mux(*Packet, io.Writer) error
  77. }
  78. type SampleRater interface {
  79. SampleRate() (int, error)
  80. }
  81. type CodecParser interface {
  82. SampleRater
  83. Parse(*Packet, io.Writer) error
  84. }
  85. type GetWriter interface {
  86. GetWriter(Info) WriteCloser
  87. }
  88. type Handler interface {
  89. HandleReader(ReadCloser)
  90. HandleWriter(WriteCloser)
  91. }
  92. type Alive interface {
  93. Alive() bool
  94. }
  95. type Closer interface {
  96. Info() Info
  97. Close(error)
  98. }
  99. type CalcTime interface {
  100. CalcBaseTimestamp()
  101. }
  102. type Info struct {
  103. Key string
  104. URL string
  105. UID string
  106. Inter bool
  107. }
  108. func (info Info) IsInterval() bool {
  109. return info.Inter
  110. }
  111. func (info Info) String() string {
  112. return fmt.Sprintf("<key: %s, URL: %s, UID: %s, Inter: %v>",
  113. info.Key, info.URL, info.UID, info.Inter)
  114. }
  115. type ReadCloser interface {
  116. Closer
  117. Alive
  118. Read(*Packet) error
  119. }
  120. type WriteCloser interface {
  121. Closer
  122. Alive
  123. CalcTime
  124. Write(*Packet) error
  125. }