Fixed invalid header error, but still not playing for some reason

This commit is contained in:
Unknown 2018-01-01 17:08:26 +10:30
parent a6303a9617
commit 8fde0c5747
3 changed files with 4 additions and 21 deletions

View File

@ -33,7 +33,7 @@ package packets
import ( import (
"net" "net"
"fmt" _"fmt"
) )
const ( const (
@ -97,20 +97,13 @@ func toUint(arr []byte) (ret uint) {
func (s *Session) HandleRtpConn(conn net.PacketConn) { func (s *Session) HandleRtpConn(conn net.PacketConn) {
buf := make([]byte, 4096) buf := make([]byte, 4096)
for { for {
fmt.Println("handling rtp conn")
n, _, err := conn.ReadFrom(buf) n, _, err := conn.ReadFrom(buf)
fmt.Printf("n: %v\n",n)
fmt.Println("here1")
if err != nil { if err != nil {
panic(err) panic(err)
} }
fmt.Println("here2")
cpy := make([]byte, n) cpy := make([]byte, n)
fmt.Println("here3")
copy(cpy, buf) copy(cpy, buf)
fmt.Println("here4")
go s.handleRtp(cpy) go s.handleRtp(cpy)
fmt.Println("here5")
} }
} }
@ -158,9 +151,8 @@ func (s *Session) handleRtp(buf []byte) {
} }
} }
packet.Payload = buf[i:] packet.Payload = buf[i:]
fmt.Println("sending rtp packet")
s.rtpChan <- packet s.rtpChan <- packet
fmt.Println("Sent")
} }
func (s *Session) handleRtcp(buf []byte) { func (s *Session) handleRtcp(buf []byte) {

View File

@ -28,7 +28,7 @@ LICENSE
package packets package packets
import "fmt" import _"fmt"
type RtpToTsConverter interface { type RtpToTsConverter interface {
Convert() Convert()
@ -66,23 +66,18 @@ func (c* rtpToTsConverter) Convert() {
select { select {
default: default:
case rtpPacket := <-c.inputChan: case rtpPacket := <-c.inputChan:
fmt.Println("case1")
if GetNalType( rtpPacket.Payload ) == 28 { if GetNalType( rtpPacket.Payload ) == 28 {
nalUnitChan<-ParseNALFragment(rtpPacket.Payload) nalUnitChan<-ParseNALFragment(rtpPacket.Payload)
} else { } else {
nalUnitChan<-ParseNALSpsPps(rtpPacket.Payload) nalUnitChan<-ParseNALSpsPps(rtpPacket.Payload)
} }
fmt.Println("done case1")
case nalUnit := <-nalUnitChan: case nalUnit := <-nalUnitChan:
fmt.Println("case2")
nalUnitByteSlice := nalUnit.ToByteSlice() nalUnitByteSlice := nalUnit.ToByteSlice()
fmt.Printf("len(nalUnitByteSlice): %v\n", len(nalUnitByteSlice))
for ii := range nalUnitByteSlice { for ii := range nalUnitByteSlice {
pesDataChan<-nalUnitByteSlice[ii] pesDataChan<-nalUnitByteSlice[ii]
} }
if nalFragment, isNALFragment := nalUnit.(*NALFragment); if nalFragment, isNALFragment := nalUnit.(*NALFragment);
(isNALFragment && nalFragment.End) || !isNALFragment { (isNALFragment && nalFragment.End) || !isNALFragment {
fmt.Printf("lenPesDataChan: %v\n",len(pesDataChan))
pesDataChanLen := len(pesDataChan) pesDataChanLen := len(pesDataChan)
pesPkt := new(PESPacket) pesPkt := new(PESPacket)
pesPkt.StreamID = 0xE0 pesPkt.StreamID = 0xE0
@ -106,13 +101,10 @@ func (c* rtpToTsConverter) Convert() {
} }
pesPktChan<-pesPkt.ToByteSlice() pesPktChan<-pesPkt.ToByteSlice()
} }
fmt.Println("done case2")
case pesPkt := <-pesPktChan: case pesPkt := <-pesPktChan:
fmt.Println("case3")
for ii:=range pesPkt { for ii:=range pesPkt {
payloadByteChan<-pesPkt[ii] payloadByteChan<-pesPkt[ii]
} }
fmt.Println("done loading")
firstPacket:=true firstPacket:=true
for len(payloadByteChan) > 0 { for len(payloadByteChan) > 0 {
lengthOfByteChan := len(payloadByteChan) lengthOfByteChan := len(payloadByteChan)
@ -150,7 +142,6 @@ func (c* rtpToTsConverter) Convert() {
} }
c.tsChan<-c.currentTsPacket c.tsChan<-c.currentTsPacket
} }
fmt.Println("done case3")
} }
} }
} }

View File

@ -328,9 +328,9 @@ func input(input string, output string) {
ii++ ii++
} else { } else {
donePSI = true donePSI = true
fmt.Println("getting TS packet")
packet := <-converter.TsChan packet := <-converter.TsChan
packetByteSlice := packet.ToByteSlice() packetByteSlice := packet.ToByteSlice()
fmt.Printf("ts packet: %v\n", packetByteSlice)
copy(clip[clipSize:upperBound],packetByteSlice) copy(clip[clipSize:upperBound],packetByteSlice)
} }
//fmt.Println(clip[clipSize:upperBound]) //fmt.Println(clip[clipSize:upperBound])