Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a context parameter to the sample provider NextSample interface #343

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading