mirror of
https://github.com/openlibrecommunity/olcrtc.git
synced 2026-05-26 07:08:11 +00:00
feat: add VideoTrack capability to provider and carrier interfaces
This commit is contained in:
@@ -19,13 +19,20 @@ type ByteStream interface {
|
||||
CanSend() bool
|
||||
}
|
||||
|
||||
// VideoTrack is a carrier capability for publishing a local video track.
|
||||
type VideoTrack interface {
|
||||
AddTrack(track *webrtc.TrackLocalStaticRTP) (*webrtc.RTPSender, error)
|
||||
}
|
||||
|
||||
type legacySession struct {
|
||||
provider provider.Provider
|
||||
}
|
||||
|
||||
// Capabilities reports the transport primitives supported by the legacy carrier.
|
||||
func (s *legacySession) Capabilities() Capabilities {
|
||||
return Capabilities{ByteStream: true}
|
||||
caps := Capabilities{ByteStream: true}
|
||||
_, caps.VideoTrack = s.provider.(provider.VideoTrackCapable)
|
||||
return caps
|
||||
}
|
||||
|
||||
// OpenByteStream adapts the legacy provider to a generic byte stream capability.
|
||||
@@ -33,6 +40,15 @@ func (s *legacySession) OpenByteStream() (ByteStream, error) {
|
||||
return &legacyByteStream{provider: s.provider}, nil
|
||||
}
|
||||
|
||||
// OpenVideoTrack adapts a legacy provider to the generic video track capability.
|
||||
func (s *legacySession) OpenVideoTrack() (VideoTrack, error) {
|
||||
publisher, ok := s.provider.(provider.VideoTrackCapable)
|
||||
if !ok {
|
||||
return nil, ErrVideoTrackUnsupported
|
||||
}
|
||||
return &legacyVideoTrack{provider: publisher}, nil
|
||||
}
|
||||
|
||||
type legacyByteStream struct {
|
||||
provider provider.Provider
|
||||
}
|
||||
@@ -55,3 +71,11 @@ func (p *legacyByteStream) WatchConnection(ctx context.Context) {
|
||||
p.provider.WatchConnection(ctx)
|
||||
}
|
||||
func (p *legacyByteStream) CanSend() bool { return p.provider.CanSend() }
|
||||
|
||||
type legacyVideoTrack struct {
|
||||
provider provider.VideoTrackCapable
|
||||
}
|
||||
|
||||
func (v *legacyVideoTrack) AddTrack(track *webrtc.TrackLocalStaticRTP) (*webrtc.RTPSender, error) {
|
||||
return v.provider.AddVideoTrack(track)
|
||||
}
|
||||
|
||||
@@ -13,11 +13,14 @@ var (
|
||||
ErrCarrierNotFound = errors.New("carrier not found")
|
||||
// ErrByteStreamUnsupported is returned when a carrier cannot provide a byte stream.
|
||||
ErrByteStreamUnsupported = errors.New("carrier does not support byte stream")
|
||||
// ErrVideoTrackUnsupported is returned when a carrier cannot publish video tracks.
|
||||
ErrVideoTrackUnsupported = errors.New("carrier does not support video tracks")
|
||||
)
|
||||
|
||||
// Capabilities describes the transport primitives a carrier can expose.
|
||||
type Capabilities struct {
|
||||
ByteStream bool
|
||||
VideoTrack bool
|
||||
}
|
||||
|
||||
// Session is the carrier-level runtime handle.
|
||||
@@ -30,6 +33,11 @@ type ByteStreamCapable interface {
|
||||
OpenByteStream() (ByteStream, error)
|
||||
}
|
||||
|
||||
// VideoTrackCapable is implemented by carriers that can publish video tracks.
|
||||
type VideoTrackCapable interface {
|
||||
OpenVideoTrack() (VideoTrack, error)
|
||||
}
|
||||
|
||||
// Config holds carrier configuration.
|
||||
type Config struct {
|
||||
RoomURL string
|
||||
|
||||
@@ -35,8 +35,10 @@ type Provider interface {
|
||||
CanSend() bool
|
||||
GetSendQueue() chan []byte
|
||||
GetBufferedAmount() uint64
|
||||
}
|
||||
|
||||
// AddVideoTrack adds a video track to the connection.
|
||||
// VideoTrackCapable is implemented by providers that can publish video tracks.
|
||||
type VideoTrackCapable interface {
|
||||
AddVideoTrack(track *webrtc.TrackLocalStaticRTP) (*webrtc.RTPSender, error)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user