49 #define PES_COLL_TASK_STACK_SIZE 1024 * 4 50 #define PES_COLLECTION_PRIORITY STB_TPID_CBUFF_PRIORITY - 1 53 #define PES_HDR_DATA_LEN_BYTE 0x08 55 typedef enum e_pes_state
57 LOOKING_PREFIX_BYTE_ONE,
58 LOOKING_PREFIX_BYTE_TWO,
59 LOOKING_PREFIX_CODE_THREE,
62 LOOKING_LENGTH_BYTE_ONE,
63 LOOKING_LENGTH_BYTE_TWO,
68 #define FIXED_BUFFER_LENGTH 8192L 72 #ifdef STB_PES_COLLECTION_PRINT_REQUIRED 73 #define STB_PRINT_PES_ERROR 74 #ifdef STB_PES_COLLECTION_CHANNEL_DEBUG_REQUIRED 75 #define STB_PES_COLLECTION_PRINT(x) DEBUG_PRINTX_CONDITIONAL(DEBUG_STB_OSD) x 77 #define STB_PES_COLLECTION_PRINT(x) STB_SPDebugWrite x 80 #define STB_PES_COLLECTION_PRINT(x) 88 U8BIT lowest_data_identifier;
89 U8BIT highest_data_identifier;
90 void (*callback_function)(U32BIT, U8BIT,
void *, U32BIT);
98 static BOOLEAN initialised;
100 static void *pes_collection_task;
102 static U8BIT pes_collection_path = INVALID_RES_ID;
103 static BOOLEAN reset_pes_collection_task;
106 static void *pes_request_semaphore;
108 static U32BIT next_avaialable_handle;
110 static U8BIT *pes_fixed_buffer;
111 static BOOLEAN task_running;
116 static void PesCollectionTask(
void *unused);
132 static void PesCollectionTask(
void *unused)
134 U8BIT data_identifier;
135 U32BIT m_buf_size, pes_len, num_bytes_obtained;
136 U32BIT nbytes, available_bytes, remaining_bytes, i;
142 #ifdef STB_PRINT_PES_ERROR 146 FUNCTION_START(PesCollectionTask);
148 USE_UNWANTED_PARAM(unused);
153 state = LOOKING_PREFIX_BYTE_ONE;
154 num_bytes_obtained = 0;
155 #ifdef STB_PRINT_PES_ERROR 158 demux = INVALID_RES_ID;
162 if (reset_pes_collection_task)
164 reset_pes_collection_task = FALSE;
165 state = LOOKING_PREFIX_BYTE_ONE;
167 if (pes_collection_path != INVALID_RES_ID)
173 demux = INVALID_RES_ID;
177 if (demux != INVALID_RES_ID)
180 STB_PES_COLLECTION_PRINT((
"DMX PES returns %d", nbytes));
200 case LOOKING_PREFIX_BYTE_ONE:
202 if (buffer[i] == 0x00)
204 state = LOOKING_PREFIX_BYTE_TWO;
205 num_bytes_obtained = 0;
207 #ifdef STB_PRINT_PES_ERROR 215 #ifdef STB_PES_COLLECTION_PRINT_REQUIRED 218 STB_PES_COLLECTION_PRINT((
"PES %d: %u=0x%02x", __LINE__, i, buffer[i]));
224 case LOOKING_PREFIX_BYTE_TWO:
226 if (buffer[i] == 0x00)
228 state = LOOKING_PREFIX_CODE_THREE;
232 state = LOOKING_PREFIX_BYTE_ONE;
233 STB_PES_COLLECTION_PRINT((
"PES %d: %u=0x%02x\n", __LINE__, i, buffer[i]));
238 case LOOKING_PREFIX_CODE_THREE:
240 if (buffer[i] == 0x01)
242 state = LOOKING_STREAM_ID;
246 if (!(buffer[i] == 0x00))
248 state = LOOKING_PREFIX_BYTE_ONE;
249 STB_PES_COLLECTION_PRINT((
"PES %d: %u=0x%02x", __LINE__, i, buffer[i]));
255 case LOOKING_STREAM_ID:
257 if (buffer[i] == 0xbd)
259 state = LOOKING_LENGTH_BYTE_ONE;
263 state = LOOKING_PREFIX_BYTE_ONE;
264 STB_PES_COLLECTION_PRINT((
"PES %d: %u=0x%02x", __LINE__, i, buffer[i]));
269 case LOOKING_LENGTH_BYTE_ONE:
272 m_buf_size = (buffer[i] << 8) + 0xff + 6;
274 if (malloc_buf != NULL)
276 if (malloc_buf != pes_fixed_buffer)
283 if ((m_buf_size <= FIXED_BUFFER_LENGTH) && (pes_fixed_buffer != NULL))
285 malloc_buf = pes_fixed_buffer;
292 if (malloc_buf == NULL)
294 state = LOOKING_PREFIX_BYTE_ONE;
298 malloc_buf[0] = 0x00;
299 malloc_buf[1] = 0x00;
300 malloc_buf[2] = 0x01;
301 malloc_buf[3] = 0xbd;
302 malloc_buf[4] = buffer[i];
303 pes_len = (buffer[i] << 8);
304 state = LOOKING_LENGTH_BYTE_TWO;
309 case LOOKING_LENGTH_BYTE_TWO:
311 malloc_buf[5] = buffer[i];
312 pes_len += buffer[i];
314 state = LOOKING_FOR_END;
317 num_bytes_obtained = 6;
321 case LOOKING_FOR_END:
325 remaining_bytes = (pes_len + 6) - num_bytes_obtained;
327 if (remaining_bytes <= (nbytes - i))
330 #ifdef STB_PRINT_PES_ERROR 333 memcpy((
void *)&malloc_buf[num_bytes_obtained], (
void *)&buffer[i], (
size_t)remaining_bytes);
335 data_identifier = malloc_buf[PES_HDR_DATA_LEN_BYTE + malloc_buf[PES_HDR_DATA_LEN_BYTE] + 1];
337 if (!reset_pes_collection_task)
339 STB_PES_COLLECTION_PRINT((
"PES size %d", pes_len + 6));
344 pes_request_ptr = pes_request_link_list;
346 while (pes_request_ptr != NULL)
348 if ((data_identifier >= pes_request_ptr->lowest_data_identifier) &&
349 (data_identifier <= pes_request_ptr->highest_data_identifier))
351 (*pes_request_ptr->callback_function)(pes_request_ptr->handle,
354 num_bytes_obtained + remaining_bytes);
357 pes_request_ptr = pes_request_ptr->next_ptr;
362 if (malloc_buf != pes_fixed_buffer)
369 state = LOOKING_PREFIX_BYTE_ONE;
374 i += remaining_bytes - 1;
379 available_bytes = nbytes - i;
380 memcpy((
void *)&malloc_buf[num_bytes_obtained], (
void *)&buffer[i], (
size_t)available_bytes);
381 num_bytes_obtained += available_bytes;
382 i += available_bytes;
389 state = LOOKING_PREFIX_BYTE_ONE;
390 STB_PES_COLLECTION_PRINT((
"PES %d: %u=0x%02x", __LINE__, i, buffer[i]));
398 STB_PES_COLLECTION_PRINT((
"PesCollectionTask Terminated"));
400 FUNCTION_FINISH(PesCollectionTask);
422 pes_fixed_buffer = (U8BIT *)
STB_GetMemory(FIXED_BUFFER_LENGTH);
426 pes_collection_task =
STB_OSCreateTask(PesCollectionTask, NULL, PES_COLL_TASK_STACK_SIZE,
427 PES_COLLECTION_PRIORITY, (U8BIT *)
"PesColl");
429 reset_pes_collection_task = FALSE;
451 reset_pes_collection_task = TRUE;
473 if ((pes_collection_path != INVALID_RES_ID) && (pes_collection_path != path))
482 reset_pes_collection_task = TRUE;
487 pes_collection_path = INVALID_RES_ID;
491 pes_collection_path = path;
538 U8BIT lowest_data_identifier, U8BIT highest_data_identifier)
547 if (initialised == TRUE)
550 if ((callback_function) &&
551 (lowest_data_identifier <= highest_data_identifier))
555 if (pes_request_ptr != NULL)
558 next_avaialable_handle++;
559 pes_request_ptr->handle = next_avaialable_handle;
562 pes_request_ptr->callback_function = callback_function;
563 pes_request_ptr->lowest_data_identifier = lowest_data_identifier;
564 pes_request_ptr->highest_data_identifier = highest_data_identifier;
570 pes_request_ptr->next_ptr = pes_request_link_list;
571 pes_request_link_list = pes_request_ptr;
574 retval = pes_request_ptr->handle;
609 if (initialised == TRUE)
615 pes_request_ptr = pes_request_link_list;
616 prev_pes_request_ptr = NULL;
619 while (pes_request_ptr != NULL)
621 if (handle == pes_request_ptr->handle)
624 if (prev_pes_request_ptr == NULL)
627 pes_request_link_list = pes_request_link_list->next_ptr;
632 prev_pes_request_ptr->next_ptr = pes_request_ptr->next_ptr;
643 prev_pes_request_ptr = pes_request_ptr;
644 pes_request_ptr = pes_request_ptr->next_ptr;
void * STB_GetMemory(U32BIT bytes)
Attempts to allocate memory from the heap.
void STB_PesCollectionTaskInitialise(void)
Initialises the PES collection task.
void STB_FlushPesCollectionTask(void)
Flushes the PES collection task.
Header file - macros and function prototypes for public use.
void * STB_OSCreateSemaphore(void)
Create a Semaphore.
void STB_ChangePesCollectionPID(U8BIT path, U16BIT text_pid)
Changes the PID that the DMX is using to gather data on.
void STB_OSSemaphoreSignal(void *semaphore)
Signal a Semaphore to Release it by decrementing its counter.
void STB_OSSemaphoreWait(void *semaphore)
Wait on Semaphore Indefinity or Until Released.
U32BIT STB_RegisterPesCollectionCallback(void(*callback_function)(U32BIT, U8BIT, void *, U32BIT), U8BIT lowest_data_identifier, U8BIT highest_data_identifier)
Used to register a callback function that will receive specific PES data packets. In theory...
void STB_FreeMemory(void *addr)
Releases previously allocated heap memory.
void STB_SPDebugWrite(const char *format,...)
Write debug string to serial/debug port. <CR><LF> characters will be automatically added to the end o...
Debug functions header file.
void STB_DMXReadTextPES(U8BIT path, U8BIT **buffer, U32BIT *num_bytes)
Reads Teletext PES data from the demux.
Header file - Function prototypes for operating system.
System Wide Global Technical Data Type Definitions.
void STB_UnregisterPesCollectionCallback(U32BIT handle)
Used to un-register a callback function that will receive specific PES data packets.
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...
Header file - Function prototypes for heap memory.
void STB_DPSetTextPID(U8BIT path, U16BIT pid)
Writes teletext PID value into decode path store.
void STB_OSTaskDelay(U16BIT timeout)
Delay Task for Specifed Time Period.
Header file - Function prototypes for Demux control.
Header file - Function prototypes for PES collection task.
U8BIT STB_DPGetPathDemux(U8BIT path)
Returns the demux path ID acquired by the given decode path.
U16BIT STB_DPGetTextPID(U8BIT path)
Reads the teletext PID value from decode path store.