DSMCC  17.9.0
 All Data Structures Files Functions Typedefs
sfm_main.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  *******************************************************************************/
24 /*---includes for this file--------------------------------------------------*/
25 #include <string.h>
26 
27 #include "sfm_main.h"
28 #include "sfm_filter.h"
29 #include "sfm_cache.h"
30 
31 /*---- Constant definitions for this file-------------------------------------*/
32 
33 #define KILOBYTES(n) (n << 10)
34 #define MEGABYTES(n) (n << 20)
35 
36 #define INITERR(x, ...) if (pSetup->errPrintf) \
37  pSetup->errPrintf( "ERROR: " x "\n", ##__VA_ARGS__);
38 
39 #define INITWRN(x, ...) if (pSetup->errPrintf) \
40  pSetup->errPrintf( "Warning: " x "\n", ##__VA_ARGS__);
41 
42 /*---- Local typedef structs for this file------------------------------------*/
43 
44 
45 /*---- Local (static) variable declarations for this file---------------------*/
46 /* (internal variables declared static to make them local) */
47 
48 /*---- LOCAL function definitions for this file ------------------------------*/
49 /* (internal functions declared static to make them local) */
50 
51 
52 
53 /*---- GLOBAL function definitions for this file -----------------------------*/
54 
55 
56 
63 {
64  S_SfmInstance *sfm = NULL;
65  S_SfmSetup *sptr;
66 
67  FUNCTION_START(SFM_CreateInstance)
68  if (pSetup != NULL)
69  {
70  if (pSetup->memAlloc == NULL)
71  {
72  INITERR("memAlloc NULL")
73  }
74  else if (pSetup->memFree == NULL)
75  {
76  INITERR("memFree NULL")
77  }
78  else if (pSetup->mutexLock == NULL)
79  {
80  INITERR("mutexLock NULL")
81  }
82  else if (pSetup->mutexUnlock == NULL)
83  {
84  INITERR("mutexUnlock NULL")
85  }
86  else if (pSetup->hwFilterCallback == NULL)
87  {
88  INITERR("hwFilterCallback NULL")
89  }
90  else if (pSetup->sfmMutex == NULL)
91  {
92  INITERR("sfmMutex NULL")
93  }
94  else
95  {
96  if (pSetup->maxPidFilters < 4)
97  {
98  INITWRN("maxPidFilters set to 4")
99  pSetup->maxPidFilters = 4;
100  }
101  else if (pSetup->maxPidFilters > 32)
102  {
103  INITWRN("maxPidFilters set to 32")
104  pSetup->maxPidFilters = 32;
105  }
106  if (pSetup->maxSecFiltersPerPid == 0)
107  {
108  INITWRN("maxSecFiltersPerPid set to 1")
109  pSetup->maxSecFiltersPerPid = 1;
110  }
111  if (pSetup->maxAvailableSectionFilters == 0 ||
112  pSetup->maxAvailableSectionFilters > NUM_SECTION_FILTERS_MAXIMUM)
113  {
114  INITWRN("maxAvailableSectionFilters set to %d", NUM_SECTION_FILTERS_MAXIMUM)
115  pSetup->maxAvailableSectionFilters = NUM_SECTION_FILTERS_MAXIMUM;
116  }
117  else if (pSetup->maxAvailableSectionFilters < NUM_SECTION_FILTERS_MINIMUM)
118  {
119  INITWRN("maxAvailableSectionFilters set to %d", NUM_SECTION_FILTERS_MINIMUM)
120  pSetup->maxAvailableSectionFilters = NUM_SECTION_FILTERS_MINIMUM;
121  }
122  sfm = pSetup->memAlloc( sizeof(S_SfmInstance));
123  if (sfm == NULL)
124  {
125  INITERR("memory fail")
126  }
127  else
128  {
129  sptr = &sfm->setup;
130  memcpy( sptr, pSetup, sizeof(S_SfmSetup));
131  sptr++;
132  memset(sptr, 0, sizeof(S_SfmInstance) - sizeof(S_SfmSetup));
133  if (!SFMFilterCreateResources( sfm ))
134  {
135  INITERR("PID resources fail")
136  sfm->setup.memFree( sfm );
137  sfm = NULL;
138  }
139  sfm->cache = SFMCacheCreate( sfm );
140  if (sfm->cache == NULL)
141  {
142  INITWRN("Cache initialisation failed - zero cache")
143  }
144  SFMFilterInitCaching( sfm );
145  }
146  }
147  }
148  FUNCTION_FINISH(SFM_CreateInstance)
149  return sfm;
150 }
151 
161 void SFM_DestroyInstance( H_SfmInstance sfm, void **pSfmMtx,
162  void **pCchMtx, void **pBufMtx )
163 {
164  FUNCTION_START(SFM_DestroyInstance)
165 
166  if (pSfmMtx != NULL)
167  {
168  *pSfmMtx = sfm->setup.sfmMutex;
169  }
170  if (pCchMtx != NULL)
171  {
172  *pCchMtx = sfm->setup.cacheMutex;
173  }
174 
175  SFMCacheDestroy( sfm, pBufMtx );
176 
178 
179  sfm->setup.memFree( sfm );
180 
181  FUNCTION_FINISH(SFM_DestroyInstance)
182 }
183 
192 void SFM_SetDebugConfig( H_SfmInstance sfm, F_Printf errPrintf,
193  F_Printf dbgPrintf, U32BIT dbgState )
194 {
195  FUNCTION_START(SFM_SetDebugConfig)
196  ASSERT(sfm != NULL)
197  sfm->setup.errPrintf = errPrintf;
198  sfm->setup.dbgPrintf = dbgPrintf;
199  sfm->setup.dbgState = dbgState;
200  FUNCTION_FINISH(SFM_SetDebugConfig)
201 }
202 
209 void SFM_SetDebugState( H_SfmInstance sfm, U32BIT dbgState )
210 {
211  sfm->setup.dbgState = dbgState;
212 }
213 
221 {
222  FUNCTION_START(SFM_SetDsmInstance)
223  sfm->dsmcc = dsmcc;
224  FUNCTION_FINISH(SFM_SetDsmInstance)
225 }
226 
233 void SFM_SetDemuxHandle( H_SfmInstance sfm, DMXREF demux )
234 {
235  FUNCTION_START(SFM_SetDemuxHandle)
236  sfm->demux = demux;
237  FUNCTION_FINISH(SFM_SetDemuxHandle)
238 }
239 
240 /*------------- Functions process section data from platform -----------------*/
241 
257 E_SFM_STATUS SFM_RequireSection( H_SfmInstance sfm, PIDFILT pfid,
258  U8BIT *pHeader, void **phBuffer )
259 {
260  E_SFM_STATUS result;
261  FUNCTION_START(SFM_RequireSection)
262 
263  // dsmcc sections always have indicator for current/next set to current ...
264  ASSERT((pHeader[5] & 0x1) == 0x1 )
265 
266  result = SFMFilterRequiresSection( sfm, pfid,
267  (U16BIT)((pHeader[3] << 8) | pHeader[4]), // table id extension
268  pHeader[0], // table id
269  (pHeader[5] >> 1) & 0x1F, // version (used by cache)
270  phBuffer );
271 
272  DBGLOG(DF_HWSF, "pfid=%x, sz=0x%x t=0x%x e=0x%x, %d, %d RESULT=%d", pfid,
273  (((int)(pHeader[1] & 0x0f) << 8) | pHeader[2]) + 3, *pHeader,
274  ((pHeader[3] << 8) | pHeader[4]), pHeader[6] + 1, pHeader[7] + 1, result)
275 
276  if (result == SFM_UPDATE_CACHE)
277  {
278  SFMCacheAddBlock( sfm, pHeader[1], pHeader[6], phBuffer );
279  if (*phBuffer == NULL)
280  {
281  result = SFM_IGNORE;
282  }
283  }
284  FUNCTION_FINISH(SFM_RequireSection)
285  return result;
286 }
287 
299 void SFM_ProcessSection( H_SfmInstance sfm, U8BIT *pSection, void *hBuffer )
300 {
301  FUNCTION_START(SFM_AddSectionFilter)
302  if (SFMFilterValidHandle( sfm, hBuffer ))
303  {
304  SFMFilterProcessSection( sfm, pSection, hBuffer );
305  }
306  else if (SFMCacheValidHandle( sfm, hBuffer ))
307  {
308  SFMCacheProcessSection( sfm, pSection, hBuffer );
309  }
310  else
311  {
312  ERRLOG("Invalid buffer handle")
313  }
314  FUNCTION_FINISH(SFM_AddSectionFilter)
315 }
316 
H_SfmInstance SFM_CreateInstance(S_SfmSetup *pSetup)
Create Section Filter Manager instance, using setup structure.
Definition: sfm_main.c:62
void SFM_SetDemuxHandle(H_SfmInstance sfm, DMXREF demux)
Set handle to be passed to F_DvpFilterSetup and F_DvpFilterRemove.
Definition: sfm_main.c:233
void SFMFilterProcessSection(H_SfmInstance sfm, U8BIT *pSection, H_DsmResource pDsmRes)
Get DSM-CC filter request and pass section buffer to DSM-CC with it's filter handle This should only ...
Definition: sfm_filter.c:1274
BOOLEAN SFMFilterCreateResources(H_SfmInstance sfm)
Create Filter resources for Section Filter Manager instance.
Definition: sfm_filter.c:829
void SFMCacheAddBlock(H_SfmInstance sfm, U8BIT size1, U8BIT bknum, void **phBuffer)
Allocates space in cache for section data If allocation is made, *phBuffer has holds cache location...
Definition: sfm_cache.c:638
void SFM_SetDebugState(H_SfmInstance sfm, U32BIT dbgState)
This allows controlling software to reconfigure SFM debug output.
Definition: sfm_main.c:209
Section Filter Manasger (SFM): cache definitions.
Section Filter Manager (SFM): filters.
void SFMCacheProcessSection(H_SfmInstance sfm, U8BIT *pSection, H_CacheFilter cfilter)
Tells SFM Cache to update DSM-CC with cached buffer (reported to F_CacheMatch callback funtion...
Definition: sfm_cache.c:790
Section Filter Manager (SFM): main definitions.
void SFM_DestroyInstance(H_SfmInstance sfm, void **pSfmMtx, void **pCchMtx, void **pBufMtx)
Destroy Section Filter Manager instance, and return mutexes so that they may be destroyed by client...
Definition: sfm_main.c:161
E_SFM_STATUS SFMFilterRequiresSection(H_SfmInstance sfm, PIDFILT pfid, U16BIT teid, U8BIT tid, U8BIT vers, void **phBuffer)
This function performs minimal checking of section header data to find out whether SFM requires this ...
Definition: sfm_filter.c:1165
void SFMFilterDestroyResources(H_SfmInstance sfm)
Destroy Filter resources for Section Filter Manager instance.
Definition: sfm_filter.c:929
void SFM_SetDebugConfig(H_SfmInstance sfm, F_Printf errPrintf, F_Printf dbgPrintf, U32BIT dbgState)
This allows controlling software to reconfigure SFM debug output.
Definition: sfm_main.c:192
BOOLEAN SFMCacheValidHandle(H_SfmInstance sfm, void *ptr)
Definition: sfm_cache.c:757
void SFM_SetDsmInstance(H_SfmInstance sfm, H_DsmCoreInst dsmcc)
Set instance handle for DSM-CC that SFM is supporting.
Definition: sfm_main.c:220
void SFMFilterInitCaching(H_SfmInstance sfm)
Initialise caching references.
Definition: sfm_filter.c:904
void SFM_ProcessSection(H_SfmInstance sfm, U8BIT *pSection, void *hBuffer)
Process required section buffer. This should only be called after calling SFM_RequireSection and with...
Definition: sfm_main.c:299
E_SFM_STATUS SFM_RequireSection(H_SfmInstance sfm, PIDFILT pfid, U8BIT *pHeader, void **phBuffer)
This function performs minimal checking of section header data to find out whether SFM requires this ...
Definition: sfm_main.c:257