- libeplayer3: sync with max_10

This commit is contained in:
vanhofen
2023-01-24 21:00:47 +01:00
committed by Thilo Graf
parent 02994964e7
commit c0034ff0b7
65 changed files with 1100 additions and 959 deletions

View File

@@ -54,6 +54,7 @@ typedef struct BufferingNode_s
{
uint32_t dataSize;
OutputType_t dataType;
void *stamp;
struct BufferingNode_s *next;
} BufferingNode_t;
@@ -71,6 +72,7 @@ static pthread_t bufferingThread;
static pthread_mutex_t bufferingMtx;
static pthread_cond_t bufferingExitCond;
static pthread_cond_t bufferingDataConsumedCond;
static pthread_cond_t bufferingWriteFinishedCond;
static pthread_cond_t bufferingdDataAddedCond;
static bool hasBufferingThreadStarted = false;
static BufferingNode_t *bufferingQueueHead = NULL;
@@ -85,6 +87,11 @@ static int g_pfd[2] = {-1, -1};
static pthread_mutex_t *g_pDVBMtx = NULL;
static bool g_bDuringWrite = false;
static bool g_bSignalWriteFinish = false;
static void *g_pWriteStamp = NULL;
/* ***************************** */
/* Prototypes */
/* ***************************** */
@@ -147,6 +154,12 @@ static void LinuxDvbBuffThread(Context_t *context)
while (0 == PlaybackDieNow(0))
{
pthread_mutex_lock(&bufferingMtx);
g_bDuringWrite = false;
if (g_bSignalWriteFinish)
{
pthread_cond_signal(&bufferingWriteFinishedCond);
g_bSignalWriteFinish = false;
}
if (nodePtr)
{
free(nodePtr);
@@ -183,23 +196,28 @@ static void LinuxDvbBuffThread(Context_t *context)
bufferingDataSize = 0;
}
}
pthread_mutex_unlock(&bufferingMtx);
/* We will write data without mutex
* this have some disadvantage because we can
* write some portion of data after LinuxDvbBuffFlush,
* for example after seek, this will be fixed later
* for example after seek.
*/
if (nodePtr && !context->playback->isSeeking)
if (nodePtr && !context->playback->isSeeking && context->playback->stamp == nodePtr->stamp)
{
/* Write data to valid output */
uint8_t *dataPtr = (uint8_t *)nodePtr + sizeof(BufferingNode_t);
int fd = nodePtr->dataType == OUTPUT_VIDEO ? videofd : audiofd;
g_bDuringWrite = true;
pthread_mutex_unlock(&bufferingMtx);
if (0 != WriteWithRetry(context, g_pfd[0], fd, g_pDVBMtx, dataPtr, nodePtr->dataSize))
{
buff_err("Something is WRONG\n");
}
}
else
{
pthread_mutex_unlock(&bufferingMtx);
}
}
pthread_mutex_lock(&bufferingMtx);
@@ -258,6 +276,7 @@ int32_t LinuxDvbBuffOpen(Context_t *context, char *type, int outfd, void *mtx)
pthread_cond_init(&bufferingExitCond, NULL);
pthread_cond_init(&bufferingDataConsumedCond, NULL);
pthread_cond_init(&bufferingWriteFinishedCond, NULL);
pthread_cond_init(&bufferingdDataAddedCond, NULL);
}
}
@@ -321,6 +340,7 @@ int32_t LinuxDvbBuffClose(Context_t *context __attribute__((unused)))
/*
pthread_mutex_destroy(&bufferingMtx);
pthread_cond_destroy(&bufferingDataConsumedCond);
pthread_cond_destroy(&bufferingWriteFinishedCond);
pthread_cond_destroy(&bufferingdDataAddedCond);
*/
}
@@ -356,6 +376,12 @@ int32_t LinuxDvbBuffFlush(Context_t *context __attribute__((unused)))
/* signal that queue is empty */
pthread_cond_signal(&bufferingDataConsumedCond);
while (g_bDuringWrite && !PlaybackDieNow(0))
{
g_bSignalWriteFinish = true;
pthread_cond_wait(&bufferingWriteFinishedCond, &bufferingMtx);
}
pthread_mutex_unlock(&bufferingMtx);
buff_printf(40, "EXIT\n");
@@ -372,6 +398,11 @@ int32_t LinuxDvbBuffResume(Context_t *context __attribute__((unused)))
return 0;
}
void LinuxDvbBuffSetStamp(void *stamp)
{
g_pWriteStamp = stamp;
}
ssize_t BufferingWriteV(int fd, const struct iovec *iov, int ic)
{
OutputType_t dataType = OUTPUT_UNK;
@@ -445,6 +476,7 @@ ssize_t BufferingWriteV(int fd, const struct iovec *iov, int ic)
chunkSize -= sizeof(BufferingNode_t);
nodePtr->dataSize = chunkSize;
nodePtr->dataType = dataType;
nodePtr->stamp = g_pWriteStamp;
nodePtr->next = NULL;
/* signal that we added some data to queue */

View File

@@ -73,6 +73,8 @@ bool isBufferedOutput = false;
pthread_mutex_t LinuxDVBmutex;
static int64_t last_pts = 0;
/* ***************************** */
/* Prototypes */
/* ***************************** */
@@ -94,7 +96,6 @@ int LinuxDvbStop(Context_t *context, char *type);
#define getLinuxDVBMutex() pthread_mutex_lock(&LinuxDVBmutex)
#define releaseLinuxDVBMutex() pthread_mutex_unlock(&LinuxDVBmutex)
int LinuxDvbOpen(Context_t *context __attribute__((unused)), char *type)
{
uint8_t video = !strcmp("video", type);
@@ -196,7 +197,7 @@ int LinuxDvbClear(Context_t *context __attribute__((unused)), char *type __attri
int LinuxDvbPts(Context_t *context __attribute__((unused)), unsigned long long int *pts)
{
*((unsigned long long int *)pts) = (unsigned long long int)0;
*((unsigned long long int *)pts) = (unsigned long long int)last_pts;
return 0;
}
@@ -207,7 +208,6 @@ int LinuxDvbGetFrameCount(Context_t *context __attribute__((unused)), unsigned l
int LinuxDvbSwitch(Context_t *context __attribute__((unused)), char *type __attribute__((unused)))
{
return cERR_LINUXDVB_NO_ERROR;
}
@@ -231,7 +231,7 @@ static int Write(Context_t *context, void *_out)
audio = !strcmp("audio", out->type);
linuxdvb_printf(20, "DataLength=%u PrivateLength=%u Pts=%"PRIu64" FrameRate=%d\n",
out->len, out->extralen, out->pts, out->frameRate);
out->len, out->extralen, out->pts, out->frameRate);
linuxdvb_printf(20, "v%d a%d\n", video, audio);
if (video)
@@ -300,6 +300,16 @@ static int Write(Context_t *context, void *_out)
}
}
if (out->pts != INVALID_PTS_VALUE)
{
if (out->pts > last_pts)
{
usleep((out->pts - last_pts) / 90 * 900);
//usleep((out->pts - last_pts) / 90 * 500);
}
last_pts = out->pts;
}
call.fd = videofd;
call.data = out->data;
call.len = out->len;

View File

@@ -288,7 +288,10 @@ int LinuxDvbPlay(Context_t *context, char *type)
{
linuxdvb_printf(20, "found writer %s for encoding %s\n", writer->caps->name, Encoding);
ret = ioctl(videofd, VIDEO_SET_STREAMTYPE, LinuxDvbMapStreamType(writer->caps->dvbStreamType, true));
if (ret < 0) ret = ioctl(videofd, VIDEO_SET_STREAMTYPE, LinuxDvbMapStreamType(writer->caps->dvbStreamType, false));
if (ret < 0)
ret = ioctl(videofd, VIDEO_SET_STREAMTYPE, LinuxDvbMapStreamType(writer->caps->dvbStreamType, false));
if (ret < 0)
{
linuxdvb_err("VIDEO_SET_STREAMTYPE: ERROR %d, %s\n", errno, strerror(errno));
@@ -331,7 +334,10 @@ int LinuxDvbPlay(Context_t *context, char *type)
{
linuxdvb_printf(20, "found writer %s for encoding %s\n", writer->caps->name, Encoding);
ret = ioctl(audiofd, AUDIO_SET_BYPASS_MODE, LinuxDvbMapBypassMode(writer->caps->dvbStreamType, true));
if (ret < 0) ret = ioctl(audiofd, AUDIO_SET_BYPASS_MODE, LinuxDvbMapBypassMode(writer->caps->dvbStreamType, false));
if (ret < 0)
ret = ioctl(audiofd, AUDIO_SET_BYPASS_MODE, LinuxDvbMapBypassMode(writer->caps->dvbStreamType, false));
if (ret < 0)
{
linuxdvb_err("AUDIO_SET_BYPASS_MODE: ERROR %d, %s\n", errno, strerror(errno));
@@ -587,7 +593,6 @@ int LinuxDvbAVSync(Context_t *context __attribute__((unused)), char *type __attr
if (audiofd != -1)
{
getLinuxDVBMutex();
if (ioctl(audiofd, AUDIO_SET_AV_SYNC, 0) == -1) //context->playback->AVSync) == -1)
{
linuxdvb_err("AUDIO_SET_AV_SYNC: ERROR %d, %s\n", errno, strerror(errno));
@@ -722,7 +727,10 @@ int LinuxDvbSwitch(Context_t *context, char *type)
{
linuxdvb_printf(10, "found writer %s for encoding %s\n", writer->caps->name, Encoding);
ret = ioctl(audiofd, AUDIO_SET_BYPASS_MODE, LinuxDvbMapBypassMode(writer->caps->dvbStreamType, true));
if (ret < 0) ret = ioctl(audiofd, AUDIO_SET_BYPASS_MODE, LinuxDvbMapBypassMode(writer->caps->dvbStreamType, false));
if (ret < 0)
ret = ioctl(audiofd, AUDIO_SET_BYPASS_MODE, LinuxDvbMapBypassMode(writer->caps->dvbStreamType, false));
if (ret < 0)
{
linuxdvb_err("AUDIO_SET_BYPASS_MODE: ERROR %d, %s\n", errno, strerror(errno));
@@ -770,7 +778,10 @@ int LinuxDvbSwitch(Context_t *context, char *type)
{
linuxdvb_printf(10, "found writer %s for encoding %s\n", writer->caps->name, Encoding);
ret = ioctl(videofd, VIDEO_SET_STREAMTYPE, LinuxDvbMapStreamType(writer->caps->dvbStreamType, true));
if (ret < 0) ret = ioctl(videofd, VIDEO_SET_STREAMTYPE, LinuxDvbMapStreamType(writer->caps->dvbStreamType, false));
if (ret < 0)
ret = ioctl(videofd, VIDEO_SET_STREAMTYPE, LinuxDvbMapStreamType(writer->caps->dvbStreamType, false));
if (ret < 0)
{
linuxdvb_err("VIDEO_SET_STREAMTYPE: ERROR %d, %s\n", errno, strerror(errno));
@@ -821,7 +832,7 @@ static int Write(Context_t *context, void *_out)
audio = !strcmp("audio", out->type);
linuxdvb_printf(20, "DataLength=%u PrivateLength=%u Pts=%" PRIu64 " FrameRate=%d\n",
out->len, out->extralen, out->pts, out->frameRate);
out->len, out->extralen, out->pts, out->frameRate);
linuxdvb_printf(20, "v%d a%d\n", video, audio);
if (video)
@@ -862,6 +873,7 @@ static int Write(Context_t *context, void *_out)
}
else
{
bool changed = false;
if (evt.type == VIDEO_EVENT_SIZE_CHANGED)
{
linuxdvb_printf(10, "VIDEO_EVENT_SIZE_CHANGED type: 0x%x\n", evt.type);
@@ -871,12 +883,14 @@ static int Write(Context_t *context, void *_out)
videoInfo.width = evt.u.size.w;
videoInfo.height = evt.u.size.h;
videoInfo.aspect_ratio = evt.u.size.aspect_ratio;
changed = true;
}
else if (evt.type == VIDEO_EVENT_FRAME_RATE_CHANGED)
{
linuxdvb_printf(10, "VIDEO_EVENT_FRAME_RATE_CHANGED type: 0x%x\n", evt.type);
linuxdvb_printf(10, "framerate : %d\n", evt.u.frame_rate);
videoInfo.frame_rate = evt.u.frame_rate;
changed = true;
}
else if (evt.type == 16 /*VIDEO_EVENT_PROGRESSIVE_CHANGED*/)
{
@@ -884,11 +898,23 @@ static int Write(Context_t *context, void *_out)
linuxdvb_printf(10, "progressive : %d\n", evt.u.frame_rate);
videoInfo.progressive = evt.u.frame_rate;
context->manager->video->Command(context, MANAGER_UPDATED_TRACK_INFO, NULL);
changed = true;
}
else
{
linuxdvb_err("unhandled DVBAPI Video Event %d\n", evt.type);
}
if (changed &&
videoInfo.width != -1 &&
videoInfo.height != -1 &&
videoInfo.aspect_ratio != -1 &&
videoInfo.frame_rate != -1 &&
videoInfo.progressive != -1)
{
E2iSendMsg("{\"v_e\":{\"w\":%d,\"h\":%d,\"a\":%d,\"f\":%d,\"p\":%d}}\n",
videoInfo.width, videoInfo.height, videoInfo.aspect_ratio, videoInfo.frame_rate, videoInfo.progressive);
}
}
}
@@ -1028,7 +1054,6 @@ static int reset(Context_t *context)
if (isBufferedOutput)
LinuxDvbBuffFlush(context);
return ret;
}
@@ -1094,6 +1119,7 @@ static int Command(Context_t *context, OutputCmd_t command, void *argument)
}
case OUTPUT_CLEAR:
{
reset(context);
ret = LinuxDvbClear(context, (char *)argument);
reset(context);
sCURRENT_PTS = 0;

View File

@@ -429,7 +429,6 @@ int LinuxDvbContinue(Context_t *context __attribute__((unused)), char *type)
linuxdvb_printf(10, "exiting\n");
return ret;
}
@@ -490,7 +489,6 @@ int LinuxDvbAudioMute(Context_t *context __attribute__((unused)), char *flag)
return ret;
}
int LinuxDvbFlush(Context_t *context __attribute__((unused)), char *type)
{
unsigned char video = !strcmp("video", type);
@@ -619,7 +617,6 @@ int LinuxDvbFastForward(Context_t *context, char *type)
}
#endif
int LinuxDvbReverse(Context_t *context __attribute__((unused)), char *type __attribute__((unused)))
{
int ret = cERR_LINUXDVB_NO_ERROR;
@@ -781,7 +778,8 @@ int LinuxDvbGetFrameCount(Context_t *context __attribute__((unused)), unsigned l
linuxdvb_err("VIDEO_GET_PLAY_INFO: %s\n", strerror(errno));
ret = cERR_LINUXDVB_ERROR;
}
else linuxdvb_err("V: %llu\n", playInfo.frame_count);
else
linuxdvb_err("V: %llu\n", playInfo.frame_count);
}
else if (audiofd != -1)
{
@@ -791,7 +789,8 @@ int LinuxDvbGetFrameCount(Context_t *context __attribute__((unused)), unsigned l
linuxdvb_err("AUDIO_GET_PLAY_INFO: %s\n", strerror(errno));
ret = cERR_LINUXDVB_ERROR;
}
else linuxdvb_err("A: %llu\n", playInfo.frame_count);
else
linuxdvb_err("A: %llu\n", playInfo.frame_count);
}
else
{
@@ -934,7 +933,6 @@ int LinuxDvbSwitch(Context_t *context, char *type)
}
releaseLinuxDVBMutex();
}
linuxdvb_printf(10, "exiting\n");
@@ -963,7 +961,7 @@ static int Write(void *_context, void *_out)
audio = !strcmp("audio", out->type);
linuxdvb_printf(20, "DataLength=%u PrivateLength=%u Pts=%llu FrameRate=%f\n",
out->len, out->extralen, out->pts, out->frameRate);
out->len, out->extralen, out->pts, out->frameRate);
linuxdvb_printf(20, "v%d a%d\n", video, audio);
if (video)
@@ -1228,6 +1226,7 @@ static int Command(void *_context, OutputCmd_t command, void *argument)
}
case OUTPUT_CLEAR:
{
reset(context);
ret = LinuxDvbClear(context, (char *)argument);
reset(context);
sCURRENT_PTS = 0;

View File

@@ -37,6 +37,7 @@
#include "common.h"
#include "debug.h"
#include "output.h"
#include "writer.h"
/* ***************************** */
/* Makros/Constants */
@@ -60,13 +61,13 @@ Number, Style, Name,, MarginL, MarginR, MarginV, Effect,, Text
/* Types */
/* ***************************** */
/* ***************************** */
/* Variables */
/* ***************************** */
static pthread_mutex_t mutex;
static int isSubtitleOpened = 0;
static SubWriter_t *g_subWriter;
/* ***************************** */
/* Prototypes */
@@ -158,7 +159,6 @@ static char *json_string_escape(char *str)
*ptr1++ = *ptr2;
break;
}
++ptr2;
}
*ptr1 = '\0';
@@ -167,7 +167,10 @@ static char *json_string_escape(char *str)
static int Flush()
{
fprintf(stderr, "{\"s_f\":{\"r\":0}}\n");
if (g_subWriter)
g_subWriter->reset();
E2iSendMsg("{\"s_f\":{\"r\":0}}\n");
return cERR_SUBTITLE_NO_ERROR;
}
@@ -190,6 +193,11 @@ static int Write(Context_t *context, void *data)
context->manager->subtitle->Command(context, MANAGER_GET, &curtrackid);
if (curtrackid != (int32_t)out->trackId)
{
if (g_subWriter)
{
g_subWriter = NULL;
g_subWriter->close();
}
Flush();
}
context->manager->subtitle->Command(context, MANAGER_GETENCODING, &Encoding);
@@ -201,25 +209,60 @@ static int Write(Context_t *context, void *data)
}
subtitle_printf(20, "Encoding:%s Text:%s Len:%d\n", Encoding, (const char *) out->data, out->len);
SubtitleCodecId_t subCodecId = SUBTITLE_CODEC_ID_UNKNOWN;
if (!strncmp("S_TEXT/SUBRIP", Encoding, 13))
{
fprintf(stderr, "{\"s_a\":{\"id\":%d,\"s\":%" PRId64 ",\"e\":%" PRId64 ",\"t\":\"%s\"}}\n", out->trackId, out->pts / 90, out->pts / 90 + out->durationMS, json_string_escape((char *)out->data));
}
subCodecId = SUBTITLE_CODEC_ID_SUBRIP;
else if (!strncmp("S_TEXT/ASS", Encoding, 10))
{
fprintf(stderr, "{\"s_a\":{\"id\":%d,\"s\":%" PRId64 ",\"e\":%" PRId64 ",\"t\":\"%s\"}}\n", out->trackId, out->pts / 90, out->pts / 90 + out->durationMS, ass_get_text((char *)out->data));
}
else if (!strncmp("D_WEBVTT/SUBTITLES", Encoding, 18))
{
fprintf(stderr, "{\"s_a\":{\"id\":%d,\"s\":%" PRId64 ",\"e\":%" PRId64 ",\"t\":\"%s\"}}\n", out->trackId, out->pts / 90, out->pts / 90 + out->durationMS, json_string_escape((char *)out->data));
}
else
{
subtitle_err("unknown encoding %s\n", Encoding);
return cERR_SUBTITLE_ERROR;
}
subCodecId = SUBTITLE_CODEC_ID_ASS;
else if (!strncmp("S_TEXT/WEBVTT", Encoding, 18))
subCodecId = SUBTITLE_CODEC_ID_WEBVTT;
else if (!strncmp("S_GRAPHIC/PGS", Encoding, 13))
subCodecId = SUBTITLE_CODEC_ID_PGS;
else if (!strncmp("S_GRAPHIC/DVB", Encoding, 13))
subCodecId = SUBTITLE_CODEC_ID_DVB;
else if (!strncmp("S_GRAPHIC/XSUB", Encoding, 14))
subCodecId = SUBTITLE_CODEC_ID_XSUB;
switch (subCodecId)
{
case SUBTITLE_CODEC_ID_SUBRIP:
case SUBTITLE_CODEC_ID_WEBVTT:
E2iSendMsg("{\"s_a\":{\"id\":%d,\"s\":%"PRId64",\"e\":%"PRId64",\"t\":\"%s\"}}\n", out->trackId, out->pts / 90, out->pts / 90 + out->durationMS, json_string_escape((char *)out->data));
break;
case SUBTITLE_CODEC_ID_ASS:
E2iSendMsg("{\"s_a\":{\"id\":%d,\"s\":%"PRId64",\"e\":%"PRId64",\"t\":\"%s\"}}\n", out->trackId, out->pts / 90, out->pts / 90 + out->durationMS, ass_get_text((char *)out->data));
break;
case SUBTITLE_CODEC_ID_PGS:
case SUBTITLE_CODEC_ID_DVB:
case SUBTITLE_CODEC_ID_XSUB:
{
if (!g_subWriter)
{
g_subWriter = &WriterSubPGS;
//g_subWriter->open(subCodecId, out->extradata, out->extralen);
}
WriterSubCallData_t subPacket;
memset(&subPacket, 0x00, sizeof(subPacket));
subPacket.codecId = subCodecId;
subPacket.trackId = out->trackId;
subPacket.data = out->data;
subPacket.len = out->len;
subPacket.pts = out->pts;
subPacket.dts = out->dts;
subPacket.private_data = out->extradata;
subPacket.private_size = out->extralen;
subPacket.durationMS = out->durationMS;
subPacket.width = out->width;
subPacket.height = out->height;
g_subWriter->write(&subPacket);
}
break;
default:
subtitle_err("unknown encoding %s\n", Encoding);
return cERR_SUBTITLE_ERROR;
}
subtitle_printf(10, "<\n");
return cERR_SUBTITLE_NO_ERROR;
}
@@ -252,8 +295,13 @@ static int32_t subtitle_Close(Context_t *context __attribute__((unused)))
getMutex(__LINE__);
isSubtitleOpened = 0;
if (g_subWriter)
{
g_subWriter->close();
g_subWriter = NULL;
}
isSubtitleOpened = 0;
releaseMutex(__LINE__);
subtitle_printf(10, "<\n");
@@ -325,7 +373,6 @@ static int Command(Context_t *context, OutputCmd_t command, void *argument __att
return ret;
}
static char *SubtitleCapabilitis[] = { "subtitle", NULL };
Output_t SubtitleOutput =

