44 #define LOOK_AHEAD_DIFF 1000 53 #define LOOK_AHEAD_THRESHOLD 2500 55 #define PDBG(x) TRACE(TICS, x) 71 static void TaskMain(
void *task_arg);
75 static void *taskSemaphore = NULL;
76 static void *taskHandle;
97 if (taskSemaphore == NULL)
106 if (taskHandle == NULL)
124 if (taskSemaphore != NULL && producerCanSignal)
126 producerCanSignal =
FALSE;
138 underflowCallback = callback;
162 semaphore = taskSemaphore;
163 taskSemaphore = NULL;
178 static void TaskMain(
void *task_arg)
183 U32BIT refItemTime, lastItemTime;
184 U32BIT clockTime, refClockTime;
185 U32BIT relativeClockTime, relativeItemTime;
193 relativeItemTime = 0;
199 DBG((
"Entering main loop"));
202 PDBG((
"Waiting for semaphore"));
203 producerCanSignal =
TRUE;
205 producerCanSignal =
FALSE;
229 refClockTime = lastLookahead + clockTime - relativeItemTime;
230 PDBG((
"Recalculating refClockTime: %d + %d - %d = %d",
231 lastLookahead, clockTime, relativeItemTime, refClockTime));
232 DBG((
"taskState = %d", taskState));
239 PDBG((
"Streaming stopped RID=%d",lastRequestId));
240 if (underflowCallback != NULL)
243 if (lastLookahead > 0)
246 clockTime += lastLookahead;
247 if (clockTime > refClockTime)
249 clockTime -= refClockTime;
260 underflowCallback(lastRequestId,clockTime);
266 PDBG((
"Invalid item, streaming stopped"));
273 if (refClockTime == 0 && clockTime != 0)
276 refClockTime = clockTime;
280 if (refItemTime == 0)
286 prevItemTime = lastItemTime;
290 if ((clockTime < refClockTime) ||
291 (lastItemTime < refItemTime) ||
296 PDBG((
"Resetting PCR monitor - invalid values (%u,%u) (%u,%u) %d prev=%u",
297 clockTime,refClockTime, lastItemTime,refItemTime, lastLookahead, prevItemTime ));
302 relativeItemTime = 0;
308 PDBG((
"Resetting PCR monitor RID=%d->%d DID=%d->%d",lastRequestId,item->
requestId,lastDownloadId,item->
downloadId));
314 relativeItemTime = 0;
319 if (refClockTime == 0 || refItemTime == 0)
321 HandleQueueItem(item);
326 assert(clockTime >= refClockTime);
327 assert(lastItemTime >= refItemTime);
329 relativeClockTime = clockTime - refClockTime;
330 relativeItemTime = lastItemTime - refItemTime;
331 lastLookahead = relativeItemTime - relativeClockTime;
333 DBG((
"curr [%d] - ref [%d] = %d, " 334 "item [%d] - ref [%d] = %d, lla = %d",
335 clockTime, refClockTime, clockTime - refClockTime,
336 lastItemTime, refItemTime, lastItemTime - refItemTime, lastLookahead));
339 DBG((
"Flow control - pausing"));
345 HandleQueueItem(item);
352 DBG((
"TaskMain: Left main loop"));
377 DBG((
"TaskMain: Sending %d/%d bytes (offset %d, last=%s)",
378 len, item->
len, item->
offset, last ?
"TRUE" :
"FALSE"));
382 if (processed == len)
U32BIT STB_OSGetClockMilliseconds(void)
Get Current Computer Clock Time.
void STB_OSSemaphoreWait(void *semaphore)
Wait on Semaphore Indefinity or Until Released.
U32BIT DVB_MhegICStreamHandleData(U8BIT *data, U32BIT len, BOOLEAN last)
Handle transport stream data. The data is part of a single-program transport stream, containing audio, video and/or subtitles (in one or more languages). The video is H.264 SD video and the audio is HE-AAC audio. The stream contains PAT and PMT (other SI data can be ignored). This function can block until the data has been processed / buffered. It may also return when part of the block has been processed. This would cause a subsequent call with the rest of the block. When the last block is presented (last=TRUE), the function should indicate that the block has been completely processed only when this is a true reflection of the presentation status.
void STB_OSTaskDelay(U16BIT timeout)
Delay Task for Specifed Time Period.
Common header internal to IC streamer.
E_MhegErr MHEG5StreamerStartTask(U32BIT stack, U8BIT priority)
Start streamer task. The task passes stream data to the external application and generates stream and...
#define LOOK_AHEAD_THRESHOLD
void MHEG5QueueUpdateItem(MHEG5QueueItem *item, U32BIT processed)
Update the number of bytes processed in a queue item. The same item will be returned by the next call...
BOOLEAN MHEG5QueueIsValidItem(MHEG5QueueItem *item)
Tell whether the item returned by MHEG5QueueGetHeadItem is valid. If the item is invalid, then streaming is disabled.
void MHEG5StreamerRegisterUnderflowCallback(void(*callback)(U32BIT requestId, U32BIT playoutTime))
Register notification callback for underflow events. If a callback is already registered for the even...
IC Streamer queue manager.
void * STB_OSCreateSemaphore(void)
Create a Binary Semaphore. That is maximum value of 1. The initial value should be 1...
void MHEG5StreamerSendSignalToTask(void)
Send signal to streamer task to wake it up (if it's asleep)
MHEG5QueueItem * MHEG5QueueGetHeadItem(void)
Return the item at the head of the queue (the next item to consume). The function returns an "invalid...
Mheg5 logging and debug printing.
void MHEG5QueueReleaseItem(MHEG5QueueItem *item)
Release an item from the queue. If the item is no longer in the queue (because the queue has been cle...
Interaction Channel Streaming functions required by MHEG5 engine References: [1] UK1 Profile - Digita...
void * STB_OSCreateTask(void(*function)(void *), void *param, U32BIT stack, U8BIT priority, U8BIT *name)
Create a New Task to the calling process. Upon success, the created task runs on its own stack...
void MHEG5StreamerStopTask(void)
Stop streamer task. This function blocks until the task is stopped.
void STB_OSDestroyTask(void *task)
Delete Task must be called upon termination of each task as it frees all OS specific resources alloca...
void STB_OSDeleteSemaphore(void *semaphore)
Delete a Semaphore.
void STB_OSSemaphoreSignal(void *semaphore)
Signal a Semaphore to Release it by decrementing its counter.
Header file - Function prototypes for operating system.