Skip to content
Open
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
2 changes: 2 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@
#### Broadcaster

#### CLI

- \#1844 Fix livepeer_bench segment path handling on Windows (@lukiod)
13 changes: 10 additions & 3 deletions cmd/livepeer_bench/livepeer_bench.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -87,7 +87,6 @@ func main() {
ffmpeg.InitFFmpegWithLogLevel(ffmpeg.LogLevel(*log * 8))

var wg sync.WaitGroup
dir := path.Dir(*in)

table := tablewriter.NewWriter(os.Stderr)
data := [][]string{
Expand Down Expand Up @@ -139,7 +138,7 @@ func main() {
if v == nil {
continue
}
u := path.Join(dir, v.URI)
u := segmentPath(*in, v.URI)
in := &ffmpeg.TranscodeOptionsIn{
Fname: u,
Accel: accel,
Expand Down Expand Up @@ -223,6 +222,14 @@ func main() {
}
}

// segmentPath returns the path to a playlist segment by joining the input
// manifest's directory with the segment's URI (which is relative to the
// manifest). filepath is used instead of path so that Windows-style backslash
// separators in the manifest path are handled correctly.
func segmentPath(manifest, segmentURI string) string {
return filepath.Join(filepath.Dir(manifest), segmentURI)
}

func parseVideoProfiles(inp string) []ffmpeg.VideoProfile {
profiles := []ffmpeg.VideoProfile{}
if inp != "" {
Expand Down
30 changes: 30 additions & 0 deletions cmd/livepeer_bench/livepeer_bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"path/filepath"
"runtime"
"testing"
)

func TestSegmentPath(t *testing.T) {
// Windows-style manifest path with backslash separators, as reported in
// issue #1844. On Windows the path package treats backslashes as ordinary
// characters, so path.Dir/path.Join produce a broken segment path;
// filepath handles them as separators.
if runtime.GOOS == "windows" {
const manifest = `C:\bench\media\input.m3u8`
want := filepath.Join(`C:\bench\media`, "seg0.ts")
if got := segmentPath(manifest, "seg0.ts"); got != want {
t.Fatalf("segmentPath(%q) = %q, want %q", manifest, got, want)
}
return
}

// POSIX-style manifest path: forward slashes. filepath and path agree on
// this input, but this guards the normal case against regression.
const manifest = "/tmp/bench/media/input.m3u8"
want := filepath.Join("/tmp/bench/media", "seg0.ts")
if got := segmentPath(manifest, "seg0.ts"); got != want {
t.Fatalf("segmentPath(%q) = %q, want %q", manifest, got, want)
}
}
Loading