Audio+video handling, break data loop on command message since it should only ever be an unpublish if working correctly, or exit anyway for non-proper protocol

This commit is contained in:
Muaz Ahmad 2023-08-18 14:43:52 +05:00
parent 5a21ef83d2
commit f165efcdc2
2 changed files with 34 additions and 4 deletions

View file

@ -1,7 +1,6 @@
package rtmp
import (
"fmt"
"stream_server/rtmp/flv"
)
@ -15,12 +14,19 @@ func HandleDataLoop(chnk_wrp_ptr *ChunkWrapper) {
return
}
for {
p, err := chnk_wrp_ptr.ReadChunk()
msg_ptr, err := chnk_wrp_ptr.ReadChunk()
if err != nil {
return
} else if msg_ptr == nil {
continue
}
switch msg_ptr.msg_type {
case 20:
return
case 8, 9:
if err = file_writer.WriteMediaTag(&(msg_ptr.data), msg_ptr.timestamp, msg_ptr.msg_type); err != nil {
return
}
if p != nil {
fmt.Println(p.msg_type, p.msg_len)
}
}
}

View file

@ -49,6 +49,30 @@ func (writer *FLVWriter) WriteMetadataTag(data *[]byte) (err error) {
return
}
func (writer *FLVWriter) WriteMediaTag(data *[]byte, timestamp uint32, media_type uint8) (err error) {
uint24_buf := make([]byte, 4)
tag_header := make([]byte, 11)
tag_header[0] = media_type
data_len := uint32(len(*data))
binary.BigEndian.PutUint32(uint24_buf, data_len)
copy(tag_header[1:4], uint24_buf[1:])
binary.BigEndian.PutUint32(uint24_buf, timestamp)
copy(tag_header[4:7], uint24_buf[1:])
tag_header[7] = uint24_buf[0]
if _, err = writer.w.Write(tag_header); err != nil {
return
}
if _, err = writer.w.Write(*data); err != nil {
return
}
tag_len_buf := make([]byte, 4)
binary.BigEndian.PutUint32(tag_len_buf, data_len + 11)
_, err = writer.w.Write(tag_len_buf)
return
}
func (writer *FLVWriter) write_flv_header() (err error) {
header := make([]byte, 13)