func (dpx *Demultiplexer) Start() {
	for true {
		dpx.Packet = new(C.AVPacket)
		C.av_init_packet(dpx.Packet)

		if C.av_read_frame(dpx.Ds.Ctx, dpx.Packet) >= 0 {
			C.av_dup_packet(dpx.Packet)
		} else {
			println("end of file reached, closing channels")
			for i := 0; i < len(*dpx.tracks); i++ {
				print("closing channel ")
				println(i)
				close((*dpx.tracks)[i].stream)
			}
			break
		}
		var re Packet

		re.Pts = int64(dpx.Packet.pts)
		re.Dts = int64(dpx.Packet.dts)
		re.Size = int(dpx.Packet.size)
		re.Data = make([]byte, re.Size)
		data := (*(*[1 << 30]byte)(unsafe.Pointer(dpx.Packet.data)))[0:dpx.Packet.size]
		for i := 0; i < re.Size; i++ {
			re.Data[i] = data[i]
		}
		re.Stream = int(dpx.Packet.stream_index)
		re.Flags = int(dpx.Packet.flags)
		re.Duration = int(dpx.Packet.duration)
		re.Pos = int64(dpx.Packet.pos)
		C.av_free_packet(dpx.Packet)
		(*dpx.tracks)[re.Stream].stream <- re
	}
	//re * Packet
}
func (dpx *Demultiplexer) ReadPacket(re *Packet) bool {
	dpx.Packet = new(C.AVPacket)

	C.av_init_packet(dpx.Packet)
	defer C.av_free_packet(dpx.Packet)
	if C.av_read_frame(dpx.Ds.Ctx, dpx.Packet) >= 0 {
		C.av_dup_packet(dpx.Packet)
	} else {
		return false
	}
	re.Pts = int64(dpx.Packet.pts)
	re.Dts = int64(dpx.Packet.dts)
	re.Size = int(dpx.Packet.size)
	re.Data = make([]byte, re.Size)
	data := (*(*[1 << 30]byte)(unsafe.Pointer(dpx.Packet.data)))[0:dpx.Packet.size]
	for i := 0; i < re.Size; i++ {
		re.Data[i] = data[i]
	}
	re.Stream = int(dpx.Packet.stream_index)
	re.Flags = int(dpx.Packet.flags)
	re.Duration = int(dpx.Packet.duration)
	re.Pos = int64(dpx.Packet.pos)
	return true
}
Example #3
0
func av_dup_packet(packet *avPacket) {
	C.av_dup_packet((*C.AVPacket)(unsafe.Pointer(packet)))
}
Example #4
0
func (p *Packet) AvDupPacket() int {
	return int(C.av_dup_packet((*C.struct_AVPacket)(p)))

}
Example #5
0
//int 	av_dup_packet (AVPacket *pkt)
func Av_dup_packet(p *AVPacket) int {
	return int(C.av_dup_packet((*C.struct_AVPacket)(p)))

}