av/packet/RtpToTsConverter.go

86 lines
2.3 KiB
Go
Raw Normal View History

/*
NAME
RtpToTsConverter.go - provides utilities for the conversion of Rtp packets
to equivalent MpegTs packets.
DESCRIPTION
See Readme.md
AUTHOR
Saxon Nelson-Milton <saxon.milton@gmail.com>
LICENSE
RtpToTsConverter.go is Copyright (C) 2017 the Australian Ocean Lab (AusOcean)
It is free software: you can redistribute it and/or modify them
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
It is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with revid in gpl.txt. If not, see [GNU licenses](http://www.gnu.org/licenses).
*/
package packet
type RtpToTsConverter interface {
2017-12-12 09:40:32 +03:00
Convert()
}
type rtpToTsConverter struct {
2017-12-12 09:40:32 +03:00
TsChan <-chan *MpegTsPacket
RtpChan chan<- RtpPacket
tsChan chan<- *MpegTsPacket
rtpChan <-chan RtpPacket
currentTsPacket *MpegTsPacket
currentCC byte
payloadByteChan chan byte
}
2017-12-12 09:40:32 +03:00
func NewRtpToTsConverter() (c *rtpToTsConverter) {
c = new(rtpToTsConverter)
tsChan := make(chan *MpegTsPacket,100)
rtpChan := make(chan RtpPacket,100)
2017-12-12 09:40:32 +03:00
c.TsChan = tsChan
c.RtpChan = rtpChan
c.tsChan = tsChan
c.rtpChan = rtpChan
c.currentTsPacket = new(MpegTsPacket)
c.currentCC = 0
c.payloadByteChan = make(chan byte, 10000)
2017-12-12 09:40:32 +03:00
return
}
2017-12-12 09:40:32 +03:00
func (c* rtpToTsConverter) Convert() {
for {
select{
default:
case rtpPacket := <-c.rtpChan:
for ii := range rtpPacket.Payload {
c.payloadByteChan<-rtpPacket.Payload[ii]
}
for len(c.payloadByteChan) > 156 {
2017-12-12 09:40:32 +03:00
c.currentTsPacket = new(MpegTsPacket)
c.currentTsPacket.SyncByte = 0x47
c.currentTsPacket.TEI = false
c.currentTsPacket.PUSI = true
c.currentTsPacket.Priority = false
c.currentTsPacket.PID = 4096
c.currentTsPacket.TSC = 0
c.currentTsPacket.AFC = 1
2017-12-12 09:40:32 +03:00
c.currentTsPacket.Payload = make([]byte, 156)
for ii:=0; ii < 156; ii++ {
c.currentTsPacket.Payload[ii] = <-c.payloadByteChan
}
c.tsChan<-c.currentTsPacket
}
}
}
}