-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
transmux: add test for stream and file based concat
- Loading branch information
1 parent
c7b2d8a
commit 19aa630
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package video | ||
|
||
import ( | ||
"github.com/stretchr/testify/require" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestItConcatsStreams(t *testing.T) { | ||
// test pre-reqs | ||
tr := populateRenditionSegmentList() | ||
segmentList := tr.GetSegmentList("rendition-1080p0") | ||
concatDir, err := os.MkdirTemp(os.TempDir(), "concat_stage_") | ||
require.NoError(t, err) | ||
// verify file-based concatenation | ||
totalBytesWritten, err := ConcatTS(concatDir+"test.ts", segmentList, false) | ||
require.NoError(t, err) | ||
require.Equal(t, int64(594644), totalBytesWritten) | ||
// verify stream-based concatenation | ||
totalBytesW, err := ConcatTS(concatDir+"test.ts", segmentList, true) | ||
require.NoError(t, err) | ||
require.Equal(t, int64(594644), totalBytesW) | ||
} | ||
|
||
func populateRenditionSegmentList() *TRenditionList { | ||
segmentFiles := []string{"../test/fixtures/seg-0.ts", "../test/fixtures/seg-1.ts", "../test/fixtures/seg-2.ts"} | ||
|
||
renditionList := &TRenditionList{ | ||
RenditionSegmentTable: make(map[string]*TSegmentList), | ||
} | ||
segmentList := &TSegmentList{ | ||
SegmentDataTable: make(map[int][]byte), | ||
} | ||
|
||
for i, filePath := range segmentFiles { | ||
data := readSegmentData(filePath) | ||
segmentList.AddSegmentData(i, data) | ||
} | ||
|
||
renditionList.AddRenditionSegment("rendition-1080p0", segmentList) | ||
|
||
return renditionList | ||
} | ||
|
||
func readSegmentData(filePath string) []byte { | ||
data, _ := os.ReadFile(filePath) | ||
return data | ||
} |