Browse Source

record: rename recFormat into format (#2776)

pull/2775/head
Alessandro Ros 2 years ago committed by GitHub
parent
commit
5da2ded815
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      internal/record/agent_instance.go
  2. 12
      internal/record/agent_test.go
  3. 2
      internal/record/format.go
  4. 46
      internal/record/format_fmp4.go
  5. 24
      internal/record/format_fmp4_part.go
  6. 24
      internal/record/format_fmp4_segment.go
  7. 18
      internal/record/format_fmp4_track.go
  8. 34
      internal/record/format_mpegts.go
  9. 12
      internal/record/format_mpegts_segment.go

6
internal/record/agent_instance.go

@ -24,7 +24,7 @@ type agentInstance struct {
resolvedPath string resolvedPath string
writer *asyncwriter.Writer writer *asyncwriter.Writer
format recFormat format format
terminate chan struct{} terminate chan struct{}
done chan struct{} done chan struct{}
@ -48,13 +48,13 @@ func (a *agentInstance) initialize() {
switch a.wrapper.Format { switch a.wrapper.Format {
case conf.RecordFormatMPEGTS: case conf.RecordFormatMPEGTS:
a.format = &recFormatMPEGTS{ a.format = &formatMPEGTS{
a: a, a: a,
} }
a.format.initialize() a.format.initialize()
default: default:
a.format = &recFormatFMP4{ a.format = &formatFMP4{
a: a, a: a,
} }
a.format.initialize() a.format.initialize()

12
internal/record/agent_test.go

@ -7,7 +7,7 @@ import (
"time" "time"
"github.com/bluenviron/gortsplib/v4/pkg/description" "github.com/bluenviron/gortsplib/v4/pkg/description"
"github.com/bluenviron/gortsplib/v4/pkg/format" rtspformat "github.com/bluenviron/gortsplib/v4/pkg/format"
"github.com/bluenviron/mediacommon/pkg/codecs/h265" "github.com/bluenviron/mediacommon/pkg/codecs/h265"
"github.com/bluenviron/mediacommon/pkg/codecs/mpeg4audio" "github.com/bluenviron/mediacommon/pkg/codecs/mpeg4audio"
"github.com/bluenviron/mediacommon/pkg/formats/fmp4" "github.com/bluenviron/mediacommon/pkg/formats/fmp4"
@ -28,20 +28,20 @@ func TestAgent(t *testing.T) {
desc := &description.Session{Medias: []*description.Media{ desc := &description.Session{Medias: []*description.Media{
{ {
Type: description.MediaTypeVideo, Type: description.MediaTypeVideo,
Formats: []format.Format{&format.H265{ Formats: []rtspformat.Format{&rtspformat.H265{
PayloadTyp: 96, PayloadTyp: 96,
}}, }},
}, },
{ {
Type: description.MediaTypeVideo, Type: description.MediaTypeVideo,
Formats: []format.Format{&format.H264{ Formats: []rtspformat.Format{&rtspformat.H264{
PayloadTyp: 96, PayloadTyp: 96,
PacketizationMode: 1, PacketizationMode: 1,
}}, }},
}, },
{ {
Type: description.MediaTypeAudio, Type: description.MediaTypeAudio,
Formats: []format.Format{&format.MPEG4Audio{ Formats: []rtspformat.Format{&rtspformat.MPEG4Audio{
PayloadTyp: 96, PayloadTyp: 96,
Config: &mpeg4audio.Config{ Config: &mpeg4audio.Config{
Type: 2, Type: 2,
@ -225,14 +225,14 @@ func TestAgentFMP4NegativeDTS(t *testing.T) {
desc := &description.Session{Medias: []*description.Media{ desc := &description.Session{Medias: []*description.Media{
{ {
Type: description.MediaTypeVideo, Type: description.MediaTypeVideo,
Formats: []format.Format{&format.H264{ Formats: []rtspformat.Format{&rtspformat.H264{
PayloadTyp: 96, PayloadTyp: 96,
PacketizationMode: 1, PacketizationMode: 1,
}}, }},
}, },
{ {
Type: description.MediaTypeAudio, Type: description.MediaTypeAudio,
Formats: []format.Format{&format.MPEG4Audio{ Formats: []rtspformat.Format{&rtspformat.MPEG4Audio{
PayloadTyp: 96, PayloadTyp: 96,
Config: &mpeg4audio.Config{ Config: &mpeg4audio.Config{
Type: 2, Type: 2,

2
internal/record/rec_format.go → internal/record/format.go

@ -1,6 +1,6 @@
package record package record
type recFormat interface { type format interface {
initialize() initialize()
close() close()
} }

46
internal/record/rec_format_fmp4.go → internal/record/format_fmp4.go

@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/bluenviron/gortsplib/v4/pkg/format" rtspformat "github.com/bluenviron/gortsplib/v4/pkg/format"
"github.com/bluenviron/mediacommon/pkg/codecs/ac3" "github.com/bluenviron/mediacommon/pkg/codecs/ac3"
"github.com/bluenviron/mediacommon/pkg/codecs/av1" "github.com/bluenviron/mediacommon/pkg/codecs/av1"
"github.com/bluenviron/mediacommon/pkg/codecs/h264" "github.com/bluenviron/mediacommon/pkg/codecs/h264"
@ -96,19 +96,19 @@ func jpegExtractSize(image []byte) (int, int, error) {
} }
} }
type recFormatFMP4 struct { type formatFMP4 struct {
a *agentInstance a *agentInstance
tracks []*recFormatFMP4Track tracks []*formatFMP4Track
hasVideo bool hasVideo bool
currentSegment *recFormatFMP4Segment currentSegment *formatFMP4Segment
nextSequenceNumber uint32 nextSequenceNumber uint32
} }
func (f *recFormatFMP4) initialize() { func (f *formatFMP4) initialize() {
nextID := 1 nextID := 1
addTrack := func(codec fmp4.Codec) *recFormatFMP4Track { addTrack := func(codec fmp4.Codec) *formatFMP4Track {
initTrack := &fmp4.InitTrack{ initTrack := &fmp4.InitTrack{
TimeScale: 90000, TimeScale: 90000,
Codec: codec, Codec: codec,
@ -116,7 +116,7 @@ func (f *recFormatFMP4) initialize() {
initTrack.ID = nextID initTrack.ID = nextID
nextID++ nextID++
track := newRecFormatFMP4Track(f, initTrack) track := newFormatFMP4Track(f, initTrack)
f.tracks = append(f.tracks, track) f.tracks = append(f.tracks, track)
return track return track
@ -135,7 +135,7 @@ func (f *recFormatFMP4) initialize() {
for _, media := range f.a.wrapper.Stream.Desc().Medias { for _, media := range f.a.wrapper.Stream.Desc().Medias {
for _, forma := range media.Formats { for _, forma := range media.Formats {
switch forma := forma.(type) { switch forma := forma.(type) {
case *format.AV1: case *rtspformat.AV1:
codec := &fmp4.CodecAV1{ codec := &fmp4.CodecAV1{
SequenceHeader: []byte{ SequenceHeader: []byte{
8, 0, 0, 0, 66, 167, 191, 228, 96, 13, 0, 64, 8, 0, 0, 0, 66, 167, 191, 228, 96, 13, 0, 64,
@ -189,7 +189,7 @@ func (f *recFormatFMP4) initialize() {
}) })
}) })
case *format.VP9: case *rtspformat.VP9:
codec := &fmp4.CodecVP9{ codec := &fmp4.CodecVP9{
Width: 1280, Width: 1280,
Height: 720, Height: 720,
@ -261,10 +261,10 @@ func (f *recFormatFMP4) initialize() {
}) })
}) })
case *format.VP8: case *rtspformat.VP8:
// TODO // TODO
case *format.H265: case *rtspformat.H265:
vps, sps, pps := forma.SafeParams() vps, sps, pps := forma.SafeParams()
if vps == nil || sps == nil || pps == nil { if vps == nil || sps == nil || pps == nil {
@ -360,7 +360,7 @@ func (f *recFormatFMP4) initialize() {
}) })
}) })
case *format.H264: case *rtspformat.H264:
sps, pps := forma.SafeParams() sps, pps := forma.SafeParams()
if sps == nil || pps == nil { if sps == nil || pps == nil {
@ -438,7 +438,7 @@ func (f *recFormatFMP4) initialize() {
}) })
}) })
case *format.MPEG4Video: case *rtspformat.MPEG4Video:
config := forma.SafeParams() config := forma.SafeParams()
if config == nil { if config == nil {
@ -499,7 +499,7 @@ func (f *recFormatFMP4) initialize() {
}) })
}) })
case *format.MPEG1Video: case *rtspformat.MPEG1Video:
codec := &fmp4.CodecMPEG1Video{ codec := &fmp4.CodecMPEG1Video{
Config: []byte{ Config: []byte{
0x00, 0x00, 0x01, 0xb3, 0x78, 0x04, 0x38, 0x35, 0x00, 0x00, 0x01, 0xb3, 0x78, 0x04, 0x38, 0x35,
@ -551,7 +551,7 @@ func (f *recFormatFMP4) initialize() {
}) })
}) })
case *format.MJPEG: case *rtspformat.MJPEG:
codec := &fmp4.CodecMJPEG{ codec := &fmp4.CodecMJPEG{
Width: 800, Width: 800,
Height: 600, Height: 600,
@ -585,7 +585,7 @@ func (f *recFormatFMP4) initialize() {
}) })
}) })
case *format.Opus: case *rtspformat.Opus:
codec := &fmp4.CodecOpus{ codec := &fmp4.CodecOpus{
ChannelCount: func() int { ChannelCount: func() int {
if forma.IsStereo { if forma.IsStereo {
@ -621,7 +621,7 @@ func (f *recFormatFMP4) initialize() {
return nil return nil
}) })
case *format.MPEG4Audio: case *rtspformat.MPEG4Audio:
codec := &fmp4.CodecMPEG4Audio{ codec := &fmp4.CodecMPEG4Audio{
Config: *forma.GetConfig(), Config: *forma.GetConfig(),
} }
@ -653,7 +653,7 @@ func (f *recFormatFMP4) initialize() {
return nil return nil
}) })
case *format.MPEG1Audio: case *rtspformat.MPEG1Audio:
codec := &fmp4.CodecMPEG1Audio{ codec := &fmp4.CodecMPEG1Audio{
SampleRate: 32000, SampleRate: 32000,
ChannelCount: 2, ChannelCount: 2,
@ -701,7 +701,7 @@ func (f *recFormatFMP4) initialize() {
return nil return nil
}) })
case *format.AC3: case *rtspformat.AC3:
codec := &fmp4.CodecAC3{ codec := &fmp4.CodecAC3{
SampleRate: forma.SampleRate, SampleRate: forma.SampleRate,
ChannelCount: forma.ChannelCount, ChannelCount: forma.ChannelCount,
@ -767,13 +767,13 @@ func (f *recFormatFMP4) initialize() {
return nil return nil
}) })
case *format.G722: case *rtspformat.G722:
// TODO // TODO
case *format.G711: case *rtspformat.G711:
// TODO // TODO
case *format.LPCM: case *rtspformat.LPCM:
codec := &fmp4.CodecLPCM{ codec := &fmp4.CodecLPCM{
LittleEndian: false, LittleEndian: false,
BitDepth: forma.BitDepth, BitDepth: forma.BitDepth,
@ -809,7 +809,7 @@ func (f *recFormatFMP4) initialize() {
}()) }())
} }
func (f *recFormatFMP4) close() { func (f *formatFMP4) close() {
if f.currentSegment != nil { if f.currentSegment != nil {
f.currentSegment.close() //nolint:errcheck f.currentSegment.close() //nolint:errcheck
} }

24
internal/record/rec_format_fmp4_part.go → internal/record/format_fmp4_part.go

@ -15,7 +15,7 @@ import (
func writePart( func writePart(
f io.Writer, f io.Writer,
sequenceNumber uint32, sequenceNumber uint32,
partTracks map[*recFormatFMP4Track]*fmp4.PartTrack, partTracks map[*formatFMP4Track]*fmp4.PartTrack,
) error { ) error {
fmp4PartTracks := make([]*fmp4.PartTrack, len(partTracks)) fmp4PartTracks := make([]*fmp4.PartTrack, len(partTracks))
i := 0 i := 0
@ -39,31 +39,31 @@ func writePart(
return err return err
} }
type recFormatFMP4Part struct { type formatFMP4Part struct {
s *recFormatFMP4Segment s *formatFMP4Segment
sequenceNumber uint32 sequenceNumber uint32
startDTS time.Duration startDTS time.Duration
created time.Time created time.Time
partTracks map[*recFormatFMP4Track]*fmp4.PartTrack partTracks map[*formatFMP4Track]*fmp4.PartTrack
endDTS time.Duration endDTS time.Duration
} }
func newRecFormatFMP4Part( func newFormatFMP4Part(
s *recFormatFMP4Segment, s *formatFMP4Segment,
sequenceNumber uint32, sequenceNumber uint32,
startDTS time.Duration, startDTS time.Duration,
) *recFormatFMP4Part { ) *formatFMP4Part {
return &recFormatFMP4Part{ return &formatFMP4Part{
s: s, s: s,
startDTS: startDTS, startDTS: startDTS,
sequenceNumber: sequenceNumber, sequenceNumber: sequenceNumber,
created: timeNow(), created: timeNow(),
partTracks: make(map[*recFormatFMP4Track]*fmp4.PartTrack), partTracks: make(map[*formatFMP4Track]*fmp4.PartTrack),
} }
} }
func (p *recFormatFMP4Part) close() error { func (p *formatFMP4Part) close() error {
if p.s.fi == nil { if p.s.fi == nil {
p.s.fpath = encodeRecordPath(&recordPathParams{time: p.created}, p.s.f.a.resolvedPath) p.s.fpath = encodeRecordPath(&recordPathParams{time: p.created}, p.s.f.a.resolvedPath)
p.s.f.a.wrapper.Log(logger.Debug, "creating segment %s", p.s.fpath) p.s.f.a.wrapper.Log(logger.Debug, "creating segment %s", p.s.fpath)
@ -92,7 +92,7 @@ func (p *recFormatFMP4Part) close() error {
return writePart(p.s.fi, p.sequenceNumber, p.partTracks) return writePart(p.s.fi, p.sequenceNumber, p.partTracks)
} }
func (p *recFormatFMP4Part) record(track *recFormatFMP4Track, sample *sample) error { func (p *formatFMP4Part) record(track *formatFMP4Track, sample *sample) error {
partTrack, ok := p.partTracks[track] partTrack, ok := p.partTracks[track]
if !ok { if !ok {
partTrack = &fmp4.PartTrack{ partTrack = &fmp4.PartTrack{
@ -108,6 +108,6 @@ func (p *recFormatFMP4Part) record(track *recFormatFMP4Track, sample *sample) er
return nil return nil
} }
func (p *recFormatFMP4Part) duration() time.Duration { func (p *formatFMP4Part) duration() time.Duration {
return p.endDTS - p.startDTS return p.endDTS - p.startDTS
} }

24
internal/record/rec_format_fmp4_segment.go → internal/record/format_fmp4_segment.go

@ -13,7 +13,7 @@ import (
var timeNow = time.Now var timeNow = time.Now
func writeInit(f io.Writer, tracks []*recFormatFMP4Track) error { func writeInit(f io.Writer, tracks []*formatFMP4Track) error {
fmp4Tracks := make([]*fmp4.InitTrack, len(tracks)) fmp4Tracks := make([]*fmp4.InitTrack, len(tracks))
for i, track := range tracks { for i, track := range tracks {
fmp4Tracks[i] = track.initTrack fmp4Tracks[i] = track.initTrack
@ -33,26 +33,26 @@ func writeInit(f io.Writer, tracks []*recFormatFMP4Track) error {
return err return err
} }
type recFormatFMP4Segment struct { type formatFMP4Segment struct {
f *recFormatFMP4 f *formatFMP4
startDTS time.Duration startDTS time.Duration
fpath string fpath string
fi *os.File fi *os.File
curPart *recFormatFMP4Part curPart *formatFMP4Part
} }
func newRecFormatFMP4Segment( func newFormatFMP4Segment(
f *recFormatFMP4, f *formatFMP4,
startDTS time.Duration, startDTS time.Duration,
) *recFormatFMP4Segment { ) *formatFMP4Segment {
return &recFormatFMP4Segment{ return &formatFMP4Segment{
f: f, f: f,
startDTS: startDTS, startDTS: startDTS,
} }
} }
func (s *recFormatFMP4Segment) close() error { func (s *formatFMP4Segment) close() error {
var err error var err error
if s.curPart != nil { if s.curPart != nil {
@ -74,9 +74,9 @@ func (s *recFormatFMP4Segment) close() error {
return err return err
} }
func (s *recFormatFMP4Segment) record(track *recFormatFMP4Track, sample *sample) error { func (s *formatFMP4Segment) record(track *formatFMP4Track, sample *sample) error {
if s.curPart == nil { if s.curPart == nil {
s.curPart = newRecFormatFMP4Part(s, s.f.nextSequenceNumber, sample.dts) s.curPart = newFormatFMP4Part(s, s.f.nextSequenceNumber, sample.dts)
s.f.nextSequenceNumber++ s.f.nextSequenceNumber++
} else if s.curPart.duration() >= s.f.a.wrapper.PartDuration { } else if s.curPart.duration() >= s.f.a.wrapper.PartDuration {
err := s.curPart.close() err := s.curPart.close()
@ -86,7 +86,7 @@ func (s *recFormatFMP4Segment) record(track *recFormatFMP4Track, sample *sample)
return err return err
} }
s.curPart = newRecFormatFMP4Part(s, s.f.nextSequenceNumber, sample.dts) s.curPart = newFormatFMP4Part(s, s.f.nextSequenceNumber, sample.dts)
s.f.nextSequenceNumber++ s.f.nextSequenceNumber++
} }

18
internal/record/rec_format_fmp4_track.go → internal/record/format_fmp4_track.go

@ -4,24 +4,24 @@ import (
"github.com/bluenviron/mediacommon/pkg/formats/fmp4" "github.com/bluenviron/mediacommon/pkg/formats/fmp4"
) )
type recFormatFMP4Track struct { type formatFMP4Track struct {
f *recFormatFMP4 f *formatFMP4
initTrack *fmp4.InitTrack initTrack *fmp4.InitTrack
nextSample *sample nextSample *sample
} }
func newRecFormatFMP4Track( func newFormatFMP4Track(
f *recFormatFMP4, f *formatFMP4,
initTrack *fmp4.InitTrack, initTrack *fmp4.InitTrack,
) *recFormatFMP4Track { ) *formatFMP4Track {
return &recFormatFMP4Track{ return &formatFMP4Track{
f: f, f: f,
initTrack: initTrack, initTrack: initTrack,
} }
} }
func (t *recFormatFMP4Track) record(sample *sample) error { func (t *formatFMP4Track) record(sample *sample) error {
// wait the first video sample before setting hasVideo // wait the first video sample before setting hasVideo
if t.initTrack.Codec.IsVideo() { if t.initTrack.Codec.IsVideo() {
t.f.hasVideo = true t.f.hasVideo = true
@ -34,7 +34,7 @@ func (t *recFormatFMP4Track) record(sample *sample) error {
sample.Duration = uint32(durationGoToMp4(t.nextSample.dts-sample.dts, t.initTrack.TimeScale)) sample.Duration = uint32(durationGoToMp4(t.nextSample.dts-sample.dts, t.initTrack.TimeScale))
if t.f.currentSegment == nil { if t.f.currentSegment == nil {
t.f.currentSegment = newRecFormatFMP4Segment(t.f, sample.dts) t.f.currentSegment = newFormatFMP4Segment(t.f, sample.dts)
// BaseTime is negative, this is not supported by fMP4. Reject the sample silently. // BaseTime is negative, this is not supported by fMP4. Reject the sample silently.
} else if (sample.dts - t.f.currentSegment.startDTS) < 0 { } else if (sample.dts - t.f.currentSegment.startDTS) < 0 {
return nil return nil
@ -53,7 +53,7 @@ func (t *recFormatFMP4Track) record(sample *sample) error {
return err return err
} }
t.f.currentSegment = newRecFormatFMP4Segment(t.f, t.nextSample.dts) t.f.currentSegment = newFormatFMP4Segment(t.f, t.nextSample.dts)
} }
return nil return nil

34
internal/record/rec_format_mpegts.go → internal/record/format_mpegts.go

@ -7,7 +7,7 @@ import (
"io" "io"
"time" "time"
"github.com/bluenviron/gortsplib/v4/pkg/format" rtspformat "github.com/bluenviron/gortsplib/v4/pkg/format"
"github.com/bluenviron/mediacommon/pkg/codecs/ac3" "github.com/bluenviron/mediacommon/pkg/codecs/ac3"
"github.com/bluenviron/mediacommon/pkg/codecs/h264" "github.com/bluenviron/mediacommon/pkg/codecs/h264"
"github.com/bluenviron/mediacommon/pkg/codecs/h265" "github.com/bluenviron/mediacommon/pkg/codecs/h265"
@ -38,17 +38,17 @@ func (d *dynamicWriter) setTarget(w io.Writer) {
d.w = w d.w = w
} }
type recFormatMPEGTS struct { type formatMPEGTS struct {
a *agentInstance a *agentInstance
dw *dynamicWriter dw *dynamicWriter
bw *bufio.Writer bw *bufio.Writer
mw *mpegts.Writer mw *mpegts.Writer
hasVideo bool hasVideo bool
currentSegment *recFormatMPEGTSSegment currentSegment *formatMPEGTSSegment
} }
func (f *recFormatMPEGTS) initialize() { func (f *formatMPEGTS) initialize() {
var tracks []*mpegts.Track var tracks []*mpegts.Track
addTrack := func(codec mpegts.Codec) *mpegts.Track { addTrack := func(codec mpegts.Codec) *mpegts.Track {
@ -62,7 +62,7 @@ func (f *recFormatMPEGTS) initialize() {
for _, media := range f.a.wrapper.Stream.Desc().Medias { for _, media := range f.a.wrapper.Stream.Desc().Medias {
for _, forma := range media.Formats { for _, forma := range media.Formats {
switch forma := forma.(type) { switch forma := forma.(type) {
case *format.H265: case *rtspformat.H265:
track := addTrack(&mpegts.CodecH265{}) track := addTrack(&mpegts.CodecH265{})
var dtsExtractor *h265.DTSExtractor var dtsExtractor *h265.DTSExtractor
@ -90,7 +90,7 @@ func (f *recFormatMPEGTS) initialize() {
return f.recordH26x(track, dts, durationGoToMPEGTS(tunit.PTS), durationGoToMPEGTS(dts), randomAccess, tunit.AU) return f.recordH26x(track, dts, durationGoToMPEGTS(tunit.PTS), durationGoToMPEGTS(dts), randomAccess, tunit.AU)
}) })
case *format.H264: case *rtspformat.H264:
track := addTrack(&mpegts.CodecH264{}) track := addTrack(&mpegts.CodecH264{})
var dtsExtractor *h264.DTSExtractor var dtsExtractor *h264.DTSExtractor
@ -118,7 +118,7 @@ func (f *recFormatMPEGTS) initialize() {
return f.recordH26x(track, dts, durationGoToMPEGTS(tunit.PTS), durationGoToMPEGTS(dts), idrPresent, tunit.AU) return f.recordH26x(track, dts, durationGoToMPEGTS(tunit.PTS), durationGoToMPEGTS(dts), idrPresent, tunit.AU)
}) })
case *format.MPEG4Video: case *rtspformat.MPEG4Video:
track := addTrack(&mpegts.CodecMPEG4Video{}) track := addTrack(&mpegts.CodecMPEG4Video{})
firstReceived := false firstReceived := false
@ -148,7 +148,7 @@ func (f *recFormatMPEGTS) initialize() {
return f.mw.WriteMPEG4Video(track, durationGoToMPEGTS(tunit.PTS), tunit.Frame) return f.mw.WriteMPEG4Video(track, durationGoToMPEGTS(tunit.PTS), tunit.Frame)
}) })
case *format.MPEG1Video: case *rtspformat.MPEG1Video:
track := addTrack(&mpegts.CodecMPEG1Video{}) track := addTrack(&mpegts.CodecMPEG1Video{})
firstReceived := false firstReceived := false
@ -178,7 +178,7 @@ func (f *recFormatMPEGTS) initialize() {
return f.mw.WriteMPEG1Video(track, durationGoToMPEGTS(tunit.PTS), tunit.Frame) return f.mw.WriteMPEG1Video(track, durationGoToMPEGTS(tunit.PTS), tunit.Frame)
}) })
case *format.Opus: case *rtspformat.Opus:
track := addTrack(&mpegts.CodecOpus{ track := addTrack(&mpegts.CodecOpus{
ChannelCount: func() int { ChannelCount: func() int {
if forma.IsStereo { if forma.IsStereo {
@ -202,7 +202,7 @@ func (f *recFormatMPEGTS) initialize() {
return f.mw.WriteOpus(track, durationGoToMPEGTS(tunit.PTS), tunit.Packets) return f.mw.WriteOpus(track, durationGoToMPEGTS(tunit.PTS), tunit.Packets)
}) })
case *format.MPEG4Audio: case *rtspformat.MPEG4Audio:
track := addTrack(&mpegts.CodecMPEG4Audio{ track := addTrack(&mpegts.CodecMPEG4Audio{
Config: *forma.GetConfig(), Config: *forma.GetConfig(),
}) })
@ -221,7 +221,7 @@ func (f *recFormatMPEGTS) initialize() {
return f.mw.WriteMPEG4Audio(track, durationGoToMPEGTS(tunit.PTS), tunit.AUs) return f.mw.WriteMPEG4Audio(track, durationGoToMPEGTS(tunit.PTS), tunit.AUs)
}) })
case *format.MPEG1Audio: case *rtspformat.MPEG1Audio:
track := addTrack(&mpegts.CodecMPEG1Audio{}) track := addTrack(&mpegts.CodecMPEG1Audio{})
f.a.wrapper.Stream.AddReader(f.a.writer, media, forma, func(u unit.Unit) error { f.a.wrapper.Stream.AddReader(f.a.writer, media, forma, func(u unit.Unit) error {
@ -238,7 +238,7 @@ func (f *recFormatMPEGTS) initialize() {
return f.mw.WriteMPEG1Audio(track, durationGoToMPEGTS(tunit.PTS), tunit.Frames) return f.mw.WriteMPEG1Audio(track, durationGoToMPEGTS(tunit.PTS), tunit.Frames)
}) })
case *format.AC3: case *rtspformat.AC3:
track := addTrack(&mpegts.CodecAC3{}) track := addTrack(&mpegts.CodecAC3{})
sampleRate := time.Duration(forma.SampleRate) sampleRate := time.Duration(forma.SampleRate)
@ -279,16 +279,16 @@ func (f *recFormatMPEGTS) initialize() {
}()) }())
} }
func (f *recFormatMPEGTS) close() { func (f *formatMPEGTS) close() {
if f.currentSegment != nil { if f.currentSegment != nil {
f.currentSegment.close() //nolint:errcheck f.currentSegment.close() //nolint:errcheck
} }
} }
func (f *recFormatMPEGTS) setupSegment(dts time.Duration, isVideo bool, randomAccess bool) error { func (f *formatMPEGTS) setupSegment(dts time.Duration, isVideo bool, randomAccess bool) error {
switch { switch {
case f.currentSegment == nil: case f.currentSegment == nil:
f.currentSegment = newRecFormatMPEGTSSegment(f, dts) f.currentSegment = newFormatMPEGTSSegment(f, dts)
case (!f.hasVideo || isVideo) && case (!f.hasVideo || isVideo) &&
randomAccess && randomAccess &&
@ -298,7 +298,7 @@ func (f *recFormatMPEGTS) setupSegment(dts time.Duration, isVideo bool, randomAc
return err return err
} }
f.currentSegment = newRecFormatMPEGTSSegment(f, dts) f.currentSegment = newFormatMPEGTSSegment(f, dts)
case (dts - f.currentSegment.lastFlush) >= f.a.wrapper.PartDuration: case (dts - f.currentSegment.lastFlush) >= f.a.wrapper.PartDuration:
err := f.bw.Flush() err := f.bw.Flush()
@ -312,7 +312,7 @@ func (f *recFormatMPEGTS) setupSegment(dts time.Duration, isVideo bool, randomAc
return nil return nil
} }
func (f *recFormatMPEGTS) recordH26x(track *mpegts.Track, goDTS time.Duration, func (f *formatMPEGTS) recordH26x(track *mpegts.Track, goDTS time.Duration,
pts int64, dts int64, randomAccess bool, au [][]byte, pts int64, dts int64, randomAccess bool, au [][]byte,
) error { ) error {
f.hasVideo = true f.hasVideo = true

12
internal/record/rec_format_mpegts_segment.go → internal/record/format_mpegts_segment.go

@ -8,8 +8,8 @@ import (
"github.com/bluenviron/mediamtx/internal/logger" "github.com/bluenviron/mediamtx/internal/logger"
) )
type recFormatMPEGTSSegment struct { type formatMPEGTSSegment struct {
f *recFormatMPEGTS f *formatMPEGTS
startDTS time.Duration startDTS time.Duration
lastFlush time.Duration lastFlush time.Duration
@ -18,8 +18,8 @@ type recFormatMPEGTSSegment struct {
fi *os.File fi *os.File
} }
func newRecFormatMPEGTSSegment(f *recFormatMPEGTS, startDTS time.Duration) *recFormatMPEGTSSegment { func newFormatMPEGTSSegment(f *formatMPEGTS, startDTS time.Duration) *formatMPEGTSSegment {
s := &recFormatMPEGTSSegment{ s := &formatMPEGTSSegment{
f: f, f: f,
startDTS: startDTS, startDTS: startDTS,
lastFlush: startDTS, lastFlush: startDTS,
@ -31,7 +31,7 @@ func newRecFormatMPEGTSSegment(f *recFormatMPEGTS, startDTS time.Duration) *recF
return s return s
} }
func (s *recFormatMPEGTSSegment) close() error { func (s *formatMPEGTSSegment) close() error {
err := s.f.bw.Flush() err := s.f.bw.Flush()
if s.fi != nil { if s.fi != nil {
@ -49,7 +49,7 @@ func (s *recFormatMPEGTSSegment) close() error {
return err return err
} }
func (s *recFormatMPEGTSSegment) Write(p []byte) (int, error) { func (s *formatMPEGTSSegment) Write(p []byte) (int, error) {
if s.fi == nil { if s.fi == nil {
s.fpath = encodeRecordPath(&recordPathParams{time: s.created}, s.f.a.resolvedPath) s.fpath = encodeRecordPath(&recordPathParams{time: s.created}, s.f.a.resolvedPath)
s.f.a.wrapper.Log(logger.Debug, "creating segment %s", s.fpath) s.f.a.wrapper.Log(logger.Debug, "creating segment %s", s.fpath)
Loading…
Cancel
Save