single publisher integration test

This commit is contained in:
David Zhao
2021-01-13 17:38:40 -08:00
parent 233306d83a
commit 9a10a57b30
5 changed files with 166 additions and 48 deletions
+27
View File
@@ -19,9 +19,11 @@ import (
// makes it easier to debug and create RTP streams
type TrackWriter struct {
ctx context.Context
cancel context.CancelFunc
track *webrtc.TrackLocalStaticSample
filePath string
mime string
done chan bool
ogg *oggreader.OggReader
ivfheader *ivfreader.IVFFileHeader
@@ -30,15 +32,23 @@ type TrackWriter struct {
}
func NewTrackWriter(ctx context.Context, track *webrtc.TrackLocalStaticSample, filePath string) *TrackWriter {
ctx, cancel := context.WithCancel(ctx)
return &TrackWriter{
ctx: ctx,
cancel: cancel,
track: track,
filePath: filePath,
mime: track.Codec().MimeType,
done: make(chan bool),
}
}
func (w *TrackWriter) Start() error {
if w.filePath == "" {
go w.writeNull()
return nil
}
file, err := os.Open(w.filePath)
if err != nil {
return err
@@ -70,6 +80,23 @@ func (w *TrackWriter) Start() error {
return nil
}
func (w *TrackWriter) Stop() {
w.cancel()
}
func (w *TrackWriter) writeNull() {
defer w.onWriteComplete()
sample := media.Sample{Data: []byte{0x0, 0xff, 0xff, 0xff, 0xff}, Duration: time.Second}
for {
select {
case <-time.After(20 * time.Millisecond):
w.track.WriteSample(sample)
case <-w.ctx.Done():
break
}
}
}
func (w *TrackWriter) writeOgg() {
// Keep track of last granule, the difference is the amount of samples in the buffer
var lastGranule uint64