View File

@@ -138,7 +138,7 @@ stb_type_t GetSTBType()
type = STB_DREAMBOX;
}
else if (access("/proc/stb/info/vumodel", F_OK) != -1 &&
access("/proc/stb/info/boxtype", F_OK) == -1)
access("/proc/stb/info/boxtype", F_OK) == -1)
{
// some STB like Octagon SF4008 has also /proc/stb/info/vumodel
// but VU PLUS does not have /proc/stb/info/boxtype

View File

@@ -57,7 +57,6 @@
/* Types */
/* ***************************** */
/* ***************************** */
/* Varaibles */
/* ***************************** */

View File

@@ -41,6 +41,7 @@
#include <libavutil/intreadwrite.h>
#include "ffmpeg/latmenc.h"
#include "ffmpeg/mpeg4audio.h"
#include "stm_ioctls.h"
#include "bcm_ioctls.h"
@@ -66,6 +67,8 @@
/* Variables */
/* ***************************** */
static bool needInitHeader = true;
/// ** AAC ADTS format **
///
/// AAAAAAAA AAAABCCD EEFFFFGH HHIJKLMM
@@ -130,6 +133,7 @@ static int reset()
free(pLATMCtx);
pLATMCtx = NULL;
}
needInitHeader = true;
return 0;
}
@@ -169,7 +173,7 @@ static int _writeData(WriterAVCallData_t *call, int type)
else // check LOAS header
{
if (!(call->len > 2 && call->data[0] == 0x56 && (call->data[1] >> 4) == 0xe &&
((uint32_t)(AV_RB16(call->data + 1) & 0x1FFF) + 3) == call->len))
((uint32_t)(AV_RB16(call->data + 1) & 0x1FFF) + 3) == call->len))
{
aac_err("parsing Data with wrong latm header. ignoring...\n");
return 0;
@@ -194,35 +198,25 @@ static int writeDataADTS(WriterAVCallData_t *call)
{
aac_printf(10, "\n");
if (call == NULL)
if (call == NULL || call->data == NULL || call->len <= 0 || call->fd < 0)
{
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))
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 adtsHeaderSize = (call->private_data == NULL || needInitHeader == false) ? AAC_HEADER_LENGTH : call->private_size;
uint32_t PacketLength = call->len + adtsHeaderSize;
uint8_t PesHeader[PES_MAX_HEADER_SIZE + AAC_HEADER_LENGTH + MAX_PCE_SIZE];
uint32_t headerSize = InsertPesHeader(PesHeader, PacketLength, MPEG_AUDIO_PES_START_CODE, call->Pts, 0);
uint8_t *pExtraData = &PesHeader[headerSize];
needInitHeader = false;
aac_printf(10, "AudioPts %lld\n", call->Pts);
if (call->private_data == NULL)
@@ -232,7 +226,7 @@ static int writeDataADTS(WriterAVCallData_t *call)
}
else
{
memcpy(pExtraData, call->private_data, AAC_HEADER_LENGTH);
memcpy(pExtraData, call->private_data, adtsHeaderSize);
}
pExtraData[3] &= 0xC0;
@@ -252,7 +246,7 @@ static int writeDataADTS(WriterAVCallData_t *call)
struct iovec iov[2];
iov[0].iov_base = PesHeader;
iov[0].iov_len = headerSize + AAC_HEADER_LENGTH;
iov[0].iov_len = headerSize + adtsHeaderSize;
iov[1].iov_base = call->data;
iov[1].iov_len = call->len;

