Eliminated some unnecessary buffer copies.

This commit is contained in:
Alan Noble 2017-09-21 07:50:22 +09:30
parent 9c7df83011
commit e3c62afb43
1 changed files with 6 additions and 7 deletions

View File

@ -178,7 +178,7 @@ func readWriteVideo(input string, output string) error {
} }
} }
if *flags&(filterDropAudio) == 0 { if *flags&filterDropAudio == 0 {
audioArg[0] = "-acodec" audioArg[0] = "-acodec"
audioArg[1] = "copy" audioArg[1] = "copy"
} else { } else {
@ -306,9 +306,8 @@ func sendClipToHTTP(clip []byte, output string, _ net.Conn) error {
func sendClipToUDP(clip []byte, _ string, conn net.Conn) error { func sendClipToUDP(clip []byte, _ string, conn net.Conn) error {
size := UDPPackets * mp2tPacketSize size := UDPPackets * mp2tPacketSize
fmt.Printf("Sending %d UDP packets of size %d (%d bytes)\n", len(clip)/size, size, len(clip)) fmt.Printf("Sending %d UDP packets of size %d (%d bytes)\n", len(clip)/size, size, len(clip))
pkt := make([]byte, size)
for offset := 0; offset < len(clip); offset += size { for offset := 0; offset < len(clip); offset += size {
copy(pkt, clip[offset:offset+size]) pkt := clip[offset : offset+size]
_, err := conn.Write(pkt) _, err := conn.Write(pkt)
if err != nil { if err != nil {
fmt.Printf("UDP write error %s. Is your player listening?\n", err) fmt.Printf("UDP write error %s. Is your player listening?\n", err)
@ -346,12 +345,11 @@ func sendClipToStdout(clip []byte, _ string, _ net.Conn) error {
packetCount := 0 packetCount := 0
discontinuities := 0 discontinuities := 0
pkt := make([]byte, mp2tPacketSize)
var cc int var cc int
for offset := 0; offset < len(clip); offset += mp2tPacketSize { for offset := 0; offset < len(clip); offset += mp2tPacketSize {
packetCount++ packetCount++
copy(pkt, clip[offset:offset+mp2tPacketSize]) pkt := clip[offset : offset+mp2tPacketSize]
pktPid, err := packet.Pid(pkt) pktPid, err := packet.Pid(pkt)
if err != nil { if err != nil {
@ -419,6 +417,7 @@ func sendClipToStdout(clip []byte, _ string, _ net.Conn) error {
// mp2tDumpProgram dumps MPEG-TS Program Association Table (PAT) and Program Map Tables (PMT). // mp2tDumpProgram dumps MPEG-TS Program Association Table (PAT) and Program Map Tables (PMT).
func mp2tDumpProgram(clip []byte) error { func mp2tDumpProgram(clip []byte) error {
// NB: Comcast API requires a buffered reader
reader := bufio.NewReader(bytes.NewReader(clip)) reader := bufio.NewReader(bytes.NewReader(clip))
_, err := packet.Sync(reader) _, err := packet.Sync(reader)
@ -505,7 +504,7 @@ func mp2tGetPcr(pkt []byte) (uint64, uint32, bool) {
} }
// RTPEncapsulate encapsulates MPEG-TS packets within an RTP header, // RTPEncapsulate encapsulates MPEG-TS packets within an RTP header,
// setting the payload type accordingly and incrementing the RTP sequence number. // setting the payload type accordingly (to 33) and incrementing the RTP sequence number.
func RTPEncapsulate(mp2tPacket []byte, pkt []byte) { func RTPEncapsulate(mp2tPacket []byte, pkt []byte) {
// RTP packet encapsulates the MP2T // RTP packet encapsulates the MP2T
// first 12 bytes is the header // first 12 bytes is the header