Skip to content

Commit

Permalink
Transcript: support custom fix and overlay queue code format
Browse files Browse the repository at this point in the history
  • Loading branch information
limjoe committed Aug 28, 2024
1 parent fa51e36 commit 7d39667
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 64 deletions.
7 changes: 7 additions & 0 deletions platform/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"path"
"path/filepath"
"runtime"
"strconv"
"strings"
"syscall"
"time"
Expand Down Expand Up @@ -134,7 +135,13 @@ func doMain(ctx context.Context) error {

// For transcript queue limit.
setEnvDefault("SRS_TRANSCRIPT_FIX_QUEUE_LIMIT", "2")
if _, err := strconv.ParseInt(envTranscriptFixQueueLimit(), 10, 64); err != nil {
return errors.Wrapf(err, "parse env transcript fix queue limit %v", envTranscriptFixQueueLimit())
}
setEnvDefault("SRS_TRANSCRIPT_OVERLAY_QUEUE_LIMIT", "9")
if _, err := strconv.ParseInt(envTranscriptOverlayQueueLimit(), 10, 64); err != nil {
return errors.Wrapf(err, "parse env transcript overlay queue limit %v", envTranscriptOverlayQueueLimit())
}

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, "+
Expand Down
79 changes: 15 additions & 64 deletions platform/transcript.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,6 @@ import (
"github.com/sashabaranov/go-openai"
)

// 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)
}
}

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)
}
}

return maxFixQueueLimit, nil
}

var transcriptWorker *TranscriptWorker

type TranscriptWorker struct {
Expand Down Expand Up @@ -1748,14 +1714,11 @@ 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)
}
// Get total segments in overlay HLS.
maxOverlaySegments, _ := strconv.ParseInt(envTranscriptOverlayQueueLimit(), 10, 64)

// Wait if ASR queue is full.
if v.AsrQueue.count() >= maxOverlaySegments+1 {
if v.AsrQueue.count() >= int(maxOverlaySegments)+1 {

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 nil
}

Expand Down Expand Up @@ -1829,14 +1792,11 @@ 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)
}
// Get total segments in overlay HLS.
maxOverlaySegments, _ := strconv.ParseInt(envTranscriptOverlayQueueLimit(), 10, 64)

// Wait if Fix queue is full.
if v.FixQueue.count() >= maxOverlaySegments+1 {
if v.FixQueue.count() >= int(maxOverlaySegments)+1 {

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 nil
}

Expand Down Expand Up @@ -1960,14 +1920,11 @@ 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)
}
// Get total segments in manually fix queue.
maxFixQueueLimit, _ := strconv.ParseInt(envTranscriptFixQueueLimit(), 10, 64)

// Ignore if not enough segments.
if v.FixQueue.count() <= maxFixQueueLimit {
if v.FixQueue.count() <= int(maxFixQueueLimit) {

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 nil
}

Expand All @@ -1986,14 +1943,11 @@ 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)
}
// Get total segments in overlay HLS.
maxOverlaySegments, _ := strconv.ParseInt(envTranscriptOverlayQueueLimit(), 10, 64)

// Wait if Overlay queue is full.
if v.OverlayQueue.count() >= maxOverlaySegments+1 {
if v.OverlayQueue.count() >= int(maxOverlaySegments)+1 {

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 nil
}

Expand Down Expand Up @@ -2083,14 +2037,11 @@ 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)
}
// Get total segments in overlay HLS.
maxOverlaySegments, _ := strconv.ParseInt(envTranscriptOverlayQueueLimit(), 10, 64)

// Ignore if not enough segments.
if v.OverlayQueue.count() <= maxOverlaySegments {
if v.OverlayQueue.count() <= int(maxOverlaySegments) {

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.
select {
case <-ctx.Done():
case <-time.After(1 * time.Second):
Expand Down

0 comments on commit 7d39667

Please sign in to comment.