1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2025-06-28 16:32:46 +02:00

Well it works when we place the buffer at the right place :)

This commit is contained in:
Yohann D'ANELLO
2020-11-07 20:36:33 +01:00
parent 4888a4d5fc
commit eb0b022c11
3 changed files with 21 additions and 57 deletions

View File

@ -4,8 +4,6 @@ package webrtc
import (
"bufio"
"fmt"
"github.com/pion/webrtc/v3/pkg/media"
"github.com/pion/webrtc/v3/pkg/media/ivfreader"
"io"
"log"
"math/rand"
@ -16,6 +14,8 @@ import (
"github.com/pion/rtp"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v3/pkg/media"
"github.com/pion/webrtc/v3/pkg/media/h264reader"
"gitlab.crans.org/nounous/ghostream/messaging"
)
@ -34,8 +34,8 @@ func ingest(name string, q *messaging.Quality) {
return
}
f, _ := os.Open("output.ivf")
h264, _, err := ivfreader.NewWith(f)
f, _ := os.Open("CoffeeRun.h264")
h264, err := h264reader.NewReader(f)
// Start ffmpag to convert videoInput to audio UDP
ffmpeg, err := startFFmpeg(videoInput, firstPort)
@ -46,8 +46,9 @@ func ingest(name string, q *messaging.Quality) {
// Receive video
go func() {
var spsAndPpsCache []byte
for {
nal, _, h264Err := h264.ParseNextFrame()
nal, h264Err := h264.NextNAL()
if h264Err == io.EOF {
fmt.Printf("All video frames parsed and sent")
return
@ -57,14 +58,25 @@ func ingest(name string, q *messaging.Quality) {
break
}
time.Sleep(time.Millisecond * 33)
time.Sleep(time.Second / 60)
if videoTracks[name] == nil {
videoTracks[name] = make([]*webrtc.Track, 0)
}
nal.Data = append([]byte{0x00, 0x00, 0x00, 0x01}, nal.Data...)
if nal.UnitType == h264reader.NalUnitTypeSPS || nal.UnitType == h264reader.NalUnitTypePPS {
spsAndPpsCache = append(spsAndPpsCache, nal.Data...)
continue
} else if nal.UnitType == h264reader.NalUnitTypeCodedSliceIdr {
nal.Data = append(spsAndPpsCache, nal.Data...)
spsAndPpsCache = []byte{}
}
for _, videoTrack := range videoTracks[name] {
if ivfErr := videoTrack.WriteSample(media.Sample{Data: nal, Samples: 90000}); ivfErr != nil {
panic(ivfErr)
if h264Err = videoTrack.WriteSample(media.Sample{Data: nal.Data, Samples: 90000}); h264Err != nil {
panic(h264Err)
}
}
}

View File

@ -75,7 +75,7 @@ func newPeerHandler(name string, localSdpChan chan webrtc.SessionDescription, re
}
// Create video track
payloadType := getPayloadType(mediaEngine, webrtc.RTPCodecTypeVideo, "VP8")
payloadType := getPayloadType(mediaEngine, webrtc.RTPCodecTypeVideo, "H264")
videoTrack, err := peerConnection.NewTrack(payloadType, rand.Uint32(), "video", "pion")
if err != nil {
log.Println("Failed to create new video track", err)