Skip to content

Commit

Permalink
chore: refactor for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
tobbee committed Jan 15, 2024
1 parent b11e61e commit 5ce5d24
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
6 changes: 6 additions & 0 deletions cmd/ts-info/app/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ dataLoop:
case astits.StreamTypeAACAudio:
e = &elementaryStream{PID: es.ElementaryPID, Codec: "AAC", Type: "audio"}
esKinds[es.ElementaryPID] = "AAC"
case astits.StreamTypeHEVCVideo:
e = &elementaryStream{PID: es.ElementaryPID, Codec: "HEVC", Type: "video"}
esKinds[es.ElementaryPID] = "HEVC"
case astits.StreamTypePrivateData:
e = &elementaryStream{PID: es.ElementaryPID, Codec: "PrivateData", Type: "data"}
esKinds[es.ElementaryPID] = "PrivateData"
}
if e != nil {
jp.print(e)
Expand Down
31 changes: 15 additions & 16 deletions cmd/ts-info/app/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import (
"github.com/asticode/go-astits"
)

type avcFrameData struct {
PID uint16 `json:"pid"`
RAI bool `json:"rai"`
PTS int64 `json:"pts"`
DTS *int64 `json:"dts,omitempty"`
NALUS []avcNALU `json:"nalus"`
type naluFrameData struct {
PID uint16 `json:"pid"`
RAI bool `json:"rai"`
PTS int64 `json:"pts"`
DTS *int64 `json:"dts,omitempty"`
NALUS []naluData `json:"nalus"`
}

type avcNALU struct {
type naluData struct {
Type string `json:"type"`
Len int `json:"len"`
Data string `json:"data,omitempty"`
Expand All @@ -31,27 +31,26 @@ func parseAVCPES(jp *jsonPrinter, d *astits.DemuxerData, ps *avcPS, verbose bool
if pes.Header.OptionalHeader.PTS == nil {
return nil, fmt.Errorf("no PTS in PES")
}
ad := avcFrameData{
nfd := naluFrameData{
PID: pid,
}
if fp != nil {
af := fp.AdaptationField
if af != nil {
ad.RAI = af.RandomAccessIndicator
nfd.RAI = af.RandomAccessIndicator
}
}
pts := *pes.Header.OptionalHeader.PTS
data := pes.Data
ad.PTS = pts.Base

nfd.PTS = pts.Base
dts := pes.Header.OptionalHeader.DTS
if dts != nil {
ad.DTS = &dts.Base
nfd.DTS = &dts.Base
}
data := pes.Data
nalus := avc.ExtractNalusFromByteStream(data)
firstPS := false
for _, nalu := range nalus {
var seiMsg string
seiMsg := ""
naluType := avc.GetNaluType(nalu[0])
switch naluType {
case avc.NALU_SPS:
Expand Down Expand Up @@ -88,7 +87,7 @@ func parseAVCPES(jp *jsonPrinter, d *astits.DemuxerData, ps *avcPS, verbose bool
}
seiMsg = strings.Join(seiTexts, ", ")
}
ad.NALUS = append(ad.NALUS, avcNALU{
nfd.NALUS = append(nfd.NALUS, naluData{
Type: naluType.String(),
Len: len(nalu),
Data: seiMsg,
Expand All @@ -105,7 +104,7 @@ func parseAVCPES(jp *jsonPrinter, d *astits.DemuxerData, ps *avcPS, verbose bool
printPS(jp, pid, "PPS", nr, ps.ppsnalus[nr], ps.ppss[nr], verbose)
}
}
jp.print(ad)
jp.print(nfd)
return ps, jp.error()
}

Expand Down

0 comments on commit 5ce5d24

Please sign in to comment.