Skip to content

Commit f6346a0

Browse files
committed
testing
1 parent 413b746 commit f6346a0

File tree

1 file changed

+43
-21
lines changed

1 file changed

+43
-21
lines changed

format/nvr/muxer.go

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/deepch/vdk/codec/h264parser"
1212
"github.com/deepch/vdk/format/mp4"
1313
"github.com/google/uuid"
14-
"github.com/moby/sys/mountinfo"
1514
"github.com/shirou/gopsutil/v3/disk"
1615
"os"
1716
"path/filepath"
@@ -48,6 +47,7 @@ type Muxer struct {
4847
pstart, pend time.Duration
4948
started bool
5049
serverID, streamName, channelName, streamID, channelID, hostLong, hostShort string
50+
handleFileChange func(string, string, int64, time.Time, time.Time, time.Duration)
5151
}
5252

5353
type Gof struct {
@@ -75,26 +75,27 @@ func init() {
7575

7676
}
7777

78-
func NewMuxer(serverID, streamName, channelName, streamID, channelID string, mpoint []string, patch, format string, limit int) (m *Muxer, err error) {
78+
func NewMuxer(serverID, streamName, channelName, streamID, channelID string, mpoint []string, patch, format string, limit int, c func(string, string, int64, time.Time, time.Time, time.Duration)) (m *Muxer, err error) {
7979
hostLong, _ := os.Hostname()
8080
var hostShort string
8181
if p, _, ok := strings.Cut(hostLong, "."); ok {
8282
hostShort = p
8383
}
8484
m = &Muxer{
85-
mpoint: mpoint,
86-
patch: patch,
87-
h: -1,
88-
gof: &Gof{},
89-
format: format,
90-
limit: limit,
91-
serverID: serverID,
92-
streamName: streamName,
93-
channelName: channelName,
94-
streamID: streamID,
95-
channelID: channelID,
96-
hostLong: hostLong,
97-
hostShort: hostShort,
85+
mpoint: mpoint,
86+
patch: patch,
87+
h: -1,
88+
gof: &Gof{},
89+
format: format,
90+
limit: limit,
91+
serverID: serverID,
92+
streamName: streamName,
93+
channelName: channelName,
94+
streamID: streamID,
95+
channelID: channelID,
96+
hostLong: hostLong,
97+
hostShort: hostShort,
98+
handleFileChange: c,
9899
}
99100
return
100101
}
@@ -236,14 +237,14 @@ func (m *Muxer) filePatch() (string, error) {
236237
)
237238

238239
for i, i2 := range m.mpoint {
239-
if m, err := mountinfo.Mounted(i2); err == nil && m {
240-
if d, err := disk.Usage(i2); err == nil {
241-
if d.UsedPercent < mu {
242-
ui = i
243-
mu = d.UsedPercent
244-
}
240+
//if m, err := mountinfo.Mounted(i2); err == nil && m {
241+
if d, err := disk.Usage(i2); err == nil {
242+
if d.UsedPercent < mu {
243+
ui = i
244+
mu = d.UsedPercent
245245
}
246246
}
247+
// }
247248
}
248249

249250
if ui == -1 {
@@ -325,6 +326,15 @@ func (m *Muxer) filePatch() (string, error) {
325326
return ts, nil
326327
}
327328

329+
func (m *Muxer) Codecs() string {
330+
var codecs []string
331+
for _, stream := range m.gof.Streams {
332+
codecs = append(codecs, stream.Type().String())
333+
}
334+
335+
return strings.Join(codecs, ",")
336+
}
337+
328338
func (m *Muxer) WriteTrailer() (err error) {
329339
if m.muxer != nil {
330340
m.muxer.WriteTrailer()
@@ -341,6 +351,18 @@ func (m *Muxer) WriteTrailer() (err error) {
341351
if err = os.Rename(m.d.Name(), filepath.Join(filepath.Dir(m.d.Name()), filepath.Base(p))); err != nil {
342352
return err
343353
}
354+
var size int64
355+
if fi, err := m.d.Stat(); err == nil {
356+
size = fi.Size()
357+
}
358+
m.handleFileChange(
359+
m.Codecs(),
360+
filepath.Join(filepath.Dir(m.d.Name()), filepath.Base(p)),
361+
size,
362+
m.start,
363+
m.end,
364+
m.dur,
365+
)
344366
}
345367
err = m.d.Close()
346368
}

0 commit comments

Comments
 (0)