replace new() with initialize() (#490)

This commit is contained in:
Alessandro Ros
2023-12-26 12:48:35 +01:00
committed by GitHub
parent e77b281395
commit 2d0c530d97
37 changed files with 464 additions and 521 deletions

View File

@@ -16,35 +16,31 @@ func durationGoToMPEGTS(v time.Duration) int64 {
// mpegtsMuxer allows to save a MPEG4-audio stream into a MPEG-TS file.
type mpegtsMuxer struct {
config *mpeg4audio.Config
f *os.File
b *bufio.Writer
w *mpegts.Writer
track *mpegts.Track
f *os.File
b *bufio.Writer
w *mpegts.Writer
track *mpegts.Track
}
// newMPEGTSMuxer allocates a mpegtsMuxer.
func newMPEGTSMuxer(config *mpeg4audio.Config) (*mpegtsMuxer, error) {
f, err := os.Create("mystream.ts")
// initialize initializes a mpegtsMuxer.
func (e *mpegtsMuxer) initialize() error {
var err error
e.f, err = os.Create("mystream.ts")
if err != nil {
return nil, err
return err
}
b := bufio.NewWriter(f)
e.b = bufio.NewWriter(e.f)
track := &mpegts.Track{
e.track = &mpegts.Track{
Codec: &mpegts.CodecMPEG4Audio{
Config: *config,
Config: *e.config,
},
}
w := mpegts.NewWriter(b, []*mpegts.Track{track})
e.w = mpegts.NewWriter(e.b, []*mpegts.Track{e.track})
return &mpegtsMuxer{
config: config,
f: f,
b: b,
w: w,
track: track,
}, nil
return nil
}
// close closes all the mpegtsMuxer resources.
@@ -53,7 +49,7 @@ func (e *mpegtsMuxer) close() {
e.f.Close()
}
// encode encodes MPEG-4 audio access units into MPEG-TS.
func (e *mpegtsMuxer) encode(aus [][]byte, pts time.Duration) error {
// writeMPEG4Audio writes MPEG-4 audio access units into MPEG-TS.
func (e *mpegtsMuxer) writeMPEG4Audio(aus [][]byte, pts time.Duration) error {
return e.w.WriteMPEG4Audio(e.track, durationGoToMPEGTS(pts), aus)
}