View File

@@ -77,37 +77,26 @@ static int reset()
static int writeData(WriterAVCallData_t *call)
{
unsigned char PesHeader[PES_MAX_HEADER_SIZE + 4 + 9];
uint8_t PesHeader[PES_MAX_HEADER_SIZE + 4 + 9];
amr_printf(10, "\n");
if (call == NULL)
if (call == NULL || call->data == NULL || call->len <= 0 || call->fd < 0)
{
amr_err("call data is NULL...\n");
amr_err("call error wrong data call: %p, data: %p, len: %d, fd: %d\n", call, call->data, call->len, call->fd);
return 0;
}
amr_printf(10, "AudioPts %lld\n", call->Pts);
size_t payload_len = call->len;
bool hasCodecData = true;
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)
{
amr_err("wrong private_data. ignoring ...\n");
hasCodecData = 1;
hasCodecData = false;
}
size_t payload_len = call->len;
if (hasCodecData)
{
payload_len += 9;
@@ -122,10 +111,7 @@ static int writeData(WriterAVCallData_t *call)
if (hasCodecData)
{
uint8_t tmp[] = {0x45, 0x4d, 0x50, 0x20, 0x00, 0x00, 0x80, 0x00, 0x01};
memcpy(&PesHeader[headerSize], tmp, 9);
//memcpy(&PesHeader[headerSize], call->private_data + 8, 9);
//memset(&PesHeader[headerSize], 0, 9);
memcpy(&PesHeader[headerSize], call->private_data + 8, 9);
}
struct iovec iov[2];

View File

@@ -95,9 +95,6 @@ static int reset()
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)
@@ -132,11 +129,11 @@ static int writeData(WriterAVCallData_t *call)
data += 38;
data[0] = B_GET_BITS(width, 11, 4);
data[1] = B_SET_BITS("width [3..0]", B_GET_BITS(width, 3, 0), 7, 4) |
B_SET_BITS("'10'", 0x02, 3, 2) |
B_SET_BITS("height [11..10]", B_GET_BITS(height, 11, 10), 1, 0);
B_SET_BITS("'10'", 0x02, 3, 2) |
B_SET_BITS("height [11..10]", B_GET_BITS(height, 11, 10), 1, 0);
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);
B_SET_BITS("'100000'", 0x20, 5, 0);
iov[ic].iov_base = brcm_divx311_sequence_header;
iov[ic++].iov_len = sizeof(brcm_divx311_sequence_header);
@@ -145,7 +142,7 @@ static int writeData(WriterAVCallData_t *call)
iov[ic].iov_base = PesHeader;
uint32_t headerSize = 0;
if (memcmp(call->data, "\x00\x00\x01\xb6", 4))
if (0 != memcmp(call->data, "\x00\x00\x01\xb6", 4))
{
headerSize = InsertPesHeader(PesHeader, call->len + 4, MPEG_VIDEO_PES_START_CODE, call->Pts, 0);
memcpy(PesHeader + headerSize, "\x00\x00\x01\xb6", 4);
@@ -176,7 +173,7 @@ static WriterCaps_t divix3_caps =
"divix3",
eVideo,
"V_DIVX3",
VIDEO_ENCODING_MPEG4P2,
-1,
STREAMTYPE_DIVX311,
-1
};

