Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump Golang to 1.23 #173

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@ jobs:
golangci-lint:
runs-on: ubuntu-22.04

env:
CGO_ENABLED: '0'

steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v3
with:
go-version: "1.22"
go-version: "1.23"

- uses: golangci/golangci-lint-action@v3
with:
version: v1.59.1
version: v1.61.0

go-mod-tidy:
runs-on: ubuntu-22.04
Expand All @@ -29,7 +32,7 @@ jobs:

- uses: actions/setup-go@v3
with:
go-version: "1.22"
go-version: "1.23"

- run: |
go mod tidy
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
go: ["1.20", "1.21", "1.22"]
go: ["1.21", "1.22", "1.23"]

steps:
- uses: actions/checkout@v4
Expand All @@ -24,7 +24,7 @@ jobs:

- run: make test-nodocker

- if: matrix.go == '1.22'
- if: matrix.go == '1.23'
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BASE_IMAGE = golang:1.22-alpine3.18
LINT_IMAGE = golangci/golangci-lint:v1.59.1
BASE_IMAGE = golang:1.23-alpine3.20
LINT_IMAGE = golangci/golangci-lint:v1.61.0

.PHONY: $(shell ls)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

HLS client and muxer library for the Go programming language, written for [MediaMTX](https://github.com/bluenviron/mediamtx).

Go ≥ 1.20 is required.
Go ≥ 1.21 is required.

Features:

Expand Down
3 changes: 3 additions & 0 deletions examples/client-codec-h264-convert-to-jpeg/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build cgo
// +build cgo

package main

import (
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/bluenviron/gohlslib/v2

go 1.20
go 1.21

require (
github.com/asticode/go-astits v1.13.0
Expand Down
12 changes: 4 additions & 8 deletions muxer.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (m *Muxer) Start() error {
}
hasVideo = true
} else {
hasAudio = true
hasAudio = true //nolint:ineffassign,wastedassign
}
}
}
Expand Down Expand Up @@ -245,13 +245,9 @@ func (m *Muxer) Start() error {
m.mtracksByTrack[track] = mtrack
}

