Skip to content

Commit

Permalink
Transcript: support custom fix and overlay queue
Browse files Browse the repository at this point in the history
  • Loading branch information
limjoe committed Aug 17, 2024
1 parent 77e6ee8 commit fa51e36
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 4 deletions.
2 changes: 2 additions & 0 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,8 @@ For limit that you can control:

* `SRS_FORWARD_LIMIT`: The limit for SRS forward. Default: `10`.
* `SRS_VLIVE_LIMIT`: The limit for SRS virtual live. Default: `10`.
* `SRS_TRANSCRIPT_FIX_QUEUE_LIMIT`: The limit for SRS transcript manually fix queue. Default: `2`.
* `SRS_TRANSCRIPT_OVERLAY_QUEUE_LIMIT`: The limit for SRS transcript overlay queue. Default: `9`.

For feature control:

Expand Down
8 changes: 7 additions & 1 deletion platform/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,18 @@ func doMain(ctx context.Context) error {
setEnvDefault("SRS_VLIVE_LIMIT", "10")
setEnvDefault("SRS_CAMERA_LIMIT", "10")

// For transcript queue limit.
setEnvDefault("SRS_TRANSCRIPT_FIX_QUEUE_LIMIT", "2")
setEnvDefault("SRS_TRANSCRIPT_OVERLAY_QUEUE_LIMIT", "9")

logger.Tf(ctx, "load .env as MGMT_PASSWORD=%vB, GO_PPROF=%v, "+
"SRS_PLATFORM_SECRET=%vB, CLOUD=%v, REGION=%v, SOURCE=%v, SRT_PORT=%v, RTC_PORT=%v, "+
"NODE_ENV=%v, LOCAL_RELEASE=%v, REDIS_DATABASE=%v, REDIS_HOST=%v, REDIS_PASSWORD=%vB, REDIS_PORT=%v, RTMP_PORT=%v, "+
"PUBLIC_URL=%v, BUILD_PATH=%v, REACT_APP_LOCALE=%v, PLATFORM_LISTEN=%v, HTTP_PORT=%v, "+
"REGISTRY=%v, MGMT_LISTEN=%v, HTTPS_LISTEN=%v, AUTO_SELF_SIGNED_CERTIFICATE=%v, "+
"NAME_LOOKUP=%v, PLATFORM_DOCKER=%v, SRS_FORWARD_LIMIT=%v, SRS_VLIVE_LIMIT=%v, "+
"SRS_CAMERA_LIMIT=%v, YTDL_PROXY=%v",
"SRS_CAMERA_LIMIT=%v, YTDL_PROXY=%v"+
"SRS_TRANSCRIPT_FIX_QUEUE_LIMIT=%v, SRS_TRANSCRIPT_OVERLAY_QUEUE_LIMIT=%v",
len(envMgmtPassword()), envGoPprof(), len(envApiSecret()), envCloud(),
envRegion(), envSource(), envSrtListen(), envRtcListen(),
envNodeEnv(), envLocalRelease(),
Expand All @@ -149,6 +154,7 @@ func doMain(ctx context.Context) error {
envSelfSignedCertificate(), envNameLookup(),
envPlatformDocker(), envForwardLimit(), envVLiveLimit(),
envCameraLimit(), envYtdlProxy(),
envTranscriptFixQueueLimit(), envTranscriptOverlayQueueLimit(),
)

// Start the Go pprof if enabled.
Expand Down
67 changes: 64 additions & 3 deletions platform/transcript.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,39 @@ import (
"github.com/sashabaranov/go-openai"
)

// The total segments in overlay HLS.
const maxOverlaySegments = 9
// The default total segments in overlay HLS.
const defaultMaxOverlaySegments = 9

// Get the total segments in overlay HLS.
func GetMaxOverlaySegments() (int, error) {
var maxOverlaySegments int
if envTranscriptOverlayQueueLimit() != "" {
if iv, err := strconv.ParseInt(envTranscriptOverlayQueueLimit(), 10, 64); err != nil {
return defaultMaxOverlaySegments, errors.Wrapf(err, "parse env transcript overlay queue limit %v", envTranscriptOverlayQueueLimit())
} else {
maxOverlaySegments = int(iv)

Check failure

Code scanning / CodeQL

Incorrect conversion between integer types High

Incorrect conversion of a signed 64-bit integer from
strconv.ParseInt
to a lower bit size type int without an upper bound check.
}
}

return maxOverlaySegments, nil
}

// The default max fix queue limits.
const defaultMaxFixQueueLimit = 2

// Get the manually fix queue limit.
func GetMaxFixQueueLimit() (int, error) {
var maxFixQueueLimit int
if envTranscriptFixQueueLimit() != "" {
if iv, err := strconv.ParseInt(envTranscriptFixQueueLimit(), 10, 64); err != nil {
return defaultMaxFixQueueLimit, errors.Wrapf(err, "parse env transcript manually fix queue limit %v", envTranscriptFixQueueLimit())
} else {
maxFixQueueLimit = int(iv)

Check failure

Code scanning / CodeQL

Incorrect conversion between integer types High

Incorrect conversion of a signed 64-bit integer from
strconv.ParseInt
to a lower bit size type int without an upper bound check.
}
}

return maxFixQueueLimit, nil
}

var transcriptWorker *TranscriptWorker

Expand Down Expand Up @@ -1717,6 +1748,12 @@ func (v *TranscriptTask) DriveLiveQueue(ctx context.Context) error {
return nil
}

// Get the maxOverlaySegments value
maxOverlaySegments, err := GetMaxOverlaySegments()
if err != nil {
logger.Wf(ctx, "transcript: ignore get maxOverlaySegments err %+v, use default value %v", err, defaultMaxOverlaySegments)
}

// Wait if ASR queue is full.
if v.AsrQueue.count() >= maxOverlaySegments+1 {
return nil
Expand Down Expand Up @@ -1792,6 +1829,12 @@ func (v *TranscriptTask) DriveAsrQueue(ctx context.Context) error {
return nil
}

// Get the maxOverlaySegments value
maxOverlaySegments, err := GetMaxOverlaySegments()
if err != nil {
logger.Wf(ctx, "transcript: ignore get maxOverlaySegments err %+v, use default value %v", err, defaultMaxOverlaySegments)
}

// Wait if Fix queue is full.
if v.FixQueue.count() >= maxOverlaySegments+1 {
return nil
Expand Down Expand Up @@ -1917,8 +1960,14 @@ func (v *TranscriptTask) DriveFixQueue(ctx context.Context) error {
return nil
}

// Get the maxFixQueueLimit value
maxFixQueueLimit, err := GetMaxFixQueueLimit()
if err != nil {
logger.Wf(ctx, "transcript: ignore get maxFixQueueLimit err %+v, use default value %v", err, defaultMaxFixQueueLimit)
}

// Ignore if not enough segments.
if v.FixQueue.count() <= 2 {
if v.FixQueue.count() <= maxFixQueueLimit {
return nil
}

Expand All @@ -1937,6 +1986,12 @@ func (v *TranscriptTask) DriveFixQueue(ctx context.Context) error {
return nil
}

// Get the maxOverlaySegments value
maxOverlaySegments, err := GetMaxOverlaySegments()
if err != nil {
logger.Wf(ctx, "transcript: ignore get maxOverlaySegments err %+v, use default value %v", err, defaultMaxOverlaySegments)
}

// Wait if Overlay queue is full.
if v.OverlayQueue.count() >= maxOverlaySegments+1 {
return nil
Expand Down Expand Up @@ -2028,6 +2083,12 @@ func (v *TranscriptTask) DriveOverlayQueue(ctx context.Context) error {
return nil
}

// Get the maxOverlaySegments value
maxOverlaySegments, err := GetMaxOverlaySegments()
if err != nil {
logger.Wf(ctx, "transcript: ignore get maxOverlaySegments err %+v, use default value %v", err, defaultMaxOverlaySegments)
}

// Ignore if not enough segments.
if v.OverlayQueue.count() <= maxOverlaySegments {
select {
Expand Down
8 changes: 8 additions & 0 deletions platform/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,14 @@ func envYtdlProxy() string {
return os.Getenv("YTDL_PROXY")
}

func envTranscriptFixQueueLimit() string {
return os.Getenv("SRS_TRANSCRIPT_FIX_QUEUE_LIMIT")
}

func envTranscriptOverlayQueueLimit() string {
return os.Getenv("SRS_TRANSCRIPT_OVERLAY_QUEUE_LIMIT")
}

// rdb is a global redis client object.
var rdb *redis.Client

Expand Down

0 comments on commit fa51e36

Please sign in to comment.