View File

@@ -146,7 +146,7 @@ static int writeData(WriterAVCallData_t *call)
}
/* ***************************** */
/* Writer Definition */
/* Writer Definition */
/* ***************************** */
static WriterCaps_t caps =

View File

@@ -335,8 +335,8 @@ static int writeData(WriterAVCallData_t *call)
/* 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) ||
(call->data[0] == 0xff && call->data[1] == 0xff && call->data[2] == 0xff && call->data[3] == 0xff)))))
((call->len > 3) && ((call->data[0] == 0x00 && call->data[1] == 0x00 && call->data[2] == 0x00 && call->data[3] == 0x01) ||
(call->data[0] == 0xff && call->data[1] == 0xff && call->data[2] == 0xff && call->data[3] == 0xff)))))
{
uint32_t i = 0;
uint8_t InsertPrivData = !sps_pps_in_stream;

View File

@@ -113,26 +113,36 @@ static int32_t PreparCodecData(unsigned char *data, unsigned int cd_len, unsigne
break;
}
// ignore flags + NAL type (1 byte)
int nal_type = data[pos] & 0x3f;
int nal_count = data[pos + 1] << 8 | data[pos + 2];
pos += 3;
for (j = 0; j < nal_count; j++)
{
if (pos + 2 > cd_len)
{
h265_printf(10, "Buffer underrun in extra nal header (%d >= %u)", pos + 2, cd_len);
h265_printf(10, "Buffer underrun in extra nal header (%d >= %u)\n", pos + 2, cd_len);
break;
}
int nal_size = data[pos] << 8 | data[pos + 1];
pos += 2;
if (pos + nal_size > cd_len)
{
h265_printf(10, "Buffer underrun in extra nal (%d >= %u)", pos + 2 + nal_size, cd_len);
h265_printf(10, "Buffer underrun in extra nal (%d >= %u)\n", pos + 2 + nal_size, cd_len);
break;
}
memcpy(tmp + tmp_len, "\x00\x00\x00\x01", 4);
tmp_len += 4;
memcpy(tmp + tmp_len, data + pos, nal_size);
tmp_len += nal_size;
if ((nal_type == 0x20 || nal_type == 0x21 || nal_type == 0x22) && ((tmp_len + 4 + nal_size) < sizeof(tmp))) // use only VPS, SPS, PPS nals
{
memcpy(tmp + tmp_len, "\x00\x00\x00\x01", 4);
tmp_len += 4;
memcpy(tmp + tmp_len, data + pos, nal_size);
tmp_len += nal_size;
}
else if ((tmp_len + 4 + nal_size) >= sizeof(tmp))
{
h264_err("Ignoring nal as tmp buffer is too small tmp_len + nal = %d\n", tmp_len + 4 + nal_size);
}
pos += nal_size;
}
}
@@ -195,7 +205,7 @@ static int writeData(WriterAVCallData_t *call)
return 0;
}
if (call->InfoFlags & 0x1) // TS container
if (call->InfoFlags & 0x1) // TS container
{
h265_printf(10, "H265 simple inject method!\n");
uint32_t PacketLength = 0;
@@ -258,6 +268,7 @@ static int writeData(WriterAVCallData_t *call)
if (ic >= IOVEC_SIZE)
{
h264_err(">> Drop data due to ic overflow\n");
exit(-1);
break;
}

View File

@@ -42,7 +42,6 @@
#include "stm_ioctls.h"
#include "bcm_ioctls.h"
#include "debug.h"
#include "common.h"
#include "output.h"
#include "debug.h"
@@ -62,7 +61,7 @@
/* Variables */
/* ***************************** */
static bool must_send_header = true;
static bool must_send_header = false;
/* ***************************** */
/* Prototypes */
@@ -74,14 +73,78 @@ static bool must_send_header = true;
static int reset()
{
must_send_header = true;
must_send_header = false;
return 0;
}
static int writeDataSimple(WriterAVCallData_t *call)
{
uint8_t PesHeader[PES_MAX_HEADER_SIZE];
struct iovec iov[2];
iov[0].iov_base = PesHeader;
iov[0].iov_len = InsertPesHeader(PesHeader, call->len, MPEG_VIDEO_PES_START_CODE, call->Pts, 0);
iov[1].iov_base = call->data;
iov[1].iov_len = call->len;
return call->WriteV(call->fd, iov, 2);;
}
static int writeDataBCMV(WriterAVCallData_t *call)
{
uint8_t PesHeader[PES_MAX_HEADER_SIZE];
uint32_t pes_header_len = InsertPesHeader(PesHeader, call->len, MPEG_VIDEO_PES_START_CODE, call->Pts, 0);
uint32_t len = call->len + 4 + 4 + 2;
memcpy(PesHeader + pes_header_len, "BCMV", 4);
pes_header_len += 4;
PesHeader[pes_header_len++] = (len & 0xFF000000) >> 24;
PesHeader[pes_header_len++] = (len & 0x00FF0000) >> 16;
PesHeader[pes_header_len++] = (len & 0x0000FF00) >> 8;
PesHeader[pes_header_len++] = (len & 0x000000FF) >> 0;
PesHeader[pes_header_len++] = 0;
PesHeader[pes_header_len++] = 1;
int32_t payload_len = call->len + pes_header_len - 6;
if (payload_len > 0x8008)
payload_len = 0x8008;
int offs = 0;
int bytes = payload_len - 10 - 8;
UpdatePesHeaderPayloadSize(PesHeader, payload_len);
// pes header
if (pes_header_len != (unsigned)WriteExt(call->WriteV, call->fd, PesHeader, pes_header_len))
return -1;
if (bytes != WriteExt(call->WriteV, call->fd, call->data, bytes))
return -1;
offs += bytes;
while ((unsigned)bytes < call->len)
{
int left = call->len - bytes;
int wr = 0x8000;
if (wr > left)
wr = left;
//PesHeader[0] = 0x00;
//PesHeader[1] = 0x00;
//PesHeader[2] = 0x01;
//PesHeader[3] = 0xE0;
PesHeader[6] = 0x81;
PesHeader[7] = 0x00;
PesHeader[8] = 0x00;
pes_header_len = 9;
UpdatePesHeaderPayloadSize(PesHeader, wr + 3);
if (pes_header_len != (unsigned)WriteExt(call->WriteV, call->fd, PesHeader, pes_header_len))
return -1;
if (wr != WriteExt(call->WriteV, call->fd, call->data + offs, wr))
return -1;
bytes += wr;
offs += wr;
}
return 1;
}
static int writeData(WriterAVCallData_t *call)
{
static uint8_t PesHeader[PES_MAX_HEADER_SIZE];
mjpeg_printf(10, "\n");
if (call == NULL)
@@ -92,15 +155,12 @@ static int writeData(WriterAVCallData_t *call)
mjpeg_printf(10, "VideoPts %lld\n", call->Pts);
struct iovec iov[2];
if (STB_HISILICON == GetSTBType())
{
return writeDataSimple(call);
}
iov[0].iov_base = PesHeader;
iov[0].iov_len = InsertPesHeader(PesHeader, call->len, MPEG_VIDEO_PES_START_CODE, call->Pts, 0);
iov[1].iov_base = call->data;
iov[1].iov_len = call->len;
return call->WriteV(call->fd, iov, 2);;
return writeDataBCMV(call);
}
/* ***************************** */
@@ -123,3 +183,54 @@ struct Writer_s WriterVideoMJPEG =
&writeData,
&caps
};
static WriterCaps_t capsRV30 =
{
"rv30",
eVideo,
"V_RV30",
VIDEO_ENCODING_AUTO,
STREAMTYPE_RV30,
-1
};
struct Writer_s WriterVideoRV30 =
{
&reset,
&writeData,
&capsRV30
};
static WriterCaps_t capsRV40 =
{
"rv40",
eVideo,
"V_RV40",
VIDEO_ENCODING_AUTO,
STREAMTYPE_RV40,
-1
};
struct Writer_s WriterVideoRV40 =
{
&reset,
&writeData,
&capsRV40
};
static WriterCaps_t capsAVS2 =
{
"avs2",
eVideo,
"V_AVS2",
VIDEO_ENCODING_AUTO,
STREAMTYPE_AVS2,
-1
};
struct Writer_s WriterVideoAVS2 =
{
&reset,
&writeData,
&capsAVS2
};