if m.Variant == MuxerVariantMPEGTS {
// nothing
} else {
// add initial gaps, required by iOS LL-HLS
if m.Variant == MuxerVariantLowLatency {
m.nextSegmentID = 7
}
// add initial gaps, required by iOS LL-HLS
if m.Variant == MuxerVariantLowLatency {
m.nextSegmentID = 7
}

switch {
Expand Down
116 changes: 59 additions & 57 deletions muxer_segmenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,23 +351,21 @@

if s.muxer.Variant == MuxerVariantMPEGTS {
if track.stream.nextSegment == nil {
err := s.muxer.createFirstSegment(timestampToDuration(dts, track.ClockRate), ntp)
err = s.muxer.createFirstSegment(timestampToDuration(dts, track.ClockRate), ntp)
if err != nil {
return err
}
} else {
// switch segment
if randomAccess &&
((timestampToDuration(dts, track.ClockRate)-track.stream.nextSegment.(*muxerSegmentMPEGTS).startDTS) >= s.muxer.SegmentMinDuration ||
paramsChanged) {
err := s.muxer.rotateSegments(timestampToDuration(dts, track.ClockRate), ntp, false)
if err != nil {
return err
}
} else if randomAccess && // switch segment
((timestampToDuration(dts, track.ClockRate)-
track.stream.nextSegment.(*muxerSegmentMPEGTS).startDTS) >= s.muxer.SegmentMinDuration ||
paramsChanged) {
err = s.muxer.rotateSegments(timestampToDuration(dts, track.ClockRate), ntp, false)
if err != nil {
return err

Check warning on line 364 in muxer_segmenter.go

View check run for this annotation

Codecov / codecov/patch

muxer_segmenter.go#L364

Added line #L364 was not covered by tests
}
}

err := track.stream.nextSegment.(*muxerSegmentMPEGTS).writeH264(
err = track.stream.nextSegment.(*muxerSegmentMPEGTS).writeH264(
track,
pts,
dts,
Expand All @@ -379,25 +377,25 @@
}

return nil
} else {
ps, err := fmp4.NewPartSampleH26x(
int32(pts-dts),
randomAccess,
au)
if err != nil {
return err
}
}

return s.fmp4WriteSample(
track,
randomAccess,
paramsChanged,
&fmp4AugmentedSample{
PartSample: *ps,
dts: dts,
ntp: ntp,
})
ps, err := fmp4.NewPartSampleH26x(
int32(pts-dts),
randomAccess,
au)
if err != nil {
return err

Check warning on line 387 in muxer_segmenter.go

View check run for this annotation

Codecov / codecov/patch

muxer_segmenter.go#L387

Added line #L387 was not covered by tests
}

return s.fmp4WriteSample(
track,
randomAccess,
paramsChanged,
&fmp4AugmentedSample{
PartSample: *ps,
dts: dts,
ntp: ntp,
})
}

func (s *muxerSegmenter) writeOpus(
Expand Down Expand Up @@ -445,7 +443,8 @@
return err
}
} else if track.stream.nextSegment.(*muxerSegmentMPEGTS).audioAUCount >= mpegtsSegmentMinAUCount && // switch segment
(timestampToDuration(pts, track.ClockRate)-track.stream.nextSegment.(*muxerSegmentMPEGTS).startDTS) >= s.muxer.SegmentMinDuration {
(timestampToDuration(pts, track.ClockRate)-
track.stream.nextSegment.(*muxerSegmentMPEGTS).startDTS) >= s.muxer.SegmentMinDuration {
err := s.muxer.rotateSegments(timestampToDuration(pts, track.ClockRate), ntp, false)
if err != nil {
return err
Expand All @@ -464,34 +463,34 @@
}

return nil
} else {
sampleRate := track.Codec.(*codecs.MPEG4Audio).Config.SampleRate

for i, au := range aus {
auNTP := ntp.Add(time.Duration(i) * mpeg4audio.SamplesPerAccessUnit *
time.Second / time.Duration(sampleRate))
auPTS := pts + int64(i)*mpeg4audio.SamplesPerAccessUnit*
int64(track.ClockRate)/int64(sampleRate)

err := s.fmp4WriteSample(
track,
true,
false,
&fmp4AugmentedSample{
PartSample: fmp4.PartSample{
Payload: au,
},
dts: auPTS,
ntp: auNTP,
}

sampleRate := track.Codec.(*codecs.MPEG4Audio).Config.SampleRate

for i, au := range aus {
auNTP := ntp.Add(time.Duration(i) * mpeg4audio.SamplesPerAccessUnit *
time.Second / time.Duration(sampleRate))
auPTS := pts + int64(i)*mpeg4audio.SamplesPerAccessUnit*
int64(track.ClockRate)/int64(sampleRate)

err := s.fmp4WriteSample(
track,
true,
false,
&fmp4AugmentedSample{
PartSample: fmp4.PartSample{
Payload: au,
},
)
if err != nil {
return err
}
dts: auPTS,
ntp: auNTP,
},
)
if err != nil {
return err

Check warning on line 489 in muxer_segmenter.go

View check run for this annotation

Codecov / codecov/patch

muxer_segmenter.go#L489

Added line #L489 was not covered by tests
}

return nil
}

return nil
}

// iPhone iOS fails if part durations are less than 85% of maximum part duration.
Expand Down Expand Up @@ -567,8 +566,10 @@
if track.isLeading {
// switch segment
if randomAccess && (paramsChanged ||
(timestampToDuration(track.fmp4NextSample.dts, track.ClockRate)-track.stream.nextSegment.(*muxerSegmentFMP4).startDTS) >= s.muxer.SegmentMinDuration) {
err = s.muxer.rotateSegments(timestampToDuration(track.fmp4NextSample.dts, track.ClockRate), track.fmp4NextSample.ntp, paramsChanged)
(timestampToDuration(track.fmp4NextSample.dts, track.ClockRate)-
track.stream.nextSegment.(*muxerSegmentFMP4).startDTS) >= s.muxer.SegmentMinDuration) {
err = s.muxer.rotateSegments(timestampToDuration(track.fmp4NextSample.dts, track.ClockRate),
track.fmp4NextSample.ntp, paramsChanged)
if err != nil {
return err
}
Expand All @@ -583,7 +584,8 @@

// switch part
} else if (s.muxer.Variant == MuxerVariantLowLatency) &&
(timestampToDuration(track.fmp4NextSample.dts, track.ClockRate)-track.stream.nextPart.startDTS) >= s.fmp4AdjustedPartDuration {
(timestampToDuration(track.fmp4NextSample.dts, track.ClockRate)-
track.stream.nextPart.startDTS) >= s.fmp4AdjustedPartDuration {
err := s.muxer.rotateParts(timestampToDuration(track.fmp4NextSample.dts, track.ClockRate))
if err != nil {
return err
Expand Down
11 changes: 6 additions & 5 deletions muxer_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ func (s *muxerStream) handleMediaPlaylist(w http.ResponseWriter, r *http.Request
}

func (s *muxerStream) generateMediaPlaylistMPEGTS(
isDeltaUpdate bool,
_ bool,
rawQuery string,
) ([]byte, error) {
pl := &playlist.Media{
Expand Down Expand Up @@ -728,8 +728,8 @@ func (s *muxerStream) rotateSegments(
s.segments = append(s.segments, segment)

s.muxer.server.pathHandlers[segment.getPath()] = func(w http.ResponseWriter, _ *http.Request) {
r, err := segment.reader()
if err != nil {
r, err2 := segment.reader()
if err2 != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
Expand Down Expand Up @@ -771,7 +771,7 @@ func (s *muxerStream) rotateSegments(

// regenerate init files only if missing or codec parameters have changed
if s.muxer.Variant != MuxerVariantMPEGTS && (!s.initFilePresent || segment.isFromForcedRotation()) {
err := s.generateAndCacheInitFile()
err = s.generateAndCacheInitFile()
if err != nil {
return err
}
Expand All @@ -782,7 +782,8 @@ func (s *muxerStream) rotateSegments(
if s.muxer.targetDuration == 0 {
s.muxer.targetDuration = targetDuration
} else if targetDuration > s.muxer.targetDuration {
s.muxer.OnEncodeError(fmt.Errorf("segment duration changed from %ds to %ds - this will cause an error in iOS clients",
s.muxer.OnEncodeError(fmt.Errorf(
"segment duration changed from %ds to %ds - this will cause an error in iOS clients",
s.muxer.targetDuration, targetDuration))
s.muxer.targetDuration = targetDuration
}
Expand Down
Loading
Loading