Skip to content

Commit

Permalink
Rename modules, sample types + properties
Browse files Browse the repository at this point in the history
  • Loading branch information
tarrencev committed May 28, 2020
1 parent 879d716 commit 5ed65af
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 47 deletions.
4 changes: 2 additions & 2 deletions cmd/avp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/pion/ion/pkg/node/avp"
"github.com/pion/ion/pkg/process"
"github.com/pion/ion/pkg/process/elements"
"github.com/pion/ion/pkg/process/samplebuilder"
"github.com/pion/ion/pkg/process/samples"
)

func init() {
Expand All @@ -20,7 +20,7 @@ func init() {
}

pipelineConfig := process.Config{
SampleBuilder: samplebuilder.Config{
SampleBuilder: samples.BuilderConfig{
AudioMaxLate: conf.Pipeline.SampleBuilder.AudioMaxLate,
VideoMaxLate: conf.Pipeline.SampleBuilder.VideoMaxLate,
},
Expand Down
6 changes: 3 additions & 3 deletions pkg/process/elements/element.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package elements
import (
"errors"

"github.com/pion/ion/pkg/process/samplebuilder"
"github.com/pion/ion/pkg/process/samples"
"github.com/pion/ion/pkg/proto"
)

Expand All @@ -14,8 +14,8 @@ const (

// Element interface
type Element interface {
Write(*samplebuilder.Sample) error
Read() <-chan *samplebuilder.Sample
Write(*samples.Sample) error
Read() <-chan *samples.Sample
Close()
}

Expand Down
15 changes: 7 additions & 8 deletions pkg/process/elements/webm.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (
"github.com/at-wat/ebml-go/webm"

"github.com/pion/ion/pkg/log"
"github.com/pion/ion/pkg/process/samplebuilder"
"github.com/pion/webrtc/v2"
"github.com/pion/ion/pkg/process/samples"
)

var (
Expand Down Expand Up @@ -46,16 +45,16 @@ func NewWebmSaver(id string) *WebmSaver {
}

// Write sample to webmsaver
func (s *WebmSaver) Write(sample *samplebuilder.Sample) error {
if sample.Type == webrtc.DefaultPayloadTypeVP8 {
func (s *WebmSaver) Write(sample *samples.Sample) error {
if sample.Type == samples.TypeVP8 {
s.pushVP8(sample)
} else if sample.Type == webrtc.DefaultPayloadTypeOpus {
} else if sample.Type == samples.TypeOpus {
s.pushOpus(sample)
}
return nil
}

func (s *WebmSaver) Read() <-chan *samplebuilder.Sample {
func (s *WebmSaver) Read() <-chan *samples.Sample {
return nil
}

Expand All @@ -74,7 +73,7 @@ func (s *WebmSaver) Close() {
}
}

func (s *WebmSaver) pushOpus(sample *samplebuilder.Sample) {
func (s *WebmSaver) pushOpus(sample *samples.Sample) {
if s.audioWriter != nil {
if s.audioTimestamp == 0 {
s.audioTimestamp = sample.Timestamp
Expand All @@ -86,7 +85,7 @@ func (s *WebmSaver) pushOpus(sample *samplebuilder.Sample) {
}
}

func (s *WebmSaver) pushVP8(sample *samplebuilder.Sample) {
func (s *WebmSaver) pushVP8(sample *samples.Sample) {
// Read VP8 header.
videoKeyframe := (sample.Payload[0]&0x1 == 0)

Expand Down
14 changes: 7 additions & 7 deletions pkg/process/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/pion/ion/pkg/log"
"github.com/pion/ion/pkg/process/elements"
"github.com/pion/ion/pkg/process/samplebuilder"
"github.com/pion/ion/pkg/process/samples"
"github.com/pion/ion/pkg/rtc/transport"
)

Expand All @@ -20,7 +20,7 @@ var (

// Config for pipeline
type Config struct {
SampleBuilder samplebuilder.Config
SampleBuilder samples.BuilderConfig
WebmSaver elements.WebmSaverConfig
}

Expand All @@ -35,8 +35,8 @@ type Pipeline struct {
pub transport.Transport
elements map[string]elements.Element
elementLock sync.RWMutex
elementChans map[string]chan *samplebuilder.Sample
sampleBuilder *samplebuilder.SampleBuilder
elementChans map[string]chan *samples.Sample
sampleBuilder *samples.Builder
stop bool
liveTime time.Time
}
Expand All @@ -54,8 +54,8 @@ func NewPipeline(id string, pub transport.Transport) *Pipeline {
p := &Pipeline{
pub: pub,
elements: make(map[string]elements.Element),
elementChans: make(map[string]chan *samplebuilder.Sample),
sampleBuilder: samplebuilder.NewSampleBuilder(config.SampleBuilder),
elementChans: make(map[string]chan *samples.Sample),
sampleBuilder: samples.NewBuilder(config.SampleBuilder),
liveTime: time.Now().Add(liveCycle),
}

Expand Down Expand Up @@ -121,7 +121,7 @@ func (p *Pipeline) AddElement(name string, e elements.Element) {
p.elementLock.Lock()
defer p.elementLock.Unlock()
p.elements[name] = e
p.elementChans[name] = make(chan *samplebuilder.Sample, 100)
p.elementChans[name] = make(chan *samples.Sample, 100)
log.Infof("Pipeline.AddElement name=%s", name)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package samplebuilder
package samples

import (
"errors"
Expand All @@ -19,35 +19,27 @@ var (
ErrCodecNotSupported = errors.New("codec not supported")
)

// Sample constructed from rtp packets
type Sample struct {
Type int
Payload []byte
Timestamp uint32
SequenceNumber uint16
}

// Config .
type Config struct {
// BuilderConfig .
type BuilderConfig struct {
ID string
On bool
AudioMaxLate uint16
VideoMaxLate uint16
}

// SampleBuilder Module for building video/audio samples from rtp streams
type SampleBuilder struct {
// Builder Module for building video/audio samples from rtp streams
type Builder struct {
id string
stop bool
audioBuilder, videoBuilder *samplebuilder.SampleBuilder
audioSequence, videoSequence uint16
outChan chan *Sample
}

// NewSampleBuilder Initialize a new sample builder
func NewSampleBuilder(config Config) *SampleBuilder {
log.Infof("NewSampleBuilder with config %+v", config)
s := &SampleBuilder{
// NewBuilder Initialize a new sample builder
func NewBuilder(config BuilderConfig) *Builder {
log.Infof("NewBuilder with config %+v", config)
s := &Builder{
id: config.ID,
audioBuilder: samplebuilder.New(config.AudioMaxLate, &codecs.OpusPacket{}),
videoBuilder: samplebuilder.New(config.VideoMaxLate, &codecs.VP8Packet{}),
Expand All @@ -60,13 +52,13 @@ func NewSampleBuilder(config Config) *SampleBuilder {
return s
}

// ID SampleBuilder id
func (s *SampleBuilder) ID() string {
// ID Builder id
func (s *Builder) ID() string {
return s.id
}

// WriteRTP Write RTP packet to SampleBuilder
func (s *SampleBuilder) WriteRTP(pkt *rtp.Packet) error {
// WriteRTP Write RTP packet to Builder
func (s *Builder) WriteRTP(pkt *rtp.Packet) error {
if pkt.PayloadType == webrtc.DefaultPayloadTypeVP8 {
s.pushVP8(pkt)
return nil
Expand All @@ -78,19 +70,19 @@ func (s *SampleBuilder) WriteRTP(pkt *rtp.Packet) error {
}

// Read sample
func (s *SampleBuilder) Read() *Sample {
func (s *Builder) Read() *Sample {
return <-s.outChan
}

// Stop stop all buffer
func (s *SampleBuilder) Stop() {
func (s *Builder) Stop() {
if s.stop {
return
}
s.stop = true
}

func (s *SampleBuilder) pushOpus(pkt *rtp.Packet) {
func (s *Builder) pushOpus(pkt *rtp.Packet) {
s.audioBuilder.Push(pkt)

for {
Expand All @@ -99,7 +91,7 @@ func (s *SampleBuilder) pushOpus(pkt *rtp.Packet) {
return
}
s.outChan <- &Sample{
Type: webrtc.DefaultPayloadTypeOpus,
Type: TypeOpus,
SequenceNumber: s.audioSequence,
Timestamp: timestamp,
Payload: sample.Data,
Expand All @@ -108,7 +100,7 @@ func (s *SampleBuilder) pushOpus(pkt *rtp.Packet) {
}
}

func (s *SampleBuilder) pushVP8(pkt *rtp.Packet) {
func (s *Builder) pushVP8(pkt *rtp.Packet) {
s.videoBuilder.Push(pkt)
for {
sample, timestamp := s.videoBuilder.PopWithTimestamp()
Expand All @@ -117,7 +109,7 @@ func (s *SampleBuilder) pushVP8(pkt *rtp.Packet) {
}

s.outChan <- &Sample{
Type: webrtc.DefaultPayloadTypeVP8,
Type: TypeVP8,
SequenceNumber: s.videoSequence,
Timestamp: timestamp,
Payload: sample.Data,
Expand Down
19 changes: 19 additions & 0 deletions pkg/process/samples/sample.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package samples

// Types for samples
const (
TypeOpus = 111
TypeVP8 = 96
TypeVP9 = 98
TypeH264 = 102
TypeRGB24 = 200
)

// Sample of audio or video
type Sample struct {
Type int
Timestamp uint32
SequenceNumber uint16
Properties map[string]interface{}
Payload []byte
}

0 comments on commit 5ed65af

Please sign in to comment.