libeplayer3-arm: insert original blank lines from exteplayer3.git, for better merge

This commit is contained in:
max_10
2018-04-10 11:31:57 +02:00
committed by Thilo Graf
parent d00c87b361
commit 704bcc5a21
79 changed files with 2070 additions and 117 deletions

View File

@@ -69,12 +69,15 @@ void PutBits(BitPacker_t *ld, unsigned int code, unsigned int length)
{
unsigned int bit_buf;
unsigned int bit_left;
bit_buf = ld->BitBuffer;
bit_left = ld->Remaining;
#ifdef DEBUG_PUTBITS
if (ld->debug)
dprintf("code = %d, length = %d, bit_buf = 0x%x, bit_left = %d\n", code, length, bit_buf, bit_left);
#endif /* DEBUG_PUTBITS */
if (length < bit_left)
{
/* fits into current buffer */
@@ -96,10 +99,12 @@ void PutBits(BitPacker_t *ld, unsigned int code, unsigned int length)
bit_left = 32 - length;
bit_buf = code;
}
#ifdef DEBUG_PUTBITS
if (ld->debug)
dprintf("bit_left = %d, bit_buf = 0x%x\n", bit_left, bit_buf);
#endif /* DEBUG_PUTBITS */
/* writeback */
ld->BitBuffer = bit_buf;
ld->Remaining = bit_left;

View File

@@ -57,6 +57,7 @@
/* Types */
/* ***************************** */
/* ***************************** */
/* Varaibles */
/* ***************************** */
@@ -73,25 +74,32 @@ int32_t InsertVideoPrivateDataHeader(uint8_t *data, int32_t payload_size)
{
BitPacker_t ld2 = {data, 0, 32};
int32_t i = 0;
PutBits(&ld2, PES_PRIVATE_DATA_FLAG, 8);
PutBits(&ld2, payload_size & 0xff, 8);
PutBits(&ld2, (payload_size >> 8) & 0xff, 8);
PutBits(&ld2, (payload_size >> 16) & 0xff, 8);
for (i = 4; i < (PES_PRIVATE_DATA_LENGTH + 1); i++)
{
PutBits(&ld2, 0, 8);
}
FlushBits(&ld2);
return PES_PRIVATE_DATA_LENGTH + 1;
}
int32_t InsertPesHeader(uint8_t *data, int32_t size, uint8_t stream_id, uint64_t pts, int32_t pic_start_code)
{
BitPacker_t ld2 = {data, 0, 32};
if (size > (MAX_PES_PACKET_SIZE - 13))
{
size = -1; // unbounded
}
PutBits(&ld2, 0x0, 8);
PutBits(&ld2, 0x0, 8);
PutBits(&ld2, 0x1, 8); // Start Code
@@ -113,6 +121,7 @@ int32_t InsertPesHeader(uint8_t *data, int32_t size, uint8_t stream_id, uint64_t
PutBits(&ld2, 0x0, 1); // Copyright
PutBits(&ld2, 0x0, 1); // Original or Copy
//7 = 6+1
if (pts != INVALID_PTS_VALUE)
{
PutBits(&ld2, 0x2, 2);
@@ -121,6 +130,7 @@ int32_t InsertPesHeader(uint8_t *data, int32_t size, uint8_t stream_id, uint64_t
{
PutBits(&ld2, 0x0, 2); // PTS_DTS flag
}
PutBits(&ld2, 0x0, 1); // ESCR_flag
PutBits(&ld2, 0x0, 1); // ES_rate_flag
PutBits(&ld2, 0x0, 1); // DSM_trick_mode_flag
@@ -128,6 +138,7 @@ int32_t InsertPesHeader(uint8_t *data, int32_t size, uint8_t stream_id, uint64_t
PutBits(&ld2, 0x0, 1); // PES_CRC_flag
PutBits(&ld2, 0x0, 1); // PES_extension_flag
//8 = 7+1
if (pts != INVALID_PTS_VALUE)
{
PutBits(&ld2, 0x5, 8);
@@ -137,6 +148,7 @@ int32_t InsertPesHeader(uint8_t *data, int32_t size, uint8_t stream_id, uint64_t
PutBits(&ld2, 0x0, 8); // PES_header_data_length
}
//9 = 8+1
if (pts != INVALID_PTS_VALUE)
{
PutBits(&ld2, 0x2, 4);
@@ -148,6 +160,7 @@ int32_t InsertPesHeader(uint8_t *data, int32_t size, uint8_t stream_id, uint64_t
PutBits(&ld2, 0x1, 1);
}
//14 = 9+5
if (pic_start_code)
{
PutBits(&ld2, 0x0, 8);
@@ -157,6 +170,8 @@ int32_t InsertPesHeader(uint8_t *data, int32_t size, uint8_t stream_id, uint64_t
PutBits(&ld2, (pic_start_code >> 8) & 0xff, 8); // For any extra information (like in mpeg4p2, the pic_start_code)
//14 + 4 = 18
}
FlushBits(&ld2);
return (ld2.Ptr - data);
}

View File

@@ -143,7 +143,7 @@ LATMContext *pLATMCtx = NULL;
/* ***************************** */
/* ***************************** */
/* Functions */
/* MISC Functions */
/* ***************************** */
static int reset()
@@ -159,16 +159,19 @@ static int reset()
static int _writeData(WriterAVCallData_t *call, int type)
{
aac_printf(10, "\n _writeData type[%d]\n", type);
if (call == NULL)
{
aac_err("call data is NULL...\n");
return 0;
}
if ((call->data == NULL) || (call->len < 8))
{
aac_err("parsing Data with missing AAC header. ignoring...\n");
return 0;
}
/* simple validation */
if (0 == type) // check ADTS header
{
@@ -195,9 +198,13 @@ static int _writeData(WriterAVCallData_t *call, int type)
return 0;
}
}
unsigned char PesHeader[PES_MAX_HEADER_SIZE];
aac_printf(10, "AudioPts %lld\n", call->Pts);
unsigned int HeaderLength = InsertPesHeader(PesHeader, call->len, MPEG_AUDIO_PES_START_CODE, call->Pts, 0);
struct iovec iov[2];
iov[0].iov_base = PesHeader;
iov[0].iov_len = HeaderLength;
@@ -209,31 +216,37 @@ static int _writeData(WriterAVCallData_t *call, int type)
static int writeDataADTS(WriterAVCallData_t *call)
{
aac_printf(10, "\n");
if (call == NULL)
{
aac_err("call data is NULL...\n");
return 0;
}
if ((call->data == NULL) || (call->len <= 0))
{
aac_err("parsing NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
aac_err("file pointer < 0. ignoring ...\n");
return 0;
}
if ((call->private_data && 0 == strncmp("ADTS", (const char *)call->private_data, call->private_size)) ||
HasADTSHeader(call->data, call->len))
{
//printf("%hhx %hhx %hhx %hhx %hhx %hhx %hhx %hhx\n", call->data[0], call->data[1], call->data[2], call->data[3], call->data[4], call->data[5], call->data[6], call->data[7]);
return _writeData(call, 0);
}
uint32_t PacketLength = call->len + AAC_HEADER_LENGTH;
uint8_t PesHeader[PES_MAX_HEADER_SIZE + AAC_HEADER_LENGTH];
uint32_t headerSize = InsertPesHeader(PesHeader, PacketLength, MPEG_AUDIO_PES_START_CODE, call->Pts, 0);
uint8_t *pExtraData = &PesHeader[headerSize];
aac_printf(10, "AudioPts %lld\n", call->Pts);
if (call->private_data == NULL)
{
@@ -244,6 +257,7 @@ static int writeDataADTS(WriterAVCallData_t *call)
{
memcpy(pExtraData, call->private_data, AAC_HEADER_LENGTH);
}
pExtraData[3] &= 0xC0;
/* frame size over last 2 bits */
pExtraData[3] |= (PacketLength & 0x1800) >> 11;
@@ -256,33 +270,41 @@ static int writeDataADTS(WriterAVCallData_t *call)
/* buffer fullness(0x7FF for VBR) continued over 6 first bits + 2 zeros for
* number of raw data blocks */
pExtraData[6] = 0xFC;
//PesHeader[6] = 0x81;
struct iovec iov[2];
iov[0].iov_base = PesHeader;
iov[0].iov_len = headerSize + AAC_HEADER_LENGTH;
iov[1].iov_base = call->data;
iov[1].iov_len = call->len;
return call->WriteV(call->fd, iov, 2);
}
static int writeDataLATM(WriterAVCallData_t *call)
{
aac_printf(10, "\n");
if (call == NULL)
{
aac_err("call data is NULL...\n");
return 0;
}
if ((call->data == NULL) || (call->len <= 0))
{
aac_err("parsing NULL Data. ignoring...\n");
return 0;
}
if (call->private_data && 0 == strncmp("LATM", (const char *)call->private_data, call->private_size))
{
return _writeData(call, 1);
}
aac_printf(10, "AudioPts %lld\n", call->Pts);
if (!pLATMCtx)
{
pLATMCtx = malloc(sizeof(LATMContext));
@@ -290,11 +312,13 @@ static int writeDataLATM(WriterAVCallData_t *call)
pLATMCtx->mod = 14;
pLATMCtx->counter = 0;
}
if (!pLATMCtx)
{
aac_err("parsing NULL pLATMCtx. ignoring...\n");
return 0;
}
unsigned char PesHeader[PES_MAX_HEADER_SIZE];
int ret = latmenc_decode_extradata(pLATMCtx, call->private_data, call->private_size);
if (ret)
@@ -310,14 +334,19 @@ static int writeDataLATM(WriterAVCallData_t *call)
aac_err("latm_write_packet failed. ignoring...\n");
return 0;
}
unsigned int HeaderLength = InsertPesHeader(PesHeader, pLATMCtx->len + 3, MPEG_AUDIO_PES_START_CODE, call->Pts, 0);
struct iovec iov[3];
iov[0].iov_base = PesHeader;
iov[0].iov_len = HeaderLength;
iov[1].iov_base = pLATMCtx->loas_header;
iov[1].iov_len = 3;
iov[2].iov_base = pLATMCtx->buffer;
iov[2].iov_len = pLATMCtx->len;
return call->WriteV(call->fd, iov, 3);
}

View File

@@ -98,34 +98,45 @@ static int reset()
static int writeData(WriterAVCallData_t *call)
{
ac3_printf(10, "\n");
unsigned char PesHeader[PES_MAX_HEADER_SIZE];
if (call == NULL)
{
ac3_err("call data is NULL...\n");
return 0;
}
ac3_printf(10, "AudioPts %lld\n", call->Pts);
if ((call->data == NULL) || (call->len <= 0))
{
ac3_err("parsing NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
ac3_err("file pointer < 0. ignoring ...\n");
return 0;
}
struct iovec iov[3];
iov[0].iov_base = PesHeader;
iov[0].iov_len = InsertPesHeader(PesHeader, call->len, MPEG_AUDIO_PES_START_CODE, call->Pts, 0); //+ sizeof(AC3_SYNC_HEADER)
//PesHeader[6] = 0x81;
//PesHeader[7] = 0x80;
//PesHeader[8] = 0x09;
//iov[1].iov_base = AC3_SYNC_HEADER;
//iov[1].iov_len = sizeof(AC3_SYNC_HEADER);
iov[1].iov_base = call->data;
iov[1].iov_len = call->len;
ac3_printf(40, "PES HEADER LEN %d\n", iov[0].iov_len);
return call->WriteV(call->fd, iov, 2);
}

View File

@@ -99,23 +99,29 @@ static int reset()
static int writeData(WriterAVCallData_t *call)
{
unsigned char PesHeader[PES_MAX_HEADER_SIZE + 4 + 9];
amr_printf(10, "\n");
if (call == NULL)
{
amr_err("call data is NULL...\n");
return 0;
}
amr_printf(10, "AudioPts %lld\n", call->Pts);
if ((call->data == NULL) || (call->len <= 0))
{
amr_err("parsing NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
amr_err("file pointer < 0. ignoring ...\n");
return 0;
}
uint8_t hasCodecData = 1;
if (NULL != call->private_data && call->private_size >= 17)
{
@@ -128,11 +134,13 @@ static int writeData(WriterAVCallData_t *call)
payload_len += 9;
}
payload_len += 4;
uint32_t headerSize = InsertPesHeader(PesHeader, payload_len, MPEG_AUDIO_PES_START_CODE, call->Pts, 0);
PesHeader[headerSize++] = (payload_len >> 24) & 0xff;
PesHeader[headerSize++] = (payload_len >> 16) & 0xff;
PesHeader[headerSize++] = (payload_len >> 8) & 0xff;
PesHeader[headerSize++] = payload_len & 0xff;
if (hasCodecData)
{
uint8_t tmp[] = {0x45, 0x4d, 0x50, 0x20, 0x00, 0x00, 0x80, 0x00, 0x01};
@@ -140,12 +148,15 @@ static int writeData(WriterAVCallData_t *call)
//memcpy(&PesHeader[headerSize], call->private_data + 8, 9);
//memset(&PesHeader[headerSize], 0, 9);
}
struct iovec iov[2];
iov[0].iov_base = PesHeader;
iov[0].iov_len = headerSize;
iov[1].iov_base = call->data;
iov[1].iov_len = call->len;
int len = call->WriteV(call->fd, iov, 2);
amr_printf(10, "amr_Write-< len=%d\n", len);
return len;
}

View File

@@ -118,25 +118,32 @@ static int writeData(WriterAVCallData_t *call)
unsigned char PesHeader[PES_MAX_HEADER_SIZE + 4];
// unsigned char Version = 5;
// unsigned int FakeStartCode = (Version << 8) | PES_VERSION_FAKE_START_CODE;
divx_printf(10, "\n");
if (call == NULL)
{
divx_err("call data is NULL...\n");
return 0;
}
if ((call->data == NULL) || (call->len <= 0))
{
divx_err("parsing NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
divx_err("file pointer < 0. ignoring ...\n");
return 0;
}
divx_printf(10, "AudioPts %lld\n", call->Pts);
struct iovec iov[8];
int ic = 0;
if (initialHeader)
{
initialHeader = 0;
@@ -151,11 +158,14 @@ static int writeData(WriterAVCallData_t *call)
data[2] = B_GET_BITS(height, 9, 2);
data[3] = B_SET_BITS("height [1.0]", B_GET_BITS(height, 1, 0), 7, 6) |
B_SET_BITS("'100000'", 0x20, 5, 0);
iov[ic].iov_base = brcm_divx311_sequence_header;
iov[ic++].iov_len = sizeof(brcm_divx311_sequence_header);
}
iov[ic].iov_base = PesHeader;
uint32_t headerSize = 0;
if (memcmp(call->data, "\x00\x00\x01\xb6", 4))
{
headerSize = InsertPesHeader(PesHeader, call->len + 4, MPEG_VIDEO_PES_START_CODE, call->Pts, 0);
@@ -167,10 +177,14 @@ static int writeData(WriterAVCallData_t *call)
headerSize = InsertPesHeader(PesHeader, call->len, MPEG_VIDEO_PES_START_CODE, call->Pts, 0);
}
iov[ic++].iov_len = headerSize;
iov[ic].iov_base = call->data;
iov[ic++].iov_len = call->len;
int len = call->WriteV(call->fd, iov, ic);
int len = call->WriteV(call->fd, iov, ic);
divx_printf(10, "xvid_Write < len=%d\n", len);
return len;
}

View File

@@ -103,25 +103,32 @@ static int32_t reset()
static int writeData(WriterAVCallData_t *call)
{
uint8_t PesHeader[PES_AUDIO_HEADER_SIZE];
dts_printf(10, "\n");
if (call == NULL)
{
dts_err("call data is NULL...\n");
return 0;
}
dts_printf(10, "AudioPts %lld\n", call->Pts);
if ((call->data == NULL) || (call->len <= 0))
{
dts_err("parsing NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
dts_err("file pointer < 0. ignoring ...\n");
return 0;
}
uint8_t *Data = call->data;
int32_t Size = call->len;
#ifdef CHECK_FOR_DTS_HD
int32_t pos = 0;
while ((pos + 4) <= Size)
@@ -135,6 +142,7 @@ static int writeData(WriterAVCallData_t *call)
++pos;
}
#endif
// #define DO_BYTESWAP
#ifdef DO_BYTESWAP
/* 16-bit byte swap all data before injecting it */
@@ -145,11 +153,13 @@ static int writeData(WriterAVCallData_t *call)
Data[i + 1] = Tmp;
}
#endif
struct iovec iov[2];
iov[0].iov_base = PesHeader;
iov[0].iov_len = InsertPesHeader(PesHeader, Size, MPEG_AUDIO_PES_START_CODE, call->Pts, 0);
iov[1].iov_base = Data;
iov[1].iov_len = Size;
int32_t len = call->WriteV(call->fd, iov, 2);
dts_printf(10, "< len %d\n", len);
return len;

View File

@@ -95,37 +95,46 @@ static int writeData(WriterAVCallData_t *call)
{
uint8_t PesHeader[PES_MAX_HEADER_SIZE];
int32_t len = 0;
h263_printf(10, "\n");
if (call == NULL)
{
h263_err("call data is NULL...\n");
return 0;
}
h263_printf(10, "VideoPts %lld\n", call->Pts);
if ((call->data == NULL) || (call->len <= 0))
{
h263_err("NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
h263_err("file pointer < 0. ignoring ...\n");
return 0;
}
int32_t HeaderLength = InsertPesHeader(PesHeader, call->len, MPEG_VIDEO_PES_START_CODE, call->Pts, 0);
int32_t PrivateHeaderLength = InsertVideoPrivateDataHeader(&PesHeader[HeaderLength], call->len);
int32_t PesLength = PesHeader[PES_LENGTH_BYTE_0] + (PesHeader[PES_LENGTH_BYTE_1] << 8) + PrivateHeaderLength;
PesHeader[PES_LENGTH_BYTE_0] = PesLength & 0xff;
PesHeader[PES_LENGTH_BYTE_1] = (PesLength >> 8) & 0xff;
PesHeader[PES_HEADER_DATA_LENGTH_BYTE] += PrivateHeaderLength;
PesHeader[PES_FLAGS_BYTE] |= PES_EXTENSION_DATA_PRESENT;
HeaderLength += PrivateHeaderLength;
struct iovec iov[2];
iov[0].iov_base = PesHeader;
iov[0].iov_len = HeaderLength;
iov[1].iov_base = call->data;
iov[1].iov_len = call->len;
len = call->WriteV(call->fd, iov, 2);
h263_printf(10, "< len %d\n", len);
return len;
}

View File

@@ -103,34 +103,45 @@ static int sps_pps_in_stream = 0;
static int32_t UpdateExtraData(uint8_t **ppExtraData, uint32_t *pExtraDataSize, uint8_t *pData, uint32_t dataSize)
{
uint8_t *aExtraData = *ppExtraData;
if (aExtraData[0] != 1 || !pData)
{
// Not AVCC or nothing to update with.
return -1;
}
int32_t nalsize = (aExtraData[4] & 3) + 1;
uint8_t sps[256];
uint8_t spsIdx = 0;
uint8_t numSps = 0;
uint8_t pps[256];
uint8_t ppsIdx = 0;
uint8_t numPps = 0;
if (nalsize != 4)
{
return -1;
}
// Find SPS and PPS NALUs in AVCC data
uint8_t *d = pData;
while (d + 4 < pData + dataSize)
{
uint32_t nalLen = ReadUint32(d);
uint8_t nalType = d[4] & 0x1f;
if (nalType == 7)
{
/* SPS */
// 16 bits size
sps[spsIdx++] = (uint8_t)(0xFF & (nalLen >> 8));
sps[spsIdx++] = (uint8_t)(0xFF & nalLen);
if (spsIdx + nalLen >= sizeof(sps))
{
h264_err("SPS no free space to copy...\n");
@@ -138,15 +149,19 @@ static int32_t UpdateExtraData(uint8_t **ppExtraData, uint32_t *pExtraDataSize,
}
memcpy(&(sps[spsIdx]), d + 4, nalLen);
spsIdx += nalLen;
numSps += 1;
h264_printf(10, "SPS len[%u]...\n", nalLen);
}
else if (nalType == 8)
{
/* PPS */
// 16 bits size
pps[ppsIdx++] = (uint8_t)(0xFF & (nalLen >> 8));
pps[ppsIdx++] = (uint8_t)(0xFF & nalLen);
if (ppsIdx + nalLen >= sizeof(sps))
{
h264_err("PPS not free space to copy...\n");
@@ -154,7 +169,9 @@ static int32_t UpdateExtraData(uint8_t **ppExtraData, uint32_t *pExtraDataSize,
}
memcpy(&(pps[ppsIdx]), d + 4, nalLen);
ppsIdx += nalLen;
numPps += 1;
h264_printf(10, "PPS len[%u]...\n", nalLen);
}
d += 4 + nalLen;
@@ -167,18 +184,21 @@ static int32_t UpdateExtraData(uint8_t **ppExtraData, uint32_t *pExtraDataSize,
aExtraData[idx++] = sps[4]; // profile compat
aExtraData[idx++] = sps[5]; // level
aExtraData[idx++] = 0xff; // nal size - 1
aExtraData[idx++] = 0xe0 | numSps;
if (numSps)
{
memcpy(&(aExtraData[idx]), sps, spsIdx);
idx += spsIdx;
}
aExtraData[idx++] = numPps;
if (numPps)
{
memcpy(&(aExtraData[idx]), pps, ppsIdx);
idx += ppsIdx;
}
h264_printf(10, "aExtraData len[%u]...\n", idx);
*pExtraDataSize = idx;
return 0;
@@ -192,6 +212,7 @@ static int32_t PreparCodecData(unsigned char *data, unsigned int cd_len, unsigne
{
unsigned char tmp[2048];
unsigned int tmp_len = 0;
unsigned int cd_pos = 0;
h264_printf(10, "H264 have codec data..!\n");
if (cd_len > 7 && data[0] == 1)
@@ -238,9 +259,11 @@ static int32_t PreparCodecData(unsigned char *data, unsigned int cd_len, unsigne
tmp_len += 4;
memcpy(tmp + tmp_len, data + cd_pos, len);
tmp_len += len;
CodecData = malloc(tmp_len);
memcpy(CodecData, tmp, tmp_len);
CodecDataLen = tmp_len;
*NalLength = (data[4] & 0x03) + 1;
ret = 0;
}
@@ -297,28 +320,34 @@ static int writeData(WriterAVCallData_t *call)
int ic = 0;
struct iovec iov[IOVEC_SIZE];
h264_printf(20, "\n");
if (call == NULL)
{
h264_err("call data is NULL...\n");
return 0;
}
TimeDelta = call->FrameRate;
TimeScale = call->FrameScale;
/* avoid compiler warnings */
if (TimeDelta) {}
if (TimeScale) {}
VideoPts = call->Pts;
h264_printf(20, "VideoPts %lld - %d %d\n", call->Pts, TimeDelta, TimeScale);
if ((call->data == NULL) || (call->len <= 0))
{
h264_err("NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
h264_err("file pointer < 0. ignoring ...\n");
return 0;
}
/* AnnexA */
if (!avc3 && ((1 < call->private_size && 0 == call->private_data[0]) ||
((call->len > 3) && ((call->data[0] == 0x00 && call->data[1] == 0x00 && call->data[2] == 0x00 && call->data[3] == 0x01) ||
@@ -329,6 +358,7 @@ static int writeData(WriterAVCallData_t *call)
uint32_t PacketLength = 0;
uint32_t FakeStartCode = (call->Version << 8) | PES_VERSION_FAKE_START_CODE;
iov[ic++].iov_base = PesHeader;
while (InsertPrivData && i < 36 && (call->len - i) > 5)
{
if ((call->data[i] == 0x00 && call->data[i + 1] == 0x00 && call->data[i + 2] == 0x00 && call->data[i + 3] == 0x01 && (call->data[i + 4] == 0x67 || call->data[i + 4] == 0x68)))
@@ -338,6 +368,7 @@ static int writeData(WriterAVCallData_t *call)
}
i += 1;
}
if (InsertPrivData && call->private_size > 0 /*&& initialHeader*/) // some rtsp streams can update codec data at runtime
{
initialHeader = 0;
@@ -345,10 +376,13 @@ static int writeData(WriterAVCallData_t *call)
iov[ic++].iov_len = call->private_size;
PacketLength += call->private_size;
}
iov[ic].iov_base = call->data;
iov[ic++].iov_len = call->len;
PacketLength += call->len;
iov[0].iov_len = InsertPesHeader(PesHeader, -1, MPEG_VIDEO_PES_START_CODE, VideoPts, FakeStartCode);
return call->WriteV(call->fd, iov, ic);
}
else if (!call->private_data || call->private_size < 7 || 1 != call->private_data[0])
@@ -356,9 +390,12 @@ static int writeData(WriterAVCallData_t *call)
h264_err("No valid private data available! [%d]\n", (int)call->private_size);
return 0;
}
uint32_t PacketLength = 0;
ic = 0;
iov[ic++].iov_base = PesHeader;
//if (initialHeader)
{
if (CodecData)
@@ -366,19 +403,23 @@ static int writeData(WriterAVCallData_t *call)
free(CodecData);
CodecData = NULL;
}
uint8_t *private_data = call->private_data;
uint32_t private_size = call->private_size;
if (PreparCodecData(private_data, private_size, &NalLengthBytes))
{
UpdateExtraData(&private_data, &private_size, call->data, call->len);
PreparCodecData(private_data, private_size, &NalLengthBytes);
}
if (private_data != call->private_data)
{
avc3 = 1;
free(private_data);
private_data = NULL;
}
if (CodecData != NULL)
{
iov[ic].iov_base = CodecData;
@@ -387,6 +428,7 @@ static int writeData(WriterAVCallData_t *call)
initialHeader = 0;
}
}
if (CodecData != NULL)
{
uint32_t pos = 0;
@@ -397,6 +439,7 @@ static int writeData(WriterAVCallData_t *call)
h264_err(">> Drop data due to ic overflow\n");
break;
}
uint32_t pack_len = 0;
uint32_t i = 0;
for (i = 0; i < NalLengthBytes; i++, pos++)
@@ -404,21 +447,28 @@ static int writeData(WriterAVCallData_t *call)
pack_len <<= 8;
pack_len += call->data[pos];
}
if ((pos + pack_len) > call->len)
{
pack_len = call->len - pos;
}
iov[ic].iov_base = Head;
iov[ic++].iov_len = sizeof(Head);
PacketLength += sizeof(Head);
iov[ic].iov_base = call->data + pos;
iov[ic++].iov_len = pack_len;
PacketLength += pack_len;
pos += pack_len;
}
while ((pos + NalLengthBytes) < call->len);
h264_printf(10, "<<<< PacketLength [%d]\n", PacketLength);
iov[0].iov_len = InsertPesHeader(PesHeader, -1, MPEG_VIDEO_PES_START_CODE, VideoPts, 0);
len = call->WriteV(call->fd, iov, ic);
PacketLength += iov[0].iov_len;
if (PacketLength != len)
@@ -426,6 +476,7 @@ static int writeData(WriterAVCallData_t *call)
h264_err("<<<< not all data have been written [%d/%d]\n", len, PacketLength);
}
}
h264_printf(10, "< len %d\n", len);
return len;
}

View File

@@ -105,7 +105,9 @@ static int32_t PreparCodecData(unsigned char *data, unsigned int cd_len, unsigne
{
unsigned char tmp[2048];
unsigned int tmp_len = 0;
h264_printf(10, "H265 have codec data..!");
if (cd_len > 3 && (data[0] || data[1] || data[2] > 1))
{
if (cd_len > 22)
@@ -115,6 +117,7 @@ static int32_t PreparCodecData(unsigned char *data, unsigned int cd_len, unsigne
{
h264_printf(10, "Unsupported extra data version %d, decoding may fail", (int)data[0]);
}
*NalLength = (data[21] & 3) + 1;
int num_param_sets = data[22];
uint32_t pos = 23;
@@ -150,6 +153,7 @@ static int32_t PreparCodecData(unsigned char *data, unsigned int cd_len, unsigne
pos += nal_size;
}
}
CodecData = malloc(tmp_len);
memcpy(CodecData, tmp, tmp_len);
CodecDataLen = tmp_len;
@@ -160,6 +164,7 @@ static int32_t PreparCodecData(unsigned char *data, unsigned int cd_len, unsigne
{
*NalLength = 0;
}
return ret;
}
@@ -179,33 +184,40 @@ static int writeData(WriterAVCallData_t *call)
int ic = 0;
struct iovec iov[IOVEC_SIZE];
h264_printf(20, "\n");
if (call == NULL)
{
h264_err("call data is NULL...\n");
return 0;
}
TimeDelta = call->FrameRate;
TimeScale = call->FrameScale;
/* avoid compiler warnings */
if (TimeDelta) {}
if (TimeScale) {}
VideoPts = call->Pts;
h264_printf(20, "VideoPts %lld - %d %d\n", call->Pts, TimeDelta, TimeScale);
if ((call->data == NULL) || (call->len <= 0))
{
h264_err("NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
h264_err("file pointer < 0. ignoring ...\n");
return 0;
}
if (call->InfoFlags & 0x1) // TS container
{
h264_printf(10, "H265 simple inject method!\n");
uint32_t PacketLength = 0;
uint32_t FakeStartCode = (call->Version << 8) | PES_VERSION_FAKE_START_CODE;
iov[ic++].iov_base = PesHeader;
initialHeader = 0;
if (initialHeader)
@@ -215,17 +227,24 @@ static int writeData(WriterAVCallData_t *call)
iov[ic++].iov_len = call->private_size;
PacketLength += call->private_size;
}
iov[ic].iov_base = "";
iov[ic++].iov_len = 1;
iov[ic].iov_base = call->data;
iov[ic++].iov_len = call->len;
PacketLength += call->len;
iov[0].iov_len = InsertPesHeader(PesHeader, -1, MPEG_VIDEO_PES_START_CODE, VideoPts, FakeStartCode);
return call->WriteV(call->fd, iov, ic);
}
uint32_t PacketLength = 0;
ic = 0;
iov[ic++].iov_base = PesHeader;
if (initialHeader)
{
if (CodecData)
@@ -233,9 +252,12 @@ static int writeData(WriterAVCallData_t *call)
free(CodecData);
CodecData = NULL;
}
uint8_t *private_data = call->private_data;
uint32_t private_size = call->private_size;
PreparCodecData(private_data, private_size, &NalLengthBytes);
if (CodecData != NULL)
{
iov[ic].iov_base = CodecData;
@@ -244,6 +266,7 @@ static int writeData(WriterAVCallData_t *call)
initialHeader = 0;
}
}
if (CodecData != NULL)
{
uint32_t pos = 0;
@@ -254,6 +277,7 @@ static int writeData(WriterAVCallData_t *call)
h264_err(">> Drop data due to ic overflow\n");
break;
}
uint32_t pack_len = 0;
uint32_t i = 0;
for (i = 0; i < NalLengthBytes; i++, pos++)
@@ -261,21 +285,28 @@ static int writeData(WriterAVCallData_t *call)
pack_len <<= 8;
pack_len += call->data[pos];
}
if ((pos + pack_len) > call->len)
{
pack_len = call->len - pos;
}
iov[ic].iov_base = Head;
iov[ic++].iov_len = sizeof(Head);
PacketLength += sizeof(Head);
iov[ic].iov_base = call->data + pos;
iov[ic++].iov_len = pack_len;
PacketLength += pack_len;
pos += pack_len;
}
while ((pos + NalLengthBytes) < call->len);
h264_printf(10, "<<<< PacketLength [%d]\n", PacketLength);
iov[0].iov_len = InsertPesHeader(PesHeader, -1, MPEG_VIDEO_PES_START_CODE, VideoPts, 0);
len = call->WriteV(call->fd, iov, ic);
PacketLength += iov[0].iov_len;
if (PacketLength != len)
@@ -283,6 +314,7 @@ static int writeData(WriterAVCallData_t *call)
h264_err("<<<< not all data have been written [%d/%d]\n", len, PacketLength);
}
}
h264_printf(10, "< len %d\n", len);
return len;
}

View File

@@ -59,7 +59,6 @@
/* ***************************** */
//#define SAM_WITH_DEBUG
#ifdef SAM_WITH_DEBUG
#define LPCM_DEBUG
#else
@@ -135,23 +134,29 @@ static int32_t reset()
static int writeData(WriterAVCallData_t *call)
{
lpcm_printf(10, "\n");
if (!call)
{
lpcm_err("call data is NULL...\n");
return 0;
}
lpcm_printf(10, "AudioPts %lld\n", call->Pts);
if (!call->data || (call->len <= 0))
{
lpcm_err("parsing NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
lpcm_err("file pointer < 0. ignoring ...\n");
return 0;
}
pcmPrivateData_t *pcmPrivateData = (pcmPrivateData_t *)call->private_data;
int32_t i_rate = (int32_t)pcmPrivateData->sample_rate;
int32_t i_channels = (int32_t)pcmPrivateData->channels;
int32_t i_nb_samples = call->len / (i_channels * 2);
@@ -161,6 +166,7 @@ static int writeData(WriterAVCallData_t *call)
lpcm_err("Error DVD LPCM supports a maximum of eight channels i_channels[%d]\n", i_channels);
return 0;
}
if (pcmPrivateData->bResampling || NULL == p_buffer)
{
lpcm_printf(1, "i_rate: [%d]\n", i_rate);
@@ -183,6 +189,7 @@ static int writeData(WriterAVCallData_t *call)
lpcm_err("Error DVD LPCM sample_rate not supported [%d]\n", i_rate);
return 0;
}
/* In DVD LCPM, a frame is always 150 PTS ticks. */
i_frame_samples = i_rate * 150 / 90000;
i_frame_size = i_frame_samples * i_channels * 2 + LLPCM_VOB_HEADER_LEN;
@@ -191,6 +198,7 @@ static int writeData(WriterAVCallData_t *call)
free(p_buffer);
}
p_buffer = malloc(i_frame_samples * i_channels * 16);
if (NULL != p_frame_buffer)
{
free(p_frame_buffer);
@@ -200,9 +208,11 @@ static int writeData(WriterAVCallData_t *call)
i_frame_num = 0;
i_bitspersample = 16;
}
const int i_num_frames = (i_buffer_used + i_nb_samples) / i_frame_samples;
const int i_leftover_samples = (i_buffer_used + i_nb_samples) % i_frame_samples;
const int i_start_offset = -i_buffer_used;
int32_t i_bytes_consumed = 0;
int32_t i = 0;
for (i = 0; i < i_num_frames; ++i)
@@ -214,9 +224,11 @@ static int writeData(WriterAVCallData_t *call)
frame[3] = (i_frame_num + i) & 0x1f; /* no emphasis, no mute */
frame[4] = (i_freq_code << 4) | (i_channels - 1);
frame[5] = 0x80; /* neutral dynamic range */
const int i_consume_samples = i_frame_samples - i_buffer_used;
const int i_kept_bytes = i_buffer_used * i_channels * 2;
const int i_consume_bytes = i_consume_samples * i_channels * 2;
#ifdef WORDS_BIGENDIAN
memcpy(frame + 6, p_buffer, i_kept_bytes);
memcpy(frame + 6 + i_kept_bytes, call->data + i_bytes_consumed, i_consume_bytes);
@@ -224,15 +236,20 @@ static int writeData(WriterAVCallData_t *call)
swab(p_buffer, frame + 6, i_kept_bytes);
swab(call->data + i_bytes_consumed, frame + 6 + i_kept_bytes, i_consume_bytes);
#endif
i_frame_num++;
i_buffer_used = 0;
i_bytes_consumed += i_consume_bytes;
/* We need to find i_length by means of next_pts due to possible roundoff errors. */
uint64_t this_pts = call->Pts + (i * i_frame_samples + i_start_offset) * 90000 / i_rate;
uint32_t pes_header_size = 0;
pes_header_size = InsertPesHeader(PesHeader, i_frame_size + 1, MPEG_AUDIO_PES_START_CODE, this_pts, 0);
PesHeader[pes_header_size] = 0xa0;
pes_header_size += 1;
struct iovec iov[2];
iov[0].iov_base = PesHeader;
iov[0].iov_len = pes_header_size;
@@ -240,8 +257,10 @@ static int writeData(WriterAVCallData_t *call)
iov[1].iov_len = i_frame_size;
i_ret_size += call->WriteV(call->fd, iov, 2);
}
memcpy(p_buffer, call->data + i_bytes_consumed, i_leftover_samples * i_channels * 2);
i_buffer_used = i_leftover_samples;
return i_ret_size;
}

View File

@@ -94,24 +94,31 @@ static int reset()
static int writeData(WriterAVCallData_t *call)
{
unsigned char PesHeader[PES_MAX_HEADER_SIZE + 22];
mp3_printf(10, "\n");
if (call == NULL)
{
mp3_err("call data is NULL...\n");
return 0;
}
mp3_printf(10, "AudioPts %lld\n", call->Pts);
if ((call->data == NULL) || (call->len <= 0))
{
mp3_err("parsing NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
mp3_err("file pointer < 0. ignoring ...\n");
return 0;
}
call->private_size = 0;
uint32_t headerSize = InsertPesHeader(PesHeader, call->len + call->private_size, MPEG_AUDIO_PES_START_CODE, call->Pts, 0);
if (call->private_size > 0)
{
@@ -123,7 +130,9 @@ static int writeData(WriterAVCallData_t *call)
iov[0].iov_len = headerSize;
iov[1].iov_base = call->data;
iov[1].iov_len = call->len;
int len = call->WriteV(call->fd, iov, 2);
mp3_printf(10, "mp3_Write-< len=%d\n", len);
return len;
}

View File

@@ -95,36 +95,47 @@ static int reset()
static int writeData(WriterAVCallData_t *call)
{
unsigned char PesHeader[PES_MAX_HEADER_SIZE];
int len = 0;
unsigned int Position = 0;
mpeg2_printf(10, "\n");
if (call == NULL)
{
mpeg2_err("call data is NULL...\n");
return 0;
}
mpeg2_printf(10, "VideoPts %lld\n", call->Pts);
if ((call->data == NULL) || (call->len <= 0))
{
mpeg2_err("parsing NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
mpeg2_err("file pointer < 0. ignoring ...\n");
return 0;
}
while (Position < call->len)
{
int PacketLength = (call->len - Position) <= MAX_PES_PACKET_SIZE ?
(call->len - Position) : MAX_PES_PACKET_SIZE;
int Remaining = call->len - Position - PacketLength;
mpeg2_printf(20, "PacketLength=%d, Remaining=%d, Position=%d\n", PacketLength, Remaining, Position);
struct iovec iov[2];
iov[0].iov_base = PesHeader;
iov[0].iov_len = InsertPesHeader(PesHeader, PacketLength, 0xe0, call->Pts, 0);
iov[1].iov_base = call->data + Position;
iov[1].iov_len = PacketLength;
ssize_t l = call->WriteV(call->fd, iov, 2);
if (l < 0)
{
@@ -132,9 +143,11 @@ static int writeData(WriterAVCallData_t *call)
break;
}
len += l;
Position += PacketLength;
call->Pts = INVALID_PTS_VALUE;
}
mpeg2_printf(10, "< len %d\n", len);
return len;
}

View File

@@ -103,32 +103,40 @@ static int reset()
static int writeData(WriterAVCallData_t *call)
{
unsigned char PesHeader[PES_MAX_HEADER_SIZE];
mpeg4_printf(10, "\n");
if (call == NULL)
{
mpeg4_err("call data is NULL...\n");
return 0;
}
if ((call->data == NULL) || (call->len <= 0))
{
mpeg4_err("parsing NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
mpeg4_err("file pointer < 0. ignoring ...\n");
return 0;
}
mpeg4_printf(10, "VideoPts %lld\n", call->Pts);
unsigned int PacketLength = call->len;
if (initialHeader && call->private_size && call->private_data != NULL)
{
PacketLength += call->private_size;
}
struct iovec iov[3];
int ic = 0;
iov[ic].iov_base = PesHeader;
iov[ic++].iov_len = InsertPesHeader(PesHeader, PacketLength, MPEG_VIDEO_PES_START_CODE, call->Pts, 0);
if (initialHeader && call->private_size && call->private_data != NULL)
{
initialHeader = 0;
@@ -137,8 +145,11 @@ static int writeData(WriterAVCallData_t *call)
}
iov[ic].iov_base = call->data;
iov[ic++].iov_len = call->len;
int len = call->WriteV(call->fd, iov, ic);
mpeg4_printf(10, "xvid_Write < len=%d\n", len);
return len;
}

View File

@@ -56,8 +56,6 @@
/* Makros/Constants */
/* ***************************** */
//#define SAM_WITH_DEBUG
#ifdef SAM_WITH_DEBUG
#define PCM_DEBUG
#else
@@ -113,26 +111,32 @@ static int32_t reset()
static int writeData(WriterAVCallData_t *call)
{
pcm_printf(10, "\n");
if (!call)
{
pcm_err("call data is NULL...\n");
return 0;
}
pcm_printf(10, "AudioPts %lld\n", call->Pts);
if (!call->data || (call->len <= 0))
{
pcm_err("parsing NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
pcm_err("file pointer < 0. ignoring ...\n");
return 0;
}
static uint8_t PesHeader[PES_MAX_HEADER_SIZE + 22];
pcmPrivateData_t *pcmPrivateData = (pcmPrivateData_t *)call->private_data;
uint8_t *buffer = call->data;
uint32_t size = call->len;
if (pcmPrivateData->bResampling || NULL == fixed_buffer)
{
if (0)
@@ -143,14 +147,18 @@ static int writeData(WriterAVCallData_t *call)
printf("ioctl %d", ioctl(call->fd, AUDIO_PLAY));
printf("ioctl %d", ioctl(call->fd, AUDIO_CONTINUE));
}
int32_t format = 0x01;
int32_t width = 0;
int32_t depth = 0;
int32_t rate = (uint64_t)pcmPrivateData->sample_rate;
int32_t channels = (uint8_t) pcmPrivateData->channels;
int32_t block_align = 0;
int32_t byterate = 0;
uint32_t codecID = (uint32_t)pcmPrivateData->ffmpeg_codec_id;
//uint8_t dataPrecision = 0;
uint8_t LE = 0;
switch (codecID)
@@ -183,7 +191,9 @@ static int writeData(WriterAVCallData_t *call)
default:
break;
}
uint8_t *data = codec_data;
byterate = channels * rate * width / 8;
block_align = channels * width / 8;
memset(data, 0, sizeof(codec_data));
@@ -209,10 +219,12 @@ static int writeData(WriterAVCallData_t *call)
/* word size */
*(data++) = depth & 0xff;
*(data++) = (depth >> 8) & 0xff;
uint32_t nfixed_buffersize = rate * 30 / 1000;
nfixed_buffersize *= channels * depth / 8;
fixed_buffertimestamp = call->Pts;
fixed_bufferduration = 90000 * nfixed_buffersize / byterate;
if (fixed_buffersize != nfixed_buffersize || NULL == fixed_buffer)
{
fixed_buffersize = nfixed_buffersize;
@@ -227,6 +239,7 @@ static int writeData(WriterAVCallData_t *call)
if (LE) {}
//printf("PCM fixed_buffersize [%u] [%s]\n", fixed_buffersize, LE ? "LE":"BE");
}
while (size > 0)
{
uint32_t cpSize = (fixed_buffersize - fixed_bufferfilled);
@@ -236,10 +249,12 @@ static int writeData(WriterAVCallData_t *call)
fixed_bufferfilled += size;
return size;
}
memcpy(fixed_buffer + fixed_bufferfilled, buffer, cpSize);
fixed_bufferfilled = 0;
buffer += cpSize;
size -= cpSize;
uint32_t addHeaderSize = 0;
if (IsDreambox())
{
@@ -253,13 +268,17 @@ static int writeData(WriterAVCallData_t *call)
PesHeader[headerSize++] = 0x4D; // M
PesHeader[headerSize++] = 0x41; // A
}
PesHeader[headerSize++] = (fixed_buffersize >> 24) & 0xff;
PesHeader[headerSize++] = (fixed_buffersize >> 16) & 0xff;
PesHeader[headerSize++] = (fixed_buffersize >> 8) & 0xff;
PesHeader[headerSize++] = fixed_buffersize & 0xff;
memcpy(PesHeader + headerSize, codec_data, sizeof(codec_data));
headerSize += sizeof(codec_data);
PesHeader[6] |= 1;
struct iovec iov[2];
iov[0].iov_base = PesHeader;
iov[0].iov_len = headerSize;
@@ -267,10 +286,13 @@ static int writeData(WriterAVCallData_t *call)
iov[1].iov_len = fixed_buffersize;
call->WriteV(call->fd, iov, 2);
fixed_buffertimestamp += fixed_bufferduration;
int g_fd_dump = open("/hdd/lpcm/ffmpeg.pes", O_CREAT | O_RDWR | O_APPEND, S_IRUSR | S_IWUSR);
int g_fd_dump = open("/hdd/lpcm/ffmpeg.pes", O_CREAT |
O_RDWR | O_APPEND, S_IRUSR | S_IWUSR);
call->WriteV(g_fd_dump, iov, 2);
close(g_fd_dump);
}
return size;
}

View File

@@ -79,6 +79,7 @@ if (debug_level >= level) printf("[%s:%s] " fmt, __FILE__, __FUNCTION__, ## x);
#define vc1_err(fmt, x...)
#endif
/* ***************************** */
/* Types */
/* ***************************** */
@@ -110,28 +111,35 @@ static int reset()
static int writeData(WriterAVCallData_t *call)
{
//int len = 0;
vc1_printf(10, "\n");
if (call == NULL)
{
vc1_err("call data is NULL...\n");
return 0;
}
if ((call->data == NULL) || (call->len <= 0))
{
vc1_err("parsing NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
vc1_err("file pointer < 0. ignoring ...\n");
return 0;
}
vc1_printf(10, "VideoPts %lld\n", call->Pts);
vc1_printf(10, "Got Private Size %d\n", call->private_size);
unsigned char PesHeader[PES_MAX_HEADER_SIZE + sizeof(Vc1FrameStartCode)];
int32_t ic = 0;
struct iovec iov[5];
unsigned int PacketLength = 0;
iov[ic++].iov_base = PesHeader;
if (initialHeader)
{
@@ -152,6 +160,7 @@ static int writeData(WriterAVCallData_t *call)
PacketLength += videocodecdata.length;
}
}
uint8_t needFrameStartCode = 0;
if (sizeof(Vc1FrameStartCode) >= call->len ||
memcmp(call->data, Vc1FrameStartCode, sizeof(Vc1FrameStartCode)) != 0)
@@ -159,22 +168,28 @@ static int writeData(WriterAVCallData_t *call)
needFrameStartCode = 1;
PacketLength += sizeof(Vc1FrameStartCode);
}
iov[ic].iov_base = call->data;
iov[ic++].iov_len = call->len;
PacketLength += call->len;
iov[0].iov_len = InsertPesHeader(PesHeader, PacketLength, MPEG_VIDEO_PES_START_CODE, call->Pts, 0);
/* some mipsel receiver(s) like et4x00 needs to have Copy(0)/Original(1) flag set to Original */
PesHeader[6] |= 1;
if (needFrameStartCode)
{
memcpy(PesHeader + iov[0].iov_len, Vc1FrameStartCode, sizeof(Vc1FrameStartCode));
iov[0].iov_len += sizeof(Vc1FrameStartCode);
}
if (videocodecdata.data)
{
free(videocodecdata.data);
videocodecdata.data = NULL;
}
return call->WriteV(call->fd, iov, ic);
}

View File

@@ -54,7 +54,6 @@
/* ***************************** */
//#define SAM_WITH_DEBUG
#ifdef SAM_WITH_DEBUG
#define VP_DEBUG
#else
@@ -77,6 +76,7 @@ if (debug_level >= level) printf("[%s:%s] " fmt, __FILE__, __FUNCTION__, ## x);
#define vp_err(fmt, x...)
#endif
/* ***************************** */
/* Types */
/* ***************************** */
@@ -101,25 +101,31 @@ static int reset()
static int writeData(WriterAVCallData_t *call, int is_vp6)
{
vp_printf(10, "\n");
if (call == NULL)
{
vp_err("call data is NULL...\n");
return 0;
}
if ((call->data == NULL) || (call->len <= 0))
{
vp_err("parsing NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
vp_err("file pointer < 0. ignoring ...\n");
return 0;
}
vp_printf(10, "VideoPts %lld\n", call->Pts);
vp_printf(10, "Got Private Size %d\n", call->private_size);
unsigned char PesHeader[PES_MAX_HEADER_SIZE];
struct iovec iov[2];
iov[0].iov_base = PesHeader;
uint32_t pes_header_len = InsertPesHeader(PesHeader, call->len, MPEG_VIDEO_PES_START_CODE, call->Pts, 0);
uint32_t len = call->len + 4 + 6;
@@ -138,6 +144,7 @@ static int writeData(WriterAVCallData_t *call, int is_vp6)
iov[0].iov_len = pes_header_len;
iov[1].iov_base = call->data;
iov[1].iov_len = call->len;
return call->WriteV(call->fd, iov, 2);
}

View File

@@ -53,8 +53,6 @@
/* Makros/Constants */
/* ***************************** */
//#define SAM_WITH_DEBUG
#ifdef SAM_WITH_DEBUG
#define WMA_DEBUG
#else
@@ -106,28 +104,36 @@ static int reset()
static int writeData(WriterAVCallData_t *call)
{
//int len = 0;
wma_printf(10, "\n");
if (call == NULL)
{
wma_err("call data is NULL...\n");
return 0;
}
wma_printf(10, "AudioPts %lld\n", call->Pts);
if ((call->data == NULL) || (call->len <= 0))
{
wma_err("parsing NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
wma_err("file pointer < 0. ignoring ...\n");
return 0;
}
uint32_t packetLength = 4 + call->private_size + call->len;
if (IsDreambox())
{
packetLength += 4;
}
if ((packetLength + PES_MAX_HEADER_SIZE) > MaxPesHeader)
{
if (PesHeader)
@@ -137,6 +143,7 @@ static int writeData(WriterAVCallData_t *call)
MaxPesHeader = packetLength + PES_MAX_HEADER_SIZE;
PesHeader = malloc(MaxPesHeader);
}
uint32_t headerSize = InsertPesHeader(PesHeader, packetLength, MPEG_AUDIO_PES_START_CODE, call->Pts, 0);
if (IsDreambox())
{
@@ -145,14 +152,18 @@ static int writeData(WriterAVCallData_t *call)
PesHeader[headerSize++] = 0x4D; // M
PesHeader[headerSize++] = 0x41; // A
}
size_t payload_len = call->len;
PesHeader[headerSize++] = (payload_len >> 24) & 0xff;
PesHeader[headerSize++] = (payload_len >> 16) & 0xff;
PesHeader[headerSize++] = (payload_len >> 8) & 0xff;
PesHeader[headerSize++] = payload_len & 0xff;
memcpy(PesHeader + headerSize, call->private_data, call->private_size);
headerSize += call->private_size;
PesHeader[6] |= 1;
struct iovec iov[2];
iov[0].iov_base = PesHeader;
iov[0].iov_len = headerSize;

View File

@@ -108,27 +108,33 @@ static int reset()
static int writeData(WriterAVCallData_t *call)
{
wmv_printf(10, "\n");
if (call == NULL)
{
wmv_err("call data is NULL...\n");
return 0;
}
if ((call->data == NULL) || (call->len <= 0))
{
wmv_err("parsing NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
wmv_err("file pointer < 0. ignoring ...\n");
return 0;
}
wmv_printf(10, "VideoPts %lld\n", call->Pts);
wmv_printf(10, "Got Private Size %d\n", call->private_size);
unsigned char PesHeader[PES_MAX_HEADER_SIZE + sizeof(Vc1FrameStartCode)];
int32_t ic = 0;
struct iovec iov[5];
unsigned int PacketLength = 0;
iov[ic++].iov_base = PesHeader;
if (initialHeader)
{
@@ -138,8 +144,10 @@ static int writeData(WriterAVCallData_t *call)
free(videocodecdata.data);
videocodecdata.data = NULL;
}
unsigned int codec_size = call->private_size;
if (codec_size > 4) codec_size = 4;
videocodecdata.length = 33;
uint8_t *data = videocodecdata.data = malloc(videocodecdata.length);
memset(videocodecdata.data, 0, videocodecdata.length);
@@ -158,6 +166,7 @@ static int writeData(WriterAVCallData_t *call)
PacketLength += videocodecdata.length;
}
}
uint8_t needFrameStartCode = 0;
if (sizeof(Vc1FrameStartCode) >= call->len ||
memcmp(call->data, Vc1FrameStartCode, sizeof(Vc1FrameStartCode)) != 0)
@@ -165,22 +174,28 @@ static int writeData(WriterAVCallData_t *call)
needFrameStartCode = 1;
PacketLength += sizeof(Vc1FrameStartCode);
}
iov[ic].iov_base = call->data;
iov[ic++].iov_len = call->len;
PacketLength += call->len;
iov[0].iov_len = InsertPesHeader(PesHeader, PacketLength, MPEG_VIDEO_PES_START_CODE, call->Pts, 0);
/* some mipsel receiver(s) like et4x00 needs to have Copy(0)/Original(1) flag set to Original */
PesHeader[6] |= 1;
if (needFrameStartCode)
{
memcpy(PesHeader + iov[0].iov_len, Vc1FrameStartCode, sizeof(Vc1FrameStartCode));
iov[0].iov_len += sizeof(Vc1FrameStartCode);
}
if (videocodecdata.data)
{
free(videocodecdata.data);
videocodecdata.data = NULL;
}
return call->WriteV(call->fd, iov, ic);
}

View File

@@ -111,7 +111,7 @@ ssize_t WriteWithRetry(Context_t *context, int pipefd, int fd, const void *buf,
{
fd_set rfds;
fd_set wfds;
ssize_t ret;
int retval = -1;
int maxFd = pipefd > fd ? pipefd : fd;
@@ -125,36 +125,36 @@ ssize_t WriteWithRetry(Context_t *context, int pipefd, int fd, const void *buf,
FD_SET(pipefd, &rfds);
FD_SET(fd, &wfds);
/* When we PAUSE LINUX DVB outputs buffers then audio/video buffers
* will be filled to full unfortunately, in such case after resume
/* When we PAUSE LINUX DVB outputs buffers then audio/video buffers
* will be filled to full unfortunately, in such case after resume
* select never return with fd set - bug in DVB drivers?
* So, there will be to workarounds:
* 1. write to pipe pipe at resume to exit select immediately
* 2. even if fd is not set exit from select after 0,1s
* 2. even if fd is not set exit from select after 0,1s
* (it seems that second workaround is not needed)
*/
//tv.tv_sec = 0;
//tv.tv_usec = 100000; // 100ms
retval = select(maxFd + 1, &rfds, &wfds, NULL, NULL); //&tv);
if (retval < 0)
{
break;
}
//if (retval == 0)
//{
// //printf("RETURN FROM SELECT DUE TO TIMEOUT TIMEOUT\n");
// continue;
//}
if(FD_ISSET(pipefd, &rfds))
{
FlusPipe(pipefd);
//printf("RETURN FROM SELECT DUE TO pipefd SET\n");
continue;
}
if(FD_ISSET(fd, &wfds))
{
ret = write(fd, buf, size);
@@ -173,7 +173,7 @@ ssize_t WriteWithRetry(Context_t *context, int pipefd, int fd, const void *buf,
{
break;
}
return ret;
}
else if (ret == 0)
@@ -186,7 +186,7 @@ ssize_t WriteWithRetry(Context_t *context, int pipefd, int fd, const void *buf,
FlusPipe(pipefd);
continue;
}
size -= ret;
buf += ret;
}
@@ -219,12 +219,15 @@ ssize_t write_with_retry(int fd, const void *buf, size_t size)
break;
}
}
if (ret < 0)
{
return ret;
}
size -= ret;
buf += ret;
if (size > 0)
{
if (usleep(1000))
@@ -255,6 +258,7 @@ ssize_t writev_with_retry(int fd, const struct iovec *iov, size_t ic)
Writer_t *getWriter(char *encoding)
{
int i;
for (i = 0; AvailableWriter[i] != NULL; i++)
{
if (strcmp(AvailableWriter[i]->caps->textEncoding, encoding) == 0)
@@ -263,13 +267,16 @@ Writer_t *getWriter(char *encoding)
return AvailableWriter[i];
}
}
writer_printf(1, "%s: no writer found for \"%s\"\n", __func__, encoding);
return NULL;
}
Writer_t *getDefaultVideoWriter()
{
int i;
for (i = 0; AvailableWriter[i] != NULL; i++)
{
if (strcmp(AvailableWriter[i]->caps->textEncoding, "V_MPEG2") == 0)
@@ -278,13 +285,16 @@ Writer_t *getDefaultVideoWriter()
return AvailableWriter[i];
}
}
writer_printf(1, "%s: no writer found\n", __func__);
return NULL;
}
Writer_t *getDefaultAudioWriter()
{
int i;
for (i = 0; AvailableWriter[i] != NULL; i++)
{
if (strcmp(AvailableWriter[i]->caps->textEncoding, "A_MP3") == 0)
@@ -293,6 +303,8 @@ Writer_t *getDefaultAudioWriter()
return AvailableWriter[i];
}
}
writer_printf(1, "%s: no writer found\n", __func__);
return NULL;
}

View File

@@ -43,6 +43,7 @@
#include <libavutil/intreadwrite.h>
#include "ffmpeg/latmenc.h"
#include "common.h"
#include "output.h"
#include "debug.h"
@@ -157,17 +158,21 @@ static int reset()
static int _writeData(void *_call, int type)
{
WriterAVCallData_t *call = (WriterAVCallData_t *) _call;
aac_printf(10, "\n _writeData type[%d]\n", type);
if (call == NULL)
{
aac_err("call data is NULL...\n");
return 0;
}
if ((call->data == NULL) || (call->len < 8))
{
aac_err("parsing Data with missing AAC header. ignoring...\n");
return 0;
}
/* simple validation */
if (0 == type) // check ADTS header
{
@@ -194,9 +199,13 @@ static int _writeData(void *_call, int type)
return 0;
}
}
unsigned char PesHeader[PES_MAX_HEADER_SIZE];
aac_printf(10, "AudioPts %lld\n", call->Pts);
unsigned int HeaderLength = InsertPesHeader(PesHeader, call->len, MPEG_AUDIO_PES_START_CODE, call->Pts, 0);
struct iovec iov[2];
iov[0].iov_base = PesHeader;
iov[0].iov_len = HeaderLength;
@@ -208,31 +217,38 @@ static int _writeData(void *_call, int type)
static int writeDataADTS(void *_call)
{
WriterAVCallData_t *call = (WriterAVCallData_t *) _call;
aac_printf(10, "\n");
if (call == NULL)
{
aac_err("call data is NULL...\n");
return 0;
}
if ((call->data == NULL) || (call->len <= 0))
{
aac_err("parsing NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
aac_err("file pointer < 0. ignoring ...\n");
return 0;
}
if ((call->private_data && 0 == strncmp("ADTS", call->private_data, call->private_size)) ||
HasADTSHeader(call->data, call->len))
{
return _writeData(_call, 0);
}
uint32_t PacketLength = call->len + AAC_HEADER_LENGTH;
uint8_t PesHeader[PES_MAX_HEADER_SIZE + AAC_HEADER_LENGTH];
uint32_t headerSize = InsertPesHeader(PesHeader, PacketLength, MPEG_AUDIO_PES_START_CODE, call->Pts, 0);
uint8_t *pExtraData = &PesHeader[headerSize];
aac_printf(10, "AudioPts %lld\n", call->Pts);
if (call->private_data == NULL)
{
@@ -243,6 +259,7 @@ static int writeDataADTS(void *_call)
{
memcpy(pExtraData, call->private_data, AAC_HEADER_LENGTH);
}
pExtraData[3] &= 0xC0;
/* frame size over last 2 bits */
pExtraData[3] |= (PacketLength & 0x1800) >> 11;
@@ -255,33 +272,41 @@ static int writeDataADTS(void *_call)
/* buffer fullness(0x7FF for VBR) continued over 6 first bits + 2 zeros for
* number of raw data blocks */
pExtraData[6] = 0xFC;
struct iovec iov[2];
iov[0].iov_base = PesHeader;
iov[0].iov_len = headerSize + AAC_HEADER_LENGTH;
iov[1].iov_base = call->data;
iov[1].iov_len = call->len;
return writev(call->fd, iov, 2);
}
static int writeDataLATM(void *_call)
{
WriterAVCallData_t *call = (WriterAVCallData_t *) _call;
aac_printf(10, "\n");
if (call == NULL)
{
aac_err("call data is NULL...\n");
return 0;
}
if ((call->data == NULL) || (call->len <= 0))
{
aac_err("parsing NULL Data. ignoring...\n");
return 0;
}
if (call->private_data && 0 == strncmp("LATM", call->private_data, call->private_size))
{
return _writeData(_call, 1);
}
aac_printf(10, "AudioPts %lld\n", call->Pts);
if (!pLATMCtx)
{
pLATMCtx = malloc(sizeof(LATMContext));
@@ -289,11 +314,13 @@ static int writeDataLATM(void *_call)
pLATMCtx->mod = 14;
pLATMCtx->counter = 0;
}
if (!pLATMCtx)
{
aac_err("parsing NULL pLATMCtx. ignoring...\n");
return 0;
}
unsigned char PesHeader[PES_MAX_HEADER_SIZE];
int ret = latmenc_decode_extradata(pLATMCtx, call->private_data, call->private_size);
if (ret)
@@ -309,14 +336,19 @@ static int writeDataLATM(void *_call)
aac_err("latm_write_packet failed. ignoring...\n");
return 0;
}
unsigned int HeaderLength = InsertPesHeader(PesHeader, pLATMCtx->len + 3, MPEG_AUDIO_PES_START_CODE, call->Pts, 0);
struct iovec iov[3];
iov[0].iov_base = PesHeader;
iov[0].iov_len = HeaderLength;
iov[1].iov_base = pLATMCtx->loas_header;
iov[1].iov_len = 3;
iov[2].iov_base = pLATMCtx->buffer;
iov[2].iov_len = pLATMCtx->len;
return writev(call->fd, iov, 3);
}

View File

@@ -98,29 +98,38 @@ static int reset()
static int writeData(void *_call)
{
WriterAVCallData_t *call = (WriterAVCallData_t *) _call;
ac3_printf(10, "\n");
unsigned char PesHeader[PES_MAX_HEADER_SIZE];
if (call == NULL)
{
ac3_err("call data is NULL...\n");
return 0;
}
ac3_printf(10, "AudioPts %lld\n", call->Pts);
if ((call->data == NULL) || (call->len <= 0))
{
ac3_err("parsing NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
ac3_err("file pointer < 0. ignoring ...\n");
return 0;
}
struct iovec iov[2];
iov[0].iov_base = PesHeader;
iov[0].iov_len = InsertPesHeader(PesHeader, call->len, PRIVATE_STREAM_1_PES_START_CODE, call->Pts, 0);
iov[1].iov_base = call->data;
iov[1].iov_len = call->len;
return writev(call->fd, iov, 2);
}

View File

@@ -101,6 +101,7 @@ static uint8_t updateCodecData(uint8_t *data, int32_t size)
{
static uint8_t *oldData = NULL;
static int32_t oldSize = 0;
uint8_t update = 0;
if (data != NULL && size > 0)
{
@@ -121,6 +122,7 @@ static uint8_t updateCodecData(uint8_t *data, int32_t size)
}
}
}
if (update)
{
if (oldData != NULL)
@@ -131,43 +133,56 @@ static uint8_t updateCodecData(uint8_t *data, int32_t size)
memcpy(oldData, data, size);
oldSize = size;
}
return update;
}
static int writeData(void *_call)
{
WriterAVCallData_t *call = (WriterAVCallData_t *) _call;
unsigned char PesHeader[PES_MAX_HEADER_SIZE];
divx_printf(10, "\n");
if (call == NULL)
{
divx_err("call data is NULL...\n");
return 0;
}
if ((call->data == NULL) || (call->len <= 0))
{
divx_err("parsing NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
divx_err("file pointer < 0. ignoring ...\n");
return 0;
}
divx_printf(10, "VideoPts %lld\n", call->Pts);
struct iovec iov[4];
int ic = 0;
iov[ic].iov_base = PesHeader;
iov[ic++].iov_len = InsertPesHeader(PesHeader, call->len, MPEG_VIDEO_PES_START_CODE, call->Pts, 0);
if (updateCodecData(call->private_data, call->private_size))
{
iov[ic].iov_base = call->private_data;
iov[ic++].iov_len = call->private_size;
}
iov[ic].iov_base = call->data;
iov[ic++].iov_len = call->len;
int len = writev(call->fd, iov, ic);
divx_printf(10, "xvid_Write < len=%d\n", len);
return len;
}

View File

@@ -101,6 +101,7 @@ static uint8_t updateCodecData(uint8_t *data, int32_t size)
{
static uint8_t *oldData = NULL;
static int32_t oldSize = 0;
uint8_t update = 0;
if (data != NULL && size > 0)
{
@@ -121,6 +122,7 @@ static uint8_t updateCodecData(uint8_t *data, int32_t size)
}
}
}
if (update)
{
if (oldData != NULL)
@@ -131,12 +133,14 @@ static uint8_t updateCodecData(uint8_t *data, int32_t size)
memcpy(oldData, data, size);
oldSize = size;
}
return update;
}
static int writeData(void *_call)
{
WriterAVCallData_t *call = (WriterAVCallData_t *) _call;
unsigned char PesHeader[PES_MAX_HEADER_SIZE];
unsigned char FakeHeaders[64]; // 64bytes should be enough to make the fake headers
unsigned int FakeHeaderLength;
@@ -144,26 +148,34 @@ static int writeData(void *_call)
unsigned int FakeStartCode = (Version << 8) | PES_VERSION_FAKE_START_CODE;
unsigned int usecPerFrame = 41708; /* Hellmaster1024: default value */
BitPacker_t ld = {FakeHeaders, 0, 32};
divx_printf(10, "\n");
if (call == NULL)
{
divx_err("call data is NULL...\n");
return 0;
}
if ((call->data == NULL) || (call->len <= 0))
{
divx_err("parsing NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
divx_err("file pointer < 0. ignoring ...\n");
return 0;
}
divx_printf(10, "AudioPts %lld\n", call->Pts);
usecPerFrame = 1000000000 / call->FrameRate;
divx_printf(10, "Microsecends per frame = %d\n", usecPerFrame);
memset(FakeHeaders, 0, sizeof(FakeHeaders));
/* Create info record for frame parser */
/* divx4 & 5
VOS
@@ -177,23 +189,30 @@ static int writeData(void *_call)
PutBits(&ld, usecPerFrame, 32);
// microseconds per frame
FlushBits(&ld);
FakeHeaderLength = (ld.Ptr - (FakeHeaders));
struct iovec iov[4];
int ic = 0;
iov[ic].iov_base = PesHeader;
iov[ic++].iov_len = InsertPesHeader(PesHeader, call->len, MPEG_VIDEO_PES_START_CODE, call->Pts, FakeStartCode);
iov[ic].iov_base = FakeHeaders;
iov[ic++].iov_len = FakeHeaderLength;
if (initialHeader)
{
iov[ic].iov_base = call->private_data;
iov[ic++].iov_len = call->private_size;
initialHeader = 0;
}
iov[ic].iov_base = call->data;
iov[ic++].iov_len = call->len;
int len = writev(call->fd, iov, ic);
divx_printf(10, "xvid_Write < len=%d\n", len);
return len;
}

View File

@@ -102,26 +102,34 @@ static int reset()
static int32_t writeData(void *_call)
{
WriterAVCallData_t *call = (WriterAVCallData_t *) _call;
uint8_t PesHeader[PES_AUDIO_HEADER_SIZE];
dts_printf(10, "\n");
if (call == NULL)
{
dts_err("call data is NULL...\n");
return 0;
}
dts_printf(10, "AudioPts %lld\n", call->Pts);
if ((call->data == NULL) || (call->len <= 0))
{
dts_err("parsing NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
dts_err("file pointer < 0. ignoring ...\n");
return 0;
}
uint8_t *Data = call->data;
int32_t Size = call->len;
#ifdef CHECK_FOR_DTS_HD
int32_t pos = 0;
while ((pos + 4) <= Size)
@@ -135,6 +143,7 @@ static int32_t writeData(void *_call)
++pos;
}
#endif
// #define DO_BYTESWAP
#ifdef DO_BYTESWAP
/* 16-bit byte swap all data before injecting it */
@@ -145,11 +154,13 @@ static int32_t writeData(void *_call)
Data[i + 1] = Tmp;
}
#endif
struct iovec iov[2];
iov[0].iov_base = PesHeader;
iov[0].iov_len = InsertPesHeader(PesHeader, Size, MPEG_AUDIO_PES_START_CODE, call->Pts, 0);
iov[1].iov_base = Data;
iov[1].iov_len = Size;
int32_t len = writev(call->fd, iov, 2);
dts_printf(10, "< len %d\n", len);
return len;

View File

@@ -97,39 +97,52 @@ static int reset()
static int writeData(void *_call)
{
WriterAVCallData_t *call = (WriterAVCallData_t *) _call;
unsigned char PesHeader[PES_MAX_HEADER_SIZE];
int len = 0;
h263_printf(10, "\n");
if (call == NULL)
{
h263_err("call data is NULL...\n");
return 0;
}
h263_printf(10, "VideoPts %lld\n", call->Pts);
if ((call->data == NULL) || (call->len <= 0))
{
h263_err("NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
h263_err("file pointer < 0. ignoring ...\n");
return 0;
}
int HeaderLength = InsertPesHeader(PesHeader, call->len, H263_VIDEO_PES_START_CODE, call->Pts, 0);
int PrivateHeaderLength = InsertVideoPrivateDataHeader(&PesHeader[HeaderLength], call->len);
int PesLength = PesHeader[PES_LENGTH_BYTE_0] + (PesHeader[PES_LENGTH_BYTE_1] << 8) + PrivateHeaderLength;
PesHeader[PES_LENGTH_BYTE_0] = PesLength & 0xff;
PesHeader[PES_LENGTH_BYTE_1] = (PesLength >> 8) & 0xff;
PesHeader[PES_HEADER_DATA_LENGTH_BYTE] += PrivateHeaderLength;
PesHeader[PES_FLAGS_BYTE] |= PES_EXTENSION_DATA_PRESENT;
HeaderLength += PrivateHeaderLength;
struct iovec iov[2];
iov[0].iov_base = PesHeader;
iov[0].iov_len = HeaderLength;
iov[1].iov_base = call->data;
iov[1].iov_len = call->len;
len = writev(call->fd, iov, 2);
h263_printf(10, "< len %d\n", len);
return len;
}

View File

@@ -113,34 +113,45 @@ static int avc3 = 0;
static int32_t UpdateExtraData(uint8_t **ppExtraData, uint32_t *pExtraDataSize, uint8_t *pData, uint32_t dataSize)
{
uint8_t *aExtraData = *ppExtraData;
if (aExtraData[0] != 1 || !pData)
{
// Not AVCC or nothing to update with.
return -1;
}
int32_t nalsize = (aExtraData[4] & 3) + 1;
uint8_t sps[256];
uint8_t spsIdx = 0;
uint8_t numSps = 0;
uint8_t pps[256];
uint8_t ppsIdx = 0;
uint8_t numPps = 0;
if (nalsize != 4)
{
return -1;
}
// Find SPS and PPS NALUs in AVCC data
uint8_t *d = pData;
while (d + 4 < pData + dataSize)
{
uint32_t nalLen = ReadUint32(d);
uint8_t nalType = d[4] & 0x1f;
if (nalType == 7)
{
/* SPS */
// 16 bits size
sps[spsIdx++] = (uint8_t)(0xFF & (nalLen >> 8));
sps[spsIdx++] = (uint8_t)(0xFF & nalLen);
if (spsIdx + nalLen >= sizeof(sps))
{
h264_err("SPS no free space to copy...\n");
@@ -148,15 +159,19 @@ static int32_t UpdateExtraData(uint8_t **ppExtraData, uint32_t *pExtraDataSize,
}
memcpy(&(sps[spsIdx]), d + 4, nalLen);
spsIdx += nalLen;
numSps += 1;
h264_printf(10, "SPS len[%u]...\n", nalLen);
}
else if (nalType == 8)
{
/* PPS */
// 16 bits size
pps[ppsIdx++] = (uint8_t)(0xFF & (nalLen >> 8));
pps[ppsIdx++] = (uint8_t)(0xFF & nalLen);
if (ppsIdx + nalLen >= sizeof(sps))
{
h264_err("PPS not free space to copy...\n");
@@ -164,7 +179,9 @@ static int32_t UpdateExtraData(uint8_t **ppExtraData, uint32_t *pExtraDataSize,
}
memcpy(&(pps[ppsIdx]), d + 4, nalLen);
ppsIdx += nalLen;
numPps += 1;
h264_printf(10, "PPS len[%u]...\n", nalLen);
}
d += 4 + nalLen;
@@ -177,18 +194,21 @@ static int32_t UpdateExtraData(uint8_t **ppExtraData, uint32_t *pExtraDataSize,
aExtraData[idx++] = sps[4]; // profile compat
aExtraData[idx++] = sps[5]; // level
aExtraData[idx++] = 0xff; // nal size - 1
aExtraData[idx++] = 0xe0 | numSps;
if (numSps)
{
memcpy(&(aExtraData[idx]), sps, spsIdx);
idx += spsIdx;
}
aExtraData[idx++] = numPps;
if (numPps)
{
memcpy(&(aExtraData[idx]), pps, ppsIdx);
idx += ppsIdx;
}
h264_printf(10, "aExtraData len[%u]...\n", idx);
*pExtraDataSize = idx;
return 0;
@@ -204,6 +224,7 @@ static int32_t reset()
static int32_t writeData(void *_call)
{
WriterAVCallData_t *call = (WriterAVCallData_t *) _call;
uint8_t PesHeader[PES_MAX_HEADER_SIZE];
uint64_t VideoPts;
uint32_t TimeDelta;
@@ -212,25 +233,31 @@ static int32_t writeData(void *_call)
int32_t ic = 0;
struct iovec iov[128];
h264_printf(10, "\n");
if (call == NULL)
{
h264_err("call data is NULL...\n");
return 0;
}
TimeDelta = call->FrameRate;
TimeScale = call->FrameScale;
VideoPts = call->Pts;
h264_printf(10, "VideoPts %lld - %d %d\n", call->Pts, TimeDelta, TimeScale);
if ((call->data == NULL) || (call->len <= 0))
{
h264_err("NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
h264_err("file pointer < 0. ignoring ...\n");
return 0;
}
/* AnnexA */
if (!avc3 && ((1 < call->private_size && 0 == call->private_data[0]) ||
(call->len > 3) && ((call->data[0] == 0x00 && call->data[1] == 0x00 && call->data[2] == 0x00 && call->data[3] == 0x01) ||
@@ -238,6 +265,7 @@ static int32_t writeData(void *_call)
{
uint32_t PacketLength = 0;
uint32_t FakeStartCode = /*(call->Version << 8) | */PES_VERSION_FAKE_START_CODE;
iov[ic++].iov_base = PesHeader;
initialHeader = 0;
if (initialHeader)
@@ -247,16 +275,20 @@ static int32_t writeData(void *_call)
iov[ic++].iov_len = call->private_size;
PacketLength += call->private_size;
}
iov[ic].iov_base = "";
iov[ic++].iov_len = 1;
iov[ic].iov_base = call->data;
iov[ic++].iov_len = call->len;
PacketLength += call->len;
/*Hellmaster1024: some packets will only be accepted by the player if we send one byte more than
data is available. The content of this byte does not matter. It will be ignored
by the player */
iov[ic].iov_base = "\0";
iov[ic++].iov_len = 1;
iov[0].iov_len = InsertPesHeader(PesHeader, -1, MPEG_VIDEO_PES_START_CODE, VideoPts, FakeStartCode);
int ret = writev(call->fd, iov, ic);
return ret;
@@ -266,6 +298,7 @@ static int32_t writeData(void *_call)
h264_err("No valid private data available!\n");
return 0;
}
if (initialHeader)
{
uint8_t *private_data = call->private_data;
@@ -276,8 +309,11 @@ static int32_t writeData(void *_call)
unsigned int ParamOffset;
unsigned int InitialHeaderLength = 0;
unsigned int ParametersLength;
ParametersLength = 0;
unsigned char HeaderData[19];
if (private_size <= sizeof(avcC_t))
{
UpdateExtraData(&private_data, &private_size, call->data, call->len);
@@ -287,6 +323,7 @@ static int32_t writeData(void *_call)
avcCHeader = (avcC_t *)private_data;
}
}
HeaderData[ParametersLength++] = 0x00; // Start code
HeaderData[ParametersLength++] = 0x00;
HeaderData[ParametersLength++] = 0x01;
@@ -294,14 +331,17 @@ static int32_t writeData(void *_call)
// Container message version - changes when/if we vary the format of the message
HeaderData[ParametersLength++] = CONTAINER_PARAMETERS_VERSION;
HeaderData[ParametersLength++] = 0xff; // Field separator
if (TimeDelta == 0xffffffff)
TimeDelta = (TimeScale > 1000) ? 1001 : 1;
HeaderData[ParametersLength++] = (TimeScale >> 24) & 0xff; // Output the timescale
HeaderData[ParametersLength++] = (TimeScale >> 16) & 0xff;
HeaderData[ParametersLength++] = 0xff;
HeaderData[ParametersLength++] = (TimeScale >> 8) & 0xff;
HeaderData[ParametersLength++] = TimeScale & 0xff;
HeaderData[ParametersLength++] = 0xff;
HeaderData[ParametersLength++] = (TimeDelta >> 24) & 0xff; // Output frame period
HeaderData[ParametersLength++] = (TimeDelta >> 16) & 0xff;
HeaderData[ParametersLength++] = 0xff;
@@ -309,7 +349,9 @@ static int32_t writeData(void *_call)
HeaderData[ParametersLength++] = TimeDelta & 0xff;
HeaderData[ParametersLength++] = 0xff;
HeaderData[ParametersLength++] = 0x80; // Rsbp trailing bits
assert(ParametersLength <= sizeof(HeaderData));
ic = 0;
iov[ic].iov_base = PesHeader;
iov[ic++].iov_len = InsertPesHeader(PesHeader, ParametersLength, MPEG_VIDEO_PES_START_CODE, INVALID_PTS_VALUE, 0);
@@ -320,8 +362,10 @@ static int32_t writeData(void *_call)
{
return len;
}
NalLengthBytes = (avcCHeader->NalLengthMinusOne & 0x03) + 1;
ParamSets = avcCHeader->NumParamSets & 0x1f;
h264_printf(20, "avcC contents:\n");
h264_printf(20, " version: %d\n", avcCHeader->Version);
h264_printf(20, " profile: %d\n", avcCHeader->Profile);
@@ -329,13 +373,16 @@ static int32_t writeData(void *_call)
h264_printf(20, " level: %d\n", avcCHeader->Level);
h264_printf(20, " nal length bytes: %d\n", NalLengthBytes);
h264_printf(20, " number of sequence param sets: %d\n", ParamSets);
ParamOffset = 0;
ic = 0;
iov[ic++].iov_base = PesHeader;
for (i = 0; i < ParamSets; i++)
{
unsigned int PsLength = (avcCHeader->Params[ParamOffset] << 8) + avcCHeader->Params[ParamOffset + 1];
h264_printf(20, " sps %d has length %d\n", i, PsLength);
iov[ic].iov_base = (char *)Head;
iov[ic++].iov_len = sizeof(Head);
InitialHeaderLength += sizeof(Head);
@@ -344,13 +391,18 @@ static int32_t writeData(void *_call)
InitialHeaderLength += PsLength;
ParamOffset += PsLength + 2;
}
ParamSets = avcCHeader->Params[ParamOffset];
h264_printf(20, " number of picture param sets: %d\n", ParamSets);
ParamOffset++;
for (i = 0; i < ParamSets; i++)
{
unsigned int PsLength = (avcCHeader->Params[ParamOffset] << 8) + avcCHeader->Params[ParamOffset + 1];
h264_printf(20, " pps %d has length %d\n", i, PsLength);
iov[ic].iov_base = (char *) Head;
iov[ic++].iov_len = sizeof(Head);
InitialHeaderLength += sizeof(Head);
@@ -359,27 +411,34 @@ static int32_t writeData(void *_call)
InitialHeaderLength += PsLength;
ParamOffset += PsLength + 2;
}
iov[0].iov_len = InsertPesHeader(PesHeader, InitialHeaderLength, MPEG_VIDEO_PES_START_CODE, INVALID_PTS_VALUE, 0);
ssize_t l = writev(call->fd, iov, ic);
if (private_data != call->private_data)
{
free(private_data);
}
if (l < 0)
{
return l;
}
len += l;
initialHeader = 0;
}
unsigned int SampleSize = call->len;
unsigned int NalStart = 0;
unsigned int VideoPosition = 0;
do
{
unsigned int NalLength;
unsigned char NalData[4];
int NalPresent = 1;
memcpy(NalData, call->data + VideoPosition, NalLengthBytes);
VideoPosition += NalLengthBytes;
NalStart += NalLengthBytes;
@@ -398,11 +457,14 @@ static int32_t writeData(void *_call)
NalLength = (NalData[0] << 24) | (NalData[1] << 16) | (NalData[2] << 8) | (NalData[3]);
break;
}
h264_printf(20, "NalStart = %u + NalLength = %u > SampleSize = %u\n", NalStart, NalLength, SampleSize);
if (NalStart + NalLength > SampleSize)
{
h264_printf(20, "nal length past end of buffer - size %u frame offset %u left %u\n",
NalLength, NalStart, SampleSize - NalStart);
NalStart = SampleSize;
}
else
@@ -410,30 +472,37 @@ static int32_t writeData(void *_call)
NalStart += NalLength;
ic = 0;
iov[ic++].iov_base = PesHeader;
if (NalPresent)
{
NalPresent = 0;
iov[ic].iov_base = (char *)Head;
iov[ic++].iov_len = sizeof(Head);
}
iov[ic].iov_base = call->data + VideoPosition;
iov[ic++].iov_len = NalLength;
VideoPosition += NalLength;
h264_printf(20, " pts=%llu\n", VideoPts);
iov[0].iov_len = InsertPesHeader(PesHeader, NalLength, MPEG_VIDEO_PES_START_CODE, VideoPts, 0);
ssize_t l = writev(call->fd, iov, ic);
if (l < 0)
return l;
len += l;
VideoPts = INVALID_PTS_VALUE;
}
}
while (NalStart < SampleSize);
if (len < 0)
{
h264_err("error writing data errno = %d\n", errno);
h264_err("%s\n", strerror(errno));
}
h264_printf(10, "< len %d\n", len);
return len;
}

View File

@@ -97,30 +97,39 @@ static int reset()
static int writeData(void *_call)
{
WriterAVCallData_t *call = (WriterAVCallData_t *) _call;
unsigned char PesHeader[PES_MAX_HEADER_SIZE];
mp3_printf(10, "\n");
if (call == NULL)
{
mp3_err("call data is NULL...\n");
return 0;
}
mp3_printf(10, "AudioPts %lld\n", call->Pts);
if ((call->data == NULL) || (call->len <= 0))
{
mp3_err("parsing NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
mp3_err("file pointer < 0. ignoring ...\n");
return 0;
}
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;
int len = writev(call->fd, iov, 2);
mp3_printf(10, "mp3_Write-< len=%d\n", len);
return len;
}

View File

@@ -97,37 +97,49 @@ static int reset()
static int writeData(void *_call)
{
WriterAVCallData_t *call = (WriterAVCallData_t *) _call;
unsigned char PesHeader[PES_MAX_HEADER_SIZE];
int len = 0;
unsigned int Position = 0;
mpeg2_printf(10, "\n");
if (call == NULL)
{
mpeg2_err("call data is NULL...\n");
return 0;
}
mpeg2_printf(10, "VideoPts %lld\n", call->Pts);
if ((call->data == NULL) || (call->len <= 0))
{
mpeg2_err("parsing NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
mpeg2_err("file pointer < 0. ignoring ...\n");
return 0;
}
while (Position < call->len)
{
int32_t PacketLength = (call->len - Position) <= MAX_PES_PACKET_SIZE ?
(call->len - Position) : MAX_PES_PACKET_SIZE;
int32_t Remaining = call->len - Position - PacketLength;
mpeg2_printf(20, "PacketLength=%d, Remaining=%d, Position=%d\n", PacketLength, Remaining, Position);
struct iovec iov[2];
iov[0].iov_base = PesHeader;
iov[0].iov_len = InsertPesHeader(PesHeader, PacketLength, 0xe0, call->Pts, 0);
iov[1].iov_base = call->data + Position;
iov[1].iov_len = PacketLength;
ssize_t l = writev(call->fd, iov, 2);
if (l < 0)
{
@@ -135,9 +147,11 @@ static int writeData(void *_call)
break;
}
len += l;
Position += PacketLength;
call->Pts = INVALID_PTS_VALUE;
}
mpeg2_printf(10, "< len %d\n", len);
return len;
}

View File

@@ -124,10 +124,13 @@ static int32_t prepareClipPlay(int32_t uNoOfChannels, int32_t uSampleRate, int32
uBitsPerSample/*Format->wBitsPerSample*/,
(uBitsPerSample/*Format->wBitsPerSample*/ / 8)
);
SubFrameLen = 0;
SubFramesPerPES = 0;
breakBufferFillSize = 0;
memcpy(lpcm_prv, clpcm_prv, sizeof(lpcm_prv));
//figure out size of subframe
//and set up sample rate
switch (uSampleRate)
@@ -158,14 +161,18 @@ static int32_t prepareClipPlay(int32_t uNoOfChannels, int32_t uSampleRate, int32
default:
break;
}
SubFrameLen *= uNoOfChannels;
SubFrameLen *= (uBitsPerSample / 8);
//rewrite PES size to have as many complete subframes per PES as we can
// FIXME: PES header size was hardcoded to 18 in previous code. Actual size returned by InsertPesHeader is 14.
SubFramesPerPES = ((2048 - 18) - sizeof(lpcm_prv)) / SubFrameLen;
SubFrameLen *= SubFramesPerPES;
//set number of channels
lpcm_prv[10] = uNoOfChannels - 1;
switch (uBitsPerSample)
{
case 24:
@@ -176,6 +183,7 @@ static int32_t prepareClipPlay(int32_t uNoOfChannels, int32_t uSampleRate, int32
printf("inappropriate bits per sample (%d) - must be 16 or 24\n", uBitsPerSample);
return 1;
}
return 0;
}
@@ -188,25 +196,33 @@ static int32_t reset()
static int32_t writeData(void *_call)
{
WriterAVCallData_t *call = (WriterAVCallData_t *) _call;
unsigned char PesHeader[PES_MAX_HEADER_SIZE];
pcm_printf(10, "\n");
if (!call)
{
pcm_err("call data is NULL...\n");
return 0;
}
pcm_printf(10, "AudioPts %lld\n", call->Pts);
if (!call->data || (call->len <= 0))
{
pcm_err("parsing NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
pcm_err("file pointer < 0. ignoring ...\n");
return 0;
}
pcmPrivateData_t *pcmPrivateData = (pcmPrivateData_t *)call->private_data;
if (initialHeader)
{
uint32_t codecID = (uint32_t)pcmPrivateData->ffmpeg_codec_id;
@@ -240,11 +256,14 @@ static int32_t writeData(void *_call)
initialHeader = 0;
prepareClipPlay(pcmPrivateData->channels, pcmPrivateData->sample_rate, pcmPrivateData->bits_per_coded_sample, LE);
}
uint8_t *buffer = call->data;
uint32_t size = call->len;
uint32_t n;
uint8_t *injectBuffer = malloc(SubFrameLen);
uint32_t pos;
for (pos = 0; pos < size;)
{
//printf("PCM %s - Position=%d\n", __FUNCTION__, pos);
@@ -255,6 +274,7 @@ static int32_t writeData(void *_call)
//printf("PCM %s - Unplayed=%d\n", __FUNCTION__, breakBufferFillSize);
break;
}
//get first PES's worth
if (breakBufferFillSize > 0)
{
@@ -268,12 +288,15 @@ static int32_t writeData(void *_call)
memcpy(injectBuffer, &buffer[pos], sizeof(uint8_t)*SubFrameLen);
pos += SubFrameLen;
}
struct iovec iov[3];
iov[0].iov_base = PesHeader;
iov[1].iov_base = lpcm_prv;
iov[1].iov_len = sizeof(lpcm_prv);
iov[2].iov_base = injectBuffer;
iov[2].iov_len = SubFrameLen;
//write the PCM data
if (16 == pcmPrivateData->bits_per_coded_sample)
{
@@ -305,8 +328,10 @@ static int32_t writeData(void *_call)
p[ 8] = t;
}
}
//increment err... subframe count?
lpcm_prv[1] = ((lpcm_prv[1] + SubFramesPerPES) & 0x1F);
iov[0].iov_len = InsertPesHeader(PesHeader, iov[1].iov_len + iov[2].iov_len, PCM_PES_START_CODE, call->Pts, 0);
int32_t len = writev(call->fd, iov, 3);
if (len < 0)
@@ -315,6 +340,7 @@ static int32_t writeData(void *_call)
}
}
free(injectBuffer);
return size;
}

View File

@@ -70,23 +70,30 @@ int InsertVideoPrivateDataHeader(unsigned char *data, int payload_size)
{
BitPacker_t ld2 = {data, 0, 32};
int i;
PutBits(&ld2, PES_PRIVATE_DATA_FLAG, 8);
PutBits(&ld2, payload_size & 0xff, 8);
PutBits(&ld2, (payload_size >> 8) & 0xff, 8);
PutBits(&ld2, (payload_size >> 16) & 0xff, 8);
for (i = 4; i < (PES_PRIVATE_DATA_LENGTH + 1); i++)
PutBits(&ld2, 0, 8);
FlushBits(&ld2);
return PES_PRIVATE_DATA_LENGTH + 1;
}
int InsertPesHeader(unsigned char *data, int size, unsigned char stream_id, unsigned long long int pts, int pic_start_code)
{
BitPacker_t ld2 = {data, 0, 32};
if (size > (MAX_PES_PACKET_SIZE - 13))
{
size = -1; // unbounded
}
PutBits(&ld2, 0x0, 8);
PutBits(&ld2, 0x0, 8);
PutBits(&ld2, 0x1, 8); // Start Code
@@ -108,6 +115,7 @@ int InsertPesHeader(unsigned char *data, int size, unsigned char stream_id, unsi
PutBits(&ld2, 0x0, 1); // Copyright
PutBits(&ld2, 0x0, 1); // Original or Copy
//7 = 6+1
if (pts != INVALID_PTS_VALUE)
{
PutBits(&ld2, 0x2, 2);
@@ -116,6 +124,7 @@ int InsertPesHeader(unsigned char *data, int size, unsigned char stream_id, unsi
{
PutBits(&ld2, 0x0, 2); // PTS_DTS flag
}
PutBits(&ld2, 0x0, 1); // ESCR_flag
PutBits(&ld2, 0x0, 1); // ES_rate_flag
PutBits(&ld2, 0x0, 1); // DSM_trick_mode_flag
@@ -123,11 +132,13 @@ int InsertPesHeader(unsigned char *data, int size, unsigned char stream_id, unsi
PutBits(&ld2, 0x0, 1); // PES_CRC_flag
PutBits(&ld2, 0x0, 1); // PES_extension_flag
//8 = 7+1
if (pts != INVALID_PTS_VALUE)
PutBits(&ld2, 0x5, 8);
else
PutBits(&ld2, 0x0, 8); // PES_header_data_length
//9 = 8+1
if (pts != INVALID_PTS_VALUE)
{
PutBits(&ld2, 0x2, 4);
@@ -139,6 +150,7 @@ int InsertPesHeader(unsigned char *data, int size, unsigned char stream_id, unsi
PutBits(&ld2, 0x1, 1);
}
//14 = 9+5
if (pic_start_code)
{
PutBits(&ld2, 0x0, 8);
@@ -148,6 +160,8 @@ int InsertPesHeader(unsigned char *data, int size, unsigned char stream_id, unsi
PutBits(&ld2, (pic_start_code >> 8) & 0xff, 8); // For any extra information (like in mpeg4p2, the pic_start_code)
//14 + 4 = 18
}
FlushBits(&ld2);
return (ld2.Ptr - data);
}

View File

@@ -127,25 +127,31 @@ static int reset()
static int writeData(void *_call)
{
WriterAVCallData_t *call = (WriterAVCallData_t *) _call;
int len = 0;
vc1_printf(10, "\n");
if (call == NULL)
{
vc1_err("call data is NULL...\n");
return 0;
}
if ((call->data == NULL) || (call->len <= 0))
{
vc1_err("parsing NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
vc1_err("file pointer < 0. ignoring ...\n");
return 0;
}
vc1_printf(10, "VideoPts %lld\n", call->Pts);
vc1_printf(10, "Got Private Size %d\n", call->private_size);
if (initialHeader)
{
unsigned char PesHeader[PES_MAX_HEADER_SIZE];
@@ -153,18 +159,25 @@ static int writeData(void *_call)
unsigned char *PesPtr;
unsigned int crazyFramerate = 0;
struct iovec iov[2];
vc1_printf(10, "Framerate: %u\n", call->FrameRate);
vc1_printf(10, "biWidth: %d\n", call->Width);
vc1_printf(10, "biHeight: %d\n", call->Height);
crazyFramerate = ((10000000.0 / call->FrameRate) * 1000.0);
vc1_printf(10, "crazyFramerate: %u\n", crazyFramerate);
memset(PesPayload, 0, sizeof(PesPayload));
PesPtr = PesPayload;
memcpy(PesPtr, SequenceLayerStartCode, sizeof(SequenceLayerStartCode));
PesPtr += sizeof(SequenceLayerStartCode);
memcpy(PesPtr, Metadata, sizeof(Metadata));
PesPtr += METADATA_STRUCT_C_START;
PesPtr += WMV3_PRIVATE_DATA_LENGTH;
/* Metadata Header Struct A */
*PesPtr++ = (call->Height >> 0) & 0xff;
*PesPtr++ = (call->Height >> 8) & 0xff;
@@ -174,43 +187,56 @@ static int writeData(void *_call)
*PesPtr++ = (call->Width >> 8) & 0xff;
*PesPtr++ = (call->Width >> 16) & 0xff;
*PesPtr++ = call->Width >> 24;
PesPtr += 12; /* Skip flag word and Struct B first 8 bytes */
*PesPtr++ = (crazyFramerate >> 0) & 0xff;
*PesPtr++ = (crazyFramerate >> 8) & 0xff;
*PesPtr++ = (crazyFramerate >> 16) & 0xff;
*PesPtr++ = crazyFramerate >> 24;
iov[0].iov_base = PesHeader;
iov[1].iov_base = PesPayload;
iov[1].iov_len = PesPtr - PesPayload;
iov[0].iov_len = InsertPesHeader(PesHeader, iov[1].iov_len, VC1_VIDEO_PES_START_CODE, INVALID_PTS_VALUE, 0);
len = writev(call->fd, iov, 2);
/* For VC1 the codec private data is a standard vc1 sequence header so we just copy it to the output */
iov[0].iov_base = PesHeader;
iov[1].iov_base = call->private_data;
iov[1].iov_len = call->private_size;
iov[0].iov_len = InsertPesHeader(PesHeader, iov[1].iov_len, VC1_VIDEO_PES_START_CODE, INVALID_PTS_VALUE, 0);
len = writev(call->fd, iov, 2);
initialHeader = 0;
}
if (call->len > 0 && call->data)
{
uint32_t Position = 0;
uint8_t insertSampleHeader = 1;
while (Position < call->len)
{
int32_t PacketLength = (call->len - Position) <= MAX_PES_PACKET_SIZE ?
(call->len - Position) : MAX_PES_PACKET_SIZE;
int32_t Remaining = call->len - Position - PacketLength;
vc1_printf(20, "PacketLength=%d, Remaining=%d, Position=%d\n", PacketLength, Remaining, Position);
uint8_t PesHeader[PES_MAX_HEADER_SIZE];
int32_t HeaderLength = InsertPesHeader(PesHeader, PacketLength, VC1_VIDEO_PES_START_CODE, call->Pts, 0);
if (insertSampleHeader)
{
const uint8_t Vc1FrameStartCode[] = {0, 0, 1, VC1_FRAME_START_CODE};
if (!FrameHeaderSeen && (call->len > 3) && (memcmp(call->data, Vc1FrameStartCode, 4) == 0))
{
FrameHeaderSeen = 1;
}
if (!FrameHeaderSeen)
{
memcpy(&PesHeader[HeaderLength], Vc1FrameStartCode, sizeof(Vc1FrameStartCode));
@@ -218,11 +244,13 @@ static int writeData(void *_call)
}
insertSampleHeader = 0;
}
struct iovec iov[2];
iov[0].iov_base = PesHeader;
iov[0].iov_len = HeaderLength;
iov[1].iov_base = call->data + Position;
iov[1].iov_len = PacketLength;
ssize_t l = writev(call->fd, iov, 2);
if (l < 0)
{
@@ -230,10 +258,12 @@ static int writeData(void *_call)
break;
}
len += l;
Position += PacketLength;
call->Pts = INVALID_PTS_VALUE;
}
}
vc1_printf(10, "< %d\n", len);
return len;
}

View File

@@ -50,8 +50,6 @@
/* Makros/Constants */
/* ***************************** */
//#define SAM_WITH_DEBUG
#ifdef SAM_WITH_DEBUG
#define VORBIS_DEBUG
#else
@@ -98,30 +96,42 @@ static int reset()
static int writeData(void *_call)
{
WriterAVCallData_t *call = (WriterAVCallData_t *) _call;
unsigned char PesHeader[PES_MAX_HEADER_SIZE];
vorbis_printf(10, "\n");
if (call == NULL)
{
vorbis_err("call data is NULL...\n");
return 0;
}
vorbis_printf(10, "AudioPts %lld\n", call->Pts);
if ((call->data == NULL) || (call->len <= 0))
{
vorbis_err("parsing NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
vorbis_err("file pointer < 0. ignoring ...\n");
return 0;
}
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);
int len = write(call->fd, PacketStart, call->len + HeaderLength);
free(PacketStart);
vorbis_printf(10, "vorbis_Write-< len=%d\n", len);
return len;
}

View File

@@ -51,8 +51,6 @@
/* Makros/Constants */
/* ***************************** */
//#define SAM_WITH_DEBUG
#ifdef SAM_WITH_DEBUG
#define WMA_DEBUG
#else
@@ -102,32 +100,41 @@ static int reset()
static int writeData(void *_call)
{
WriterAVCallData_t *call = (WriterAVCallData_t *) _call;
int len = 0;
wma_printf(10, "\n");
if (call == NULL)
{
wma_err("call data is NULL...\n");
return 0;
}
wma_printf(10, "AudioPts %lld\n", call->Pts);
if ((call->data == NULL) || (call->len <= 0))
{
wma_err("parsing NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
wma_err("file pointer < 0. ignoring ...\n");
return 0;
}
if (initialHeader)
{
unsigned char PesHeader[PES_MAX_HEADER_SIZE];
if ((call->private_size <= 0) || (call->private_data == NULL))
{
wma_err("private NULL.\n");
return -1;
}
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);
@@ -136,6 +143,7 @@ static int writeData(void *_call)
len = writev(call->fd, iov, 2);
initialHeader = 0;
}
if (len > -1 && call->len > 0 && call->data)
{
unsigned char PesHeader[PES_MAX_HEADER_SIZE];
@@ -144,10 +152,13 @@ static int writeData(void *_call)
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;
ssize_t l = writev(call->fd, iov, 2);
len = (l > -1) ? len + l : l;
}
wma_printf(10, "wma < %d\n", len);
return len;
}

View File

@@ -128,31 +128,40 @@ static int reset()
static int writeData(void *_call)
{
WriterAVCallData_t *call = (WriterAVCallData_t *) _call;
awmv_t private_data;
int len = 0;
wmv_printf(10, "\n");
if (call == NULL)
{
wmv_err("call data is NULL...\n");
return 0;
}
if ((call->data == NULL) || (call->len <= 0))
{
wmv_err("parsing NULL Data. ignoring...\n");
return 0;
}
if (call->fd < 0)
{
wmv_err("file pointer < 0. ignoring ...\n");
return 0;
}
wmv_printf(10, "VideoPts %lld\n", call->Pts);
wmv_printf(10, "Got Private Size %d\n", call->private_size);
memcpy(private_data.privateData, call->private_data,
call->private_size > WMV3_PRIVATE_DATA_LENGTH ? WMV3_PRIVATE_DATA_LENGTH : call->private_size);
private_data.width = call->Width;
private_data.height = call->Height;
private_data.framerate = call->FrameRate;
#define PES_MIN_HEADER_SIZE 9
if (initialHeader)
{
@@ -160,16 +169,22 @@ static int writeData(void *_call)
unsigned char *PesPtr;
unsigned int MetadataLength;
unsigned int crazyFramerate = 0;
wmv_printf(10, "Framerate: %u\n", private_data.framerate);
wmv_printf(10, "biWidth: %d\n", private_data.width);
wmv_printf(10, "biHeight: %d\n", private_data.height);
crazyFramerate = ((10000000.0 / private_data.framerate) * 1000.0);
wmv_printf(10, "crazyFramerate: %u\n", crazyFramerate);
PesPtr = &PesPacket[PES_MIN_HEADER_SIZE];
memcpy(PesPtr, Metadata, sizeof(Metadata));
PesPtr += METADATA_STRUCT_C_START;
memcpy(PesPtr, private_data.privateData, WMV3_PRIVATE_DATA_LENGTH);
PesPtr += WMV3_PRIVATE_DATA_LENGTH;
/* Metadata Header Struct A */
*PesPtr++ = (private_data.height >> 0) & 0xff;
*PesPtr++ = (private_data.height >> 8) & 0xff;
@@ -179,16 +194,23 @@ static int writeData(void *_call)
*PesPtr++ = (private_data.width >> 8) & 0xff;
*PesPtr++ = (private_data.width >> 16) & 0xff;
*PesPtr++ = private_data.width >> 24;
PesPtr += 12; /* Skip flag word and Struct B first 8 bytes */
*PesPtr++ = (crazyFramerate >> 0) & 0xff;
*PesPtr++ = (crazyFramerate >> 8) & 0xff;
*PesPtr++ = (crazyFramerate >> 16) & 0xff;
*PesPtr++ = crazyFramerate >> 24;
MetadataLength = PesPtr - &PesPacket[PES_MIN_HEADER_SIZE];
int HeaderLength = InsertPesHeader(PesPacket, MetadataLength, VC1_VIDEO_PES_START_CODE, INVALID_PTS_VALUE, 0);
len = write(call->fd, PesPacket, HeaderLength + MetadataLength);
initialHeader = 0;
}
if (call->len > 0 && call->data)
{
unsigned int Position = 0;
@@ -197,12 +219,16 @@ static int writeData(void *_call)
{
int PacketLength = (call->len - Position) <= MAX_PES_PACKET_SIZE ?
(call->len - Position) : MAX_PES_PACKET_SIZE;
int Remaining = call->len - Position - PacketLength;
wmv_printf(20, "PacketLength=%d, Remaining=%d, Position=%d\n", PacketLength, Remaining, Position);
unsigned char PesHeader[PES_MAX_HEADER_SIZE];
memset(PesHeader, '0', PES_MAX_HEADER_SIZE);
int HeaderLength = InsertPesHeader(PesHeader, PacketLength, VC1_VIDEO_PES_START_CODE, call->Pts, 0);
unsigned char *PacketStart;
if (insertSampleHeader)
{
unsigned int PesLength;
@@ -215,18 +241,23 @@ static int writeData(void *_call)
PesHeader[PES_LENGTH_BYTE_1] = (PesLength >> 8) & 0xff;
PesHeader[PES_HEADER_DATA_LENGTH_BYTE] += PrivateHeaderLength;
PesHeader[PES_FLAGS_BYTE] |= PES_EXTENSION_DATA_PRESENT;
HeaderLength += PrivateHeaderLength;
insertSampleHeader = 0;
}
PacketStart = malloc(call->len + HeaderLength);
memcpy(PacketStart, PesHeader, HeaderLength);
memcpy(PacketStart + HeaderLength, call->data + Position, PacketLength);
len = write(call->fd, PacketStart, PacketLength + HeaderLength);
free(PacketStart);
Position += PacketLength;
call->Pts = INVALID_PTS_VALUE;
}
}
wmv_printf(10, "< %d\n", len);
return len;
}

View File

@@ -100,6 +100,7 @@ static Writer_t *AvailableWriter[] =
Writer_t *getWriter(char *encoding)
{
int i;
for (i = 0; AvailableWriter[i] != NULL; i++)
{
if (strcmp(AvailableWriter[i]->caps->textEncoding, encoding) == 0)
@@ -108,13 +109,16 @@ Writer_t *getWriter(char *encoding)
return AvailableWriter[i];
}
}
writer_printf(1, "%s: no writer found for \"%s\"\n", __func__, encoding);
return NULL;
}
Writer_t *getDefaultVideoWriter()
{
int i;
for (i = 0; AvailableWriter[i] != NULL; i++)
{
if (strcmp(AvailableWriter[i]->caps->textEncoding, "V_MPEG2") == 0)
@@ -123,13 +127,16 @@ Writer_t *getDefaultVideoWriter()
return AvailableWriter[i];
}
}
writer_printf(1, "%s: no writer found\n", __func__);
return NULL;
}
Writer_t *getDefaultAudioWriter()
{
int i;
for (i = 0; AvailableWriter[i] != NULL; i++)
{
if (strcmp(AvailableWriter[i]->caps->textEncoding, "A_MP3") == 0)
@@ -138,6 +145,8 @@ Writer_t *getDefaultAudioWriter()
return AvailableWriter[i];
}
}
writer_printf(1, "%s: no writer found\n", __func__);
return NULL;
}