Frame index methods added.

This commit is contained in:
zergon321
2021-11-07 22:29:10 +03:00
parent 04dde536b0
commit 6e90eeb5bd
5 changed files with 23 additions and 5 deletions

View File

@@ -132,7 +132,9 @@ func (audio *AudioStream) ReadAudioFrame() (*AudioFrame, bool, error) {
data := C.GoBytes(unsafe.Pointer(
audio.buffer), maxBufferSize)
frame := newAudioFrame(audio,
int64(audio.frame.pts), data)
int64(audio.frame.pts),
int(audio.frame.coded_picture_number),
int(audio.frame.display_picture_number), data)
return frame, true, nil
}

View File

@@ -14,12 +14,14 @@ func (frame *AudioFrame) Data() []byte {
}
// newAudioFrame returns a newly created audio frame.
func newAudioFrame(stream Stream, pts int64, data []byte) *AudioFrame {
func newAudioFrame(stream Stream, pts int64, codedPictureNum, displayPictureNum int, data []byte) *AudioFrame {
frame := new(AudioFrame)
frame.stream = stream
frame.pts = pts
frame.data = data
frame.codedPictureNumber = codedPictureNum
frame.displayPictureNumber = displayPictureNum
return frame
}

View File

@@ -14,8 +14,10 @@ type Frame interface {
// baseFrame contains the information
// common for all frames of any type.
type baseFrame struct {
stream Stream
pts int64
stream Stream
pts int64
codedPictureNumber int
displayPictureNumber int
}
// PresentationOffset returns the duration offset
@@ -28,3 +30,11 @@ func (frame *baseFrame) PresentationOffset() (time.Duration, error) {
return time.ParseDuration(fmt.Sprintf("%fs", tm))
}
func (frame *baseFrame) IndexCoded() int {
return frame.codedPictureNumber
}
func (frame *baseFrame) IndexDisplay() int {
return frame.displayPictureNumber
}

View File

@@ -138,6 +138,8 @@ func (video *VideoStream) ReadVideoFrame() (*VideoFrame, bool, error) {
Pointer(video.rgbaFrame.data[0]),
video.bufSize)
frame := newVideoFrame(video, int64(video.frame.pts),
int(video.frame.coded_picture_number),
int(video.frame.display_picture_number),
int(video.codecCtx.width), int(video.codecCtx.height), data)
return frame, true, nil

View File

@@ -21,7 +21,7 @@ func (frame *VideoFrame) Image() *image.RGBA {
}
// newVideoFrame returns a newly created video frame.
func newVideoFrame(stream Stream, pts int64, width, height int, pix []byte) *VideoFrame {
func newVideoFrame(stream Stream, pts int64, codedPictureNum, displayPictureNum, width, height int, pix []byte) *VideoFrame {
upLeft := image.Point{0, 0}
lowRight := image.Point{width, height}
img := image.NewRGBA(image.Rectangle{upLeft, lowRight})
@@ -31,6 +31,8 @@ func newVideoFrame(stream Stream, pts int64, width, height int, pix []byte) *Vid
frame.stream = stream
frame.pts = pts
frame.img = img
frame.codedPictureNumber = codedPictureNum
frame.displayPictureNumber = displayPictureNum
return frame
}