Skip to content

Commit

Permalink
chore: refactor and add livesim2 version to CMAF-ingest requests
Browse files Browse the repository at this point in the history
  • Loading branch information
tobbee committed Jan 15, 2025
1 parent c3baf65 commit 2b789af
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions cmd/livesim2/app/cmaf-ingester.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"sync/atomic"
"time"

"github.com/Dash-Industry-Forum/livesim2/internal"
"github.com/Dash-Industry-Forum/livesim2/pkg/cmaf"
m "github.com/Eyevinn/dash-mpd/mpd"
"github.com/Eyevinn/mp4ff/bits"
Expand Down Expand Up @@ -509,7 +510,8 @@ func setReqHeaders(req *http.Request, contentType, user, password string) {
default:
slog.Warn("unknown content type", "type", contentType)
}
setIngestHeader(req)
req.Header.Set("DASH-IF-Ingest", CMAFIngestVersion)
req.Header.Set("DASH-IF-livesim2", internal.GetVersion())
}

// sendMediaSegments sends all media segments for all representations. isLast triggers lmsg insertion.
Expand Down Expand Up @@ -616,7 +618,7 @@ func (c *cmafIngester) sendMediaSegment(ctx context.Context, wg *sync.WaitGroup,
http.Error(src, "writeSegment", http.StatusInternalServerError)
return
}
src.setReqHeaders(req)
setReqHeaders(req, src.contentType, src.user, src.password)
slog.Info("Sending media segment", "url", u)
err = c.sendRequest(ctx, req, u)
if err != nil {
Expand Down Expand Up @@ -675,7 +677,7 @@ func (cs *cmafSource) startReadAndSendChunked(ctx context.Context, finishedCh ch
cs.log.Error("creating request", "err", err)
return
}
cs.setReqHeaders(req)
setReqHeaders(req, cs.contentType, cs.user, cs.password)
cs.req = req
resp, err := http.DefaultClient.Do(req)
if err != nil {
Expand All @@ -697,11 +699,6 @@ func (cs *cmafSource) startReadAndSendChunked(ctx context.Context, finishedCh ch
finishedCh <- struct{}{}
}

func (cs *cmafSource) setReqHeaders(req *http.Request) {
setReqHeaders(req, cs.contentType, cs.user, cs.password)
req.Header.Set("Connection", "keep-alive")
}

func (cs *cmafSource) Header() http.Header {
return cs.h
}
Expand Down Expand Up @@ -833,7 +830,3 @@ func setRawInitProps(rawInit []byte, rd cmafRepData, startTimeS int64) (newRawIn
}
return sw.Bytes(), nil
}

func setIngestHeader(req *http.Request) {
req.Header.Set("DASH-IF-Ingest", CMAFIngestVersion)
}

0 comments on commit 2b789af

Please sign in to comment.