Skip to content

Commit

Permalink
Test write first seg to disk
Browse files Browse the repository at this point in the history
  • Loading branch information
mjh1 committed Feb 20, 2025
1 parent 232df3a commit a801afc
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions server/ai_live_video.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func startTrickleSubscribe(ctx context.Context, url *url.URL, params aiRequestPa
seq := trickle.GetSeq(segment)
clog.V(8).Infof(ctx, "trickle subscribe read data received seq=%d", seq)

n, err := copySegment(segment, multiWriter)
n, err := copySegment(segment, multiWriter, firstSegment)

Check warning on line 218 in server/ai_live_video.go

View check run for this annotation

Codecov / codecov/patch

server/ai_live_video.go#L218

Added line #L218 was not covered by tests
if err != nil {
params.liveParams.stopPipeline(fmt.Errorf("trickle subscribe error copying: %w", err))
return
Expand Down Expand Up @@ -274,9 +274,19 @@ func ffmpegOutput(ctx context.Context, outputUrl string, r io.ReadCloser, params
}
}

func copySegment(segment *http.Response, w io.Writer) (int64, error) {
func copySegment(segment *http.Response, w io.Writer, first bool) (int64, error) {

Check warning on line 277 in server/ai_live_video.go

View check run for this annotation

Codecov / codecov/patch

server/ai_live_video.go#L277

Added line #L277 was not covered by tests
defer segment.Body.Close()
return io.Copy(w, segment.Body)
var r io.Reader = segment.Body
if first {
outputfile, err := os.Create("/tmp/firstseg.ts")
if err != nil {
clog.Errorf(context.Background(), "Error creating first segment file: %v", err)
} else {
r = io.TeeReader(segment.Body, outputfile)
}

Check warning on line 286 in server/ai_live_video.go

View check run for this annotation

Codecov / codecov/patch

server/ai_live_video.go#L279-L286

Added lines #L279 - L286 were not covered by tests
}

return io.Copy(w, r)

Check warning on line 289 in server/ai_live_video.go

View check run for this annotation

Codecov / codecov/patch

server/ai_live_video.go#L289

Added line #L289 was not covered by tests
}

func startControlPublish(control *url.URL, params aiRequestParams) {
Expand Down

0 comments on commit a801afc

Please sign in to comment.