View File

@@ -80,26 +80,13 @@ static int writeData(WriterAVCallData_t *call)
mp3_printf(10, "\n");
if (call == NULL)
if (call == NULL || call->data == NULL || call->len <= 0 || call->fd < 0)
{
mp3_err("call data is NULL...\n");
mp3_err("Wrong input call: %p, data: %p, len: %d, fd: %d\n", call, call->data, call->len, call->fd);
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);
@@ -157,20 +144,3 @@ struct Writer_s WriterAudioMPEGL3 =
&writeData,
&caps_mpegl3
};
static WriterCaps_t caps_vorbis =
{
"vorbis",
eAudio,
"A_VORBIS",
AUDIO_ENCODING_VORBIS,
AUDIO_ENCODING_MP3,
-1
};
struct Writer_s WriterAudioVORBIS =
{
&reset,
&writeData,
&caps_vorbis
};

View File

@@ -65,7 +65,6 @@ static bool must_send_header = true;
static uint8_t *private_data = NULL;
static uint32_t private_size = 0;
/* ***************************** */
/* Prototypes */
/* ***************************** */
@@ -116,26 +115,40 @@ static int writeData(WriterAVCallData_t *call)
uint32_t sheader_data_len = 0;
while (pos < data_len && ok)
{
if (pos >= data_len) break;
if (pos >= data_len)
break;
pos += 7;
if (pos >= data_len) break;
if (pos >= data_len)
break;
sheader_data_len = 12;
if (data[pos] & 2)
{
// intra matrix
pos += 64;
if (pos >= data_len) break;
if (pos >= data_len)
break;
sheader_data_len += 64;
}
if (data[pos] & 1)
{
// non intra matrix
pos += 64;
if (pos >= data_len) break;
if (pos >= data_len)
break;
sheader_data_len += 64;
}
pos += 1;
if (pos + 3 >= data_len) break;
if (pos + 3 >= data_len)
break;
if (!memcmp(&data[pos], "\x00\x00\x01\xb5", 4))
{
// extended start code
@@ -152,9 +165,14 @@ static int writeData(WriterAVCallData_t *call)
}
}
while (memcmp(&data[pos], "\x00\x00\x01", 3));
if (!ok) break;
if (!ok)
break;
}
if (pos + 3 >= data_len) break;
if (pos + 3 >= data_len)
break;
if (!memcmp(&data[pos], "\x00\x00\x01\xb2", 4))
{
// private data
@@ -171,7 +189,9 @@ static int writeData(WriterAVCallData_t *call)
}
}
while (memcmp(&data[pos], "\x00\x00\x01", 3));
if (!ok) break;
if (!ok)
break;
}
free(private_data);
@@ -239,9 +259,11 @@ static int writeData(WriterAVCallData_t *call)
PesHeader[6] = 0x81;
UpdatePesHeaderPayloadSize(PesHeader, data_len + iov[0].iov_len - 6);
if (iov[0].iov_len != (unsigned)WriteExt(call->WriteV, call->fd, iov[0].iov_base, iov[0].iov_len)) return -1;
if (iov[1].iov_len != (unsigned)WriteExt(call->WriteV, call->fd, iov[1].iov_base, iov[1].iov_len)) return -1;
if (iov[0].iov_len != (unsigned)WriteExt(call->WriteV, call->fd, iov[0].iov_base, iov[0].iov_len))
return -1;
if (iov[1].iov_len != (unsigned)WriteExt(call->WriteV, call->fd, iov[1].iov_base, iov[1].iov_len))
return -1;
return 1;
}

