mirror of
https://github.com/zergon321/reisen.git
synced 2025-09-26 20:01:14 +08:00
31 lines
654 B
Go
31 lines
654 B
Go
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
|
|
}
|
|
|
|
// 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))
|
|
}
|