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 up lowest tier audio bitrate #37

Merged
merged 18 commits into from
Feb 19, 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
19 changes: 10 additions & 9 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ jobs:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Go 1.x
uses: actions/setup-go@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: |
docker-compose up -d minio db redis &&
docker-compose up -d cworker conductor &&
docker-compose up minio-prepare
- uses: actions/setup-go@v3
with:
go-version: '1.17'
go-version: '1.20.x'
id: go

- name: Install ffmpeg
uses: FedericoCarboni/setup-ffmpeg@v1-beta
id: setup-ffmpeg

- name: Run tests
run: make test
run: go test -covermode=count -coverprofile=coverage.out ./...
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
coverage.*
*.sqlite*
./transcoder
data/
27 changes: 27 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
linters-settings:
errcheck:
check-type-assertions: true
goconst:
min-len: 2
min-occurrences: 3

linters:
disable-all: true
enable:
- dupl
- gocritic
- goconst
- gocyclo
- gofmt
- goimports
- gosimple
- govet
- gosec
- ineffassign
- misspell
- staticcheck
- sqlclosecheck
- unused

run:
timeout: 10m
10 changes: 0 additions & 10 deletions Dockerfile-ffmpeg

This file was deleted.

17 changes: 0 additions & 17 deletions Dockerfile-ffprobe

This file was deleted.

25 changes: 0 additions & 25 deletions Dockerfile.test

This file was deleted.

14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,26 @@ CXX=x86_64-linux-musl-g++
GOARCH=amd64
GOOS=linux
LDFLAGS=-ldflags "-linkmode external -extldflags -static"
GO_BUILD=go1.17 build
GO_BUILD=go1.20 build
BUILD_DIR=dist
LOCAL_ARCH=$(shell uname)
VERSION := $(shell git describe --tags --match 'v*'|sed -e 's/v//')
TRANSCODER_VERSION ?= $(shell git describe --tags --match 'transcoder-v*'|sed 's/transcoder-v\([0-9.]*\).*/\1/')

transcoder: $(BUILD_DIR)/$(GOOS)_$(GOARCH)/transcoder
GOARCH=$(GOARCH) GOOS=$(GOOS) CGO_ENABLED=0 \
$(GO_BUILD) -o $(BUILD_DIR)/$(GOOS)_$(GOARCH)/transcoder \
-ldflags "-s -w -X github.com/lbryio/transcoder/internal/version.Version=$(VERSION)" \
-ldflags "-s -w -X github.com/lbryio/transcoder/internal/version.Version=$(TRANSCODER_VERSION)" \
./pkg/conductor/cmd/

conductor_image:
docker buildx build -f Dockerfile-conductor -t odyseeteam/transcoder-conductor:dev --platform linux/amd64 .
docker buildx build -f docker/Dockerfile-conductor -t odyseeteam/transcoder-conductor:$(TRANSCODER_VERSION) --platform linux/amd64 .

cworker_image:
docker buildx build -f Dockerfile-cworker -t odyseeteam/transcoder-cworker:dev --platform linux/amd64 .
docker buildx build -f docker/Dockerfile-cworker -t odyseeteam/transcoder-cworker:$(TRANSCODER_VERSION) --platform linux/amd64 .

test_down:
docker-compose down

test_prepare:
docker-compose up -d minio db redis
Expand All @@ -35,7 +39,7 @@ towerz:
tccli:
GOARCH=$(GOARCH) GOOS=$(GOOS) CGO_ENABLED=0 \
$(GO_BUILD) -o $(BUILD_DIR)/$(GOOS)_$(GOARCH)/tccli \
-ldflags "-s -w -X github.com/lbryio/transcoder/internal/version.Version=$(VERSION)" \
-ldflags "-s -w -X github.com/lbryio/transcoder/internal/version.Version=$(TRANSCODER_VERSION)" \
./tccli/

tccli_mac:
Expand Down
8 changes: 1 addition & 7 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,7 @@ var (
ErrNotFound = errors.New("fragment not found")
ErrChannelNotEnabled = resolve.ErrChannelNotEnabled

errRefetch = errors.New("should refetch")
sdHashRe = regexp.MustCompile(`/([A-Za-z0-9]{32,96})/?`)

fetchErrorTypes = map[int]string{
http.StatusInternalServerError: failureServerError,
http.StatusNotFound: failureNotFound,
}
sdHashRe = regexp.MustCompile(`/([A-Za-z0-9]{32,96})/?`)
)

