From 7fcf9dc1070b955845699a7963227cac19fd4fbc Mon Sep 17 00:00:00 2001 From: qydysky <32743305+qydysky@users.noreply.github.com> Date: Mon, 29 Aug 2022 02:19:31 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E5=A4=8D=E5=88=87=E6=8D=A2=E6=88=BF?= =?utf8?q?=E9=97=B4=E5=90=8E=E7=9B=B4=E6=92=AD=E6=B5=81=E6=9C=8D=E5=8A=A1?= =?utf8?q?=E6=97=A0=E6=B3=95=E7=BB=A7=E7=BB=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Reply/F.go | 38 +- Reply/Msg.go | 11 +- Reply/Reply.go | 44 +- Reply/flvDecode.go | 1240 +++++++++++++++++------------------ bili_danmu.go | 2 +- demo/config/config_K_v.json | 2 +- 6 files changed, 671 insertions(+), 666 deletions(-) diff --git a/Reply/F.go b/Reply/F.go index 7ec5e4a..b09fcce 100644 --- a/Reply/F.go +++ b/Reply/F.go @@ -318,14 +318,19 @@ func StreamOStatus(roomid int) bool { // 停止实例 func StreamOStop(roomid int) { - if roomid != -1 { // 针对某房间 - if v, ok := streamO.Load(roomid); ok { + switch roomid { + case -2: // 其他房间 + streamO.Range(func(_roomid, v interface{}) bool { + if c.C.Roomid == _roomid { + return true + } if v.(*M4SStream).Status.Islive() { v.(*M4SStream).Stop() } - streamO.Delete(roomid) - } - } else { //所有房间 + streamO.Delete(_roomid) + return true + }) + case -1: // 所有房间 streamO.Range(func(_roomid, v interface{}) bool { if v.(*M4SStream).Status.Islive() { v.(*M4SStream).Stop() @@ -333,6 +338,13 @@ func StreamOStop(roomid int) { return true }) streamO = new(psync.Map) + default: // 针对某房间 + if v, ok := streamO.Load(roomid); ok { + if v.(*M4SStream).Status.Islive() { + v.(*M4SStream).Stop() + } + streamO.Delete(roomid) + } } } @@ -447,9 +459,7 @@ func Autobanf(s string) bool { File: "Autoban.txt", }) - for _, v := range strings.Split(f, "\n") { - autoban.Banbuf = append(autoban.Banbuf, v) - } + autoban.Banbuf = append(autoban.Banbuf, strings.Split(f, "\n")...) } if len(autoban.buf) < 10 { @@ -1061,12 +1071,16 @@ func init() { // 获取当前房间的 var currentStreamO *M4SStream - if v, ok := streamO.Load(c.C.Roomid); ok { - currentStreamO = v.(*M4SStream) - } + streamO.Range(func(key, value interface{}) bool { + if key != nil && c.C.Roomid == key.(int) { + currentStreamO = value.(*M4SStream) + return false + } + return true + }) // 未准备好 - if !currentStreamO.Status.Islive() { + if currentStreamO == nil || !currentStreamO.Status.Islive() { w.Header().Set("Retry-After", "1") w.WriteHeader(http.StatusServiceUnavailable) return diff --git a/Reply/Msg.go b/Reply/Msg.go index 0cf386f..a92f15c 100644 --- a/Reply/Msg.go +++ b/Reply/Msg.go @@ -13,7 +13,7 @@ import ( var msglog = c.C.Log.Base(`Msg`) -//Msg类型数据处理方法map +// Msg类型数据处理方法map var Msg_map = map[string]func(replyF, string){ `VOICE_JOIN_ROOM_COUNT_INFO`: replyF.voice_join_room_count_info, //连麦等待 `VOICE_JOIN_LIST`: nil, @@ -103,9 +103,10 @@ var Msg_map = map[string]func(replyF, string){ "VIDEO_CONNECTION_JOIN_END": replyF.video_connection_join_end, //结束了与某人的视频连线 "VIDEO_CONNECTION_MSG": replyF.video_connection_msg, //视频连线状态改变 "WARNING": replyF.warning, //超管警告 + "DANMU_AGGREGATION": nil, //聚合弹幕 } -//屏蔽不需要的消息 +// 屏蔽不需要的消息 func init() { { //加载不需要的消息 bb, err := ioutil.ReadFile("config/config_disable_msg.json") @@ -126,8 +127,8 @@ func init() { } } -//Msg类型数据处理方法挑选 -//识别cmd字段类型,查找上述map中设置的方法,并将json转为字符串型传入 +// Msg类型数据处理方法挑选 +// 识别cmd字段类型,查找上述map中设置的方法,并将json转为字符串型传入 func Msg(b []byte) { msglog := msglog.Base_add(`select func`) @@ -145,6 +146,4 @@ func Msg(b []byte) { } else { (replyF{}).defaultMsg(string(b)) } - - return } diff --git a/Reply/Reply.go b/Reply/Reply.go index 1664a08..92216ab 100644 --- a/Reply/Reply.go +++ b/Reply/Reply.go @@ -427,29 +427,29 @@ func (replyF) special_gift(s string) { // Msg-大航海购买,由于信息少,用user_toast_msg进行替代 func (replyF) guard_buy(s string) { - username := p.Json().GetValFromS(s, "data.username") - gift_name := p.Json().GetValFromS(s, "data.gift_name") - price := p.Json().GetValFromS(s, "data.price") + // username := p.Json().GetValFromS(s, "data.username") + // gift_name := p.Json().GetValFromS(s, "data.gift_name") + // price := p.Json().GetValFromS(s, "data.price") - var sh []interface{} - var sh_log []interface{} + // var sh []interface{} + // var sh_log []interface{} - if username != nil { - sh = append(sh, username) - } - if gift_name != nil { - sh = append(sh, "购买了", gift_name) - } - if price != nil { - sh_log = append(sh, "¥", int(price.(float64))/1000) //不在界面显示价格 - } - { //额外 ass - Assf(fmt.Sprintln(sh...)) - } - fmt.Println("\n====") - fmt.Println(sh...) - fmt.Print("====\n\n") - msglog.Base_add("礼").Log_show_control(false).L(`I: `, sh_log...) + // if username != nil { + // sh = append(sh, username) + // } + // if gift_name != nil { + // sh = append(sh, "购买了", gift_name) + // } + // if price != nil { + // sh_log = append(sh, "¥", int(price.(float64))/1000) //不在界面显示价格 + // } + // { //额外 ass + // Assf(fmt.Sprintln(sh...)) + // } + // fmt.Println("\n====") + // fmt.Println(sh...) + // fmt.Print("====\n\n") + // msglog.Base_add("礼").Log_show_control(false).L(`I: `, sh_log...) } @@ -718,7 +718,7 @@ func (replyF) live(s string) { //开始录制 go func() { if v, ok := c.C.K_v.LoadV(`仅保存当前直播间流`).(bool); ok && v { - StreamOStop(-1) //停止其他房间录制 + StreamOStop(-2) //停止其他房间录制 } c.C.Danmu_Main_mq.Push_tag(`savestream`, SavestreamO{ Roomid: type_item.Roomid, diff --git a/Reply/flvDecode.go b/Reply/flvDecode.go index ecaf1e4..7ce8788 100644 --- a/Reply/flvDecode.go +++ b/Reply/flvDecode.go @@ -3,16 +3,10 @@ package reply import ( "bytes" "errors" - "fmt" - "os" - "time" // "math" - c "github.com/qydysky/bili_danmu/CV" F "github.com/qydysky/bili_danmu/F" - - reqf "github.com/qydysky/part/reqf" ) const ( @@ -25,20 +19,20 @@ const ( script_tag = byte(0x12) //custom define - eof_tag = byte(0x00) + // eof_tag = byte(0x00) ) var ( flv_header_sign = []byte{0x46, 0x4c, 0x56} - flvlog = c.C.Log.Base(`flv解码`) - send_sign = []byte{0x00} + // flvlog = c.C.Log.Base(`flv解码`) + // send_sign = []byte{0x00} ) -type flv_source struct { - buf []byte - Rval reqf.Rval - Inuse bool -} +// type flv_source struct { +// buf []byte +// Rval reqf.Rval +// Inuse bool +// } // func Stream_sync(sources []*flv_source) (buf_p *[]byte,err error) { // var ( @@ -78,14 +72,14 @@ type flv_source struct { // } // } -type flv_tag struct { - Tag byte - Offset int64 - Timestamp int32 - PreSize int32 - FirstByte byte - Buf *[]byte -} +// type flv_tag struct { +// Tag byte +// Offset int64 +// Timestamp int32 +// PreSize int32 +// FirstByte byte +// Buf *[]byte +// } // func Tag_stream(c chan []byte,co chan []byte) ( bool) { // //check channel @@ -155,275 +149,273 @@ type flv_tag struct { // return true // } -func Stream(path string, front_buf *[]byte, streamChan chan []byte, cancel chan struct{}) error { - flvlog.L(`T: `, path) - defer flvlog.L(`T: `, `退出`) - //file - f, err := os.OpenFile(path, os.O_RDONLY, 0644) - if err != nil { - return err - } - defer f.Close() - defer close(streamChan) +// func Stream(path string, front_buf *[]byte, streamChan chan []byte, cancel chan struct{}) error { +// flvlog.L(`T: `, path) +// defer flvlog.L(`T: `, `退出`) +// //file +// f, err := os.OpenFile(path, os.O_RDONLY, 0644) +// if err != nil { +// return err +// } +// defer f.Close() +// defer close(streamChan) + +// //get flv header(9byte) + FirstTagSize(4byte) +// { +// buf := make([]byte, flv_header_size+previou_tag_size) +// if _, err := f.Read(buf); err != nil { +// return err +// } +// if bytes.Index(buf, flv_header_sign) != 0 { +// return errors.New(`no flv`) +// } +// *front_buf = append(*front_buf, buf...) +// } - //get flv header(9byte) + FirstTagSize(4byte) - { - buf := make([]byte, flv_header_size+previou_tag_size) - if _, err := f.Read(buf); err != nil { - return err - } - if bytes.Index(buf, flv_header_sign) != 0 { - return errors.New(`no flv`) - } - *front_buf = append(*front_buf, buf...) - } +// type flv_tag struct { +// Tag byte +// Offset int64 +// Timestamp int32 +// PreSize int32 +// FirstByte byte +// Buf *[]byte +// } - type flv_tag struct { - Tag byte - Offset int64 - Timestamp int32 - PreSize int32 - FirstByte byte - Buf *[]byte - } +// var seachtag = func(f *os.File, begin_offset int64) (available_offset int64) { +// available_offset += begin_offset +// f.Seek(begin_offset, 0) //seek to begin - var seachtag = func(f *os.File, begin_offset int64) (available_offset int64) { - available_offset += begin_offset - f.Seek(begin_offset, 0) //seek to begin - - buf := make([]byte, 1024*1024*10) - if size, _ := f.Read(buf); size == 0 { - return - } else { - for buf_offset := 0; buf_offset < size; { - if tag_offset := bytes.IndexAny(buf[buf_offset:], string([]byte{video_tag, audio_tag, script_tag})); tag_offset == -1 { - return - } else if streamid_offset := bytes.Index(buf[tag_offset:], []byte{0x00, 0x00, 0x00}); streamid_offset == -1 { - return - } else if streamid_offset == 8 { - available_offset += int64(tag_offset + buf_offset) - return - } else { - buf_offset += tag_offset + 1 - } - } - } - return - } - - //get tag func - var getTag = func(f *os.File) (t flv_tag) { - t.Offset, _ = f.Seek(0, 1) - Buf := []byte{} - t.Buf = &Buf +// buf := make([]byte, 1024*1024*10) +// if size, _ := f.Read(buf); size == 0 { +// return +// } else { +// for buf_offset := 0; buf_offset < size; { +// if tag_offset := bytes.IndexAny(buf[buf_offset:], string([]byte{video_tag, audio_tag, script_tag})); tag_offset == -1 { +// return +// } else if streamid_offset := bytes.Index(buf[tag_offset:], []byte{0x00, 0x00, 0x00}); streamid_offset == -1 { +// return +// } else if streamid_offset == 8 { +// available_offset += int64(tag_offset + buf_offset) +// return +// } else { +// buf_offset += tag_offset + 1 +// } +// } +// } +// return +// } - buf := make([]byte, tag_header_size) - if size, err := f.Read(buf); err != nil || size == 0 { - t.Tag = eof_tag - return - } - Buf = append(Buf, buf...) - t.Tag = buf[0] - t.Timestamp = F.Btoi32([]byte{buf[7], buf[4], buf[5], buf[6]}, 0) +// //get tag func +// var getTag = func(f *os.File) (t flv_tag) { +// t.Offset, _ = f.Seek(0, 1) +// Buf := []byte{} +// t.Buf = &Buf - size := F.Btoi32(append([]byte{0x00}, buf[1:4]...), 0) +// buf := make([]byte, tag_header_size) +// if size, err := f.Read(buf); err != nil || size == 0 { +// t.Tag = eof_tag +// return +// } +// Buf = append(Buf, buf...) +// t.Tag = buf[0] +// t.Timestamp = F.Btoi32([]byte{buf[7], buf[4], buf[5], buf[6]}, 0) - data := make([]byte, size) - if size, err := f.Read(data); err != nil || size == 0 { - t.Tag = eof_tag - return - } - t.FirstByte = data[0] +// size := F.Btoi32(append([]byte{0x00}, buf[1:4]...), 0) - pre_tag := make([]byte, previou_tag_size) - if size, err := f.Read(pre_tag); err != nil || size == 0 { - t.Tag = eof_tag - return - } - t.PreSize = F.Btoi32(pre_tag, 0) +// data := make([]byte, size) +// if size, err := f.Read(data); err != nil || size == 0 { +// t.Tag = eof_tag +// return +// } +// t.FirstByte = data[0] - Buf = append(Buf, append(data, pre_tag...)...) - // if t.PreSize == 0{fmt.Println(t.Tag,size,data[size:])} +// pre_tag := make([]byte, previou_tag_size) +// if size, err := f.Read(pre_tag); err != nil || size == 0 { +// t.Tag = eof_tag +// return +// } +// t.PreSize = F.Btoi32(pre_tag, 0) - return - } +// Buf = append(Buf, append(data, pre_tag...)...) +// // if t.PreSize == 0{fmt.Println(t.Tag,size,data[size:])} - //get first video and audio tag - //find last_keyframe_video_offset - var ( - last_keyframe_video_offsets []int64 - first_video_tag bool - first_audio_tag bool - // last_timestamps []int32 - ) - for { - t := getTag(f) - if t.Tag == script_tag { - *front_buf = append(*front_buf, *t.Buf...) - } else if t.Tag == video_tag { - if !first_video_tag { - first_video_tag = true - *front_buf = append(*front_buf, *t.Buf...) - } +// return +// } - if t.FirstByte&0xf0 == 0x10 { - if len(last_keyframe_video_offsets) > 2 { - // last_timestamps = append(last_timestamps[1:], t.Timestamp) - last_keyframe_video_offsets = append(last_keyframe_video_offsets[1:], t.Offset) - } else { - // last_timestamps = append(last_timestamps, t.Timestamp) - last_keyframe_video_offsets = append(last_keyframe_video_offsets, t.Offset) - } - } - } else if t.Tag == audio_tag { - if !first_audio_tag { - first_audio_tag = true - *front_buf = append(*front_buf, *t.Buf...) - } - } else { //eof_tag - break - } - } +// //get first video and audio tag +// //find last_keyframe_video_offset +// var ( +// last_keyframe_video_offsets []int64 +// first_video_tag bool +// first_audio_tag bool +// // last_timestamps []int32 +// ) +// for { +// t := getTag(f) +// if t.Tag == script_tag { +// *front_buf = append(*front_buf, *t.Buf...) +// } else if t.Tag == video_tag { +// if !first_video_tag { +// first_video_tag = true +// *front_buf = append(*front_buf, *t.Buf...) +// } - //seed to the second last tag - if len(last_keyframe_video_offsets) == 0 { - flvlog.L(`W: `, `no keyframe`) - return errors.New(`no keyframe`) - } - f.Seek(last_keyframe_video_offsets[0], 0) - - // var ( - // last_video_keyframe_timestramp int32 - // video_keyframe_speed int32 - // ) - //copy when key frame - { - last_available_offset := last_keyframe_video_offsets[0] - var buf []byte - // last_Timestamp := last_timestamps[0] - for { - //退出 - select { - case <-cancel: - return nil - default: - } - t := getTag(f) - if t.Tag == eof_tag { - f.Seek(last_available_offset, 0) - time.Sleep(time.Second) - continue - } else if t.PreSize == 0 { - f.Seek(seachtag(f, last_available_offset), 0) - continue - } else if t.Tag == video_tag { - if t.FirstByte&0xf0 == 0x10 { - streamChan <- buf - buf = []byte{} - } - buf = append(buf, *t.Buf...) - } else if t.Tag == audio_tag { - buf = append(buf, *t.Buf...) - } else if t.Tag != script_tag { +// if t.FirstByte&0xf0 == 0x10 { +// if len(last_keyframe_video_offsets) > 2 { +// // last_timestamps = append(last_timestamps[1:], t.Timestamp) +// last_keyframe_video_offsets = append(last_keyframe_video_offsets[1:], t.Offset) +// } else { +// // last_timestamps = append(last_timestamps, t.Timestamp) +// last_keyframe_video_offsets = append(last_keyframe_video_offsets, t.Offset) +// } +// } +// } else if t.Tag == audio_tag { +// if !first_audio_tag { +// first_audio_tag = true +// *front_buf = append(*front_buf, *t.Buf...) +// } +// } else { //eof_tag +// break +// } +// } - } +// //seed to the second last tag +// if len(last_keyframe_video_offsets) == 0 { +// flvlog.L(`W: `, `no keyframe`) +// return errors.New(`no keyframe`) +// } +// f.Seek(last_keyframe_video_offsets[0], 0) + +// // var ( +// // last_video_keyframe_timestramp int32 +// // video_keyframe_speed int32 +// // ) +// //copy when key frame +// { +// last_available_offset := last_keyframe_video_offsets[0] +// var buf []byte +// // last_Timestamp := last_timestamps[0] +// for { +// //退出 +// select { +// case <-cancel: +// return nil +// default: +// } +// t := getTag(f) +// if t.Tag == eof_tag { +// f.Seek(last_available_offset, 0) +// time.Sleep(time.Second) +// continue +// } else if t.PreSize == 0 { +// f.Seek(seachtag(f, last_available_offset), 0) +// continue +// } else if t.Tag == video_tag { +// if t.FirstByte&0xf0 == 0x10 { +// streamChan <- buf +// buf = []byte{} +// } +// buf = append(buf, *t.Buf...) +// } else if t.Tag == audio_tag { +// buf = append(buf, *t.Buf...) +// } - last_available_offset = t.Offset +// last_available_offset = t.Offset - } - } +// } +// } - return nil -} +// return nil +// } -func TimeStramp_Check(path string) error { - //file - f, err := os.OpenFile(path, os.O_RDONLY, 0644) - if err != nil { - return err - } - defer f.Close() +// func TimeStramp_Check(path string) error { +// //file +// f, err := os.OpenFile(path, os.O_RDONLY, 0644) +// if err != nil { +// return err +// } +// defer f.Close() - //get flv header(9byte) + FirstTagSize(4byte) - { - buf := make([]byte, flv_header_size+previou_tag_size) - if _, err := f.Read(buf); err != nil { - return err - } - if bytes.Index(buf, flv_header_sign) != 0 { - return errors.New(`no flv`) - } - } +// //get flv header(9byte) + FirstTagSize(4byte) +// { +// buf := make([]byte, flv_header_size+previou_tag_size) +// if _, err := f.Read(buf); err != nil { +// return err +// } +// if bytes.Index(buf, flv_header_sign) != 0 { +// return errors.New(`no flv`) +// } +// } - type flv_tag struct { - Tag byte - Offset int64 - Timestamp int32 - PreSize int32 - FirstByte byte - } +// type flv_tag struct { +// Tag byte +// Offset int64 +// Timestamp int32 +// PreSize int32 +// FirstByte byte +// } - //get tag func - var getTag = func(f *os.File) (t flv_tag) { - t.Offset, _ = f.Seek(0, 1) +// //get tag func +// var getTag = func(f *os.File) (t flv_tag) { +// t.Offset, _ = f.Seek(0, 1) - buf := make([]byte, tag_header_size) - if size, err := f.Read(buf); err != nil || size == 0 { - t.Tag = eof_tag - return - } - t.Tag = buf[0] - t.Timestamp = F.Btoi32([]byte{buf[7], buf[4], buf[5], buf[6]}, 0) +// buf := make([]byte, tag_header_size) +// if size, err := f.Read(buf); err != nil || size == 0 { +// t.Tag = eof_tag +// return +// } +// t.Tag = buf[0] +// t.Timestamp = F.Btoi32([]byte{buf[7], buf[4], buf[5], buf[6]}, 0) - size := F.Btoi32(append([]byte{0x00}, buf[1:4]...), 0) +// size := F.Btoi32(append([]byte{0x00}, buf[1:4]...), 0) - data := make([]byte, size) - if size, err := f.Read(data); err != nil || size == 0 { - t.Tag = eof_tag - return - } - t.FirstByte = data[0] +// data := make([]byte, size) +// if size, err := f.Read(data); err != nil || size == 0 { +// t.Tag = eof_tag +// return +// } +// t.FirstByte = data[0] - pre_tag := make([]byte, previou_tag_size) - if size, err := f.Read(pre_tag); err != nil || size == 0 { - t.Tag = eof_tag - return - } - t.PreSize = F.Btoi32(pre_tag, 0) +// pre_tag := make([]byte, previou_tag_size) +// if size, err := f.Read(pre_tag); err != nil || size == 0 { +// t.Tag = eof_tag +// return +// } +// t.PreSize = F.Btoi32(pre_tag, 0) - // if t.PreSize == 0{fmt.Println(t.Tag,size,data[size:])} +// // if t.PreSize == 0{fmt.Println(t.Tag,size,data[size:])} - return - } +// return +// } - //get first video and audio tag - //find last_keyframe_video_offset - var ( - lasttimestramp int32 - // last_timestamps []int32 - ) - for { - t := getTag(f) - if t.Tag == script_tag && t.Timestamp == 0 { - continue - } else if t.Tag == video_tag || t.Tag == audio_tag { - if t.Timestamp < lasttimestramp { - fmt.Printf("error: now %d < pre %d\n", t.Timestamp, lasttimestramp) - lasttimestramp = t.Timestamp - continue - } - fmt.Printf("%d\n", t.Timestamp) - lasttimestramp = t.Timestamp - if lasttimestramp > 10000 { - return nil - } - } else { //eof_tag - break - } - } - fmt.Printf("ok\n") - return nil -} +// //get first video and audio tag +// //find last_keyframe_video_offset +// var ( +// lasttimestramp int32 +// // last_timestamps []int32 +// ) +// for { +// t := getTag(f) +// if t.Tag == script_tag && t.Timestamp == 0 { +// continue +// } else if t.Tag == video_tag || t.Tag == audio_tag { +// if t.Timestamp < lasttimestramp { +// fmt.Printf("error: now %d < pre %d\n", t.Timestamp, lasttimestramp) +// lasttimestramp = t.Timestamp +// continue +// } +// fmt.Printf("%d\n", t.Timestamp) +// lasttimestramp = t.Timestamp +// if lasttimestramp > 10000 { +// return nil +// } +// } else { //eof_tag +// break +// } +// } +// fmt.Printf("ok\n") +// return nil +// } // this fuction read []byte and return flv header and all complete keyframe if possible. // complete keyframe means the video and audio tags between two video key frames tag @@ -547,427 +539,427 @@ func Seach_stream_tag(buf []byte) (front_buf []byte, keyframe [][]byte, last_avi } // same as Seach_stream_tag but faster -func Seach_keyframe_tag(buf []byte) (front_buf []byte, keyframe [][]byte, err error) { +// func Seach_keyframe_tag(buf []byte) (front_buf []byte, keyframe [][]byte, err error) { - var ( - sign = 0x00 - // keyframe_num = -1 - tag_num = 0 - buf_offset = 0 - ) +// var ( +// sign = 0x00 +// // keyframe_num = -1 +// tag_num = 0 +// buf_offset = 0 +// ) - defer func() { - if sign != 0x07 { - front_buf = []byte{} - } - }() +// defer func() { +// if sign != 0x07 { +// front_buf = []byte{} +// } +// }() - //front_buf - if header_offset := bytes.Index(buf, flv_header_sign); header_offset != -1 { - front_buf = buf[header_offset : header_offset+flv_header_size+previou_tag_size] +// //front_buf +// if header_offset := bytes.Index(buf, flv_header_sign); header_offset != -1 { +// front_buf = buf[header_offset : header_offset+flv_header_size+previou_tag_size] - for buf_offset+tag_header_size < len(buf) { +// for buf_offset+tag_header_size < len(buf) { - fmt.Println(`front_buf`, buf_offset) +// fmt.Println(`front_buf`, buf_offset) - tag_offset := buf_offset + bytes.IndexAny(buf[buf_offset:], string([]byte{video_tag, audio_tag, script_tag})) - if tag_offset == buf_offset-1 { - err = errors.New(`no found available tag`) - // fmt.Printf("last %x\n",buf[tag_offset:tag_offset+tag_header_size]) - return //no found available video,audio,script tag - } - if tag_offset+tag_header_size > len(buf) { - err = errors.New(`reach end when get tag header`) - // fmt.Printf("last %x\n",buf[tag_offset:tag_offset+tag_header_size]) - return //buf end - } +// tag_offset := buf_offset + bytes.IndexAny(buf[buf_offset:], string([]byte{video_tag, audio_tag, script_tag})) +// if tag_offset == buf_offset-1 { +// err = errors.New(`no found available tag`) +// // fmt.Printf("last %x\n",buf[tag_offset:tag_offset+tag_header_size]) +// return //no found available video,audio,script tag +// } +// if tag_offset+tag_header_size > len(buf) { +// err = errors.New(`reach end when get tag header`) +// // fmt.Printf("last %x\n",buf[tag_offset:tag_offset+tag_header_size]) +// return //buf end +// } - if buf[tag_offset+8]|buf[tag_offset+9]|buf[tag_offset+10] != 0 { - buf_offset = tag_offset + 1 - // fmt.Printf("streamid error %x\n",buf[tag_offset:tag_offset+tag_header_size]) - continue //streamid error - } +// if buf[tag_offset+8]|buf[tag_offset+9]|buf[tag_offset+10] != 0 { +// buf_offset = tag_offset + 1 +// // fmt.Printf("streamid error %x\n",buf[tag_offset:tag_offset+tag_header_size]) +// continue //streamid error +// } - tag_size := int(F.Btoi32([]byte{0x00, buf[tag_offset+1], buf[tag_offset+2], buf[tag_offset+3]}, 0)) - if tag_offset+tag_header_size+tag_size+previou_tag_size > len(buf) { - err = errors.New(`reach end when get tag body`) - // fmt.Printf("last %x\n",buf[tag_offset:tag_offset+tag_header_size]) - return //buf end - } - if tag_size == 0 { - buf_offset = tag_offset + 1 - // fmt.Printf("tag_size error %x\n",buf[tag_offset:tag_offset+tag_header_size]) - continue //tag_size error - } +// tag_size := int(F.Btoi32([]byte{0x00, buf[tag_offset+1], buf[tag_offset+2], buf[tag_offset+3]}, 0)) +// if tag_offset+tag_header_size+tag_size+previou_tag_size > len(buf) { +// err = errors.New(`reach end when get tag body`) +// // fmt.Printf("last %x\n",buf[tag_offset:tag_offset+tag_header_size]) +// return //buf end +// } +// if tag_size == 0 { +// buf_offset = tag_offset + 1 +// // fmt.Printf("tag_size error %x\n",buf[tag_offset:tag_offset+tag_header_size]) +// continue //tag_size error +// } - tag_size_check := int(F.Btoi32(buf[tag_offset+tag_header_size+tag_size:tag_offset+tag_header_size+tag_size+previou_tag_size], 0)) - if tag_num+tag_size_check == 0 { - tag_size_check = tag_size + tag_header_size - } - if tag_size_check != tag_size+tag_header_size { - buf_offset = tag_offset + 1 - // fmt.Printf("tag_size_check error %x\n",buf[tag_offset:tag_offset+tag_header_size]) - continue //tag_size_check error - } +// tag_size_check := int(F.Btoi32(buf[tag_offset+tag_header_size+tag_size:tag_offset+tag_header_size+tag_size+previou_tag_size], 0)) +// if tag_num+tag_size_check == 0 { +// tag_size_check = tag_size + tag_header_size +// } +// if tag_size_check != tag_size+tag_header_size { +// buf_offset = tag_offset + 1 +// // fmt.Printf("tag_size_check error %x\n",buf[tag_offset:tag_offset+tag_header_size]) +// continue //tag_size_check error +// } - tag_num += 1 - - if buf[tag_offset+7]|buf[tag_offset+4]|buf[tag_offset+5]|buf[tag_offset+6] == 0 { - - if len(front_buf) != 0 { - if (buf[tag_offset] == video_tag) && (sign&0x04 == 0x00) { - sign |= 0x04 - front_buf = append(front_buf, buf[tag_offset:tag_offset+tag_size_check+previou_tag_size]...) - } else if (buf[tag_offset] == audio_tag) && (sign&0x02 == 0x00) { - sign |= 0x02 - front_buf = append(front_buf, buf[tag_offset:tag_offset+tag_size_check+previou_tag_size]...) - } else if (buf[tag_offset] == script_tag) && (sign&0x01 == 0x00) { - sign |= 0x01 - front_buf = append(front_buf, buf[tag_offset:tag_offset+tag_size_check+previou_tag_size]...) - } - } - buf_offset = tag_offset + tag_size_check + previou_tag_size - } - if sign == 0x07 { - break - } - } - } +// tag_num += 1 - //keyframe - var last_keyframe_offset int - for buf_offset+tag_header_size < len(buf) { - fmt.Println(`keyframe`, buf_offset) - tag_offset := buf_offset + bytes.Index(buf[buf_offset:], []byte{video_tag}) - if tag_offset == buf_offset-1 { - err = errors.New(`no found available tag`) - // fmt.Printf("last %x\n",buf[tag_offset:tag_offset+tag_header_size]) - return //no found available video,audio,script tag - } - if tag_offset+tag_header_size > len(buf) { - err = errors.New(`reach end when get tag header`) - // fmt.Printf("last %x\n",buf[tag_offset:tag_offset+tag_header_size]) - return //buf end - } +// if buf[tag_offset+7]|buf[tag_offset+4]|buf[tag_offset+5]|buf[tag_offset+6] == 0 { - if buf[tag_offset+8]|buf[tag_offset+9]|buf[tag_offset+10] != 0 { - buf_offset = tag_offset + 1 - // fmt.Printf("streamid error %x\n",buf[tag_offset:tag_offset+tag_header_size]) - continue //streamid error - } +// if len(front_buf) != 0 { +// if (buf[tag_offset] == video_tag) && (sign&0x04 == 0x00) { +// sign |= 0x04 +// front_buf = append(front_buf, buf[tag_offset:tag_offset+tag_size_check+previou_tag_size]...) +// } else if (buf[tag_offset] == audio_tag) && (sign&0x02 == 0x00) { +// sign |= 0x02 +// front_buf = append(front_buf, buf[tag_offset:tag_offset+tag_size_check+previou_tag_size]...) +// } else if (buf[tag_offset] == script_tag) && (sign&0x01 == 0x00) { +// sign |= 0x01 +// front_buf = append(front_buf, buf[tag_offset:tag_offset+tag_size_check+previou_tag_size]...) +// } +// } +// buf_offset = tag_offset + tag_size_check + previou_tag_size +// } +// if sign == 0x07 { +// break +// } +// } +// } - tag_size := int(F.Btoi32([]byte{0x00, buf[tag_offset+1], buf[tag_offset+2], buf[tag_offset+3]}, 0)) - if tag_offset+tag_header_size+tag_size+previou_tag_size > len(buf) { - err = errors.New(`reach end when get tag body`) - // fmt.Printf("last %x\n",buf[tag_offset:tag_offset+tag_header_size]) - return //buf end - } - if tag_size == 0 { - buf_offset = tag_offset + 1 - // fmt.Printf("tag_size error %x\n",buf[tag_offset:tag_offset+tag_header_size]) - continue //tag_size error - } +// //keyframe +// var last_keyframe_offset int +// for buf_offset+tag_header_size < len(buf) { +// fmt.Println(`keyframe`, buf_offset) +// tag_offset := buf_offset + bytes.Index(buf[buf_offset:], []byte{video_tag}) +// if tag_offset == buf_offset-1 { +// err = errors.New(`no found available tag`) +// // fmt.Printf("last %x\n",buf[tag_offset:tag_offset+tag_header_size]) +// return //no found available video,audio,script tag +// } +// if tag_offset+tag_header_size > len(buf) { +// err = errors.New(`reach end when get tag header`) +// // fmt.Printf("last %x\n",buf[tag_offset:tag_offset+tag_header_size]) +// return //buf end +// } - tag_size_check := int(F.Btoi32(buf[tag_offset+tag_header_size+tag_size:tag_offset+tag_header_size+tag_size+previou_tag_size], 0)) - if tag_num+tag_size_check == 0 { - tag_size_check = tag_size + tag_header_size - } - if tag_size_check != tag_size+tag_header_size { - buf_offset = tag_offset + 1 - // fmt.Printf("tag_size_check error %x\n",buf[tag_offset:tag_offset+tag_header_size]) - continue //tag_size_check error - } +// if buf[tag_offset+8]|buf[tag_offset+9]|buf[tag_offset+10] != 0 { +// buf_offset = tag_offset + 1 +// // fmt.Printf("streamid error %x\n",buf[tag_offset:tag_offset+tag_header_size]) +// continue //streamid error +// } - // fmt.Printf("%x\n",buf[tag_offset:tag_offset+tag_header_size]) +// tag_size := int(F.Btoi32([]byte{0x00, buf[tag_offset+1], buf[tag_offset+2], buf[tag_offset+3]}, 0)) +// if tag_offset+tag_header_size+tag_size+previou_tag_size > len(buf) { +// err = errors.New(`reach end when get tag body`) +// // fmt.Printf("last %x\n",buf[tag_offset:tag_offset+tag_header_size]) +// return //buf end +// } +// if tag_size == 0 { +// buf_offset = tag_offset + 1 +// // fmt.Printf("tag_size error %x\n",buf[tag_offset:tag_offset+tag_header_size]) +// continue //tag_size error +// } - tag_num += 1 +// tag_size_check := int(F.Btoi32(buf[tag_offset+tag_header_size+tag_size:tag_offset+tag_header_size+tag_size+previou_tag_size], 0)) +// if tag_num+tag_size_check == 0 { +// tag_size_check = tag_size + tag_header_size +// } +// if tag_size_check != tag_size+tag_header_size { +// buf_offset = tag_offset + 1 +// // fmt.Printf("tag_size_check error %x\n",buf[tag_offset:tag_offset+tag_header_size]) +// continue //tag_size_check error +// } - if buf[tag_offset] == video_tag { - if buf[tag_offset+11]&0xf0 == 0x10 { //key frame - if last_keyframe_offset != 0 { - keyframe = append(keyframe, buf[last_keyframe_offset:tag_offset]) - } +// // fmt.Printf("%x\n",buf[tag_offset:tag_offset+tag_header_size]) - last_keyframe_offset = tag_offset - } - } +// tag_num += 1 - buf_offset = tag_offset + tag_size_check + previou_tag_size - } +// if buf[tag_offset] == video_tag { +// if buf[tag_offset+11]&0xf0 == 0x10 { //key frame +// if last_keyframe_offset != 0 { +// keyframe = append(keyframe, buf[last_keyframe_offset:tag_offset]) +// } - return -} +// last_keyframe_offset = tag_offset +// } +// } + +// buf_offset = tag_offset + tag_size_check + previou_tag_size +// } + +// return +// } // this fuction merge two stream and return the merge buffer,which has the newest frame. // once len(merge_buf) isn't 0,old_buf can be drop and new_buf can be used from now on.or it's still need to keep buf until find the same tag. -func Merge_stream(keyframe_lists [][][]byte, last_keyframe_timestramp int) (keyframe_timestamp int, merge_buf []byte, merged int) { +// func Merge_stream(keyframe_lists [][][]byte, last_keyframe_timestramp int) (keyframe_timestamp int, merge_buf []byte, merged int) { - if len(keyframe_lists) == 0 { - return - } +// if len(keyframe_lists) == 0 { +// return +// } - // var keyframe_lists [][][]byte - // for i:=0;i len(buf[0]) { - err = errors.New(`reach end when get tag header`) - // fmt.Printf("last %x\n",buf[tag_offset:tag_offset+tag_header_size]) - return //buf end - } +// tag_offset := buf_offset + bytes.IndexAny(buf[0][buf_offset:], string([]byte{video_tag, audio_tag, script_tag})) +// if tag_offset == buf_offset-1 { +// err = errors.New(`no found available tag`) +// // fmt.Printf("last %x\n",buf[tag_offset:tag_offset+tag_header_size]) +// return //no found available video,audio,script tag +// } +// if tag_offset+tag_header_size > len(buf[0]) { +// err = errors.New(`reach end when get tag header`) +// // fmt.Printf("last %x\n",buf[tag_offset:tag_offset+tag_header_size]) +// return //buf end +// } - if buf[0][tag_offset+8]|buf[0][tag_offset+9]|buf[0][tag_offset+10] != 0 { - buf_offset = tag_offset + 1 - // fmt.Printf("streamid error %x\n",buf[tag_offset:tag_offset+tag_header_size]) - continue //streamid error - } +// if buf[0][tag_offset+8]|buf[0][tag_offset+9]|buf[0][tag_offset+10] != 0 { +// buf_offset = tag_offset + 1 +// // fmt.Printf("streamid error %x\n",buf[tag_offset:tag_offset+tag_header_size]) +// continue //streamid error +// } - tag_size := int(F.Btoi32([]byte{0x00, buf[0][tag_offset+1], buf[0][tag_offset+2], buf[0][tag_offset+3]}, 0)) - if tag_offset+tag_header_size+tag_size+previou_tag_size > len(buf[0]) { - err = errors.New(`reach end when get tag body`) - // fmt.Printf("last %x\n",buf[tag_offset:tag_offset+tag_header_size]) - return //buf end - } - if tag_size == 0 { - buf_offset = tag_offset + 1 - // fmt.Printf("tag_size error %x\n",buf[tag_offset:tag_offset+tag_header_size]) - continue //tag_size error - } +// tag_size := int(F.Btoi32([]byte{0x00, buf[0][tag_offset+1], buf[0][tag_offset+2], buf[0][tag_offset+3]}, 0)) +// if tag_offset+tag_header_size+tag_size+previou_tag_size > len(buf[0]) { +// err = errors.New(`reach end when get tag body`) +// // fmt.Printf("last %x\n",buf[tag_offset:tag_offset+tag_header_size]) +// return //buf end +// } +// if tag_size == 0 { +// buf_offset = tag_offset + 1 +// // fmt.Printf("tag_size error %x\n",buf[tag_offset:tag_offset+tag_header_size]) +// continue //tag_size error +// } - tag_size_check := int(F.Btoi32(buf[0][tag_offset+tag_header_size+tag_size:tag_offset+tag_header_size+tag_size+previou_tag_size], 0)) - if tag_num+tag_size_check == 0 { - tag_size_check = tag_size + tag_header_size - } - if tag_size_check != tag_size+tag_header_size { - buf_offset = tag_offset + 1 - // fmt.Printf("tag_size_check error %x\n",buf[tag_offset:tag_offset+tag_header_size]) - continue //tag_size_check error - } +// tag_size_check := int(F.Btoi32(buf[0][tag_offset+tag_header_size+tag_size:tag_offset+tag_header_size+tag_size+previou_tag_size], 0)) +// if tag_num+tag_size_check == 0 { +// tag_size_check = tag_size + tag_header_size +// } +// if tag_size_check != tag_size+tag_header_size { +// buf_offset = tag_offset + 1 +// // fmt.Printf("tag_size_check error %x\n",buf[tag_offset:tag_offset+tag_header_size]) +// continue //tag_size_check error +// } - tag_num += 1 +// tag_num += 1 - time_stamp := int(F.Btoi32([]byte{buf[0][tag_offset+7], buf[0][tag_offset+4], buf[0][tag_offset+5], buf[0][tag_offset+6]}, 0)) +// time_stamp := int(F.Btoi32([]byte{buf[0][tag_offset+7], buf[0][tag_offset+4], buf[0][tag_offset+5], buf[0][tag_offset+6]}, 0)) - // if tag_num == 1 && last_keyframe_timestamp != 0 { - // diff_time = last_keyframe_timestamp + 3000 - time_stamp - // fmt.Printf("时间戳调整 last:%d now:%d diff:%d\n",last_keyframe_timestamp,time_stamp,diff_time) +// // if tag_num == 1 && last_keyframe_timestamp != 0 { +// // diff_time = last_keyframe_timestamp + 3000 - time_stamp +// // fmt.Printf("时间戳调整 last:%d now:%d diff:%d\n",last_keyframe_timestamp,time_stamp,diff_time) - if buf[0][tag_offset] == video_tag && buf[0][tag_offset+11]&0xf0 == 0x10 { - first_t = time_stamp - } else { - last_t = time_stamp - } - // } +// if buf[0][tag_offset] == video_tag && buf[0][tag_offset+11]&0xf0 == 0x10 { +// first_t = time_stamp +// } else { +// last_t = time_stamp +// } +// // } - buf_offset = tag_offset + tag_size_check + previou_tag_size - } - for keyframe_interval = 100; keyframe_interval <= last_t-first_t; keyframe_interval += 100 { - } - } +// buf_offset = tag_offset + tag_size_check + previou_tag_size +// } +// for keyframe_interval = 100; keyframe_interval <= last_t-first_t; keyframe_interval += 100 { +// } +// } - tag_num = 0 - base_keyframe_time = 0 +// tag_num = 0 +// base_keyframe_time = 0 - for i := 0; i < len(buf); i += 1 { - keyframe_timestamp = last_keyframe_timestamp + keyframe_interval +// for i := 0; i < len(buf); i += 1 { +// keyframe_timestamp = last_keyframe_timestamp + keyframe_interval - for buf_offset := 0; buf_offset+tag_header_size < len(buf[i]); { +// for buf_offset := 0; buf_offset+tag_header_size < len(buf[i]); { - tag_offset := buf_offset + bytes.IndexAny(buf[i][buf_offset:], string([]byte{video_tag, audio_tag, script_tag})) - if tag_offset == buf_offset-1 { - err = errors.New(`no found available tag`) - // fmt.Printf("last %x\n",buf[tag_offset:tag_offset+tag_header_size]) - return //no found available video,audio,script tag - } - if tag_offset+tag_header_size > len(buf[i]) { - err = errors.New(`reach end when get tag header`) - // fmt.Printf("last %x\n",buf[tag_offset:tag_offset+tag_header_size]) - return //buf end - } +// tag_offset := buf_offset + bytes.IndexAny(buf[i][buf_offset:], string([]byte{video_tag, audio_tag, script_tag})) +// if tag_offset == buf_offset-1 { +// err = errors.New(`no found available tag`) +// // fmt.Printf("last %x\n",buf[tag_offset:tag_offset+tag_header_size]) +// return //no found available video,audio,script tag +// } +// if tag_offset+tag_header_size > len(buf[i]) { +// err = errors.New(`reach end when get tag header`) +// // fmt.Printf("last %x\n",buf[tag_offset:tag_offset+tag_header_size]) +// return //buf end +// } - if buf[i][tag_offset+8]|buf[i][tag_offset+9]|buf[i][tag_offset+10] != 0 { - buf_offset = tag_offset + 1 - // fmt.Printf("streamid error %x\n",buf[tag_offset:tag_offset+tag_header_size]) - continue //streamid error - } +// if buf[i][tag_offset+8]|buf[i][tag_offset+9]|buf[i][tag_offset+10] != 0 { +// buf_offset = tag_offset + 1 +// // fmt.Printf("streamid error %x\n",buf[tag_offset:tag_offset+tag_header_size]) +// continue //streamid error +// } - tag_size := int(F.Btoi32([]byte{0x00, buf[i][tag_offset+1], buf[i][tag_offset+2], buf[i][tag_offset+3]}, 0)) - if tag_offset+tag_header_size+tag_size+previou_tag_size > len(buf[i]) { - err = errors.New(`reach end when get tag body`) - // fmt.Printf("last %x\n",buf[tag_offset:tag_offset+tag_header_size]) - return //buf end - } - if tag_size == 0 { - buf_offset = tag_offset + 1 - // fmt.Printf("tag_size error %x\n",buf[tag_offset:tag_offset+tag_header_size]) - continue //tag_size error - } +// tag_size := int(F.Btoi32([]byte{0x00, buf[i][tag_offset+1], buf[i][tag_offset+2], buf[i][tag_offset+3]}, 0)) +// if tag_offset+tag_header_size+tag_size+previou_tag_size > len(buf[i]) { +// err = errors.New(`reach end when get tag body`) +// // fmt.Printf("last %x\n",buf[tag_offset:tag_offset+tag_header_size]) +// return //buf end +// } +// if tag_size == 0 { +// buf_offset = tag_offset + 1 +// // fmt.Printf("tag_size error %x\n",buf[tag_offset:tag_offset+tag_header_size]) +// continue //tag_size error +// } - tag_size_check := int(F.Btoi32(buf[i][tag_offset+tag_header_size+tag_size:tag_offset+tag_header_size+tag_size+previou_tag_size], 0)) - if tag_num+tag_size_check == 0 { - tag_size_check = tag_size + tag_header_size - } - if tag_size_check != tag_size+tag_header_size { - buf_offset = tag_offset + 1 - // fmt.Printf("tag_size_check error %x\n",buf[tag_offset:tag_offset+tag_header_size]) - continue //tag_size_check error - } +// tag_size_check := int(F.Btoi32(buf[i][tag_offset+tag_header_size+tag_size:tag_offset+tag_header_size+tag_size+previou_tag_size], 0)) +// if tag_num+tag_size_check == 0 { +// tag_size_check = tag_size + tag_header_size +// } +// if tag_size_check != tag_size+tag_header_size { +// buf_offset = tag_offset + 1 +// // fmt.Printf("tag_size_check error %x\n",buf[tag_offset:tag_offset+tag_header_size]) +// continue //tag_size_check error +// } - tag_num += 1 +// tag_num += 1 - time_stamp := int(F.Btoi32([]byte{buf[i][tag_offset+7], buf[i][tag_offset+4], buf[i][tag_offset+5], buf[i][tag_offset+6]}, 0)) +// time_stamp := int(F.Btoi32([]byte{buf[i][tag_offset+7], buf[i][tag_offset+4], buf[i][tag_offset+5], buf[i][tag_offset+6]}, 0)) - // if tag_num == 1 && last_keyframe_timestamp != 0 { - // diff_time = last_keyframe_timestamp + 3000 - time_stamp - // fmt.Printf("时间戳调整 last:%d now:%d diff:%d\n",last_keyframe_timestamp,time_stamp,diff_time) +// // if tag_num == 1 && last_keyframe_timestamp != 0 { +// // diff_time = last_keyframe_timestamp + 3000 - time_stamp +// // fmt.Printf("时间戳调整 last:%d now:%d diff:%d\n",last_keyframe_timestamp,time_stamp,diff_time) - if buf[i][tag_offset] == video_tag && buf[i][tag_offset+11]&0xf0 == 0x10 { - // if {//key frame - base_keyframe_time = time_stamp - time_stamp = keyframe_timestamp - last_keyframe_timestamp = keyframe_timestamp - // fmt.Printf("当前关键帧时间戳 %d %d=>%d\n",last_keyframe_timestamp,base_keyframe_time,keyframe_timestamp) - // } - } else { - time_stamp += keyframe_timestamp - base_keyframe_time - } - // } +// if buf[i][tag_offset] == video_tag && buf[i][tag_offset+11]&0xf0 == 0x10 { +// // if {//key frame +// base_keyframe_time = time_stamp +// time_stamp = keyframe_timestamp +// last_keyframe_timestamp = keyframe_timestamp +// // fmt.Printf("当前关键帧时间戳 %d %d=>%d\n",last_keyframe_timestamp,base_keyframe_time,keyframe_timestamp) +// // } +// } else { +// time_stamp += keyframe_timestamp - base_keyframe_time +// } +// // } - time_stamp_byte := F.Itob32(int32(time_stamp)) +// time_stamp_byte := F.Itob32(int32(time_stamp)) - buf[i][tag_offset+7] = time_stamp_byte[0] - buf[i][tag_offset+4] = time_stamp_byte[1] - buf[i][tag_offset+5] = time_stamp_byte[2] - buf[i][tag_offset+6] = time_stamp_byte[3] +// buf[i][tag_offset+7] = time_stamp_byte[0] +// buf[i][tag_offset+4] = time_stamp_byte[1] +// buf[i][tag_offset+5] = time_stamp_byte[2] +// buf[i][tag_offset+6] = time_stamp_byte[3] - buf_offset = tag_offset + tag_size_check + previou_tag_size - } - } - return -} +// buf_offset = tag_offset + tag_size_check + previou_tag_size +// } +// } +// return +// } -func SearchStreamOffset(buf []byte) (front_buf []byte, available_offset int) { - //get flv header(9byte) + FirstTagSize(4byte) - { - if bytes.Index(buf, flv_header_sign) == 0 { - front_buf = buf[:flv_header_size+previou_tag_size] - } - } +// func SearchStreamOffset(buf []byte) (front_buf []byte, available_offset int) { +// //get flv header(9byte) + FirstTagSize(4byte) +// { +// if bytes.Index(buf, flv_header_sign) == 0 { +// front_buf = buf[:flv_header_size+previou_tag_size] +// } +// } - var sign = 0x00 - for buf_offset := 0; buf_offset < len(buf); { - if tag_offset := buf_offset + bytes.IndexAny(buf[buf_offset:], string([]byte{video_tag, audio_tag, script_tag})); tag_offset == buf_offset-1 { - return //no found available video,audio,script tag - } else if streamid_offset := tag_offset + bytes.Index(buf[tag_offset:], []byte{0x00, 0x00, 0x00}); streamid_offset == tag_offset-1 { - return //no found available streamid - } else if streamid_offset-8 != tag_offset { - buf_offset = tag_offset + 1 - continue //streamid offset error - } else if time_offset := tag_offset + 4; bytes.Index(buf[time_offset:time_offset+2], []byte{0x00, 0x00, 0x00}) == 0 { - - size := int(F.Btoi32(append([]byte{0x00}, buf[tag_offset+1:tag_offset+3]...), 0) + 7) - if (buf[tag_offset] == video_tag) && (sign&0x04 == 0x00) { - sign |= 0x04 - front_buf = append(front_buf, buf[tag_offset:tag_offset+size]...) - } else if (buf[tag_offset] == audio_tag) && (sign&0x02 == 0x00) { - sign |= 0x02 - front_buf = append(front_buf, buf[tag_offset:tag_offset+size]...) - } else if (buf[tag_offset] == script_tag) && (sign&0x01 == 0x00) { - sign |= 0x01 - front_buf = append(front_buf, buf[tag_offset:tag_offset+size]...) - } +// var sign = 0x00 +// for buf_offset := 0; buf_offset < len(buf); { +// if tag_offset := buf_offset + bytes.IndexAny(buf[buf_offset:], string([]byte{video_tag, audio_tag, script_tag})); tag_offset == buf_offset-1 { +// return //no found available video,audio,script tag +// } else if streamid_offset := tag_offset + bytes.Index(buf[tag_offset:], []byte{0x00, 0x00, 0x00}); streamid_offset == tag_offset-1 { +// return //no found available streamid +// } else if streamid_offset-8 != tag_offset { +// buf_offset = tag_offset + 1 +// continue //streamid offset error +// } else if time_offset := tag_offset + 4; bytes.Index(buf[time_offset:time_offset+2], []byte{0x00, 0x00, 0x00}) == 0 { + +// size := int(F.Btoi32(append([]byte{0x00}, buf[tag_offset+1:tag_offset+3]...), 0) + 7) +// if (buf[tag_offset] == video_tag) && (sign&0x04 == 0x00) { +// sign |= 0x04 +// front_buf = append(front_buf, buf[tag_offset:tag_offset+size]...) +// } else if (buf[tag_offset] == audio_tag) && (sign&0x02 == 0x00) { +// sign |= 0x02 +// front_buf = append(front_buf, buf[tag_offset:tag_offset+size]...) +// } else if (buf[tag_offset] == script_tag) && (sign&0x01 == 0x00) { +// sign |= 0x01 +// front_buf = append(front_buf, buf[tag_offset:tag_offset+size]...) +// } - buf_offset = tag_offset + 1 - continue //time error +// buf_offset = tag_offset + 1 +// continue //time error - } else { - available_offset = tag_offset - return - } - } - return -} +// } else { +// available_offset = tag_offset +// return +// } +// } +// return +// } diff --git a/bili_danmu.go b/bili_danmu.go index 9e1baaa..4004b38 100644 --- a/bili_danmu.go +++ b/bili_danmu.go @@ -316,7 +316,7 @@ func Start(roomid ...int) { { //附加功能 ws信息保存 reply.Save_to_json(-1, []interface{}{`{}]`}) if v, ok := c.C.K_v.LoadV(`仅保存当前直播间流`).(bool); ok && v { - reply.StreamOStop(-1) //停止其他房间录制 + reply.StreamOStop(-2) //停止其他房间录制 } } sys.Sys().Timeoutf(1) diff --git a/demo/config/config_K_v.json b/demo/config/config_K_v.json index 8c61508..345aa46 100644 --- a/demo/config/config_K_v.json +++ b/demo/config/config_K_v.json @@ -55,7 +55,7 @@ "直播流清晰度": 10000, "直播流类型-help": "flv or hls", "直播流类型": "flv", - "直播流保存位置": "E:\\test\\", + "直播流保存位置": "./live", "直播hls流缓冲": 20, "直播hls流均衡-help":"true:使用所有hls服务器", "直播hls流均衡": true, -- 2.39.2