forked from zergon321/reisen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathframe.go
44 lines (37 loc) · 992 Bytes
/
frame.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package reisen
import (
"fmt"
"time"
)
// Frame is an abstract data frame.
type Frame interface {
Data() []byte
PresentationOffset() (time.Duration, error)
}
// baseFrame contains the information
// common for all frames of any type.
type baseFrame struct {
stream Stream
pts int64
indexCoded int
indexDisplay int
}
// PresentationOffset returns the duration offset
// since the start of the media at which the frame
// should be played.
func (frame *baseFrame) PresentationOffset() (time.Duration, error) {
tbNum, tbDen := frame.stream.TimeBase()
tb := float64(tbNum) / float64(tbDen)
tm := float64(frame.pts) * tb
return time.ParseDuration(fmt.Sprintf("%fs", tm))
}
// IndexCoded returns the index of
// the frame in the bitstream order.
func (frame *baseFrame) IndexCoded() int {
return frame.indexCoded
}
// IndexDisplay returns the index of
// the frame in the display order.
func (frame *baseFrame) IndexDisplay() int {
return frame.indexDisplay
}