Almost ready to test revidInstance with raspivid

This commit is contained in:
Unknown 2018-01-09 15:36:09 +10:30
parent 6edcf8377e
commit 9ac968430e
6 changed files with 148 additions and 28 deletions

View File

@ -1 +1,76 @@
/*
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 h264
import (
"../itut"
)
type H264Parser {
inputBuffer []byte
isParsing bool
}
func (p* H264Parser)SendInputData(someData []byte){
inputBuffer = append(input, someData)
}
func (p* H264Parser)Stop(){
isParsing = false
}
func (p* H264Parser)Parse(outputChan chan<- []byte) {
isParsing = true
buffer = b.InputBuffer
for isParsing {
for i := 0 ;; i++{
var start bool
i, start = func() (int,bool) {
switch{
case reflect.DeepEqual(buffer[i:i+3],itut.StartCode1()):
return i+3, true
case reflect.DeepEqual(buffer[i:i+4],itut.StartCode2()):
return i+4, true
}
return i, false
}()
if nalType := buffer[i] & 0x1F; start && ( nalType == 1 || nalType == 5) {
for ; i < len(buffer) && !(i+3 < len(buffer) && ( reflect.DeepEqual(buffer[i:i+3],itut.StartCode1()) ||
reflect.DeepEqual(buffer[i:i+4],startCode2))); i++ {}
outputChan<-append(append(itut.StartCode1(),itut.AUD()),buffer[:i]...)
buffer = buffer[i:]
i=0
}
if i >= len(buffer) {
inputBuffer = []byte{}
break
}
}
}
}

33
itut/standards.go Normal file
View File

@ -0,0 +1,33 @@
/*
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 itut
func StartCode1() []byte { return []byte{0x00, 0x00, 0x01} }
func StartCode2() []byte { return []byte{0x00, 0x00, 0x00, 0x01} }
func AUD() []byte { return []byte{0x09, 0x10} }

View File

@ -124,6 +124,8 @@ type MpegTsPacket struct {
Payload []byte // Mpeg ts payload
}
// TODO: make payload private considering we now have FillPayload method
func (p *MpegTsPacket) FillPayload(channel chan byte){
p.Payload = []byte{}
currentPktLength := 6 + int(tools.BoolToByte(p.PCRF))*6+int(tools.BoolToByte(p.OPCRF))*6+

View File

@ -53,27 +53,3 @@ func GetStartBit(p *rtp.RtpPacket) byte {
func GetEndBit(p *rtp.RtpPacket) byte {
return (p.Payload[1] & 0x40) >> 6
}
func ParseH264Buffer(buffer []byte, outputChan chan<- []byte) {
startCode1 := []byte{0x00,0x00,0x01}
startCode2 := []byte{0x00,0x00,0x00,0x01}
for i := 0; i < len(buffer); i++ {
var start bool
i, start = func() (int,bool) {
switch{
case reflect.DeepEqual(buffer[i:i+3],startCode1):
return i+3, true
case reflect.DeepEqual(buffer[i:i+4],startCode2):
return i+4, true
}
return i, false
}()
if nalType := buffer[i] & 0x1F; start && ( nalType == 1 || nalType == 5) {
for ; i < len(buffer) && !(i+3 < len(buffer) && ( reflect.DeepEqual(buffer[i:i+3],startCode1) ||
reflect.DeepEqual(buffer[i:i+4],startCode2))); i++ {}
outputChan<-append(append(startCode1,[]byte{0x09,0xF0}...),buffer[:i]...)
buffer = buffer[i:]
i=0
}
}
}

View File

@ -54,6 +54,7 @@ type tsCreator struct {
currentPtsTime float64
currentPcrTime float64
fps uint
isGenerating bool
}
func NewTsCreator(fps uint) (c *tsCreator) {
@ -74,23 +75,28 @@ func NewTsCreator(fps uint) (c *tsCreator) {
return
}
func (c* tsCreator) genPts()(pts uint64){
func (c* tsgenerator) genPts()(pts uint64){
pts = uint64(c.currentPtsTime * float64(90000))
c.currentPtsTime += 1.0/float64(c.fps)
return
}
func (c* tsCreator) genPcr()(pcr uint64){
func (c* tsgenerator) genPcr()(pcr uint64){
pcr = uint64(c.currentPcrTime * float64(90000))
c.currentPcrTime += 1.0/float64(c.fps)
return
}
func (c *tsCreator) Convert() {
func (c *tsgenerator) Stop(){
isGenerating = false
}
func (c *tsgenerator) Convert() {
isGenerating = true
pesPktChan := make(chan []byte, 1000)
payloadByteChan := make(chan byte, 100000)
var rtpBuffer [](*rtp.RtpPacket)
for {
for isGenerating {
select {
default:
case rtpPacket := <-c.inputChan:

View File

@ -1 +1,29 @@
/*
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 tsgenerator