stream-server/rtmp/data_loop.go

35 lines
687 B
Go
Raw Normal View History

2023-08-17 16:35:06 +05:00
package rtmp
import (
"stream_server/rtmp/flv"
2023-08-18 15:50:24 +05:00
"os"
2023-08-17 16:35:06 +05:00
)
func HandleDataLoop(chnk_wrp_ptr *ChunkWrapper) {
2023-08-18 15:50:24 +05:00
base_dir, _ := os.UserHomeDir()
file_writer, err := flv.NewFLVWriter(base_dir + "/live/" + chnk_wrp_ptr.params.stream_key + "/")
defer file_writer.Close()
if err != nil {
return
}
if err = chnk_wrp_ptr.ReadMetadata(file_writer); err != nil {
return
}
2023-08-17 16:35:06 +05:00
for {
msg_ptr, err := chnk_wrp_ptr.ReadChunk()
2023-08-17 16:35:06 +05:00
if err != nil {
return
} else if msg_ptr == nil {
continue
2023-08-17 16:35:06 +05:00
}
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
}
2023-08-17 16:35:06 +05:00
}
}
}