View File

@@ -124,7 +124,7 @@ static int writeData(WriterAVCallData_t *call)
int32_t block_align = 0;
int32_t byterate = 0;
uint32_t codecID = (uint32_t)pcmPrivateData->ffmpeg_codec_id;
uint32_t codecID = (uint32_t)pcmPrivateData->codec_id;
//uint8_t dataPrecision = 0;
uint8_t LE = 0;
@@ -271,7 +271,7 @@ static WriterCaps_t caps_pcm =
"pcm",
eAudio,
"A_PCM",
AUDIO_ENCODING_LPCMA,
-1,
0x30,
-1
};
@@ -288,7 +288,7 @@ static WriterCaps_t caps_ipcm =
"ipcm",
eAudio,
"A_IPCM",
AUDIO_ENCODING_LPCMA,
-1,
0x30,
-1
};

View File

@@ -139,7 +139,7 @@ static int writeData(WriterAVCallData_t *call)
uint8_t needFrameStartCode = 0;
if (sizeof(Vc1FrameStartCode) >= call->len ||
memcmp(call->data, Vc1FrameStartCode, sizeof(Vc1FrameStartCode)) != 0)
memcmp(call->data, Vc1FrameStartCode, sizeof(Vc1FrameStartCode)) != 0)
{
needFrameStartCode = 1;
PacketLength += sizeof(Vc1FrameStartCode);

View File

@@ -150,8 +150,11 @@ static int writeData(WriterAVCallData_t *call, bool is_vp6, bool is_vp9)
int bytes = payload_len - 10 - 8;
UpdatePesHeaderPayloadSize(PesHeader, payload_len);
// pes header
if (pes_header_len != (unsigned)WriteExt(call->WriteV, call->fd, PesHeader, pes_header_len)) return -1;
if (bytes != WriteExt(call->WriteV, call->fd, call->data, bytes)) return -1;
if (pes_header_len != (unsigned)WriteExt(call->WriteV, call->fd, PesHeader, pes_header_len))
return -1;
if (bytes != WriteExt(call->WriteV, call->fd, call->data, bytes))
return -1;
offs += bytes;
@@ -161,11 +164,6 @@ static int writeData(WriterAVCallData_t *call, bool is_vp6, bool is_vp9)
int wr = 0x8000;
if (wr > left)
wr = left;
//gst_buffer_unmap(self->pesheader_buffer, &pesheadermap);
//gst_buffer_map(self->pesheader_buffer, &pesheadermap, GST_MAP_WRITE);
//pes_header = pesheadermap.data;
//PesHeader[0] = 0x00;
//PesHeader[1] = 0x00;
//PesHeader[2] = 0x01;
@@ -177,17 +175,15 @@ static int writeData(WriterAVCallData_t *call, bool is_vp6, bool is_vp9)
UpdatePesHeaderPayloadSize(PesHeader, wr + 3);
if (pes_header_len != (unsigned)WriteExt(call->WriteV, call->fd, PesHeader, pes_header_len)) return -1;
if (wr != WriteExt(call->WriteV, call->fd, call->data + offs, wr)) return -1;
if (pes_header_len != (unsigned)WriteExt(call->WriteV, call->fd, PesHeader, pes_header_len))
return -1;
if (wr != WriteExt(call->WriteV, call->fd, call->data + offs, wr))
return -1;
bytes += wr;
offs += wr;
}
//gst_buffer_unmap(self->pesheader_buffer, &pesheadermap);
//gst_buffer_map(self->pesheader_buffer, &pesheadermap, GST_MAP_WRITE);
//pes_header = pesheadermap.data;
//PesHeader[0] = 0x00;
//PesHeader[1] = 0x00;
//PesHeader[2] = 0x01;
@@ -209,11 +205,11 @@ static int writeData(WriterAVCallData_t *call, bool is_vp6, bool is_vp9)
PesHeader[29] = 0xFF;
PesHeader[33] = 0x85;
if (pes_header_len != (unsigned)WriteExt(call->WriteV, call->fd, PesHeader, 184)) return -1;
if (pes_header_len != (unsigned)WriteExt(call->WriteV, call->fd, PesHeader, 184))
return -1;
return 1;
}
//return call->WriteV(call->fd, iov, 2);
}

View File

@@ -123,7 +123,9 @@ static int writeData(WriterAVCallData_t *call)
}
unsigned int codec_size = call->private_size;
if (codec_size > 4) codec_size = 4;
if (codec_size > 4)
codec_size = 4;
videocodecdata.length = 33;
uint8_t *data = videocodecdata.data = malloc(videocodecdata.length);
@@ -135,7 +137,10 @@ static int writeData(WriterAVCallData_t *call)
/* height */
*(data++) = (call->Height >> 8) & 0xff;
*(data++) = call->Height & 0xff;
if (call->private_data && codec_size) memcpy(data, call->private_data, codec_size);
if (call->private_data && codec_size)
memcpy(data, call->private_data, codec_size);
if (STB_DREAMBOX == GetSTBType() || 0 != ioctl(call->fd, VIDEO_SET_CODEC_DATA, &videocodecdata))
{
iov[ic].iov_base = videocodecdata.data;
@@ -146,7 +151,7 @@ static int writeData(WriterAVCallData_t *call)
uint8_t needFrameStartCode = 0;
if (sizeof(Vc1FrameStartCode) >= call->len ||
memcmp(call->data, Vc1FrameStartCode, sizeof(Vc1FrameStartCode)) != 0)
memcmp(call->data, Vc1FrameStartCode, sizeof(Vc1FrameStartCode)) != 0)
{
needFrameStartCode = 1;
PacketLength += sizeof(Vc1FrameStartCode);

View File

@@ -71,6 +71,8 @@ static Writer_t *AvailableWriter[] =
&WriterAudioDTS,
&WriterAudioWMA,
&WriterAudioWMAPRO,
&WriterAudioOPUS,
&WriterAudioVORBIS,
&WriterVideoH264,
&WriterVideoH265,
@@ -86,6 +88,9 @@ static Writer_t *AvailableWriter[] =
&WriterVideoFLV,
&WriterVideoWMV,
&WriterVideoMJPEG,
&WriterVideoRV40,
&WriterVideoRV30,
&WriterVideoAVS2,
NULL
};
@@ -106,16 +111,6 @@ ssize_t WriteWithRetry(Context_t *context, int pipefd, int fd, void *pDVBMtx __a
int retval = -1;
int maxFd = pipefd > fd ? pipefd : fd;
struct timeval tv;
static bool first = true;
if (first && STB_HISILICON == GetSTBType())
{
// workaround: playback of some files does not start
// if injection of the frist frame is to fast
usleep(100000);
}
first = false;
while (size > 0 && 0 == PlaybackDieNow(0) && !context->playback->isSeeking)
{
FD_ZERO(&rfds);
@@ -144,8 +139,8 @@ ssize_t WriteWithRetry(Context_t *context, int pipefd, int fd, void *pDVBMtx __a
//if (retval == 0)
//{
// //printf("RETURN FROM SELECT DUE TO TIMEOUT\n");
// continue;
// //printf("RETURN FROM SELECT DUE TO TIMEOUT\n");
// continue;
//}
if (FD_ISSET(pipefd, &rfds))

View File

@@ -41,6 +41,7 @@
#include <libavutil/intreadwrite.h>
#include "ffmpeg/latmenc.h"
#include "ffmpeg/mpeg4audio.h"
#include "stm_ioctls.h"
#include "common.h"
@@ -63,6 +64,8 @@
/* Variables */
/* ***************************** */
static bool needInitHeader = true;
/// ** AAC ADTS format **
///
/// AAAAAAAA AAAABCCD EEFFFFGH HHIJKLMM
@@ -127,6 +130,7 @@ static int reset()
free(pLATMCtx);
pLATMCtx = NULL;
}
needInitHeader = true;
return 0;
}
@@ -168,7 +172,7 @@ static int _writeData(void *_call, int type)
else // check LOAS header
{
if (!(call->len > 2 && call->data[0] == 0x56 && (call->data[1] >> 4) == 0xe &&
(AV_RB16(call->data + 1) & 0x1FFF) + 3 == call->len))
(AV_RB16(call->data + 1) & 0x1FFF) + 3 == call->len))
{
aac_err("parsing Data with wrong latm header. ignoring...\n");
return 0;
@@ -214,15 +218,17 @@ static int writeDataADTS(void *_call)
}
if ((call->private_data && 0 == strncmp("ADTS", call->private_data, call->private_size)) ||
HasADTSHeader(call->data, call->len))
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 adtsHeaderSize = (call->private_data == NULL || needInitHeader == false) ? AAC_HEADER_LENGTH : call->private_size;
uint32_t PacketLength = call->len + adtsHeaderSize;
uint8_t PesHeader[PES_MAX_HEADER_SIZE + AAC_HEADER_LENGTH + MAX_PCE_SIZE];
uint32_t headerSize = InsertPesHeader(PesHeader, PacketLength, MPEG_AUDIO_PES_START_CODE, call->Pts, 0);
uint8_t *pExtraData = &PesHeader[headerSize];
needInitHeader = false;
aac_printf(10, "AudioPts %lld\n", call->Pts);
if (call->private_data == NULL)
@@ -232,7 +238,7 @@ static int writeDataADTS(void *_call)
}
else
{
memcpy(pExtraData, call->private_data, AAC_HEADER_LENGTH);
memcpy(pExtraData, call->private_data, adtsHeaderSize);
}
pExtraData[3] &= 0xC0;
@@ -250,7 +256,7 @@ static int writeDataADTS(void *_call)
struct iovec iov[2];
iov[0].iov_base = PesHeader;
iov[0].iov_len = headerSize + AAC_HEADER_LENGTH;
iov[0].iov_len = headerSize + adtsHeaderSize;
iov[1].iov_base = call->data;
iov[1].iov_len = call->len;

