|
|
|
@@ -14,7 +14,6 @@ import (
|
|
|
|
|
"sync"
|
|
|
|
|
"syscall"
|
|
|
|
|
"time"
|
|
|
|
|
"unsafe"
|
|
|
|
|
|
|
|
|
|
"github.com/bluenviron/mediacommon/v2/pkg/codecs/h264"
|
|
|
|
|
)
|
|
|
|
@@ -31,17 +30,6 @@ var (
|
|
|
|
|
dumpPath = ""
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func ntpTime() syscall.Timespec {
|
|
|
|
|
var t syscall.Timespec
|
|
|
|
|
syscall.Syscall(syscall.SYS_CLOCK_GETTIME, 0, uintptr(unsafe.Pointer(&t)), 0)
|
|
|
|
|
return t
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func monotonicTime() syscall.Timespec {
|
|
|
|
|
var t syscall.Timespec
|
|
|
|
|
syscall.Syscall(syscall.SYS_CLOCK_GETTIME, 1, uintptr(unsafe.Pointer(&t)), 0)
|
|
|
|
|
return t
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func multiplyAndDivide(v, m, d int64) int64 {
|
|
|
|
|
secs := v / d
|
|
|
|
@@ -345,42 +333,30 @@ outer:
|
|
|
|
|
case 'd':
|
|
|
|
|
dts := int64(buf[8])<<56 | int64(buf[7])<<48 | int64(buf[6])<<40 | int64(buf[5])<<32 |
|
|
|
|
|
int64(buf[4])<<24 | int64(buf[3])<<16 | int64(buf[2])<<8 | int64(buf[1])
|
|
|
|
|
ntpUs := int64(buf[16])<<56 | int64(buf[15])<<48 | int64(buf[14])<<40 | int64(buf[13])<<32 |
|
|
|
|
|
int64(buf[12])<<24 | int64(buf[11])<<16 | int64(buf[10])<<8 | int64(buf[9])
|
|
|
|
|
|
|
|
|
|
var nalus h264.AnnexB
|
|
|
|
|
err = nalus.Unmarshal(buf[9:])
|
|
|
|
|
err = nalus.Unmarshal(buf[17:])
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unixNTP := ntpTime()
|
|
|
|
|
unixMono := monotonicTime()
|
|
|
|
|
|
|
|
|
|
// subtract from NTP the delay from now to the moment the frame was taken
|
|
|
|
|
ntp := time.Unix(int64(unixNTP.Sec), int64(unixNTP.Nsec))
|
|
|
|
|
deltaT := time.Duration(unixMono.Nano()-dts*1e3) * time.Nanosecond
|
|
|
|
|
ntp = ntp.Add(-deltaT)
|
|
|
|
|
|
|
|
|
|
c.onData(
|
|
|
|
|
multiplyAndDivide(dts, 90000, 1e6),
|
|
|
|
|
ntp,
|
|
|
|
|
time.Unix(ntpUs/1e6, (ntpUs%1e6)*1000),
|
|
|
|
|
nalus)
|
|
|
|
|
|
|
|
|
|
case 's':
|
|
|
|
|
dts := int64(buf[8])<<56 | int64(buf[7])<<48 | int64(buf[6])<<40 | int64(buf[5])<<32 |
|
|
|
|
|
int64(buf[4])<<24 | int64(buf[3])<<16 | int64(buf[2])<<8 | int64(buf[1])
|
|
|
|
|
|
|
|
|
|
unixNTP := ntpTime()
|
|
|
|
|
unixMono := monotonicTime()
|
|
|
|
|
|
|
|
|
|
// subtract from NTP the delay from now to the moment the frame was taken
|
|
|
|
|
ntp := time.Unix(int64(unixNTP.Sec), int64(unixNTP.Nsec))
|
|
|
|
|
deltaT := time.Duration(unixMono.Nano()-dts*1e3) * time.Nanosecond
|
|
|
|
|
ntp = ntp.Add(-deltaT)
|
|
|
|
|
ntpUs := int64(buf[16])<<56 | int64(buf[15])<<48 | int64(buf[14])<<40 | int64(buf[13])<<32 |
|
|
|
|
|
int64(buf[12])<<24 | int64(buf[11])<<16 | int64(buf[10])<<8 | int64(buf[9])
|
|
|
|
|
|
|
|
|
|
c.onDataSecondary(
|
|
|
|
|
multiplyAndDivide(dts, 90000, 1e6),
|
|
|
|
|
ntp,
|
|
|
|
|
buf[9:])
|
|
|
|
|
time.Unix(ntpUs/1e6, (ntpUs%1e6)*1000),
|
|
|
|
|
buf[17:])
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return fmt.Errorf("unexpected data from pipe: '0x%.2x'", buf[0])
|
|
|
|
|