diff --git a/localsampletrack.go b/localsampletrack.go index d1b65591..e336fc12 100644 --- a/localsampletrack.go +++ b/localsampletrack.go @@ -429,7 +429,7 @@ func (s *LocalSampleTrack) writeWorker(provider SampleProvider, onComplete func( defer ticker.Stop() for { - sample, err := provider.NextSample() + sample, err := provider.NextSample(ctx) if err == io.EOF { return } diff --git a/readersampleprovider.go b/readersampleprovider.go index 29d87554..9d1673d5 100644 --- a/readersampleprovider.go +++ b/readersampleprovider.go @@ -15,6 +15,7 @@ package lksdk import ( + "context" "io" "os" "path/filepath" @@ -213,7 +214,7 @@ func (p *ReaderSampleProvider) CurrentAudioLevel() uint8 { return p.AudioLevel } -func (p *ReaderSampleProvider) NextSample() (media.Sample, error) { +func (p *ReaderSampleProvider) NextSample(ctx context.Context) (media.Sample, error) { sample := media.Sample{} switch p.Mime { case webrtc.MimeTypeH264: diff --git a/sampleprovider.go b/sampleprovider.go index fc10405f..d9269700 100644 --- a/sampleprovider.go +++ b/sampleprovider.go @@ -15,13 +15,14 @@ package lksdk import ( + "context" "time" "github.com/pion/webrtc/v3/pkg/media" ) type SampleProvider interface { - NextSample() (media.Sample, error) + NextSample(context.Context) (media.Sample, error) OnBind() error OnUnbind() error Close() error @@ -62,7 +63,7 @@ func NewNullSampleProvider(bitrate uint32) *NullSampleProvider { } } -func (p *NullSampleProvider) NextSample() (media.Sample, error) { +func (p *NullSampleProvider) NextSample(ctx context.Context) (media.Sample, error) { return media.Sample{ Data: make([]byte, p.BytesPerSample), Duration: p.SampleDuration,