|
|
|
@ -13,6 +13,7 @@ import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"github.com/q191201771/naza/pkg/bele"
|
|
|
|
|
"github.com/q191201771/naza/pkg/nazabytes"
|
|
|
|
|
"github.com/q191201771/naza/pkg/nazalog"
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"time"
|
|
|
|
@ -22,20 +23,49 @@ import (
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// lal中的支持情况列表:
|
|
|
|
|
// 支持情况 | 协议 | 类型 | 应用 | 开关手段 | 方式
|
|
|
|
|
// 已支持 | ps | pub | lalserver | http-api参数 | hook到logic中
|
|
|
|
|
// 未支持 | rtsp | pull | lalserver | http-api参数 | hook到logic中
|
|
|
|
|
// 未支持 | customize pub |
|
|
|
|
|
//
|
|
|
|
|
// | 支持情况 | 协议 | 类型 | 应用 | 开关手段 | 方式 | 测试(dump, parse) |
|
|
|
|
|
// | 已支持 | ps | pub | lalserver | http-api参数 | hook到logic中 | 00 |
|
|
|
|
|
// | 已支持 | rtsp | pull | lalserver | http-api参数 | 回调到logic中 | 00 |
|
|
|
|
|
// | 已支持 | rtsp | pull | demo/pullrtsp | 运行参数 | 回调到上层逻辑 | 11 |
|
|
|
|
|
// | 已支持 | customize pub | pub | lalserver | 参数 | 接口提供选项 | 00 |
|
|
|
|
|
// | 未支持 | rtmp | | | | | |
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
DumpTypeDefault uint32 = 0
|
|
|
|
|
DumpTypePsRtpData uint32 = 1 // 1
|
|
|
|
|
DumpTypeRtspRtpData uint32 = 17 // 1+16
|
|
|
|
|
DumpTypeRtspSdpData uint32 = 18
|
|
|
|
|
DumpTypeCustomizePubData uint32 = 33 // 1+16*2
|
|
|
|
|
DumpTypeCustomizePubAudioSpecificConfigData uint32 = 34
|
|
|
|
|
DumpTypeInnerFileHeaderData uint32 = 49 // 1+16*3
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func (d *DumpFile) WriteAvPacket(packet AvPacket, typ uint32) error {
|
|
|
|
|
out := make([]byte, 4+8+8+len(packet.Payload))
|
|
|
|
|
bele.BePutUint32(out, uint32(packet.PayloadType))
|
|
|
|
|
bele.BePutUint64(out[4:], uint64(packet.Timestamp))
|
|
|
|
|
bele.BePutUint64(out[12:], uint64(packet.Pts))
|
|
|
|
|
copy(out[20:], packet.Payload)
|
|
|
|
|
return d.WriteWithType(out, typ)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
writeVer uint32 = 3
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type DumpFile struct {
|
|
|
|
|
file *os.File
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type DumpFileMessage struct {
|
|
|
|
|
Ver uint32
|
|
|
|
|
Ver uint32 // 制造数据时的代码版本
|
|
|
|
|
Typ uint32
|
|
|
|
|
Len uint32
|
|
|
|
|
Timestamp uint32
|
|
|
|
|
Len uint32 // Body 的长度
|
|
|
|
|
Timestamp uint64 // 写入时的时间戳
|
|
|
|
|
Reserve uint32
|
|
|
|
|
Body []byte
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -49,7 +79,7 @@ func (d *DumpFile) OpenToWrite(filename string) (err error) {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
d.file, err = os.Create(filename)
|
|
|
|
|
return
|
|
|
|
|
return d.WriteWithType([]byte(LalFullInfo), DumpTypeInnerFileHeaderData)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (d *DumpFile) OpenToRead(filename string) (err error) {
|
|
|
|
@ -57,8 +87,8 @@ func (d *DumpFile) OpenToRead(filename string) (err error) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (d *DumpFile) Write(b []byte) error {
|
|
|
|
|
_, err := d.file.Write(d.pack(b))
|
|
|
|
|
func (d *DumpFile) WriteWithType(b []byte, typ uint32) error {
|
|
|
|
|
_, err := d.file.Write(d.pack(b, typ))
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -67,6 +97,11 @@ func (d *DumpFile) ReadOneMessage() (m DumpFileMessage, err error) {
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if m.Ver < writeVer {
|
|
|
|
|
nazalog.Warnf("invalid ver. ver=%d", m.Ver)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m.Typ, err = bele.ReadBeUint32(d.file)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
@ -75,14 +110,17 @@ func (d *DumpFile) ReadOneMessage() (m DumpFileMessage, err error) {
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
m.Timestamp, err = bele.ReadBeUint32(d.file)
|
|
|
|
|
m.Timestamp, err = bele.ReadBeUint64(d.file)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
m.Reserve, err = bele.ReadBeUint32(d.file)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m.Body = make([]byte, m.Len)
|
|
|
|
|
_, err = d.file.Read(m.Body)
|
|
|
|
|
// TODO(chef): [opt] 检查Ver等值 202208
|
|
|
|
|
// TODO(chef): [opt] check Read return value 202208
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -102,13 +140,20 @@ func (m *DumpFileMessage) DebugString() string {
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
func (d *DumpFile) pack(b []byte) []byte {
|
|
|
|
|
ret := make([]byte, len(b)+16)
|
|
|
|
|
bele.BePutUint32(ret, 1) // Ver
|
|
|
|
|
bele.BePutUint32(ret[4:], 1) // Typ
|
|
|
|
|
bele.BePutUint32(ret[8:], uint32(len(b))) // Len
|
|
|
|
|
//bele.BePutUint32(ret[12:], 0) // Timestamp
|
|
|
|
|
bele.BePutUint32(ret[12:], uint32(time.Now().Unix())) // Timestamp
|
|
|
|
|
copy(ret[16:], b)
|
|
|
|
|
func (d *DumpFile) pack(b []byte, typ uint32) []byte {
|
|
|
|
|
// TODO(chef): [perf] 优化这块内存 202211
|
|
|
|
|
ret := make([]byte, len(b)+24)
|
|
|
|
|
i := 0
|
|
|
|
|
bele.BePutUint32(ret[i:], writeVer) // Ver
|
|
|
|
|
i += 4
|
|
|
|
|
bele.BePutUint32(ret[i:], typ) // Typ
|
|
|
|
|
i += 4
|
|
|
|
|
bele.BePutUint32(ret[i:], uint32(len(b))) // Len
|
|
|
|
|
i += 4
|
|
|
|
|
bele.BePutUint64(ret[i:], uint64(time.Now().UnixMilli())) // Timestamp
|
|
|
|
|
i += 8
|
|
|
|
|
copy(ret[i:], "LALD")
|
|
|
|
|
i += 4
|
|
|
|
|
copy(ret[i:], b)
|
|
|
|
|
return ret
|
|
|
|
|
}
|
|
|
|
|