Skip to content

Commit

Permalink
Nits
Browse files Browse the repository at this point in the history
  • Loading branch information
xdrudis authored and edaniels committed Jan 2, 2025
1 parent 31d8dbc commit 04b4621
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions pkg/media/ivfreader/ivfreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ type IVFFrameHeader struct {
type IVFReader struct {
stream io.Reader
bytesReadSuccesfully int64
fileHeader *IVFFileHeader
timebaseDenominator uint32
timebaseNumerator uint32
}

// NewWith returns a new IVF reader and IVF file header
Expand All @@ -70,7 +71,8 @@ func NewWith(in io.Reader) (*IVFReader, *IVFFileHeader, error) {
if err != nil {
return nil, nil, err
}
reader.fileHeader = header
reader.timebaseDenominator = header.TimebaseDenominator
reader.timebaseNumerator = header.TimebaseNumerator

return reader, header, nil
}
Expand All @@ -83,7 +85,7 @@ func (i *IVFReader) ResetReader(reset func(bytesRead int64) io.Reader) {
}

func (i *IVFReader) ptsToTimestamp(pts uint64) uint64 {
return pts * uint64(i.fileHeader.TimebaseDenominator) / uint64(i.fileHeader.TimebaseNumerator)
return pts * uint64(i.timebaseDenominator) / uint64(i.timebaseNumerator)
}

// ParseNextFrame reads from stream and returns IVF frame payload, header,
Expand Down
4 changes: 2 additions & 2 deletions pkg/media/ivfwriter/ivfwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ func (i *IVFWriter) timestampToPts(timestamp uint64) uint64 {

func (i *IVFWriter) writeFrame(frame []byte, timestamp uint64) error {
frameHeader := make([]byte, 12)
binary.LittleEndian.PutUint32(frameHeader[0:], uint32(len(frame))) // Frame length
binary.LittleEndian.PutUint64(frameHeader[4:], i.timestampToPts(timestamp))
binary.LittleEndian.PutUint32(frameHeader[0:], uint32(len(frame))) // Frame length
binary.LittleEndian.PutUint64(frameHeader[4:], i.timestampToPts(timestamp)) // PTS
i.count++

if _, err := i.ioWriter.Write(frameHeader); err != nil {
Expand Down

0 comments on commit 04b4621

Please sign in to comment.