mirror of https://bitbucket.org/ausocean/av.git
revid: pid for audio being written to mts packets
This commit is contained in:
parent
3484e35692
commit
b1e5b4341f
|
@ -62,7 +62,7 @@ const (
|
|||
defaultLogVerbosity = logger.Info
|
||||
defaultSleepTime = 60 // Seconds
|
||||
sampleSize = 2 // Bytes
|
||||
blockSize = 16000 // Bytes
|
||||
chunkSize = 16000 // Bytes
|
||||
)
|
||||
|
||||
// canProfile is set to false with revid-cli is built with "-tags profile".
|
||||
|
@ -195,7 +195,7 @@ func handleFlags() revid.Config {
|
|||
|
||||
switch *inputPtr {
|
||||
case "Audio":
|
||||
cfg.WriteRate = float64(*sampleRatePtr*sampleSize) / float64(blockSize)
|
||||
cfg.WriteRate = float64(*sampleRatePtr*sampleSize) / float64(chunkSize)
|
||||
default:
|
||||
cfg.WriteRate = float64(*frameRatePtr)
|
||||
}
|
||||
|
|
|
@ -43,8 +43,8 @@ func TestEncodePcm(t *testing.T) {
|
|||
var buf bytes.Buffer
|
||||
sampleRate := 48000
|
||||
sampleSize := 2
|
||||
blockSize := 16000
|
||||
writeFreq := float64(sampleRate*sampleSize) / float64(blockSize)
|
||||
chunkSize := 16000
|
||||
writeFreq := float64(sampleRate*sampleSize) / float64(chunkSize)
|
||||
e := NewEncoder(&buf, writeFreq, Audio)
|
||||
|
||||
inPath := "../../../test/test-data/av/input/sweep_400Hz_20000Hz_-3dBFS_5s_48khz.pcm"
|
||||
|
@ -54,15 +54,15 @@ func TestEncodePcm(t *testing.T) {
|
|||
}
|
||||
|
||||
// Break pcm into blocks and encode to mts and get the resulting bytes.
|
||||
for i := 0; i < len(inPcm); i += blockSize {
|
||||
if len(inPcm)-i < blockSize {
|
||||
for i := 0; i < len(inPcm); i += chunkSize {
|
||||
if len(inPcm)-i < chunkSize {
|
||||
block := inPcm[i:]
|
||||
_, err = e.Write(block)
|
||||
if err != nil {
|
||||
t.Errorf("unable to write block: %v", err)
|
||||
}
|
||||
} else {
|
||||
block := inPcm[i : i+blockSize]
|
||||
block := inPcm[i : i+chunkSize]
|
||||
_, err = e.Write(block)
|
||||
if err != nil {
|
||||
t.Errorf("unable to write block: %v", err)
|
||||
|
@ -73,7 +73,7 @@ func TestEncodePcm(t *testing.T) {
|
|||
|
||||
// Get the first MTS packet to check
|
||||
var pkt packet.Packet
|
||||
pesPacket := make([]byte, 0, blockSize)
|
||||
pesPacket := make([]byte, 0, chunkSize)
|
||||
got := make([]byte, 0, len(inPcm))
|
||||
i := 0
|
||||
if i+PacketSize <= len(clip) {
|
||||
|
|
|
@ -99,11 +99,12 @@ var (
|
|||
)
|
||||
|
||||
const (
|
||||
sdtPid = 17
|
||||
patPid = 0
|
||||
pmtPid = 4096
|
||||
videoPid = 256
|
||||
audioPid = 210
|
||||
sdtPid = 17
|
||||
patPid = 0
|
||||
pmtPid = 4096
|
||||
videoPid = 256
|
||||
// AudioPid is the Id for packets containing audio data
|
||||
AudioPid = 210
|
||||
videoStreamID = 0xe0 // First video stream ID.
|
||||
audioStreamID = 0xc0 // First audio stream ID.
|
||||
)
|
||||
|
@ -154,7 +155,7 @@ func NewEncoder(dst io.Writer, rate float64, mediaType int) *Encoder {
|
|||
var sid byte
|
||||
switch mediaType {
|
||||
case Audio:
|
||||
mPid = audioPid
|
||||
mPid = AudioPid
|
||||
sid = audioStreamID
|
||||
case Video:
|
||||
mPid = videoPid
|
||||
|
@ -248,7 +249,9 @@ func (e *Encoder) Write(data []byte) (int, error) {
|
|||
pkt.PCR = e.pcr()
|
||||
pusi = false
|
||||
}
|
||||
_, err := e.dst.Write(pkt.Bytes(e.tsSpace[:PacketSize]))
|
||||
bytes := pkt.Bytes(e.tsSpace[:PacketSize])
|
||||
fmt.Printf("Packet: %v", bytes)
|
||||
_, err := e.dst.Write(bytes)
|
||||
if err != nil {
|
||||
return len(data), err
|
||||
}
|
||||
|
|
|
@ -187,7 +187,7 @@ func (r *Revid) setConfig(config Config) error {
|
|||
// mtsEnc and flvEnc will be called to obtain an mts encoder and flv encoder
|
||||
// respectively. multiWriter will be used to create an ioext.multiWriteCloser
|
||||
// so that encoders can write to multiple senders.
|
||||
func (r *Revid) setupPipeline(mtsEnc, flvEnc func(dst io.Writer, rate int) (io.Writer, error), multiWriter func(...io.WriteCloser) io.WriteCloser) error {
|
||||
func (r *Revid) setupPipeline(mtsEnc func(dst io.Writer, rate, mediaType int) (io.Writer, error), flvEnc func(dst io.Writer, rate int) (io.Writer, error), multiWriter func(...io.WriteCloser) io.WriteCloser) error {
|
||||
r.buffer = (*buffer)(ring.NewBuffer(ringBufferSize, ringBufferElementSize, writeTimeout))
|
||||
|
||||
r.encoder = r.encoder[:0]
|
||||
|
@ -231,7 +231,13 @@ func (r *Revid) setupPipeline(mtsEnc, flvEnc func(dst io.Writer, rate int) (io.W
|
|||
// as a destination.
|
||||
if len(mtsSenders) != 0 {
|
||||
mw := multiWriter(mtsSenders...)
|
||||
e, _ := mtsEnc(mw, int(r.config.FrameRate))
|
||||
var mediaType int
|
||||
if r.config.Input == Audio {
|
||||
mediaType = mts.Audio
|
||||
} else {
|
||||
mediaType = mts.Video
|
||||
}
|
||||
e, _ := mtsEnc(mw, int(r.config.WriteRate), mediaType)
|
||||
r.encoder = append(r.encoder, e)
|
||||
}
|
||||
|
||||
|
@ -275,8 +281,8 @@ func (r *Revid) setupPipeline(mtsEnc, flvEnc func(dst io.Writer, rate int) (io.W
|
|||
return nil
|
||||
}
|
||||
|
||||
func newMtsEncoder(dst io.Writer, fps int) (io.Writer, error) {
|
||||
e := mts.NewEncoder(dst, float64(fps), mts.Video)
|
||||
func newMtsEncoder(dst io.Writer, writeRate, mediaType int) (io.Writer, error) {
|
||||
e := mts.NewEncoder(dst, float64(writeRate), mediaType)
|
||||
return e, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue