Skip to content
This repository has been archived by the owner on Dec 27, 2020. It is now read-only.

Commit

Permalink
Add play-from-disk
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean-Der committed Sep 7, 2020
1 parent 6433909 commit 02ae911
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 5 deletions.
9 changes: 8 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#### [Play Files from Disk](examples/play-from-disk)
Example of playing file from disk.

* User declares codecs they are reading from disk
* User declares codec they are reading from disk
* On each negotiated PeerConnection they are notified if the receiver can accept what they are offering
* Read packets from disk and send until completed

#### [Play Files from Disk Dynamic](examples/play-from-disk-dynamic)
Example of playing a file from a disk and condtionally selecting codec.

* User declares codecs that are available
* On each negotiated PeerConnection a callback is fired with the codecs that are supported
* Read packets from disk and send until completed

#### [Save files to Disk](examples/save-to-disk)
Example of saving user input to disk,

Expand Down
33 changes: 33 additions & 0 deletions examples/play-from-disk/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"github.com/pion/webrtc-v3-design/webrtc"
"github.com/pion/webrtc-v3-design/webrtc/pkg/media"
)

func main() {
var s webrtc.SettingEngine

// During Offer/Answer exchange the only codec we support will be VP8
// If the remote doesn't support VP8 signaling will fail
s.SetEncodings([]*webrtc.RTPCodecCapability{
{
MimeType: "video/vp8", // Should we make this a enum?
ClockRate: 90000, // Sholud we drop from API and just assume?
},
})

peerConnection, _ := s.NewPeerConnection(webrtc.Configuration{})

track := media.NewStaticLocalRTPTrack(webrtc.RTPCodecCapability{
MimeType: "video/vp8", // Should we make this a enum?
ClockRate: 90000, // Sholud we drop from API and just assume?
})

peerConnection.AddTransceiverFromTrack(track, nil)

// TODO
// Do we expose a packetizer as a public API?
// Do we add WriteSample?
track.WriteRTP(nil)
}
6 changes: 5 additions & 1 deletion webrtc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ module github.com/pion/webrtc-v3-design/webrtc

go 1.14

require github.com/pion/webrtc-v3-design/rtpengine v0.0.0-20200905201212-4337232b67dc
require (
github.com/pion/rtcp v1.2.3
github.com/pion/rtp v1.6.0
github.com/pion/webrtc-v3-design/rtpengine v0.0.0-20200905201212-4337232b67dc
)

replace github.com/pion/webrtc-v3-design/rtpengine => ../rtpengine
21 changes: 21 additions & 0 deletions webrtc/pkg/media/track.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package media

import (
"github.com/pion/rtcp"
"github.com/pion/rtp"
"github.com/pion/webrtc-v3-design/webrtc"
)

type staticLocalRTPTrack struct{}

// NewStaticTrack returns a LocalRTPTrack with a pre-set codec.
func NewStaticLocalRTPTrack(webrtc.RTPCodecCapability) *staticLocalRTPTrack { return nil }

func (s *staticLocalRTPTrack) ID() string { return "" }
func (s *staticLocalRTPTrack) Stop() error { return nil }

func (s *staticLocalRTPTrack) WriteRTP(*rtp.Packet) error { return nil }
func (s *staticLocalRTPTrack) ReadRTCP() (rtcp.Packet, error) { return nil, nil }

// SetParameters asserts that requested codec is available from the other side
func (s *staticLocalRTPTrack) SetParameters(webrtc.RTPParameters) error { return nil }
6 changes: 3 additions & 3 deletions webrtc/track.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type TrackBase interface {
// Unlike WebAPI's MediaStreamTrack, the track directly provides RTP stream.
type LocalRTPTrack interface {
TrackBase
rtpengine.Reader
rtpengine.Writer

// SetParameters sets information about how the data is to be encoded.
// This will be called by PeerConnection according to the result of
Expand All @@ -31,7 +31,7 @@ type LocalRTPTrack interface {
// Unlike WebAPI's MediaStreamTrack, the track directly consumes RTP stream.
type RemoteRTPTrack interface {
TrackBase
rtpengine.Writer
rtpengine.Reader

// Parameters returns information about how the data is to be encoded.
// Call of this function will be redirected to associated RTPReceiver
Expand All @@ -49,7 +49,7 @@ type RemoteRTPTrack interface {
type RTPParameters struct {
SSRC uint32
SelectedCodec *RTPCodecCapability
Codecs []*RTPCodecCapability
Codecs []RTPCodecCapability
}

// RTPSender represents RTCRtpSender.
Expand Down

0 comments on commit 02ae911

Please sign in to comment.