mirror of https://bitbucket.org/ausocean/av.git
Working on RevidAPI
This commit is contained in:
parent
9ac968430e
commit
fd5a6a1ec7
|
@ -0,0 +1,46 @@
|
||||||
|
/*
|
||||||
|
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 revid
|
||||||
|
|
||||||
|
const (
|
||||||
|
// input types
|
||||||
|
raspivid = 0
|
||||||
|
rtp = 1
|
||||||
|
// input format
|
||||||
|
h264 = 2
|
||||||
|
rtp = 3
|
||||||
|
// output types
|
||||||
|
file = 4
|
||||||
|
http = 5
|
||||||
|
)
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
input uint8
|
||||||
|
output uint8
|
||||||
|
}
|
|
@ -139,5 +139,15 @@ func TestRTP(t *testing.T) {
|
||||||
Testing use with raspivid
|
Testing use with raspivid
|
||||||
*/
|
*/
|
||||||
func TestRaspividInput(t *testing.T){
|
func TestRaspividInput(t *testing.T){
|
||||||
|
config := Config{
|
||||||
|
Input: raspivid,
|
||||||
|
Output: file,
|
||||||
|
}
|
||||||
|
revidInst, err := NewRevidInstance(config)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Should not have got an error!")
|
||||||
|
}
|
||||||
|
revidInst.Run()
|
||||||
|
time.Sleep(5*time.Second)
|
||||||
|
revidInst.Stop()
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,25 +91,7 @@ type RevidInst interface {
|
||||||
ChangeState(newConfig Config) err
|
ChangeState(newConfig Config) err
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
|
||||||
// input types
|
|
||||||
raspivid = 0
|
|
||||||
rtp = 1
|
|
||||||
// input format
|
|
||||||
h264 = 2
|
|
||||||
rtp = 3
|
|
||||||
// output types
|
|
||||||
file = 4
|
|
||||||
http = 5
|
|
||||||
)
|
|
||||||
|
|
||||||
type Config struct {
|
|
||||||
input uint8
|
|
||||||
output uint8
|
|
||||||
}
|
|
||||||
|
|
||||||
type revidInst struct {
|
type revidInst struct {
|
||||||
clipCount int
|
|
||||||
expectCC int
|
expectCC int
|
||||||
dumpCC int
|
dumpCC int
|
||||||
dumpPCRBase uint64
|
dumpPCRBase uint64
|
||||||
|
@ -124,7 +106,10 @@ type revidInst struct {
|
||||||
|
|
||||||
func NewRevidInstance(config Config)(r *revid, err error){
|
func NewRevidInstance(config Config)(r *revid, err error){
|
||||||
ringBuffer = ringbuffer.NewRingBuffer(bufferSize, mp2tPacketSize*mp2tMaxPackets)
|
ringBuffer = ringbuffer.NewRingBuffer(bufferSize, mp2tPacketSize*mp2tMaxPackets)
|
||||||
Error = log.New(os.Stderr, "ERROR: ",log.Ldat|log.Ltime|log.Lshortfile)
|
r.Error = log.New(os.Stderr, "ERROR: ",log.Ldat|log.Ltime|log.Lshortfile)
|
||||||
|
r.expectCC = -1
|
||||||
|
r.dumpCC = -1
|
||||||
|
r.dumpPCRBase = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func(r *revidInst) Run(){
|
func(r *revidInst) Run(){
|
||||||
|
@ -140,10 +125,9 @@ func(r *revidInst) Stop(){
|
||||||
// input handles the reading from the specified input
|
// input handles the reading from the specified input
|
||||||
func (r *revid)input(input string, output string) {
|
func (r *revid)input(input string, output string) {
|
||||||
// (re)initialize globals
|
// (re)initialize globals
|
||||||
clipCount = 0
|
r.expectCC = -1
|
||||||
expectCC = -1
|
r.dumpCC = -1
|
||||||
dumpCC = -1
|
r.dumpPCRBase = 0
|
||||||
dumpPCRBase = 0
|
|
||||||
|
|
||||||
converter := tscreator.NewTsCreator(framesPerSec)
|
converter := tscreator.NewTsCreator(framesPerSec)
|
||||||
go converter.Convert()
|
go converter.Convert()
|
||||||
|
@ -190,7 +174,6 @@ func (r *revid)input(input string, output string) {
|
||||||
now = time.Now()
|
now = time.Now()
|
||||||
if (packetCount == mp2tMaxPackets) ||
|
if (packetCount == mp2tMaxPackets) ||
|
||||||
(now.Sub(prevTime) > clipDuration*time.Second && packetCount%packetsPerFrame == 0) {
|
(now.Sub(prevTime) > clipDuration*time.Second && packetCount%packetsPerFrame == 0) {
|
||||||
clipCount++
|
|
||||||
if err := ringBuffer.DoneWriting(clipSize); err != nil {
|
if err := ringBuffer.DoneWriting(clipSize); err != nil {
|
||||||
r.Error.Println(err.Error())
|
r.Error.Println(err.Error())
|
||||||
return
|
return
|
||||||
|
@ -223,12 +206,7 @@ func (r *revid)output(output string) {
|
||||||
|
|
||||||
// sendClipToFile writes a video clip to a /tmp file.
|
// sendClipToFile writes a video clip to a /tmp file.
|
||||||
func sendClipToFile(clip []byte, _ string, _ net.Conn) error {
|
func sendClipToFile(clip []byte, _ string, _ net.Conn) error {
|
||||||
filename := fmt.Sprintf(tempDir+"vid%03d.ts", clipCount)
|
|
||||||
fmt.Printf("Writing %s (%d bytes)\n", filename, len(clip))
|
|
||||||
err := ioutil.WriteFile(filename, clip, 0644)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Error writing file %s: %s", filename, err)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,6 +244,3 @@ func sendClipToUDP(clip []byte, _ string, conn net.Conn) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue