Updating remote

This commit is contained in:
Unknown 2018-01-01 19:44:59 +10:30
parent 8fde0c5747
commit 7e3394fe0e
2 changed files with 111 additions and 36 deletions

View File

@ -28,7 +28,10 @@ LICENSE
package packets package packets
import _"fmt" import (
"fmt"
"os"
)
type RtpToTsConverter interface { type RtpToTsConverter interface {
Convert() Convert()
@ -57,28 +60,102 @@ func NewRtpToTsConverter() (c *rtpToTsConverter) {
} }
func (c* rtpToTsConverter) Convert() { func (c* rtpToTsConverter) Convert() {
nalUnitChan := make(chan NALUnit, 10000) file,_ := os.Create("video")
pesPktChan := make(chan []byte, 10000) pesPktChan := make(chan []byte, 10000)
pesDataChan := make(chan byte, 15000) pesDataChan := make(chan byte, 15000)
nalAccessChan := make(chan []byte, 100)
data := make(chan byte,10000)
payloadByteChan := make(chan byte, 15000) payloadByteChan := make(chan byte, 15000)
// Get nal units from incoming rtp // Get nal units from incoming rtp
var sps []byte
var pps []byte
// Frist find sps
for {
rtpPacket := <-c.inputChan
fragmentType := rtpPacket.Payload[0] & 0x1F
if fragmentType == 7 {
sps = make([]byte,4+len(rtpPacket.Payload))
sps[0] = 0x00
sps[1] = 0x00
sps[2] = 0x00
sps[3] = 0x01
for i := range rtpPacket.Payload {
sps[i+4] = rtpPacket.Payload[i]
}
break
}
}
// now find pps
for {
rtpPacket := <-c.inputChan
fragmentType := rtpPacket.Payload[0] & 0x1F
if fragmentType == 8 {
pps = make([]byte,4+len(rtpPacket.Payload))
pps[0] = 0x00
pps[1] = 0x00
pps[2] = 0x00
pps[3] = 0x01
for i := range rtpPacket.Payload {
pps[i+4] = rtpPacket.Payload[i]
}
break
}
}
for { for {
select { select {
default: default:
case rtpPacket := <-c.inputChan: case rtpPacket := <-c.inputChan:
if GetNalType( rtpPacket.Payload ) == 28 { threeNUBs := rtpPacket.Payload[0] & 0xE0
nalUnitChan<-ParseNALFragment(rtpPacket.Payload) fragmentType := rtpPacket.Payload[0] & 0x1F
startBit := (rtpPacket.Payload[1] & 0x80)>>7
fiveNUBs := rtpPacket.Payload[1] & 0x1F
fragmentData := rtpPacket.Payload[2:]
fmt.Printf("fragmentType: %v\n", fragmentType)
if fragmentType == 28 {
if startBit == 1 {
if len(data) > 0 {
dataArray := make([]byte, len(data))
for ii:=0; len(data) > 0; ii++ {
dataArray[ii] = <-data
}
fmt.Printf("data array size: %v\n", len(dataArray))
nalAccessChan<-dataArray
file.Write(dataArray)
}
// load sps into data
for ii := range sps {
data<-sps[ii]
}
// load pps into data
for ii := range pps {
data<-pps[ii]
}
buffer := make([]byte,5+len(fragmentData))
buffer[0] = 0x00
buffer[1] = 0x00
buffer[2] = 0x00
buffer[3] = 0x01
buffer[4] = threeNUBs | fiveNUBs
for i := range fragmentData {
buffer[i+5] = fragmentData[i]
}
// load data into data chan
for ii := range buffer {
data<-buffer[ii]
}
} else { } else {
nalUnitChan<-ParseNALSpsPps(rtpPacket.Payload) if len(data) > 0 {
for ii := range fragmentData {
data<-fragmentData[ii]
} }
case nalUnit := <-nalUnitChan:
nalUnitByteSlice := nalUnit.ToByteSlice()
for ii := range nalUnitByteSlice {
pesDataChan<-nalUnitByteSlice[ii]
} }
if nalFragment, isNALFragment := nalUnit.(*NALFragment); }
(isNALFragment && nalFragment.End) || !isNALFragment { }
pesDataChanLen := len(pesDataChan) case nalUnit := <-nalAccessChan:
for ii := range nalUnit {
pesDataChan<-nalUnit[ii]
}
pesDataChanLen := len(nalUnit)
pesPkt := new(PESPacket) pesPkt := new(PESPacket)
pesPkt.StreamID = 0xE0 pesPkt.StreamID = 0xE0
pesPkt.Length = uint16( 3 + pesDataChanLen ) pesPkt.Length = uint16( 3 + pesDataChanLen )
@ -100,7 +177,6 @@ func (c* rtpToTsConverter) Convert() {
pesPkt.Data[ii] = <-pesDataChan pesPkt.Data[ii] = <-pesDataChan
} }
pesPktChan<-pesPkt.ToByteSlice() pesPktChan<-pesPkt.ToByteSlice()
}
case pesPkt := <-pesPktChan: case pesPkt := <-pesPktChan:
for ii:=range pesPkt { for ii:=range pesPkt {
payloadByteChan<-pesPkt[ii] payloadByteChan<-pesPkt[ii]

View File

@ -330,7 +330,6 @@ func input(input string, output string) {
donePSI = true donePSI = true
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])