mirror of https://bitbucket.org/ausocean/av.git
mts: removed readme reference, added comments to test
This commit is contained in:
parent
ddfabcf2d0
commit
3c29ca554d
|
@ -2,9 +2,6 @@
|
||||||
NAME
|
NAME
|
||||||
audio_test.go
|
audio_test.go
|
||||||
|
|
||||||
DESCRIPTION
|
|
||||||
See Readme.md
|
|
||||||
|
|
||||||
AUTHOR
|
AUTHOR
|
||||||
Trek Hopton <trek@ausocean.org>
|
Trek Hopton <trek@ausocean.org>
|
||||||
|
|
||||||
|
@ -21,8 +18,8 @@ LICENSE
|
||||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
for more details.
|
for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License in gpl.txt.
|
||||||
along with revid in gpl.txt. If not, see http://www.gnu.org/licenses.
|
If not, see http://www.gnu.org/licenses.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package mts
|
package mts
|
||||||
|
@ -30,7 +27,6 @@ package mts
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"bitbucket.org/ausocean/av/container/mts/meta"
|
"bitbucket.org/ausocean/av/container/mts/meta"
|
||||||
|
@ -39,7 +35,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestEncodePcm tests the mpegts encoder's ability to encode pcm audio data.
|
// TestEncodePcm tests the mpegts encoder's ability to encode pcm audio data.
|
||||||
// It reads and encodes input pcm data into mpegts, then decodes the mpegts compares the result to the input pcm.
|
// It reads and encodes input pcm data into mpegts, then decodes the mpegts and compares the result to the input pcm.
|
||||||
func TestEncodePcm(t *testing.T) {
|
func TestEncodePcm(t *testing.T) {
|
||||||
Meta = meta.New()
|
Meta = meta.New()
|
||||||
|
|
||||||
|
@ -54,28 +50,28 @@ func TestEncodePcm(t *testing.T) {
|
||||||
inPath := "../../../test/test-data/av/input/sweep_400Hz_20000Hz_-3dBFS_5s_48khz.pcm"
|
inPath := "../../../test/test-data/av/input/sweep_400Hz_20000Hz_-3dBFS_5s_48khz.pcm"
|
||||||
inPcm, err := ioutil.ReadFile(inPath)
|
inPcm, err := ioutil.ReadFile(inPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
t.Errorf("unable to read file: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode pcm to mts and get the resulting bytes.
|
// Break pcm into blocks and encode to mts and get the resulting bytes.
|
||||||
for i := 0; i < len(inPcm); i += blockSize {
|
for i := 0; i < len(inPcm); i += blockSize {
|
||||||
if len(inPcm)-i < blockSize {
|
if len(inPcm)-i < blockSize {
|
||||||
block := inPcm[i:]
|
block := inPcm[i:]
|
||||||
_, err = e.Write(block)
|
_, err = e.Write(block)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
t.Errorf("unable to write block: %v", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
block := inPcm[i : i+blockSize]
|
block := inPcm[i : i+blockSize]
|
||||||
_, err = e.Write(block)
|
_, err = e.Write(block)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
t.Errorf("unable to write block: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
clip := buf.Bytes()
|
clip := buf.Bytes()
|
||||||
|
|
||||||
// Decode the mts packets to extract the original data
|
// Get the first MTS packet to check
|
||||||
var pkt packet.Packet
|
var pkt packet.Packet
|
||||||
pesPacket := make([]byte, 0, blockSize)
|
pesPacket := make([]byte, 0, blockSize)
|
||||||
got := make([]byte, 0, len(inPcm))
|
got := make([]byte, 0, len(inPcm))
|
||||||
|
@ -84,12 +80,17 @@ func TestEncodePcm(t *testing.T) {
|
||||||
copy(pkt[:], clip[i:i+PacketSize])
|
copy(pkt[:], clip[i:i+PacketSize])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Loop through MTS packets until all the audio data from PES packets has been retrieved
|
||||||
for i+PacketSize <= len(clip) {
|
for i+PacketSize <= len(clip) {
|
||||||
|
|
||||||
|
// Check MTS packet
|
||||||
if pkt.PID() == audioPid {
|
if pkt.PID() == audioPid {
|
||||||
if pkt.PayloadUnitStartIndicator() {
|
if pkt.PayloadUnitStartIndicator() {
|
||||||
|
|
||||||
|
// Copy the first MTS payload
|
||||||
payload, err := pkt.Payload()
|
payload, err := pkt.Payload()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unexpected err: %v\n", err)
|
t.Errorf("unable to get MTS payload: %v", err)
|
||||||
}
|
}
|
||||||
pesPacket = append(pesPacket, payload...)
|
pesPacket = append(pesPacket, payload...)
|
||||||
|
|
||||||
|
@ -98,10 +99,11 @@ func TestEncodePcm(t *testing.T) {
|
||||||
copy(pkt[:], clip[i:i+PacketSize])
|
copy(pkt[:], clip[i:i+PacketSize])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy the rest of the MTS payloads that are part of the same PES packet
|
||||||
for (!pkt.PayloadUnitStartIndicator()) && i+PacketSize <= len(clip) {
|
for (!pkt.PayloadUnitStartIndicator()) && i+PacketSize <= len(clip) {
|
||||||
payload, err = pkt.Payload()
|
payload, err = pkt.Payload()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unexpected err: %v\n", err)
|
t.Errorf("unable to get MTS payload: %v", err)
|
||||||
}
|
}
|
||||||
pesPacket = append(pesPacket, payload...)
|
pesPacket = append(pesPacket, payload...)
|
||||||
|
|
||||||
|
@ -116,9 +118,10 @@ func TestEncodePcm(t *testing.T) {
|
||||||
copy(pkt[:], clip[i:i+PacketSize])
|
copy(pkt[:], clip[i:i+PacketSize])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Get the audio data from the current PES packet
|
||||||
pesHeader, err := pes.NewPESHeader(pesPacket)
|
pesHeader, err := pes.NewPESHeader(pesPacket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unexpected err: %v\n", err)
|
t.Errorf("unable to read PES packet: %v", err)
|
||||||
}
|
}
|
||||||
got = append(got, pesHeader.Data()...)
|
got = append(got, pesHeader.Data()...)
|
||||||
pesPacket = pesPacket[:0]
|
pesPacket = pesPacket[:0]
|
||||||
|
@ -130,8 +133,8 @@ func TestEncodePcm(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compare encoded data with original data.
|
// Compare data from MTS with original data.
|
||||||
if !bytes.Equal(got, inPcm) {
|
if !bytes.Equal(got, inPcm) {
|
||||||
t.Error("Error, unexpected output")
|
t.Error("data decoded from mts did not match input data")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,6 @@
|
||||||
NAME
|
NAME
|
||||||
encoder.go
|
encoder.go
|
||||||
|
|
||||||
DESCRIPTION
|
|
||||||
See Readme.md
|
|
||||||
|
|
||||||
AUTHOR
|
AUTHOR
|
||||||
Dan Kortschak <dan@ausocean.org>
|
Dan Kortschak <dan@ausocean.org>
|
||||||
Saxon Nelson-Milton <saxon@ausocean.org>
|
Saxon Nelson-Milton <saxon@ausocean.org>
|
||||||
|
|
Loading…
Reference in New Issue