mirror of
https://github.com/harshabose/mediasource.git
synced 2025-12-24 13:58:00 +08:00
general commit 26-02-2025 22:27
This commit is contained in:
2
go.mod
2
go.mod
@@ -1,4 +1,4 @@
|
||||
module mediasource
|
||||
module github.com/harshabose/simple_webrtc_comm/mediasource
|
||||
|
||||
go 1.23.3
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -47,6 +47,7 @@ func (track *Track) Start() {
|
||||
|
||||
track.stream.Start()
|
||||
go track.loop()
|
||||
fmt.Printf("media source track started")
|
||||
}
|
||||
|
||||
func (track *Track) loop() {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user