View File

@@ -237,14 +237,15 @@ static int32_t writeData(void *_call)
/* 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) ||
(call->data[0] == 0xff && call->data[1] == 0xff && call->data[2] == 0xff && call->data[3] == 0xff))))
(call->len > 3) && ((call->data[0] == 0x00 && call->data[1] == 0x00 && call->data[2] == 0x00 && call->data[3] == 0x01) ||
(call->data[0] == 0xff && call->data[1] == 0xff && call->data[2] == 0xff && call->data[3] == 0xff))))
{
uint32_t PacketLength = 0;
uint32_t FakeStartCode = /*(call->Version << 8) | */PES_VERSION_FAKE_START_CODE;
iov[ic++].iov_base = PesHeader;
initialHeader = 0;
if (initialHeader)
{
initialHeader = 0;
@@ -440,7 +441,7 @@ static int32_t writeData(void *_call)
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);
NalLength, NalStart, SampleSize - NalStart);
NalStart = SampleSize;
}

View File

@@ -106,7 +106,7 @@ static int writeData(void *_call)
while (Position < call->len)
{
int32_t PacketLength = (call->len - Position) <= MAX_PES_PACKET_SIZE ?
(call->len - Position) : MAX_PES_PACKET_SIZE;
(call->len - Position) : MAX_PES_PACKET_SIZE;
int32_t Remaining = call->len - Position - PacketLength;

View File

@@ -97,10 +97,10 @@ static uint32_t breakBufferFillSize = 0;
static int32_t prepareClipPlay(int32_t uNoOfChannels, int32_t uSampleRate, int32_t uBitsPerSample, uint8_t bLittleEndian __attribute__((unused)))
{
printf("rate: %d ch: %d bits: %d (%d bps)\n",
uSampleRate/*Format->dwSamplesPerSec*/,
uNoOfChannels/*Format->wChannels*/,
uBitsPerSample/*Format->wBitsPerSample*/,
(uBitsPerSample/*Format->wBitsPerSample*/ / 8)
uSampleRate/*Format->dwSamplesPerSec*/,
uNoOfChannels/*Format->wChannels*/,
uBitsPerSample/*Format->wBitsPerSample*/,
(uBitsPerSample/*Format->wBitsPerSample*/ / 8)
);
SubFrameLen = 0;
@@ -203,7 +203,7 @@ static int32_t writeData(void *_call)
if (initialHeader)
{
uint32_t codecID = (uint32_t)pcmPrivateData->ffmpeg_codec_id;
uint32_t codecID = (uint32_t)pcmPrivateData->codec_id;
uint8_t LE = 0;
switch (codecID)
{

View File

@@ -197,7 +197,7 @@ static int writeData(void *_call)
while (Position < call->len)
{
int32_t PacketLength = (call->len - Position) <= MAX_PES_PACKET_SIZE ?
(call->len - Position) : MAX_PES_PACKET_SIZE;
(call->len - Position) : MAX_PES_PACKET_SIZE;
int32_t Remaining = call->len - Position - PacketLength;

View File

@@ -134,7 +134,7 @@ static int writeData(void *_call)
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);
call->private_size > WMV3_PRIVATE_DATA_LENGTH ? WMV3_PRIVATE_DATA_LENGTH : call->private_size);
private_data.width = call->Width;
private_data.height = call->Height;
@@ -196,7 +196,7 @@ static int writeData(void *_call)
while (Position < call->len)
{
int PacketLength = (call->len - Position) <= MAX_PES_PACKET_SIZE ?
(call->len - Position) : MAX_PES_PACKET_SIZE;
(call->len - Position) : MAX_PES_PACKET_SIZE;
int Remaining = call->len - Position - PacketLength;
@@ -213,8 +213,7 @@ static int writeData(void *_call)
unsigned int PrivateHeaderLength;
PrivateHeaderLength = InsertVideoPrivateDataHeader(&PesHeader[HeaderLength], call->len);
/* Update PesLength */
PesLength = PesHeader[PES_LENGTH_BYTE_0] +
(PesHeader[PES_LENGTH_BYTE_1] << 8) + PrivateHeaderLength;
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;