45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package media
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"sync/atomic"
|
|
|
|
"yovision.local/sense/app/sense/admission"
|
|
"yovision.local/sense/app/sense/identity"
|
|
)
|
|
|
|
var activeService atomic.Pointer[Service]
|
|
|
|
func setActiveService(service *Service) { activeService.Store(service) }
|
|
func PlaybackRoute(ctx context.Context, id string) (Route, error) {
|
|
service := activeService.Load()
|
|
if service == nil {
|
|
return Route{}, fmt.Errorf("media service is not ready")
|
|
}
|
|
return service.store.Get(ctx, id)
|
|
}
|
|
func RefreshPlaybackRoute(ctx context.Context, id string) (Route, error) {
|
|
service := activeService.Load()
|
|
if service == nil {
|
|
return Route{}, fmt.Errorf("media service is not ready")
|
|
}
|
|
return service.Refresh(ctx, id)
|
|
}
|
|
func PlaybackRoutes(ctx context.Context) ([]Route, error) {
|
|
service := activeService.Load()
|
|
if service == nil {
|
|
return nil, fmt.Errorf("media service is not ready")
|
|
}
|
|
return service.store.List(ctx)
|
|
}
|
|
|
|
func ConfigureReadyProfiles(ctx context.Context, actor identity.Principal, result admission.Result) admission.MediaOutcome {
|
|
service := activeService.Load()
|
|
if service == nil {
|
|
return admission.MediaOutcome{Status: "needs_attention", Detail: "摄像机已接入,媒体服务尚未就绪"}
|
|
}
|
|
return service.ConfigureProfiles(ctx, actor, result)
|
|
}
|
|
|