-
Notifications
You must be signed in to change notification settings - Fork 128
Enabling PLC for opus decoder #992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
milos-lk
wants to merge
5
commits into
main
Choose a base branch
from
ops-plc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
126e7e7
Adding opusparse and enabling opus plc
milos-lk 79091d1
send opusdec stats message to the main bus for data gathering
milos-lk 2422aff
Updating audio qos with opusdec metrics
milos-lk 9bc3c1f
Making default opus duration a const and adding bounds check for uint…
milos-lk 2085705
Use regex key value scanner instead of in place functions
milos-lk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| package builder | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "log" | ||
| "regexp" | ||
| "time" | ||
|
|
||
| "github.com/go-gst/go-glib/glib" | ||
| "github.com/go-gst/go-gst/gst" | ||
| "github.com/livekit/protocol/logger" | ||
| "github.com/livekit/protocol/utils" | ||
| ) | ||
|
|
||
| const ( | ||
| OpusDecStatsStructName = "livekit-opus-plc-stats" | ||
| OpusDecStatsKeyPlcDurationNs = "plc-duration-ns" | ||
| OpusDecStatsKeyPlcNumSamples = "plc-num-samples" | ||
| OpusDecStatsKeyNumGap = "num-gap" | ||
| OpusDecStatsKeyNumPushed = "num-pushed" | ||
| ) | ||
|
|
||
| var ( | ||
| rePushed = regexp.MustCompile(`\bnum-pushed=\(g?uint64\)(\d+)`) | ||
| reGap = regexp.MustCompile(`\bnum-gap=\(g?uint64\)(\d+)`) | ||
| rePlcNumSamples = regexp.MustCompile(`\bplc-num-samples=\(g?uint64\)(\d+)`) | ||
| rePlcDuration = regexp.MustCompile(`\bplc-duration=\(g?uint64\)(\d+)`) | ||
| reSampleRate = regexp.MustCompile(`\bsample-rate=\(uint\)(\d+)`) | ||
| reChannels = regexp.MustCompile(`\bchannels=\(uint\)(\d+)`) | ||
| ) | ||
|
|
||
| type OpusDecStats struct { | ||
| NumPushed uint64 | ||
| NumGap uint64 | ||
| PlcNumSamples uint64 | ||
| PlcDuration time.Duration // ns | ||
| SampleRate uint64 | ||
| Channels uint64 | ||
| } | ||
|
|
||
| func serializeOpusStats(opusdec *gst.Element) (string, bool) { | ||
| gvAny, err := opusdec.GetProperty("stats") | ||
| if err != nil { | ||
| log.Printf("opusdec stats: get failed: %v", err) | ||
| return "", false | ||
| } | ||
| switch v := gvAny.(type) { | ||
| case *gst.Structure: | ||
| return v.String(), true | ||
| case *glib.Value: | ||
| return gst.ValueSerialize(v), true | ||
| case string: | ||
| return v, true | ||
| default: | ||
| log.Printf("opusdec stats: unexpected type %T", gvAny) | ||
| return "", false | ||
| } | ||
| } | ||
|
|
||
| /*** minimal parser for the serialized GstStructure ***/ | ||
|
|
||
| func parseStatsString(s string) (OpusDecStats, error) { | ||
| var st OpusDecStats | ||
|
|
||
| kv := utils.NewKVRegexScanner(s) | ||
|
|
||
| if v, ok := kv.Uint64(rePushed); ok { | ||
| st.NumPushed = v | ||
| } | ||
| if v, ok := kv.Uint64(reGap); ok { | ||
| st.NumGap = v | ||
| } | ||
| if v, ok := kv.Uint64(rePlcNumSamples); ok { | ||
| st.PlcNumSamples = v | ||
| } | ||
| if v, ok := kv.DurationNs(rePlcDuration); ok { | ||
| st.PlcDuration = v | ||
| } | ||
| if v, ok := kv.Uint64(reSampleRate); ok { | ||
| st.SampleRate = v | ||
| } | ||
| if v, ok := kv.Uint64(reChannels); ok { | ||
| st.Channels = v | ||
| } | ||
| return st, nil | ||
| } | ||
|
|
||
| func getOpusDecStats(opusdec *gst.Element) (OpusDecStats, error) { | ||
| ser, ok := serializeOpusStats(opusdec) | ||
| if !ok { | ||
| return OpusDecStats{}, fmt.Errorf("serialize error") | ||
| } | ||
| return parseStatsString(ser) | ||
| } | ||
|
|
||
| func postOpusDecStatsMessage(src *gst.Element, stats OpusDecStats) { | ||
| s := gst.NewStructureFromString( | ||
| fmt.Sprintf("%s, %s=(guint64)%d, %s=(guint64)%d, %s=(guint64)%d, %s=(guint64)%d", | ||
| OpusDecStatsStructName, | ||
| OpusDecStatsKeyPlcDurationNs, stats.PlcDuration.Nanoseconds(), | ||
| OpusDecStatsKeyPlcNumSamples, stats.PlcNumSamples, | ||
| OpusDecStatsKeyNumGap, stats.NumGap, | ||
| OpusDecStatsKeyNumPushed, stats.NumPushed, | ||
| )) | ||
| msg := gst.NewElementMessage(src, s) | ||
| sent := src.PostMessage(msg) | ||
| if !sent { | ||
| logger.Debugw("failed to send opusdec PLC stats") | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why 3ms?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
semi arbitrary chosen value :)
The case I had in mind was - if the gap is almost one frame (e.g., 18–19 ms when the true frame is 20 ms) still count it as a loss. That probably won't happen as long as we lose full packets. Added for the cases when wall-clock PTS adjustment kicks in (even then it's going to be extremely rare).