type HTTPRequester interface {
Expand Down
35 changes: 13 additions & 22 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package client
import (
"context"
"fmt"
"io/ioutil"
"math/rand"
"io"
"net/http"
"net/http/httptest"
"os"
Expand All @@ -14,6 +13,7 @@ import (
"testing"
"time"

"github.com/Pallinder/go-randomdata"
"github.com/lbryio/transcoder/library"
"github.com/lbryio/transcoder/pkg/resolve"

Expand Down Expand Up @@ -53,7 +53,7 @@ var streamFragmentCases = []struct {
{"v0_s000000.ts", 2_000_000},
{"v1_s000000.ts", 760_000},
{"v2_s000000.ts", 300_000},
{"v3_s000000.ts", 100_000},
{"v3_s000000.ts", 120_000},
}

func TestClientSuite(t *testing.T) {
Expand All @@ -75,8 +75,8 @@ func (s *clientSuite) TestPlayFragment() {
)

// Request stream and wait until it's available.
ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
wait := time.NewTicker(500 * time.Millisecond)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
wait := time.NewTicker(1000 * time.Millisecond)
Waiting:
for {
select {
Expand All @@ -102,7 +102,7 @@ Waiting:
sz, err := c.PlayFragment(streamURL, streamSDHash, tc.name, rr, httptest.NewRequest(http.MethodGet, "/", nil))
s.Require().NoError(err)
s.Require().Equal(http.StatusOK, rr.Result().StatusCode)
rbody, err := ioutil.ReadAll(rr.Result().Body)
rbody, err := io.ReadAll(rr.Result().Body)
s.Require().NoError(err)
if tc.size > 0 {
// Different transcoding runs produce slightly different files.
Expand All @@ -111,7 +111,7 @@ Waiting:
} else {
absPath, err := filepath.Abs(filepath.Join("./testdata", "known-stream", tc.name))
s.Require().NoError(err)
tbody, err := ioutil.ReadFile(absPath)
tbody, err := os.ReadFile(absPath)
s.Require().NoError(err)
s.Equal(strings.TrimRight(string(tbody), "\n"), strings.TrimRight(string(rbody), "\n"))
}
Expand All @@ -124,11 +124,12 @@ Waiting:
s.Equal("GET, OPTIONS", rr.Result().Header.Get("Access-Control-Allow-Methods"))
s.Equal("*", rr.Result().Header.Get("Access-Control-Allow-Origin"))

if strings.HasSuffix(tc.name, ".m3u8") {
switch {
case strings.HasSuffix(tc.name, ".m3u8"):
s.Equal("application/x-mpegurl", rr.Result().Header.Get("content-type"))
} else if strings.HasSuffix(tc.name, ".ts") {
case strings.HasSuffix(tc.name, ".ts"):
s.Equal("video/mp2t", rr.Result().Header.Get("content-type"))
} else if strings.HasSuffix(tc.name, ".png") {
case strings.HasSuffix(tc.name, ".png"):
s.Equal("image/png", rr.Result().Header.Get("content-type"))
}
})
Expand Down Expand Up @@ -182,7 +183,7 @@ Waiting:
})
}

c.remoteServer = "http://localhost:63333"
c.remoteServer = "http://localhost:13131"
c.cache.Clear()

for _, tc := range streamFragmentCases {
Expand All @@ -202,7 +203,7 @@ func (s *clientSuite) TestRestoreCache() {

cvDirs := []string{}
for range [10]int{} {
sdHash := randomString(96)
sdHash := randomdata.Alphanumeric(96)
library.PopulateHLSPlaylist(s.T(), dstPath, sdHash)
cvDirs = append(cvDirs, sdHash)
}
Expand Down Expand Up @@ -268,13 +269,3 @@ func (s *clientSuite) Test_getFragmentURL() {
s.Require().NoError(err)
s.Equal("https://cache-us.transcoder.odysee.com/sdhash/master.m3u8?origin=storage1", u)
}

func randomString(n int) string {
var letter = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")

b := make([]rune, n)
for i := range b {
b[i] = letter[rand.Intn(len(letter))]
}
return string(b)
}
1 change: 1 addition & 0 deletions client/openfile_darwin.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build darwin
// +build darwin

package client
Expand Down
2 changes: 1 addition & 1 deletion client/testdata/known-stream/master.m3u8
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ v1.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=655600,RESOLUTION=640x360,CODECS="avc1.4d401e,mp4a.40.2",CLOSED-CAPTIONS=NONE
v2.m3u8

#EXT-X-STREAM-INF:BANDWIDTH=180400,RESOLUTION=256x144,CODECS="avc1.4d400b,mp4a.40.2",CLOSED-CAPTIONS=NONE
#EXT-X-STREAM-INF:BANDWIDTH=215600,RESOLUTION=256x144,CODECS="avc1.4d400b,mp4a.40.2",CLOSED-CAPTIONS=NONE
v3.m3u8
40 changes: 20 additions & 20 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@ version: '3.7'

services:
conductor:
image: odyseeteam/transcoder-conductor:dev
container_name: conductor
image: odyseeteam/transcoder-conductor:24.2.3
platform: linux/amd64
container_name: tc-conductor
command:
- ./transcoder
- conductor
- --debug
# - --rmq-addr=amqp://guest:guest@rabbitmq/
# - --http-url=http://tower:8080
# - --dev-mode
# - --state-file=/storage/state.json
volumes:
- ${PWD}/conductor.ex.yml:/app/conductor.yml
ports:
- "8080:8080"
# build:
# context: .
# dockerfile: Dockerfile-tower
# dockerfile: docker/Dockerfile-tower
depends_on:
- redis
- db
Expand All @@ -29,14 +26,16 @@ services:
max_attempts: 3
window: 120s
cworker:
image: odyseeteam/transcoder-cworker:dev
container_name: cworker
image: odyseeteam/transcoder-cworker:24.2.3
platform: linux/amd64
container_name: tc-cworker
command:
- ./transcoder
- worker
- --blob-server=blobcache-eu.lbry.com
# build:
# context: .
# dockerfile: Dockerfile-worker
# dockerfile: docker/Dockerfile-worker
depends_on: ["redis"]
volumes:
- ${PWD}/worker.ex.yml:/app/worker.yml
Expand All @@ -49,7 +48,7 @@ services:
# - '9090:8080'
redis:
image: redis:7.0
container_name: redis
container_name: tc-redis
ports:
- '6379:6379'
volumes:
Expand All @@ -61,7 +60,7 @@ services:
restart: unless-stopped
db:
image: postgres:14
container_name: db
container_name: tc-db
ports:
- "5432:5432"
environment:
Expand All @@ -79,16 +78,16 @@ services:
retries: 5
minio:
image: minio/minio
container_name: minio
container_name: tc-minio
ports:
- "9000:9000"
- "38861:38861"
- "41949:41949"
volumes:
- minio-data:/data
environment:
MINIO_ACCESS_KEY: ody
MINIO_SECRET_KEY: odyseetes3
MINIO_ROOT_USER: ody
MINIO_ROOT_PASSWORD: odyseetes3
command: server --address 0.0.0.0:9000 /data
minio-prepare:
image: minio/mc
Expand All @@ -98,13 +97,14 @@ services:
/bin/sh -c "
/usr/bin/mc config host add myminio http://minio:9000 ody odyseetes3;
/usr/bin/mc mb myminio/transcoded;
/usr/bin/mc policy set download myminio/transcoded;
/usr/bin/mc anonymous set download myminio/transcoded;
/usr/bin/mc anonymous set public myminio/transcoded;
exit 0;
"
depends_on: ["minio"]

volumes:
tower-data: {}
db-data: {}
minio-data: {}
redis-data: {}

db-data:
minio-data:
redis-data:
2 changes: 1 addition & 1 deletion Dockerfile-conductor → docker/Dockerfile-conductor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM alpine:3.16
FROM alpine:3.19
EXPOSE 8080

RUN apk add --no-cache libc6-compat
Expand Down
Loading
Loading