container/mts: BytesForMetaInterval renamed to TrimToMetaRange and now returns Clip for similar reasons to previous commit

This commit is contained in:
Saxon 2019-06-15 02:12:17 +09:30
parent ceee163b74
commit 2bd7a009ce
2 changed files with 14 additions and 9 deletions

View File

@ -192,9 +192,9 @@ var (
errMetaUpperBound = errors.New("meta 'to' cannot be found")
)
// BytesForMetaInterval will return the media data as a slice between two meta
// values 'from' and 'to', of key 'key'. The meta values must not be the same.
func (c *Clip) BytesForMetaInterval(key, from, to string) ([]byte, error) {
// TrimToMetaRange returns a sub Clip with meta range described by from and to
// with key 'key'. The meta values must not be equivalent.
func (c *Clip) TrimToMetaRange(key, from, to string) (*Clip, error) {
// First check that the interval makes sense.
if from == to {
return nil, errMetaRange
@ -205,6 +205,7 @@ func (c *Clip) BytesForMetaInterval(key, from, to string) ([]byte, error) {
// Try and find from.
for i := 0; i < len(c.frames); i++ {
f := c.frames[i]
startFrameIdx := i
if f.Meta[key] == from {
start = f.idx
@ -213,7 +214,11 @@ func (c *Clip) BytesForMetaInterval(key, from, to string) ([]byte, error) {
f = c.frames[i]
if f.Meta[key] == to {
end = f.idx
return c.backing[start : end+len(f.Media)], nil
endFrameIdx := i
return &Clip{
frames: c.frames[startFrameIdx : endFrameIdx+1],
backing: c.backing[start : end+len(f.Media)],
}, nil
}
}
return nil, errMetaUpperBound

View File

@ -316,9 +316,9 @@ func TestTrimToPTSRange(t *testing.T) {
}
}
// TestBytesForMetaInterval checks that we can correctly get media data between
// two meta values using BytesForMetaInterval.
func TestBytesForMetaInterval(t *testing.T) {
// TestTrimToMetaRange checks that Clip.TrimToMetaRange correctly provides a
// sub Clip for a given meta range.
func TestTrimToMetaRange(t *testing.T) {
const (
numOfTestFrames = 10
ptsInterval = 4
@ -382,7 +382,7 @@ func TestBytesForMetaInterval(t *testing.T) {
// Run tests.
for i, test := range tests {
got, err := clip.BytesForMetaInterval(key, test.from, test.to)
got, err := clip.TrimToMetaRange(key, test.from, test.to)
// First check the error.
if err != nil && err != test.err {
@ -394,7 +394,7 @@ func TestBytesForMetaInterval(t *testing.T) {
}
// Now check data.
if test.err == nil && !bytes.Equal(test.expect, got) {
if test.err == nil && !bytes.Equal(test.expect, got.Bytes()) {
t.Errorf("did not get expected data for test: %v\n Got: %v\n, Want: %v\n", i, got, test.expect)
}
}