Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Jan 5, 2023
1 parent e0f81df commit f28a3c6
Show file tree
Hide file tree
Showing 10 changed files with 828 additions and 45 deletions.
36 changes: 36 additions & 0 deletions format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ const (
MPEG_PES_PACKET = "mpeg_pes_packet"
MPEG_SPU = "mpeg_spu"
MPEG_TS = "mpeg_ts"
MPEG_TS_PACKET = "mpeg_ts_packet"
MPEG_TS_PAT = "mpeg_ts_pat"
MPEG_TS_PMT = "mpeg_ts_pmt"
MPEG_TS_SDT = "mpeg_ts_sdt"
MSGPACK = "msgpack"
OGG = "ogg"
OGG_PAGE = "ogg_page"
Expand Down Expand Up @@ -327,3 +331,35 @@ type CSVLIn struct {
type BitCoinBlockIn struct {
HasHeader bool `doc:"Has blkdat header"`
}

type MpegTsStream struct {
ProgramPid int
Type int
}

type MpegTsProgram struct {
Number int
Pid int
StreamPids []int
}

type MpegTsPacketIn struct {
ProgramMap map[int]MpegTsProgram
StreamMap map[int]MpegTsStream
}

type MpegTsPacketOut struct {
Pid int
ContinuityCounter int
TransportScramblingControl int
PayloadUnitStart bool
Payload []byte
}

type MpegTsPatOut struct {
PidMap map[int]int // pid to program number that has pmt
}

type MpegTsPmtOut struct {
Streams map[int]MpegTsStream
}
59 changes: 32 additions & 27 deletions format/mpeg/mpeg_pes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package mpeg
// http://dvdnav.mplayerhq.hu/dvdinfo/mpeghdrs.html

import (
"log"

"github.com/wader/fq/format"
"github.com/wader/fq/pkg/bitio"
"github.com/wader/fq/pkg/decode"
Expand All @@ -19,8 +21,8 @@ func init() {
Name: format.MPEG_PES,
Description: "MPEG Packetized elementary stream",
DecodeFn: pesDecode,
RootArray: true,
RootName: "packets",
// RootArray: true,
RootName: "packets",
Dependencies: []decode.Dependency{
{Names: []string{format.MPEG_PES_PACKET}, Group: &pesPacketFormat},
{Names: []string{format.MPEG_SPU}, Group: &spuFormat},
Expand All @@ -45,36 +47,39 @@ func pesDecode(d *decode.D, _ any) any {

spuD := d.FieldArrayValue("spus")

for d.NotEnd() {
dv, v, err := d.TryFieldFormat("packet", pesPacketFormat, nil)
if dv == nil || err != nil {
break
}

switch dvv := v.(type) {
case subStreamPacket:
s, ok := substreams[dvv.number]
if !ok {
s = &subStream{}
substreams[dvv.number] = s
d.FieldArray("packets", func(d *decode.D) {
for d.NotEnd() {
dv, v, err := d.TryFieldFormat("packet", pesPacketFormat, nil)
if dv == nil || err != nil {
log.Printf("err: %#+v\n", err)
break
}
s.b = append(s.b, dvv.buf...)

if s.l == 0 && len(s.b) >= 2 {
s.l = int(s.b[0])<<8 | int(s.b[1])
// TODO: zero l?
switch dvv := v.(type) {
case subStreamPacket:
s, ok := substreams[dvv.number]
if !ok {
s = &subStream{}
substreams[dvv.number] = s
}
s.b = append(s.b, dvv.buf...)

if s.l == 0 && len(s.b) >= 2 {
s.l = int(s.b[0])<<8 | int(s.b[1])
// TODO: zero l?
}

// TODO: is this how spu end is signalled?
if s.l == len(s.b) {
spuD.FieldFormatBitBuf("spu", bitio.NewBitReader(s.b, -1), spuFormat, nil)
s.b = nil
s.l = 0
}
}

// TODO: is this how spu end is signalled?
if s.l == len(s.b) {
spuD.FieldFormatBitBuf("spu", bitio.NewBitReader(s.b, -1), spuFormat, nil)
s.b = nil
s.l = 0
}
i++
}

i++
}
})

return nil
}
6 changes: 3 additions & 3 deletions format/mpeg/mpeg_pes_packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ func pesPacketDecode(d *decode.D, _ any) any {
// nop
}

if d.BitsLeft() > 0 {
d.FieldRawLen("data", d.BitsLeft())
}
// if d.BitsLeft() > 0 {
// d.FieldRawLen("data", d.BitsLeft())
// }

return v
}
Loading

0 comments on commit f28a3c6

Please sign in to comment.