mirror of
https://github.com/aler9/gortsplib
synced 2025-10-26 16:50:32 +08:00
simplify examples (#389)
This commit is contained in:
@@ -23,7 +23,6 @@ type mpegtsMuxer struct {
|
|||||||
w *mpegts.Writer
|
w *mpegts.Writer
|
||||||
track *mpegts.Track
|
track *mpegts.Track
|
||||||
dtsExtractor *h264.DTSExtractor
|
dtsExtractor *h264.DTSExtractor
|
||||||
firstIDRReceived bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// newMPEGTSMuxer allocates a mpegtsMuxer.
|
// newMPEGTSMuxer allocates a mpegtsMuxer.
|
||||||
@@ -103,27 +102,19 @@ func (e *mpegtsMuxer) encode(au [][]byte, pts time.Duration) error {
|
|||||||
|
|
||||||
var dts time.Duration
|
var dts time.Duration
|
||||||
|
|
||||||
if !e.firstIDRReceived {
|
if e.dtsExtractor == nil {
|
||||||
// skip samples silently until we find one with a IDR
|
// skip samples silently until we find one with a IDR
|
||||||
if !idrPresent {
|
if !idrPresent {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
e.firstIDRReceived = true
|
|
||||||
e.dtsExtractor = h264.NewDTSExtractor()
|
e.dtsExtractor = h264.NewDTSExtractor()
|
||||||
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
dts, err = e.dtsExtractor.Extract(au, pts)
|
dts, err = e.dtsExtractor.Extract(au, pts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
var err error
|
|
||||||
dts, err = e.dtsExtractor.Extract(au, pts)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// encode into MPEG-TS
|
// encode into MPEG-TS
|
||||||
return e.w.WriteH26x(e.track, durationGoToMPEGTS(pts), durationGoToMPEGTS(dts), idrPresent, au)
|
return e.w.WriteH26x(e.track, durationGoToMPEGTS(pts), durationGoToMPEGTS(dts), idrPresent, au)
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ type mpegtsMuxer struct {
|
|||||||
w *mpegts.Writer
|
w *mpegts.Writer
|
||||||
track *mpegts.Track
|
track *mpegts.Track
|
||||||
dtsExtractor *h264.DTSExtractor
|
dtsExtractor *h264.DTSExtractor
|
||||||
firstIDRReceived bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// newMPEGTSMuxer allocates a mpegtsMuxer.
|
// newMPEGTSMuxer allocates a mpegtsMuxer.
|
||||||
@@ -103,27 +102,19 @@ func (e *mpegtsMuxer) encode(au [][]byte, pts time.Duration) error {
|
|||||||
|
|
||||||
var dts time.Duration
|
var dts time.Duration
|
||||||
|
|
||||||
if !e.firstIDRReceived {
|
if e.dtsExtractor == nil {
|
||||||
// skip samples silently until we find one with a IDR
|
// skip samples silently until we find one with a IDR
|
||||||
if !idrPresent {
|
if !idrPresent {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
e.firstIDRReceived = true
|
|
||||||
e.dtsExtractor = h264.NewDTSExtractor()
|
e.dtsExtractor = h264.NewDTSExtractor()
|
||||||
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
dts, err = e.dtsExtractor.Extract(au, pts)
|
dts, err = e.dtsExtractor.Extract(au, pts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
var err error
|
|
||||||
dts, err = e.dtsExtractor.Extract(au, pts)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// encode into MPEG-TS
|
// encode into MPEG-TS
|
||||||
return e.w.WriteH26x(e.track, durationGoToMPEGTS(pts), durationGoToMPEGTS(dts), idrPresent, au)
|
return e.w.WriteH26x(e.track, durationGoToMPEGTS(pts), durationGoToMPEGTS(dts), idrPresent, au)
|
||||||
|
|||||||
Reference in New Issue
Block a user