mirror of
https://github.com/zergon321/reisen.git
synced 2025-09-26 20:01:14 +08:00
Encoded packet data is now available.
This commit is contained in:
2
media.go
2
media.go
@@ -179,7 +179,7 @@ func (media *Media) ReadPacket() (*Packet, bool, error) {
|
||||
return nil, false, nil
|
||||
}
|
||||
|
||||
return &Packet{media: media}, true, nil
|
||||
return newPacket(media, media.packet), true, nil
|
||||
}
|
||||
|
||||
// CloseDecode closes the media container for decoding.
|
||||
|
52
packet.go
52
packet.go
@@ -6,24 +6,68 @@ package reisen
|
||||
// #include <libavutil/avconfig.h>
|
||||
// #include <libswscale/swscale.h>
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
// Packet is a piece of data
|
||||
// Packet is a piece of encoded data
|
||||
// acquired from the media container.
|
||||
//
|
||||
// It can be either a video frame or
|
||||
// an audio frame.
|
||||
type Packet struct {
|
||||
media *Media
|
||||
media *Media
|
||||
streamIndex int
|
||||
data []byte
|
||||
pts int64
|
||||
dts int64
|
||||
pos int64
|
||||
duration int64
|
||||
size int
|
||||
flags int
|
||||
}
|
||||
|
||||
// StreamIndex returns the index of the
|
||||
// stream the packet belongs to.
|
||||
func (pkt *Packet) StreamIndex() int {
|
||||
return int(pkt.media.packet.stream_index)
|
||||
return pkt.streamIndex
|
||||
}
|
||||
|
||||
// Type returns the type of the packet
|
||||
// (video or audio).
|
||||
func (pkt *Packet) Type() StreamType {
|
||||
return pkt.media.Streams()[pkt.StreamIndex()].Type()
|
||||
return pkt.media.Streams()[pkt.streamIndex].Type()
|
||||
}
|
||||
|
||||
// Data returns the data
|
||||
// encoded in the packet.
|
||||
func (pkt *Packet) Data() []byte {
|
||||
buf := make([]byte, pkt.size)
|
||||
|
||||
copy(buf, pkt.data)
|
||||
|
||||
return buf
|
||||
}
|
||||
|
||||
// Returns the size of the
|
||||
// packet data.
|
||||
func (pkt *Packet) Size() int {
|
||||
return pkt.size
|
||||
}
|
||||
|
||||
// newPacket creates a
|
||||
// new packet info object.
|
||||
func newPacket(media *Media, cPkt *C.AVPacket) *Packet {
|
||||
pkt := &Packet{
|
||||
media: media,
|
||||
streamIndex: int(cPkt.stream_index),
|
||||
data: C.GoBytes(unsafe.Pointer(
|
||||
cPkt.data), cPkt.size),
|
||||
pts: int64(cPkt.pts),
|
||||
dts: int64(cPkt.dts),
|
||||
pos: int64(cPkt.pos),
|
||||
duration: int64(cPkt.duration),
|
||||
size: int(cPkt.size),
|
||||
flags: int(cPkt.flags),
|
||||
}
|
||||
|
||||
return pkt
|
||||
}
|
||||
|
Reference in New Issue
Block a user