Skip to content

Instantly share code, notes, and snippets.

@Sean-Der
Created February 3, 2019 01:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sean-Der/65e3487abfa5756275cd6be95e1196d8 to your computer and use it in GitHub Desktop.
Save Sean-Der/65e3487abfa5756275cd6be95e1196d8 to your computer and use it in GitHub Desktop.
diff --git a/capture/capture.cpp b/capture/capture.cpp
index ee37276..35c4b11 100644
--- a/capture/capture.cpp
+++ b/capture/capture.cpp
@@ -5,7 +5,7 @@
int capture_start(int width, int height) {
int err;
- err = cam_open(0, width, height);
+ err = cam_open(2, width, height);
if (err) {
return err;
}
diff --git a/main.go b/main.go
index faafa4c..c11b9f6 100644
--- a/main.go
+++ b/main.go
@@ -11,11 +11,11 @@ import (
"github.com/maxhawkins/asciirtc/capture"
"github.com/pions/rtcp"
- "github.com/pions/rtp"
"github.com/pions/rtp/codecs"
"github.com/pions/webrtc"
"github.com/pions/webrtc/pkg/ice"
"github.com/pions/webrtc/pkg/media"
+ "github.com/pions/webrtc/pkg/media/samplebuilder"
)
type Demo struct {
@@ -157,50 +157,20 @@ func (d *Demo) handleTrack(ctx context.Context, track *webrtc.RTCTrack) {
}
defer capture.StopDecode()
- var ts uint32
- var payload []byte
-
+ builder := samplebuilder.New(256, &codecs.VP8Packet{})
for j := 0; ; j++ {
select {
case <-ctx.Done():
return
case newPkt := <-track.Packets:
+ builder.Push(newPkt)
- // Make a copy of the packet
- pay := make([]byte, len(newPkt.Payload))
- copy(pay, newPkt.Payload)
- newPkt = &rtp.Packet{
- Header: rtp.Header{
- Marker: newPkt.Marker,
- Timestamp: newPkt.Timestamp,
- SequenceNumber: newPkt.SequenceNumber,
- },
- Payload: pay,
- }
-
- d.jitter.Push(newPkt)
-
- for {
- p := d.jitter.Pop()
- if p == nil {
- break
- }
-
- if p.Timestamp != ts { // New packet, process the existing payload first
- if err := d.decode(payload); err != nil {
- fmt.Println(err)
- }
- payload = nil
- ts = p.Timestamp
+ for s := builder.Pop(); s != nil; s = builder.Pop() {
+ if err := d.decode(s.Data); err != nil {
+ panic(err)
}
-
- vp8 := &codecs.VP8Packet{}
- if _, err := vp8.Unmarshal(p); err != nil {
- fmt.Println(err)
- continue
- }
- payload = append(payload, vp8.Payload...)
}
+
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment