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
|
||||
|
||||
import _"fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
type RtpToTsConverter interface {
|
||||
Convert()
|
||||
|
@ -57,50 +60,123 @@ func NewRtpToTsConverter() (c *rtpToTsConverter) {
|
|||
}
|
||||
|
||||
func (c* rtpToTsConverter) Convert() {
|
||||
nalUnitChan := make(chan NALUnit, 10000)
|
||||
file,_ := os.Create("video")
|
||||
pesPktChan := make(chan []byte, 10000)
|
||||
pesDataChan := make(chan byte, 15000)
|
||||
nalAccessChan := make(chan []byte, 100)
|
||||
data := make(chan byte,10000)
|
||||
payloadByteChan := make(chan byte, 15000)
|
||||
// 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 {
|
||||
select {
|
||||
default:
|
||||
case rtpPacket := <-c.inputChan:
|
||||
if GetNalType( rtpPacket.Payload ) == 28 {
|
||||
nalUnitChan<-ParseNALFragment(rtpPacket.Payload)
|
||||
} else {
|
||||
nalUnitChan<-ParseNALSpsPps(rtpPacket.Payload)
|
||||
}
|
||||
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)
|
||||
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
|
||||
threeNUBs := rtpPacket.Payload[0] & 0xE0
|
||||
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 {
|
||||
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:
|
||||
for ii:=range pesPkt {
|
||||
payloadByteChan<-pesPkt[ii]
|
||||
|
|
|
@ -330,7 +330,6 @@ func input(input string, output string) {
|
|||
donePSI = true
|
||||
packet := <-converter.TsChan
|
||||
packetByteSlice := packet.ToByteSlice()
|
||||
fmt.Printf("ts packet: %v\n", packetByteSlice)
|
||||
copy(clip[clipSize:upperBound],packetByteSlice)
|
||||
}
|
||||
//fmt.Println(clip[clipSize:upperBound])
|
||||
|
|
Loading…
Reference in New Issue