DVBCore  20.3.0
DVBCore Documentation
stbvbi.c
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright © 2014 The DTVKit Open Software Foundation Ltd (www.dtvkit.org)
3  * Copyright © 2004 Ocean Blue Software Ltd
4  *
5  * This file is part of a DTVKit Software Component
6  * You are permitted to copy, modify or distribute this file subject to the terms
7  * of the DTVKit 1.0 Licence which can be found in licence.txt or at www.dtvkit.org
8  *
9  * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
10  * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
11  * OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
12  *
13  * If you or your organisation is not a member of DTVKit then you have access
14  * to this source code outside of the terms of the licence agreement
15  * and you are expected to delete this and any associated files immediately.
16  * Further information on DTVKit, membership and terms can be found at www.dtvkit.org
17  *******************************************************************************/
27 //---includes for this file----------------------------------------------------
28 // compiler library header files
29 
30 // third party header files
31 #include <string.h>
32 
33 // Ocean Blue Software header files
34 #include <techtype.h>
35 #include <dbgfuncs.h>
36 
37 #include "stbhwc.h"
38 #include "stbpes.h"
39 
40 
41 //---constant definitions for this file----------------------------------------
42 #define PES_HDR_DATA_LEN_BYTE 0x08
43 
44 //---local typedef structs for this file---------------------------------------
45 
46 //---local (static) variable declarations for this file------------------------
47 // (internal variables declared static to make them local)
48 static U32BIT handle;
49 static BOOLEAN initialised;
50 
51 //---local function prototypes for this file-----------------------------------
52 // (internal functions declared static to make them local)
53 static void VBIPesCallback(U32BIT handle, U8BIT data_identifier, void *buffer_ptr, U32BIT buffer_size);
54 
55 
56 //void STTTX_vbi_init(STTTX_InitParams_t* ttx_init_params);
57 //void STTTX_vbi_insert(U8* pes_data_field, U32 num_bytes);
58 
59 //---local function definitions------------------------------------------------
60 
78 static void VBIPesCallback(U32BIT handle, U8BIT data_identifier, void *buffer_ptr, U32BIT buffer_size)
79 {
80  U16BIT pes_length;
81  U16BIT processed_bytes;
82  U8BIT pes_hdr_data_len;
83  U8BIT segment_data;
84 
85  U8BIT *pes_ptr;
86 
87  FUNCTION_START(VBIPesCallback);
88 
89  USE_UNWANTED_PARAM(handle);
90  USE_UNWANTED_PARAM(data_identifier);
91  USE_UNWANTED_PARAM(buffer_size);
92 
93  pes_ptr = buffer_ptr;
94 
95  if ((pes_ptr[0] == 0x00) && (pes_ptr[1] == 0x00) && (pes_ptr[2] == 0x01))
96  {
97  // Check stream_id
98  if (pes_ptr[3] == 0xbd)
99  {
100  // private_stream_1
101  // This value is from this point forward, the size of the entire PES packet
102  // is (pes_length + 6); as the bytes before and the length bytes are not included.
103  pes_length = (pes_ptr[4] << 8) + pes_ptr[5] + 6;
104 
105  // PES_header_data_length - An 8bit field specifying the total number of bytes
106  // occupied by the optional fields and any stuffing bytes in this PES packet header.
107  pes_hdr_data_len = pes_ptr[PES_HDR_DATA_LEN_BYTE];
108 
109  // This should place data ptr at the beginning of the PES_packet_data_byte area
110  segment_data = PES_HDR_DATA_LEN_BYTE + pes_hdr_data_len + 1;
111 
112  processed_bytes = segment_data;
113 
114  if ((pes_ptr[processed_bytes] >= 0x10) && (pes_ptr[processed_bytes] <= 0x1f))
115  {
116  STB_HWVBIInsert(&pes_ptr[processed_bytes], (pes_length - pes_hdr_data_len));
117  }
118  }
119  }
120  FUNCTION_FINISH(VBIPesCallback);
121 }
122 
123 //---global function definitions-----------------------------------------------
124 
138 {
139  FUNCTION_START(STB_VBIInitialise);
140 
141  if (!initialised)
142  {
143  STB_HWInitialiseVBI();
144 
146 
147  handle = STB_RegisterPesCollectionCallback(VBIPesCallback, 0x10, 0x1f);
148 
149  initialised = TRUE;
150  }
151 
152  FUNCTION_FINISH(STB_VBIInitialise);
153 }
154 
167 {
168  FUNCTION_START(STB_VBIRemoveCallbackFunction);
169 
171 
172  initialised = FALSE;
173 
174  FUNCTION_FINISH(STB_VBIRemoveCallbackFunction);
175 }
176 
177 //*****************************************************************************
178 // End of file
179 //*****************************************************************************
180 
Function prototypes for HW control.
void STB_VBIRemoveCallbackFunction(void)
Removes the VBI callback function from the PES collection task.
Definition: stbvbi.c:166
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...
Definition: stbpes.c:537
Debug functions header file.
System Wide Global Technical Data Type Definitions.
void STB_VBIInitialise(void)
Initialises VBI insertion, and registers the callback function with PES collection task...
Definition: stbvbi.c:137
void STB_PesCollectionTaskInitialise(void)
Initialises the PES collection task.
Definition: stbpes.c:416
void STB_UnregisterPesCollectionCallback(U32BIT handle)
Used to un-register a callback function that will receive specific PES data packets.
Definition: stbpes.c:602
Header file - Function prototypes for PES collection task.