mirror of
https://github.com/tuxbox-neutrino/libstb-hal.git
synced 2025-08-27 07:23:11 +02:00
libeplayer3-arm: insert original blank lines from exteplayer3.git, for better merge
This commit is contained in:
@@ -41,13 +41,15 @@
|
||||
/* ***************************** */
|
||||
/* Types */
|
||||
/* ***************************** */
|
||||
typedef enum OutputType_e{
|
||||
typedef enum OutputType_e
|
||||
{
|
||||
OUTPUT_UNK,
|
||||
OUTPUT_AUDIO,
|
||||
OUTPUT_VIDEO,
|
||||
} OutputType_t;
|
||||
|
||||
typedef struct BufferingNode_s {
|
||||
typedef struct BufferingNode_s
|
||||
{
|
||||
uint32_t dataSize;
|
||||
OutputType_t dataType;
|
||||
struct BufferingNode_s *next;
|
||||
@@ -56,8 +58,8 @@ typedef struct BufferingNode_s {
|
||||
/* ***************************** */
|
||||
/* Makros/Constants */
|
||||
/* ***************************** */
|
||||
#define cERR_LINUX_DVB_BUFFERING_NO_ERROR 0
|
||||
#define cERR_LINUX_DVB_BUFFERING_ERROR -1
|
||||
#define cERR_LINUX_DVB_BUFFERING_NO_ERROR 0
|
||||
#define cERR_LINUX_DVB_BUFFERING_ERROR -1
|
||||
|
||||
//#define SAM_WITH_DEBUG
|
||||
#ifdef SAM_WITH_DEBUG
|
||||
@@ -83,8 +85,9 @@ if (debug_level >= level) printf("[%s:%d:%s] " fmt, __FILE__, __LINE__, __FUNCTI
|
||||
#endif
|
||||
|
||||
/* ***************************** */
|
||||
/* Varaibles */
|
||||
/* Variables */
|
||||
/* ***************************** */
|
||||
|
||||
static pthread_t bufferingThread;
|
||||
static pthread_mutex_t bufferingMtx;
|
||||
static pthread_cond_t bufferingExitCond;
|
||||
@@ -108,46 +111,54 @@ static int g_pfd[2] = {-1, -1};
|
||||
/* ***************************** */
|
||||
/* MISC Functions */
|
||||
/* ***************************** */
|
||||
|
||||
static void WriteWakeUp()
|
||||
{
|
||||
write(g_pfd[1], "x", 1);
|
||||
}
|
||||
|
||||
/* **************************** */
|
||||
/* Worker Thread */
|
||||
/* **************************** */
|
||||
static void LinuxDvbBuffThread(Context_t *context)
|
||||
/* ***************************** */
|
||||
/* Worker Thread */
|
||||
/* ***************************** */
|
||||
|
||||
static void LinuxDvbBuffThread(Context_t *context)
|
||||
{
|
||||
int flags = 0;
|
||||
static BufferingNode_t *nodePtr = NULL;
|
||||
buff_printf(20, "ENTER\n");
|
||||
|
||||
|
||||
if (pipe(g_pfd) == -1)
|
||||
{
|
||||
buff_err("critical error\n");
|
||||
}
|
||||
|
||||
/* Make read and write ends of pipe nonblocking */
|
||||
if ((flags = fcntl(g_pfd[0], F_GETFL)) == -1)
|
||||
{
|
||||
buff_err("critical error\n");
|
||||
}
|
||||
|
||||
/* Make read end nonblocking */
|
||||
flags |= O_NONBLOCK;
|
||||
if (fcntl(g_pfd[0], F_SETFL, flags) == -1)
|
||||
{
|
||||
buff_err("critical error\n");
|
||||
}
|
||||
|
||||
if ((flags = fcntl(g_pfd[1], F_GETFL)) == -1)
|
||||
{
|
||||
buff_err("critical error\n");
|
||||
}
|
||||
|
||||
/* Make write end nonblocking */
|
||||
flags |= O_NONBLOCK;
|
||||
if (fcntl(g_pfd[1], F_SETFL, flags) == -1)
|
||||
{
|
||||
buff_err("critical error\n");
|
||||
}
|
||||
|
||||
PlaybackDieNowRegisterCallback(WriteWakeUp);
|
||||
|
||||
while (0 == PlaybackDieNow(0))
|
||||
{
|
||||
pthread_mutex_lock(&bufferingMtx);
|
||||
@@ -158,11 +169,11 @@ static void LinuxDvbBuffThread(Context_t *context)
|
||||
/* signal that we free some space in queue */
|
||||
pthread_cond_signal(&bufferingDataConsumedCond);
|
||||
}
|
||||
|
||||
|
||||
if (!bufferingQueueHead)
|
||||
{
|
||||
assert(bufferingQueueTail == NULL);
|
||||
|
||||
|
||||
/* Queue is empty we need to wait for data to be added */
|
||||
pthread_cond_wait(&bufferingdDataAddedCond, &bufferingMtx);
|
||||
pthread_mutex_unlock(&bufferingMtx);
|
||||
@@ -176,7 +187,7 @@ static void LinuxDvbBuffThread(Context_t *context)
|
||||
{
|
||||
bufferingQueueTail = NULL;
|
||||
}
|
||||
|
||||
|
||||
if (bufferingDataSize >= (nodePtr->dataSize + sizeof(BufferingNode_t)))
|
||||
{
|
||||
bufferingDataSize -= (nodePtr->dataSize + sizeof(BufferingNode_t));
|
||||
@@ -188,12 +199,12 @@ static void LinuxDvbBuffThread(Context_t *context)
|
||||
}
|
||||
}
|
||||
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
|
||||
*/
|
||||
* this have some disadvantage because we can
|
||||
* write some portion of data after LinuxDvbBuffFlush,
|
||||
* for example after seek, this will be fixed later
|
||||
*/
|
||||
if (nodePtr && !context->playback->isSeeking)
|
||||
{
|
||||
/* Write data to valid output */
|
||||
@@ -205,11 +216,11 @@ static void LinuxDvbBuffThread(Context_t *context)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pthread_mutex_lock(&bufferingMtx);
|
||||
pthread_cond_signal(&bufferingExitCond);
|
||||
pthread_mutex_unlock(&bufferingMtx);
|
||||
|
||||
|
||||
buff_printf(20, "EXIT\n");
|
||||
hasBufferingThreadStarted = false;
|
||||
close(g_pfd[0]);
|
||||
@@ -228,36 +239,36 @@ int32_t LinuxDvbBuffOpen(Context_t *context, char *type, int outfd)
|
||||
{
|
||||
int32_t error = 0;
|
||||
int32_t ret = cERR_LINUX_DVB_BUFFERING_NO_ERROR;
|
||||
|
||||
|
||||
buff_printf(10, "\n");
|
||||
|
||||
if (!hasBufferingThreadStarted)
|
||||
if (!hasBufferingThreadStarted)
|
||||
{
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||
|
||||
if((error = pthread_create(&bufferingThread, &attr, (void *)&LinuxDvbBuffThread, context)) != 0)
|
||||
if ((error = pthread_create(&bufferingThread, &attr, (void *)&LinuxDvbBuffThread, context)) != 0)
|
||||
{
|
||||
buff_printf(10, "Creating thread, error:%d:%s\n", error, strerror(error));
|
||||
|
||||
hasBufferingThreadStarted = false;
|
||||
ret = cERR_LINUX_DVB_BUFFERING_ERROR;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
buff_printf(10, "Created thread\n");
|
||||
hasBufferingThreadStarted = true;
|
||||
|
||||
/* init synchronization prymitives */
|
||||
pthread_mutex_init(&bufferingMtx, NULL);
|
||||
|
||||
|
||||
pthread_cond_init(&bufferingExitCond, NULL);
|
||||
pthread_cond_init(&bufferingDataConsumedCond, NULL);
|
||||
pthread_cond_init(&bufferingdDataAddedCond, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!ret)
|
||||
{
|
||||
if (!strcmp("video", type) && -1 == videofd)
|
||||
@@ -281,21 +292,22 @@ int32_t LinuxDvbBuffOpen(Context_t *context, char *type, int outfd)
|
||||
int32_t LinuxDvbBuffClose(Context_t *context __attribute__((unused)))
|
||||
{
|
||||
int32_t ret = 0;
|
||||
|
||||
|
||||
buff_printf(10, "\n");
|
||||
videofd = -1;
|
||||
audiofd = -1;
|
||||
|
||||
if (hasBufferingThreadStarted)
|
||||
|
||||
if (hasBufferingThreadStarted)
|
||||
{
|
||||
struct timespec max_wait = {0, 0};
|
||||
|
||||
/* WakeUp if we are waiting in the write */
|
||||
|
||||
/* WakeUp if we are waiting in the write */
|
||||
WriteWakeUp();
|
||||
|
||||
|
||||
pthread_mutex_lock(&bufferingMtx);
|
||||
/* wake up if thread is waiting for data */
|
||||
/* wake up if thread is waiting for data */
|
||||
pthread_cond_signal(&bufferingdDataAddedCond);
|
||||
|
||||
/* wait for thread end */
|
||||
clock_gettime(CLOCK_REALTIME, &max_wait);
|
||||
max_wait.tv_sec += 1;
|
||||
@@ -305,9 +317,9 @@ int32_t LinuxDvbBuffClose(Context_t *context __attribute__((unused)))
|
||||
if (!hasBufferingThreadStarted)
|
||||
{
|
||||
/* destroy synchronization prymitives?
|
||||
* for a moment, we'll exit linux process,
|
||||
* so the system will do this for us
|
||||
*/
|
||||
* for a moment, we'll exit linux process,
|
||||
* so the system will do this for us
|
||||
*/
|
||||
/*
|
||||
pthread_mutex_destroy(&bufferingMtx);
|
||||
pthread_cond_destroy(&bufferingDataConsumedCond);
|
||||
@@ -315,7 +327,7 @@ int32_t LinuxDvbBuffClose(Context_t *context __attribute__((unused)))
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ret = hasBufferingThreadStarted ? cERR_LINUX_DVB_BUFFERING_ERROR : cERR_LINUX_DVB_BUFFERING_NO_ERROR;
|
||||
|
||||
buff_printf(10, "exiting with value %d\n", ret);
|
||||
@@ -326,46 +338,50 @@ int32_t LinuxDvbBuffFlush(Context_t *context __attribute__((unused)))
|
||||
{
|
||||
static BufferingNode_t *nodePtr = NULL;
|
||||
buff_printf(40, "ENTER bufferingQueueHead[%p]\n", bufferingQueueHead);
|
||||
|
||||
|
||||
/* signal if we are waiting for write to DVB decoders */
|
||||
WriteWakeUp();
|
||||
|
||||
pthread_mutex_lock(&bufferingMtx);
|
||||
while (bufferingQueueHead)
|
||||
{
|
||||
nodePtr = bufferingQueueHead;
|
||||
bufferingQueueHead = nodePtr->next;
|
||||
bufferingDataSize -= (nodePtr->dataSize + sizeof(BufferingNode_t));
|
||||
free(nodePtr);
|
||||
nodePtr = bufferingQueueHead;
|
||||
bufferingQueueHead = nodePtr->next;
|
||||
bufferingDataSize -= (nodePtr->dataSize + sizeof(BufferingNode_t));
|
||||
free(nodePtr);
|
||||
}
|
||||
bufferingQueueHead = NULL;
|
||||
bufferingQueueTail = NULL;
|
||||
buff_printf(40, "bufferingDataSize [%u]\n", bufferingDataSize);
|
||||
assert(bufferingDataSize == 0);
|
||||
bufferingDataSize = 0;
|
||||
|
||||
|
||||
/* signal that queue is empty */
|
||||
pthread_cond_signal(&bufferingDataConsumedCond);
|
||||
pthread_mutex_unlock(&bufferingMtx);
|
||||
buff_printf(40, "EXIT\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t LinuxDvbBuffResume(Context_t *context __attribute__((unused)))
|
||||
{
|
||||
/* signal if we are waiting for write to DVB decoders */
|
||||
/* signal if we are waiting for write to DVB decoders
|
||||
*
|
||||
*/
|
||||
WriteWakeUp();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssize_t BufferingWriteV(int fd, const struct iovec *iov, size_t ic)
|
||||
ssize_t BufferingWriteV(int fd, const struct iovec *iov, size_t ic)
|
||||
{
|
||||
OutputType_t dataType = OUTPUT_UNK;
|
||||
BufferingNode_t *nodePtr = NULL;
|
||||
uint8_t *dataPtr = NULL;
|
||||
uint32_t chunkSize = 0;
|
||||
uint32_t i = 0;
|
||||
|
||||
|
||||
buff_printf(60, "ENTER\n");
|
||||
if (fd == videofd)
|
||||
{
|
||||
@@ -382,13 +398,13 @@ ssize_t BufferingWriteV(int fd, const struct iovec *iov, size_t ic)
|
||||
buff_err("Unknown output type\n");
|
||||
return cERR_LINUX_DVB_BUFFERING_ERROR;
|
||||
}
|
||||
|
||||
for (i=0; i<ic; ++i)
|
||||
|
||||
for (i = 0; i < ic; ++i)
|
||||
{
|
||||
chunkSize += iov[i].iov_len;
|
||||
}
|
||||
chunkSize += sizeof(BufferingNode_t);
|
||||
|
||||
|
||||
/* Allocate memory for queue node + data */
|
||||
nodePtr = malloc(chunkSize);
|
||||
if (!nodePtr)
|
||||
@@ -396,10 +412,10 @@ ssize_t BufferingWriteV(int fd, const struct iovec *iov, size_t ic)
|
||||
buff_err("OUT OF MEM\n");
|
||||
return cERR_LINUX_DVB_BUFFERING_ERROR;
|
||||
}
|
||||
|
||||
|
||||
/* Copy data to new buffer */
|
||||
dataPtr = (uint8_t *)nodePtr + sizeof(BufferingNode_t);
|
||||
for (i=0; i<ic; ++i)
|
||||
for (i = 0; i < ic; ++i)
|
||||
{
|
||||
memcpy(dataPtr, iov[i].iov_base, iov[i].iov_len);
|
||||
dataPtr += iov[i].iov_len;
|
||||
@@ -426,13 +442,13 @@ ssize_t BufferingWriteV(int fd, const struct iovec *iov, size_t ic)
|
||||
bufferingQueueTail->next = nodePtr;
|
||||
bufferingQueueTail = nodePtr;
|
||||
}
|
||||
|
||||
|
||||
bufferingDataSize += chunkSize;
|
||||
chunkSize -= sizeof(BufferingNode_t);
|
||||
nodePtr->dataSize = chunkSize;
|
||||
nodePtr->dataType = dataType;
|
||||
nodePtr->next = NULL;
|
||||
|
||||
|
||||
/* signal that we added some data to queue */
|
||||
pthread_cond_signal(&bufferingdDataAddedCond);
|
||||
break;
|
||||
|
Reference in New Issue
Block a user