Code refactoring after #1195
This commit is contained in:
+15
-10
@@ -67,6 +67,13 @@ 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 {
|
||||
@@ -74,20 +81,18 @@ func (n *node) codec() []byte {
|
||||
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, error) {
|
||||
codecName, ok := n.Codec["codec_name"]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("codec_name not found in Codec map")
|
||||
}
|
||||
|
||||
dot = fmt.Appendf(dot, "%d [group=%s, label=%q, title=%q];\n", n.ID, group, codecName, n.codec())
|
||||
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.name(), n.codec())
|
||||
//for _, sink := range n.Childs {
|
||||
// dot = fmt.Appendf(dot, "%d -> %d;\n", n.ID, sink)
|
||||
//}
|
||||
return dot, nil
|
||||
return dot
|
||||
}
|
||||
|
||||
type conn struct {
|
||||
@@ -116,7 +121,7 @@ func (c *conn) appendDOT(dot []byte, group string) []byte {
|
||||
|
||||
for _, recv := range c.Receivers {
|
||||
dot = fmt.Appendf(dot, "%d -> %d [label=%q];\n", c.ID, recv.ID, humanBytes(recv.Bytes))
|
||||
dot, _ = recv.appendDOT(dot, "node") // TODO: handle error for debug purposes
|
||||
dot = recv.appendDOT(dot, "node")
|
||||
}
|
||||
for _, send := range c.Senders {
|
||||
dot = fmt.Appendf(dot, "%d -> %d [label=%q];\n", send.Parent, c.ID, humanBytes(send.Bytes))
|
||||
|
||||
+7
-1
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user