Skip to content

Commit

Permalink
Add a context parameter to the sample provider NextSample interface (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
biglittlebigben authored Nov 13, 2023
1 parent a3b0f9a commit 7e90bc6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion localsampletrack.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion readersampleprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package lksdk

import (
"context"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions sampleprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7e90bc6

Please sign in to comment.