general commit 26-02-2025 22:27

This commit is contained in:
harshabose
2025-02-26 22:27:57 +05:30
parent 49d86c5867
commit 8216c64c1f
7 changed files with 19 additions and 8 deletions

2
go.mod
View File

@@ -1,4 +1,4 @@
module mediasource
module github.com/harshabose/simple_webrtc_comm/mediasource
go 1.23.3

View File

@@ -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() {

View File

@@ -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

View File

@@ -47,6 +47,7 @@ func (track *Track) Start() {
track.stream.Start()
go track.loop()
fmt.Printf("media source track started")
}
func (track *Track) loop() {

View File

@@ -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
}

View File

@@ -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()

View File

@@ -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) {