diff --git a/go.mod b/go.mod index 9c56265..ef4caff 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module mediasource +module github.com/harshabose/simple_webrtc_comm/mediasource go 1.23.3 diff --git a/pkg/stream.go b/pkg/stream.go index 1047493..cab5dac 100644 --- a/pkg/stream.go +++ b/pkg/stream.go @@ -2,6 +2,7 @@ package mediasource import ( "context" + "fmt" "time" "github.com/asticode/go-astiav" @@ -9,7 +10,7 @@ import ( "github.com/harshabose/tools/buffer/pkg" "github.com/pion/webrtc/v4/pkg/media" - "mediasource/internal" + "github.com/harshabose/simple_webrtc_comm/mediasource/internal" ) type Stream struct { @@ -46,6 +47,7 @@ func (stream *Stream) Start() { stream.filter.Start() stream.encoder.Start() go stream.loop() + fmt.Printf("media source stream started") } func (stream *Stream) loop() { diff --git a/pkg/stream_options.go b/pkg/stream_options.go index 079e1b2..9463658 100644 --- a/pkg/stream_options.go +++ b/pkg/stream_options.go @@ -5,7 +5,7 @@ import ( "github.com/harshabose/simple_webrtc_comm/transcode/pkg" "github.com/harshabose/tools/buffer/pkg" - "mediasource/internal" + "github.com/harshabose/simple_webrtc_comm/mediasource/internal" ) type StreamOption = func(*Stream) error diff --git a/pkg/track.go b/pkg/track.go index 54dec3d..578df0f 100644 --- a/pkg/track.go +++ b/pkg/track.go @@ -47,6 +47,7 @@ func (track *Track) Start() { track.stream.Start() go track.loop() + fmt.Printf("media source track started") } func (track *Track) loop() { diff --git a/pkg/track_options.go b/pkg/track_options.go index 15e46ef..e0a9fcc 100644 --- a/pkg/track_options.go +++ b/pkg/track_options.go @@ -42,10 +42,9 @@ func WithOpusTrack(samplerate uint32, channelLayout uint16, id string) TrackOpti func WithStream(options ...StreamOption) TrackOption { return func(track *Track) error { - for _, option := range options { - if err := option(track.stream); err != nil { - return err - } + var err error + if track.stream, err = CreateStream(track.ctx, options...); err != nil { + return err } return nil } diff --git a/pkg/tracks.go b/pkg/tracks.go index bd1a461..e9825e1 100644 --- a/pkg/tracks.go +++ b/pkg/tracks.go @@ -48,6 +48,15 @@ func (tracks *Tracks) CreateTrack(peerConnection *webrtc.PeerConnection, options return nil } +func (tracks *Tracks) GetTrack(id string) (*Track, error) { + track, exists := tracks.tracks[id] + if !exists { + return nil, errors.New("track does not exits") + } + + return track, nil +} + func (tracks *Tracks) StartTrack(id string) { if track, ok := tracks.tracks[id]; ok { track.Start() diff --git a/tests/tracks_test.go b/tests/tracks_test.go index 8032088..4959aa3 100644 --- a/tests/tracks_test.go +++ b/tests/tracks_test.go @@ -10,7 +10,7 @@ import ( "github.com/pion/interceptor" "github.com/pion/webrtc/v4" - "mediasource/pkg" + "github.com/harshabose/simple_webrtc_comm/mediasource/pkg" ) func TestTracks(t *testing.T) {