Skip to content

Commit

Permalink
format: Some claeanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Nov 19, 2021
1 parent 527f917 commit d1b514e
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 43 deletions.
6 changes: 3 additions & 3 deletions format/flac/flac_metadatablocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ func metadatablocksDecode(d *decode.D, in interface{}) interface{} {

isLastBlock := false
for !isLastBlock {
v, dv := d.FieldFormat("metadatablock", flacMetadatablockForamt, nil)
flacMetadatablockOut, ok := dv.(format.FlacMetadatablockOut)
if v != nil && !ok {
dv, v := d.FieldFormat("metadatablock", flacMetadatablockForamt, nil)
flacMetadatablockOut, ok := v.(format.FlacMetadatablockOut)
if dv != nil && !ok {
panic(fmt.Sprintf("expected FlacMetadatablocksOut, got %#+v", flacMetadatablockOut))
}
isLastBlock = flacMetadatablockOut.IsLastBlock
Expand Down
18 changes: 9 additions & 9 deletions format/matroska/matroska.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,9 @@ func matroskaDecode(d *decode.D, in interface{}) interface{} {
t.parentD.RangeFn(t.codecPrivatePos, t.codecPrivateTagSize, func(d *decode.D) {
d.FieldStruct("value", func(d *decode.D) {
d.FieldUTF8("magic", 4, d.AssertStr("fLaC"))
v, dv := d.FieldFormat("metadatablocks", flacMetadatablocksFormat, nil)
flacMetadatablockOut, ok := dv.(format.FlacMetadatablocksOut)
if v != nil && !ok {
dv, v := d.FieldFormat("metadatablocks", flacMetadatablocksFormat, nil)
flacMetadatablockOut, ok := v.(format.FlacMetadatablocksOut)
if dv != nil && !ok {
panic(fmt.Sprintf("expected FlacMetadatablockOut got %#+v", v))
}
if flacMetadatablockOut.HasStreamInfo {
Expand All @@ -371,16 +371,16 @@ func matroskaDecode(d *decode.D, in interface{}) interface{} {
})
})
case "V_MPEG4/ISO/AVC":
v, dv := t.parentD.FieldFormatRange("value", t.codecPrivatePos, t.codecPrivateTagSize, mpegAVCDCRFormat, nil)
avcDcrOut, ok := dv.(format.AvcDcrOut)
if v != nil && !ok {
dv, v := t.parentD.FieldFormatRange("value", t.codecPrivatePos, t.codecPrivateTagSize, mpegAVCDCRFormat, nil)
avcDcrOut, ok := v.(format.AvcDcrOut)
if dv != nil && !ok {
panic(fmt.Sprintf("expected AvcDcrOut got %#+v", v))
}
t.formatInArg = format.AvcIn{LengthSize: avcDcrOut.LengthSize} //nolint:gosimple
case "V_MPEGH/ISO/HEVC":
v, dv := t.parentD.FieldFormatRange("value", t.codecPrivatePos, t.codecPrivateTagSize, mpegHEVCDCRFormat, nil)
hevcDcrOut, ok := dv.(format.HevcDcrOut)
if v != nil && !ok {
dv, v := t.parentD.FieldFormatRange("value", t.codecPrivatePos, t.codecPrivateTagSize, mpegHEVCDCRFormat, nil)
hevcDcrOut, ok := v.(format.HevcDcrOut)
if dv != nil && !ok {
panic(fmt.Sprintf("expected HevcDcrOut got %#+v", v))
}
t.formatInArg = format.HevcIn{LengthSize: hevcDcrOut.LengthSize} //nolint:gosimple
Expand Down
13 changes: 8 additions & 5 deletions format/mp3/mp3.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ func init() {
DecodeFn: mp3Decode,
Dependencies: []decode.Dependency{
{Names: []string{format.ID3V2}, Group: &headerFormat},
{Names: []string{
format.ID3V1,
format.ID3V11,
format.APEV2,
}, Group: &footerFormat},
{
Names: []string{
format.ID3V1,
format.ID3V11,
format.APEV2,
},
Group: &footerFormat,
},
{Names: []string{format.MP3_FRAME}, Group: &mp3Frame},
},
})
Expand Down
24 changes: 12 additions & 12 deletions format/mp4/boxes.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,19 +431,19 @@ func init() {
})
},
"avcC": func(ctx *decodeContext, d *decode.D) {
v, dv := d.FieldFormat("descriptor", mpegAVCDCRFormat, nil)
avcDcrOut, ok := dv.(format.AvcDcrOut)
if v != nil && !ok {
dv, v := d.FieldFormat("descriptor", mpegAVCDCRFormat, nil)
avcDcrOut, ok := v.(format.AvcDcrOut)
if dv != nil && !ok {
panic(fmt.Sprintf("expected AvcDcrOut got %#+v", v))
}
if ctx.currentTrack != nil {
ctx.currentTrack.formatInArg = format.AvcIn{LengthSize: avcDcrOut.LengthSize} //nolint:gosimple
}
},
"hvcC": func(ctx *decodeContext, d *decode.D) {
v, dv := d.FieldFormat("descriptor", mpegHEVCDCRFrameFormat, nil)
hevcDcrOut, ok := dv.(format.HevcDcrOut)
if v != nil && !ok {
dv, v := d.FieldFormat("descriptor", mpegHEVCDCRFrameFormat, nil)
hevcDcrOut, ok := v.(format.HevcDcrOut)
if dv != nil && !ok {
panic(fmt.Sprintf("expected HevcDcrOut got %#+v", v))
}
if ctx.currentTrack != nil {
Expand All @@ -453,9 +453,9 @@ func init() {
"dfLa": func(ctx *decodeContext, d *decode.D) {
d.FieldU8("version")
d.FieldU24("flags")
v, dv := d.FieldFormat("descriptor", flacMetadatablocksFormat, nil)
flacMetadatablockOut, ok := dv.(format.FlacMetadatablocksOut)
if v != nil && !ok {
dv, v := d.FieldFormat("descriptor", flacMetadatablocksFormat, nil)
flacMetadatablockOut, ok := v.(format.FlacMetadatablocksOut)
if dv != nil && !ok {
panic(fmt.Sprintf("expected FlacMetadatablockOut got %#+v", v))
}
if flacMetadatablockOut.HasStreamInfo {
Expand All @@ -478,9 +478,9 @@ func init() {
"esds": func(ctx *decodeContext, d *decode.D) {
d.FieldU32("version")

v, dv := d.FieldFormat("descriptor", mpegESFormat, nil)
mpegEsOut, ok := dv.(format.MpegEsOut)
if v != nil && !ok {
dv, v := d.FieldFormat("descriptor", mpegESFormat, nil)
mpegEsOut, ok := v.(format.MpegEsOut)
if dv != nil && !ok {
panic(fmt.Sprintf("expected mpegEsOut got %#+v", v))
}

Expand Down
6 changes: 3 additions & 3 deletions format/mpeg/mpeg_es.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ func odDecodeTag(d *decode.D, edc *esDecodeContext, expectedTagID int, fn func(d
switch format.MpegObjectTypeStreamType[objectType] {
case format.MPEGStreamTypeAudio:
fieldODDecodeTag(d, edc, "decoder_specific_info", -1, func(d *decode.D) {
v, dv := d.FieldFormat("audio_specific_config", mpegASCFormat, nil)
mpegASCout, ok := dv.(format.MPEGASCOut)
if v != nil && !ok {
dv, v := d.FieldFormat("audio_specific_config", mpegASCFormat, nil)
mpegASCout, ok := v.(format.MPEGASCOut)
if dv != nil && !ok {
panic(fmt.Sprintf("expected MPEGASCOut got %#+v", v))
}
if edc.currentDecoderConfig != nil {
Expand Down
1 change: 0 additions & 1 deletion format/mpeg/mpeg_pes_packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ func pesPacketDecode(d *decode.D, in interface{}) interface{} {
}
})
case startCode >= 0xbd:
//log.Printf("startCode: %#+v\n", startCode)
length := d.FieldU16("length")
// 0xbd-0xbd // Privatestream1
// 0xc0-0xdf // MPEG1OrMPEG2AudioStream
Expand Down
6 changes: 1 addition & 5 deletions format/mpeg/mpeg_spu.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var commandNames = decode.UToStr{
func rleValue(d *decode.D) (uint64, uint64, int) {
p := uint(d.PeekBits(8))

// match zero prefix
switch {
case p&0b1111_1100 == 0:
// 000000nnnnnnnncc
Expand Down Expand Up @@ -80,17 +81,12 @@ func decodeLines(d *decode.D, lines int, width int) []string { //nolint:unparam
pixel = fmt.Sprintf("%d", c)
}

//log.Printf("n=%d c=%d b=%d\n", n, c, b)

if n == 0 && b == 16 {
l += strings.Repeat(pixel, width-len(l))
break
}

x += int(n)

//log.Printf("n: %d c %d b %d\n", n, c, b)
// l += strings.Repeat(pixel, int(n))
}
if d.ByteAlignBits() > 0 {
d.U(d.ByteAlignBits())
Expand Down
8 changes: 3 additions & 5 deletions format/ogg/ogg.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ func decodeOgg(d *decode.D, in interface{}) interface{} {
d.FieldU8("minor")
d.FieldU16("header_packets")
d.FieldUTF8("flac_signature", 4)
v, dv := d.FieldFormat("metadatablock", flacMetadatablockFormat, nil)
flacMetadatablockOut, ok := dv.(format.FlacMetadatablockOut)
if v != nil && !ok {
dv, v := d.FieldFormat("metadatablock", flacMetadatablockFormat, nil)
flacMetadatablockOut, ok := v.(format.FlacMetadatablockOut)
if dv != nil && !ok {
panic(fmt.Sprintf("expected FlacMetadatablockOut, got %#+v", flacMetadatablockOut))
}
s.flacStreamInfo = flacMetadatablockOut.StreamInfo
Expand All @@ -158,8 +158,6 @@ func decodeOgg(d *decode.D, in interface{}) interface{} {
s.packetD.FieldFormatBitBuf("packet", bb, flacFrameFormat, nil)
default:
s.packetD.FieldFormatBitBuf("packet", bb, flacMetadatablockFormat, nil)

//d.Format(flacFrame, nil)
}
case codecUnknown:
s.packetD.FieldRootBitBuf("packet", bb)
Expand Down

0 comments on commit d1b514e

Please sign in to comment.