Skip to content

Commit

Permalink
Merge pull request #1195 from skrashevich/fix-append-dot
Browse files Browse the repository at this point in the history
fix(streams): handle missing codec_name in appendDOT function
  • Loading branch information
AlexxIT committed Jun 16, 2024
2 parents 31e57c2 + 906f554 commit d7286fa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
14 changes: 12 additions & 2 deletions internal/streams/dot.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,28 @@ type node struct {

var codecKeys = []string{"codec_name", "sample_rate", "channels", "profile", "level"}

func (n *node) name() string {
if name, ok := n.Codec["codec_name"].(string); ok {
return name
}
return "unknown"
}

func (n *node) codec() []byte {
b := make([]byte, 0, 128)
for _, k := range codecKeys {
if v := n.Codec[k]; v != nil {
b = fmt.Appendf(b, "%s=%v\n", k, v)
}
}
return b[:len(b)-1]
if l := len(b); l > 0 {
return b[:l-1]
}
return b
}

func (n *node) appendDOT(dot []byte, group string) []byte {
dot = fmt.Appendf(dot, "%d [group=%s, label=%q, title=%q];\n", n.ID, group, n.Codec["codec_name"], n.codec())
dot = fmt.Appendf(dot, "%d [group=%s, label=%q, title=%q];\n", n.ID, group, n.name(), n.codec())
//for _, sink := range n.Childs {
// dot = fmt.Appendf(dot, "%d -> %d;\n", n.ID, sink)
//}
Expand Down
8 changes: 7 additions & 1 deletion pkg/core/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,14 @@ func FFmpegCodecName(name string) string {
return "vp9"
case CodecAV1:
return "av1"
case CodecELD:
return "aac/eld"
case CodecFLAC:
return "flac"
case CodecMP3:
return "mp3"
}
return ""
return name
}

func (c *Codec) String() (s string) {
Expand Down

0 comments on commit d7286fa

Please sign in to comment.