mirror of https://bitbucket.org/ausocean/av.git
Updating remote
This commit is contained in:
parent
8fde0c5747
commit
7e3394fe0e
|
@ -28,7 +28,10 @@ LICENSE
|
||||||
|
|
||||||
package packets
|
package packets
|
||||||
|
|
||||||
import _"fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
type RtpToTsConverter interface {
|
type RtpToTsConverter interface {
|
||||||
Convert()
|
Convert()
|
||||||
|
@ -57,50 +60,123 @@ 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
|
||||||
} else {
|
startBit := (rtpPacket.Payload[1] & 0x80)>>7
|
||||||
nalUnitChan<-ParseNALSpsPps(rtpPacket.Payload)
|
fiveNUBs := rtpPacket.Payload[1] & 0x1F
|
||||||
}
|
fragmentData := rtpPacket.Payload[2:]
|
||||||
case nalUnit := <-nalUnitChan:
|
fmt.Printf("fragmentType: %v\n", fragmentType)
|
||||||
nalUnitByteSlice := nalUnit.ToByteSlice()
|
if fragmentType == 28 {
|
||||||
for ii := range nalUnitByteSlice {
|
if startBit == 1 {
|
||||||
pesDataChan<-nalUnitByteSlice[ii]
|
if len(data) > 0 {
|
||||||
}
|
dataArray := make([]byte, len(data))
|
||||||
if nalFragment, isNALFragment := nalUnit.(*NALFragment);
|
for ii:=0; len(data) > 0; ii++ {
|
||||||
(isNALFragment && nalFragment.End) || !isNALFragment {
|
dataArray[ii] = <-data
|
||||||
pesDataChanLen := len(pesDataChan)
|
}
|
||||||
pesPkt := new(PESPacket)
|
fmt.Printf("data array size: %v\n", len(dataArray))
|
||||||
pesPkt.StreamID = 0xE0
|
nalAccessChan<-dataArray
|
||||||
pesPkt.Length = uint16( 3 + pesDataChanLen )
|
file.Write(dataArray)
|
||||||
pesPkt.ScramblingControl = 0
|
}
|
||||||
pesPkt.Priority = true
|
// load sps into data
|
||||||
pesPkt.DAI = false
|
for ii := range sps {
|
||||||
pesPkt.Copyright = false
|
data<-sps[ii]
|
||||||
pesPkt.Original = true
|
}
|
||||||
pesPkt.PDI = 0
|
// load pps into data
|
||||||
pesPkt.ESCR = false
|
for ii := range pps {
|
||||||
pesPkt.ESRate = false
|
data<-pps[ii]
|
||||||
pesPkt.DSMTrickMode = false
|
}
|
||||||
pesPkt.ACI = false
|
buffer := make([]byte,5+len(fragmentData))
|
||||||
pesPkt.CRC = false
|
buffer[0] = 0x00
|
||||||
pesPkt.Ext = false
|
buffer[1] = 0x00
|
||||||
pesPkt.HeaderLength = 0
|
buffer[2] = 0x00
|
||||||
pesPkt.Data = make([]byte,pesDataChanLen)
|
buffer[3] = 0x01
|
||||||
for ii:=0; ii<pesDataChanLen; ii++ {
|
buffer[4] = threeNUBs | fiveNUBs
|
||||||
pesPkt.Data[ii] = <-pesDataChan
|
for i := range fragmentData {
|
||||||
|
buffer[i+5] = fragmentData[i]
|
||||||
|
}
|
||||||
|
// load data into data chan
|
||||||
|
for ii := range buffer {
|
||||||
|
data<-buffer[ii]
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if len(data) > 0 {
|
||||||
|
for ii := range fragmentData {
|
||||||
|
data<-fragmentData[ii]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pesPktChan<-pesPkt.ToByteSlice()
|
|
||||||
}
|
}
|
||||||
|
case nalUnit := <-nalAccessChan:
|
||||||
|
for ii := range nalUnit {
|
||||||
|
pesDataChan<-nalUnit[ii]
|
||||||
|
}
|
||||||
|
pesDataChanLen := len(nalUnit)
|
||||||
|
pesPkt := new(PESPacket)
|
||||||
|
pesPkt.StreamID = 0xE0
|
||||||
|
pesPkt.Length = uint16( 3 + pesDataChanLen )
|
||||||
|
pesPkt.ScramblingControl = 0
|
||||||
|
pesPkt.Priority = true
|
||||||
|
pesPkt.DAI = false
|
||||||
|
pesPkt.Copyright = false
|
||||||
|
pesPkt.Original = true
|
||||||
|
pesPkt.PDI = 0
|
||||||
|
pesPkt.ESCR = false
|
||||||
|
pesPkt.ESRate = false
|
||||||
|
pesPkt.DSMTrickMode = false
|
||||||
|
pesPkt.ACI = false
|
||||||
|
pesPkt.CRC = false
|
||||||
|
pesPkt.Ext = false
|
||||||
|
pesPkt.HeaderLength = 0
|
||||||
|
pesPkt.Data = make([]byte,pesDataChanLen)
|
||||||
|
for ii:=0; ii<pesDataChanLen; ii++ {
|
||||||
|
pesPkt.Data[ii] = <-pesDataChan
|
||||||
|
}
|
||||||
|
pesPktChan<-pesPkt.ToByteSlice()
|
||||||
case pesPkt := <-pesPktChan:
|
case pesPkt := <-pesPktChan:
|
||||||
for ii:=range pesPkt {
|
for ii:=range pesPkt {
|
||||||
payloadByteChan<-pesPkt[ii]
|
payloadByteChan<-pesPkt[ii]
|
||||||
|
|
|
@ -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])
|
||||||
|
|
Loading…
Reference in New Issue