mirror of https://bitbucket.org/ausocean/av.git
revid: matching up audio packet sizes, chunk sizes and rates throughout revid pipeline
This commit is contained in:
parent
b1e5b4341f
commit
09db8907a5
|
@ -30,14 +30,17 @@ package main
|
|||
|
||||
import (
|
||||
"flag"
|
||||
"math"
|
||||
"os"
|
||||
"runtime/pprof"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"bitbucket.org/ausocean/av/codec/adpcm"
|
||||
"bitbucket.org/ausocean/av/container/mts"
|
||||
"bitbucket.org/ausocean/av/container/mts/meta"
|
||||
"bitbucket.org/ausocean/av/container/mts/pes"
|
||||
"bitbucket.org/ausocean/av/revid"
|
||||
"bitbucket.org/ausocean/iot/pi/netsender"
|
||||
"bitbucket.org/ausocean/iot/pi/sds"
|
||||
|
@ -60,9 +63,7 @@ const (
|
|||
defaultLogPath = "/var/log/netsender"
|
||||
pkg = "revid-cli:"
|
||||
defaultLogVerbosity = logger.Info
|
||||
defaultSleepTime = 60 // Seconds
|
||||
sampleSize = 2 // Bytes
|
||||
chunkSize = 16000 // Bytes
|
||||
defaultSleepTime = 60 // Seconds
|
||||
)
|
||||
|
||||
// canProfile is set to false with revid-cli is built with "-tags profile".
|
||||
|
@ -193,13 +194,6 @@ func handleFlags() revid.Config {
|
|||
log.Log(logger.Error, pkg+"bad input argument")
|
||||
}
|
||||
|
||||
switch *inputPtr {
|
||||
case "Audio":
|
||||
cfg.WriteRate = float64(*sampleRatePtr*sampleSize) / float64(chunkSize)
|
||||
default:
|
||||
cfg.WriteRate = float64(*frameRatePtr)
|
||||
}
|
||||
|
||||
switch *inputCodecPtr {
|
||||
case "H264":
|
||||
cfg.InputCodec = revid.H264
|
||||
|
@ -212,6 +206,26 @@ func handleFlags() revid.Config {
|
|||
log.Log(logger.Error, pkg+"bad input codec argument")
|
||||
}
|
||||
|
||||
switch *inputPtr {
|
||||
case "Audio":
|
||||
byteDepth := *bitDepthPtr / 8
|
||||
PCMRate := *sampleRatePtr * byteDepth * *channelsPtr * *recPeriodPtr
|
||||
var byteRate int
|
||||
switch cfg.InputCodec {
|
||||
case revid.PCM:
|
||||
byteRate = PCMRate
|
||||
case revid.ADPCM:
|
||||
byteRate = adpcm.BytesOutput(PCMRate)
|
||||
}
|
||||
if byteRate < pes.MaxPesSize {
|
||||
cfg.WriteRate = 1
|
||||
} else {
|
||||
cfg.WriteRate = uint(math.Ceil(float64(byteRate) / float64(pes.MaxPesSize)))
|
||||
}
|
||||
default:
|
||||
cfg.WriteRate = *frameRatePtr
|
||||
}
|
||||
|
||||
if len(outputs) == 0 {
|
||||
cfg.Outputs = make([]uint8, 1)
|
||||
}
|
||||
|
|
|
@ -57,6 +57,13 @@ type decoder struct {
|
|||
step int16
|
||||
}
|
||||
|
||||
// BytesOutput will return the number of adpcm bytes that will be generated for the given pcm data
|
||||
func BytesOutput(pcm int) int {
|
||||
// for X pcm bytes, 2 bytes are left uncompressed, the rest is compressed by a factor of 4
|
||||
// and a start index and padding byte are added.
|
||||
return (pcm-2)/4 + 2 + 1 + 1
|
||||
}
|
||||
|
||||
// PcmBS is the size of the blocks that an encoder uses.
|
||||
// 'encodeBlock' will encode PcmBS bytes at a time and the output will be AdpcmBS bytes long.
|
||||
const PcmBS = 1010
|
||||
|
|
|
@ -262,14 +262,14 @@ func PCM(dst io.Writer, src io.Reader, delay time.Duration) error {
|
|||
tick = ticker.C
|
||||
}
|
||||
|
||||
r := bufio.NewReader(src)
|
||||
for {
|
||||
buf := make([]byte, 0, audioChunkSize)
|
||||
_, err := r.Read(buf)
|
||||
_, err := src.Read(buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
<-tick
|
||||
fmt.Printf("LEXED AUDIO: %v\n", buf[:64])
|
||||
_, err = dst.Write(buf)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -249,9 +249,7 @@ func (e *Encoder) Write(data []byte) (int, error) {
|
|||
pkt.PCR = e.pcr()
|
||||
pusi = false
|
||||
}
|
||||
bytes := pkt.Bytes(e.tsSpace[:PacketSize])
|
||||
fmt.Printf("Packet: %v", bytes)
|
||||
_, err := e.dst.Write(bytes)
|
||||
_, err := e.dst.Write(pkt.Bytes(e.tsSpace[:PacketSize]))
|
||||
if err != nil {
|
||||
return len(data), err
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ LICENSE
|
|||
|
||||
package pes
|
||||
|
||||
const MaxPesSize = 64 * 1 << 10
|
||||
const MaxPesSize = 64 * 1 << 10 // 65536
|
||||
|
||||
/*
|
||||
The below data struct encapsulates the fields of an PES packet. Below is
|
||||
|
|
|
@ -55,7 +55,7 @@ type Config struct {
|
|||
IntraRefreshPeriod uint
|
||||
RtpAddress string
|
||||
SendRetry bool
|
||||
WriteRate float64 // How many times a second revid encoders will be written to.
|
||||
WriteRate uint // How many times a second revid encoders will be written to.
|
||||
|
||||
// Video
|
||||
Height uint
|
||||
|
|
Loading…
Reference in New Issue