libeplayer3: further malloc-memcpy-write -> writev replacements; not fully regression tested

This commit is contained in:
martii
2013-06-08 11:15:09 +02:00
parent 8d8aa01f98
commit a09c2518bc
12 changed files with 134 additions and 172 deletions

View File

@@ -31,6 +31,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/uio.h>
#include <linux/dvb/video.h>
#include <linux/dvb/audio.h>
#include <memory.h>
@@ -131,32 +132,34 @@ static int writeData(void* _call)
return -1;
}
HeaderLength = InsertPesHeader (PesHeader, call->private_size, MPEG_AUDIO_PES_START_CODE, 0, 0);
unsigned char* PacketStart = malloc(call->private_size + HeaderLength);
memcpy (PacketStart, PesHeader, HeaderLength);
memcpy (PacketStart + HeaderLength, call->private_data, call->private_size);
struct iovec iov[2];
iov[0].iov_base = PesHeader;
iov[0].iov_len = InsertPesHeader (PesHeader, call->private_size, MPEG_AUDIO_PES_START_CODE, 0, 0);
iov[1].iov_base = call->private_data;
iov[1].iov_len = call->private_size;
len = write(call->fd, PacketStart, call->private_size + HeaderLength);
free(PacketStart);
len = writev(call->fd, iov, 2);
initialHeader = 0;
}
if (call->len > 0 && call->data)
if (len > -1 && call->len > 0 && call->data)
{
unsigned char PesHeader[PES_MAX_HEADER_SIZE];
int HeaderLength = InsertPesHeader (PesHeader, call->len, MPEG_AUDIO_PES_START_CODE, call->Pts, 0);
unsigned char* PacketStart = malloc(call->len + HeaderLength);
memcpy (PacketStart, PesHeader, HeaderLength);
memcpy (PacketStart + HeaderLength, call->data, call->len);
struct iovec iov[2];
iov[0].iov_base = PesHeader;
iov[0].iov_len = InsertPesHeader (PesHeader, call->len, MPEG_AUDIO_PES_START_CODE, call->Pts, 0);
iov[1].iov_base = call->data;
iov[1].iov_len = call->len;
len = write(call->fd, PacketStart, call->len + HeaderLength);
free(PacketStart);
ssize_t l = writev(call->fd, iov, 2);
if (l > -1)
len += l;
else
len = l;
}
wma_printf(10, "wma < %d\n", len);