add/remove debug
This commit is contained in:
parent
ff9f22f46d
commit
59d52825d6
@ -1,4 +1,4 @@
|
||||
|
||||
./avconv -loglevel debug -y -i /tmp/tiny2.mov \
|
||||
-bsf h264_mp4toannexb -acodec copy -vcodec copy -strict experimental /tmp/out.ts 2>&1
|
||||
avconv -loglevel debug -y -i /tmp/tiny2.mov \
|
||||
-bsf h264_mp4toannexb -an -vcodec copy -strict experimental /tmp/out.ts 2>&1
|
||||
|
||||
|
@ -13,7 +13,8 @@ import (
|
||||
|
||||
type Stream struct {
|
||||
PID uint
|
||||
Header *ts.PESHeader
|
||||
PESHeader *ts.PESHeader
|
||||
FirstTSHeader ts.TSHeader
|
||||
Title string
|
||||
Data bytes.Buffer
|
||||
Type uint
|
||||
@ -26,6 +27,7 @@ type Sample struct {
|
||||
PTS uint64
|
||||
DTS uint64
|
||||
Data []byte
|
||||
RandomAccessIndicator bool
|
||||
}
|
||||
|
||||
func readSamples(filename string, ch chan Sample) {
|
||||
@ -68,7 +70,7 @@ func readSamples(filename string, ch chan Sample) {
|
||||
return
|
||||
}
|
||||
|
||||
debugStream := true
|
||||
debugStream := false
|
||||
|
||||
onStreamPayload := func() (err error) {
|
||||
stream := findOrCreateStream(header.PID)
|
||||
@ -77,10 +79,10 @@ func readSamples(filename string, ch chan Sample) {
|
||||
|
||||
if header.PayloadUnitStart {
|
||||
stream.Data = bytes.Buffer{}
|
||||
if stream.Header, err = ts.ReadPESHeader(lr); err != nil {
|
||||
if stream.PESHeader, err = ts.ReadPESHeader(lr); err != nil {
|
||||
return
|
||||
}
|
||||
stream.PCR = header.PCR
|
||||
stream.FirstTSHeader = header
|
||||
}
|
||||
|
||||
if _, err = io.CopyN(&stream.Data, lr, lr.N); err != nil {
|
||||
@ -88,10 +90,10 @@ func readSamples(filename string, ch chan Sample) {
|
||||
}
|
||||
|
||||
if debugStream {
|
||||
fmt.Printf("stream: %d/%d\n", stream.Data.Len(), stream.Header.DataLength)
|
||||
fmt.Printf("stream: %d/%d\n", stream.Data.Len(), stream.PESHeader.DataLength)
|
||||
}
|
||||
|
||||
if stream.Data.Len() == int(stream.Header.DataLength) {
|
||||
if stream.Data.Len() == int(stream.PESHeader.DataLength) {
|
||||
if debug {
|
||||
fmt.Println(stream.Type, stream.Title, stream.Data.Len(), "total")
|
||||
fmt.Println(hex.Dump(stream.Data.Bytes()))
|
||||
@ -99,9 +101,10 @@ func readSamples(filename string, ch chan Sample) {
|
||||
ch <- Sample{
|
||||
Type: stream.Type,
|
||||
Data: stream.Data.Bytes(),
|
||||
PTS: stream.Header.PTS,
|
||||
DTS: stream.Header.DTS,
|
||||
PCR: stream.PCR,
|
||||
PTS: stream.PESHeader.PTS,
|
||||
DTS: stream.PESHeader.DTS,
|
||||
PCR: stream.FirstTSHeader.PCR,
|
||||
RandomAccessIndicator: stream.FirstTSHeader.RandomAccessIndicator,
|
||||
}
|
||||
}
|
||||
return
|
||||
@ -219,7 +222,7 @@ func main() {
|
||||
if err = ts.WritePES(bw, pes, bytes.NewReader(sample.Data)); err != nil {
|
||||
return
|
||||
}
|
||||
if err = w.Write(bw.Bytes(), false); err != nil {
|
||||
if err = w.Write(bw.Bytes(), sample.RandomAccessIndicator); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
@ -243,7 +246,7 @@ func main() {
|
||||
if true {
|
||||
fmt.Println("sample: ", len(sample.Data),
|
||||
"PCR", sample.PCR, "PTS", sample.PTS,
|
||||
"DTS", sample.DTS,
|
||||
"DTS", sample.DTS, "sync", sample.RandomAccessIndicator,
|
||||
)
|
||||
//fmt.Print(hex.Dump(sample.Data))
|
||||
}
|
||||
|
41
reader.go
41
reader.go
@ -121,6 +121,11 @@ func ReadTSHeader(r io.Reader) (self TSHeader, err error) {
|
||||
})
|
||||
}
|
||||
|
||||
// random_access_indicator
|
||||
if flags & 0x40 != 0 {
|
||||
self.RandomAccessIndicator = true
|
||||
}
|
||||
|
||||
// PCR
|
||||
if flags & 0x10 != 0 {
|
||||
var v uint64
|
||||
@ -201,6 +206,12 @@ func ReadPSI(r io.Reader) (self PSI, lr *io.LimitedReader, cr *Crc32Reader, err
|
||||
if pointer, err = ReadUInt(r, 1); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if DebugReader {
|
||||
fmt.Printf("psi: pointer=%d\n", pointer)
|
||||
}
|
||||
|
||||
|
||||
if pointer != 0 {
|
||||
if err = ReadDummy(r, int(pointer)); err != nil {
|
||||
return
|
||||
@ -360,13 +371,41 @@ func ReadPMT(r io.Reader) (self PMT, err error) {
|
||||
}
|
||||
info.ElementaryPID = flags & 0x1fff
|
||||
|
||||
if DebugReader {
|
||||
fmt.Printf("pmt: info1 %s\n", FieldsDumper{
|
||||
Fields: []struct{
|
||||
Length int
|
||||
Desc string
|
||||
}{
|
||||
{3, "reserved"},
|
||||
{13, "elementary_pid"},
|
||||
},
|
||||
Val: flags,
|
||||
Length: 16,
|
||||
})
|
||||
}
|
||||
|
||||
// Reserved(6)
|
||||
// ES Info length length(10)
|
||||
// ES Info length(10)
|
||||
if flags, err = ReadUInt(lr, 2); err != nil {
|
||||
return
|
||||
}
|
||||
length = flags & 0x3ff
|
||||
|
||||
if DebugReader {
|
||||
fmt.Printf("pmt: info2 %s\n", FieldsDumper{
|
||||
Fields: []struct{
|
||||
Length int
|
||||
Desc string
|
||||
}{
|
||||
{6, "reserved"},
|
||||
{10, "es_info_length"},
|
||||
},
|
||||
Val: flags,
|
||||
Length: 16,
|
||||
})
|
||||
}
|
||||
|
||||
if length > 0 {
|
||||
lr := &io.LimitedReader{R: lr, N: int64(length)}
|
||||
if info.Descriptors, err = readDescs(lr); err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user