92 lines
3.5 KiB
Go
92 lines
3.5 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"droboticflow/internal/domain"
|
|
"droboticflow/internal/store"
|
|
"encoding/json"
|
|
"fmt"
|
|
"math"
|
|
"os/exec"
|
|
"strconv"
|
|
)
|
|
|
|
// Operational indexing needs readable media and a consistent frame identity,
|
|
// not proof that every original presentation timestamp is a perfect CFR clock.
|
|
func validateSourceMediaAvailability(ctx context.Context, path string, count int, duration float64) error {
|
|
if count < 2 || duration <= 0 || math.IsNaN(duration) || math.IsInf(duration, 0) {
|
|
return fmt.Errorf("invalid source media duration/count")
|
|
}
|
|
out, e := exec.CommandContext(ctx, "ffprobe", "-v", "error", "-select_streams", "v:0", "-show_entries", "stream=nb_frames", "-of", "json", path).Output()
|
|
if e != nil {
|
|
return fmt.Errorf("读取视频帧信息失败:%w", e)
|
|
}
|
|
var info struct {
|
|
Streams []struct {
|
|
Frames string `json:"nb_frames"`
|
|
} `json:"streams"`
|
|
}
|
|
if json.Unmarshal(out, &info) != nil || len(info.Streams) != 1 {
|
|
return fmt.Errorf("视频帧信息不可用")
|
|
}
|
|
n, e := strconv.Atoi(info.Streams[0].Frames)
|
|
if e != nil || n != count {
|
|
return fmt.Errorf("视频帧数与时间戳数量不一致")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Review the published source identity, not mutable original files or a later
|
|
// audit job. Existing physical revisions without this index retain their reader.
|
|
func (s *server) publishedAnnotationTimeline(ctx context.Context, task domain.AnnotationTaskRecord, item *domain.HumanItemRecord, camera string) (map[string]any, error) {
|
|
if !store.AnnotationSourceAuditAdvisory() || item == nil || item.CurrentStageID == "annotation_combined" || item.CurrentStageID == "semantic_annotation" || item.CurrentStageID == "split_annotation" {
|
|
return nil, nil
|
|
}
|
|
m := mapValue(item.Subject.Payload["materialization"])
|
|
if !boolValue(m["sourceIndex"]) || stringValue(m["artifactId"]) == "" {
|
|
return nil, nil
|
|
}
|
|
run, e := s.store.GetRun(ctx, task.RunID)
|
|
if e != nil {
|
|
return nil, e
|
|
}
|
|
if run == nil {
|
|
return nil, fmt.Errorf("annotation run unavailable")
|
|
}
|
|
a := artifactByID(run.Artifacts, stringValue(m["artifactId"]))
|
|
if a == nil {
|
|
return nil, nil
|
|
}
|
|
fp := stringValue(a.Data["sourceFingerprint"])
|
|
if fp == "" {
|
|
return nil, nil
|
|
}
|
|
db, ok := s.store.(store.AnnotationProcessingStore)
|
|
if !ok {
|
|
return nil, nil
|
|
}
|
|
for _, candidate := range []struct{ id, schema string }{{sourceCertificateID(task.OrganizationID, fp), sourceCertificateSchema}, {processingSourceID(task.OrganizationID, fp), processingSourceSchema}} {
|
|
r, e := db.GetAnnotationTimelineIndex(ctx, candidate.id)
|
|
if e != nil {
|
|
return nil, e
|
|
}
|
|
if r == nil {
|
|
continue
|
|
}
|
|
if r.OrganizationID != task.OrganizationID || r.ProjectID != task.ProjectID || r.RunID != task.RunID {
|
|
return nil, fmt.Errorf("published source scope mismatch")
|
|
}
|
|
c, e := decodeAnnotationSourceIndex(r, fp, candidate.schema)
|
|
if e != nil {
|
|
return nil, e
|
|
}
|
|
g := c.Timeline
|
|
count := g.LeftFrameCount
|
|
if camera == "right" {
|
|
count = g.RightFrameCount
|
|
}
|
|
return map[string]any{"camera": camera, "frameCount": count, "leftFrameCount": g.LeftFrameCount, "rightFrameCount": g.RightFrameCount, "originTimestampUs": g.Origin, "coverageEndTimestampUs": g.End, "boundariesSeconds": g.Seconds, "rightBoundariesSeconds": g.RightSeconds, "boundaryTimestampUs": g.Stamps, "leftFrameIndices": g.Left, "rightFrameIndices": g.Right, "rangeStartSecond": g.StartSecond, "rangeEndSecond": g.EndSecond, "boundaryContract": g.Contract, "ptsToMediaScale": g.Scale, "sourceFingerprint": fp}, nil
|
|
}
|
|
return nil, nil
|
|
}
|