-
Notifications
You must be signed in to change notification settings - Fork 0
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
Multi channel #6
Open
megaadam
wants to merge
3
commits into
main
Choose a base branch
from
multi-channel
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
3 commits
Select commit
Hold shift + click to select a range
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 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
module github.com/edgeware/v2l-example-scheduler | ||
|
||
go 1.17 | ||
|
||
require github.com/edgeware/sbgo v0.0.0-20220517144721-cf8cceab4ebd |
This file contains 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 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 |
---|---|---|
|
@@ -3,10 +3,14 @@ package v2l | |
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"io/fs" | ||
"math/rand" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/edgeware/sbgo/pkg/esf" | ||
) | ||
|
||
// DeleteAllAssetPaths - delete all asset paths from server | ||
|
@@ -54,56 +58,63 @@ func DiscoverAssetPaths(dir string) ([]AssetPath, error) { | |
} | ||
assetPath := filepath.Dir(absAssetPath) // The dir containing content_info.json | ||
assetName := filepath.Base(assetPath) | ||
aps = append(aps, AssetPath{assetName, assetPath}) | ||
assetLen, err := getAssetLen(absAssetPath) | ||
if err != nil { | ||
return err | ||
} | ||
aps = append(aps, AssetPath{assetName, assetPath, assetLen}) | ||
} | ||
return nil | ||
}) | ||
return aps, err | ||
} | ||
|
||
// randomEntry - return a random entry given kind and assetPaths. Set offset, length, sctedID | ||
func randomEntry(assetPaths []AssetPath, kind string, offset, length, scteID int64) Entry { | ||
var programs []string | ||
var ads []string | ||
var fillers []string | ||
var slates []string | ||
func randomEntry(assetPaths []AssetPath, kind string, scteID int64) Entry { | ||
var selectedAssets []AssetPath | ||
var subPath = "/" + kind + "s/" | ||
for _, ap := range assetPaths { | ||
if strings.Contains(ap.Path, "/filler") { | ||
fillers = append(fillers, ap.ID) | ||
continue | ||
} | ||
if strings.Contains(ap.Path, "/slates/") { | ||
fillers = append(fillers, ap.ID) | ||
continue | ||
} | ||
if strings.Contains(ap.Path, "/ads/") { | ||
ads = append(ads, ap.ID) | ||
continue | ||
if strings.Contains(ap.Path, subPath) { | ||
selectedAssets = append(selectedAssets, ap) | ||
} | ||
programs = append(programs, ap.ID) | ||
} | ||
var assetID string | ||
switch kind { | ||
case "filler": | ||
idx := rand.Intn(len(fillers)) | ||
assetID = fillers[idx] | ||
case "slates": | ||
idx := rand.Intn(len(slates)) | ||
assetID = slates[idx] | ||
case "program": | ||
idx := rand.Intn(len(programs)) | ||
assetID = programs[idx] | ||
case "ad": | ||
idx := rand.Intn(len(ads)) | ||
assetID = ads[idx] | ||
default: | ||
panic("Unknown kind of asset") | ||
|
||
if len(selectedAssets) == 0 { | ||
panic("No such asset kind: " + kind) | ||
} | ||
|
||
asset := selectedAssets[rand.Intn(len(selectedAssets))] | ||
|
||
return Entry{ | ||
Name: assetID, | ||
AssetID: assetID, | ||
Offset: offset, | ||
Len: length, | ||
Name: asset.ID, | ||
AssetID: asset.ID, | ||
Offset: 0, | ||
Len: asset.len, | ||
SCTEEventID: scteID, | ||
} | ||
} | ||
|
||
// getAssetLen -- get length in number of GoPs | ||
func getAssetLen(assetPath string) (int64, error) { | ||
bytes, err := os.ReadFile(assetPath) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
ci, err := esf.ParseContentInfo(bytes) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: get duration from a dat file instead, |
||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
cd := ci.ContentDurationMS | ||
if cd == 0 { | ||
return 0, fmt.Errorf("\"content_duration_ms\" not found") | ||
} | ||
|
||
gd := ci.GOPDurationMS | ||
if gd == 0 { | ||
return 0, fmt.Errorf("\"constant_gop_duration_ms\" not found") | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And JSON here too |
||
|
||
return cd / gd, nil | ||
} |
Oops, something went wrong.
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.
I'd suggest that you do the modulo operation right away, so that one does not suspect an error. index should be less than nrOfChannels. From a performance point of view, it is also better to write it as
chIndex++
if chIndex == nrOfChannels {
chIndex -= nrOfChannels
}
since divisions and mod are very expensive operations.
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.
or rather this