43 #ifdef COMMON_INTERFACE 53 #define STB_RES_DBG(x) STB_SPDebugWrite x 55 #define STB_RES_DBG(x) 66 void *tuned_transport;
67 E_STB_DP_RES_OWNER owner;
91 static BOOLEAN res_initialised = FALSE;
93 static U8BIT num_tuners;
95 static U8BIT num_demuxes;
97 static U8BIT num_audio_decoders;
100 static U8BIT num_video_decoders;
102 static U8BIT num_ci_slots;
123 E_STB_TUNE_SIGNAL_TYPE signal_type;
124 #ifdef COMMON_INTERFACE 130 if (!res_initialised)
137 if (tuner_status != NULL)
139 STB_RES_DBG((
"STB_RESInitialise: Initialising %d tuners", num_tuners));
140 for (i = 0, tuner = &tuner_status[0]; i < num_tuners; tuner++, i++)
142 memset(tuner, 0,
sizeof(*tuner));
144 tuner->tuner_type = SIGNAL_NONE;
148 if ((signal_type & TUNE_SIGNAL_ANALOG) != 0)
150 tuner->tuner_type |= SIGNAL_ANALOG;
152 if ((signal_type & TUNE_SIGNAL_COFDM) != 0)
154 tuner->tuner_type |= SIGNAL_COFDM;
156 if ((signal_type & TUNE_SIGNAL_QAM) != 0)
158 tuner->tuner_type |= SIGNAL_QAM;
160 if ((signal_type & TUNE_SIGNAL_QPSK) != 0)
162 tuner->tuner_type |= SIGNAL_QPSK;
165 tuner->disabled = FALSE;
166 tuner->tuned_transport = NULL;
167 tuner->owner = RES_OWNER_NONE;
173 STB_RES_DBG((
"STB_RESInitialise: No tuners!"));
181 if (demux_status != NULL)
183 STB_RES_DBG((
"STB_RESInitialise: Initialising %d demuxes", num_demuxes));
184 for (i = 0, demux = &demux_status[0]; i < num_demuxes; demux++, i++)
186 memset(demux, 0,
sizeof(*demux));
194 STB_RES_DBG((
"STB_RESInitialise: No demuxes!"));
199 if (num_audio_decoders > 0)
202 if (audio_decoder_status != NULL)
204 STB_RES_DBG((
"STB_RESInitialise: Initialising %d audio decoders", num_audio_decoders));
205 for (i = 0, decoder = &audio_decoder_status[0]; i < num_audio_decoders; decoder++, i++)
207 decoder->is_acquired = FALSE;
211 if (ad_decoder_status != NULL)
213 STB_RES_DBG((
"STB_RESInitialise: Initialising %d AD decoders", num_audio_decoders));
214 for (i = 0, decoder = &ad_decoder_status[0]; i < num_audio_decoders; decoder++, i++)
216 decoder->is_acquired = FALSE;
222 STB_RES_DBG((
"STB_RESInitialise: No audio decoders!"));
223 audio_decoder_status = NULL;
224 ad_decoder_status = NULL;
228 if (num_video_decoders > 0)
231 if (video_decoder_status != NULL)
233 STB_RES_DBG((
"STB_RESInitialise: Initialising %d video decoders", num_video_decoders));
234 for (i = 0, decoder = &video_decoder_status[0]; i < num_video_decoders; decoder++, i++)
236 decoder->is_acquired = FALSE;
242 STB_RES_DBG((
"STB_RESInitialise: No video decoders!"));
243 video_decoder_status = NULL;
246 #ifdef COMMON_INTERFACE 247 num_ci_slots = STB_CIGetSlotCount();
248 if (num_ci_slots > 0)
251 if (ci_slot_status != NULL)
253 STB_RES_DBG((
"STB_RESInitialise: Initialising %d CI slots", num_ci_slots));
254 for (i = 0, slot = &ci_slot_status[0]; i < num_ci_slots; slot++, i++)
256 slot->usage_count = 0;
257 slot->service = NULL;
263 ci_slot_status = NULL;
267 res_initialised = TRUE;
272 return(res_initialised);
298 BOOLEAN high_priority, BOOLEAN *tuner_taken)
301 U8BIT tuner_id = INVALID_RES_ID;
305 *tuner_taken = FALSE;
309 if (transport != NULL)
312 for (i = 0; (i < num_tuners) && (tuner_id == INVALID_RES_ID); i++)
314 if ((tuner_status[i].tuned_transport == transport))
316 tuner_status[i].usage_count++;
318 if ((tuner_status[i].owner == RES_OWNER_NONE) && (owner != RES_OWNER_NONE))
321 tuner_status[i].owner = owner;
327 tuner_status[i].high_count++;
335 if ((tuner_id == INVALID_RES_ID) || (transport == NULL))
338 for (i = 0; (i < num_tuners) && (tuner_id == INVALID_RES_ID); i++)
340 if (!tuner_status[i].disabled && (tuner_status[i].usage_count == 0) &&
341 ((tuner_status[i].tuner_type & tuner_type) != 0))
345 tuner_status[i].high_count++;
348 tuner_status[i].usage_count++;
349 tuner_status[i].owner = owner;
356 if ((tuner_id == INVALID_RES_ID) && high_priority)
360 for (i = 0; (i < num_tuners) && (tuner_id == INVALID_RES_ID); i++)
362 if (!tuner_status[i].disabled && ((tuner_status[i].tuner_type & tuner_type) != 0) &&
363 (tuner_status[i].high_count == 0) && (tuner_status[i].owner == RES_OWNER_NONE))
365 tuner_status[i].tuned_transport = transport;
366 tuner_status[i].high_count++;
367 tuner_status[i].usage_count++;
368 tuner_status[i].owner = owner;
380 if (tuner_id == INVALID_RES_ID)
382 STB_RES_DBG((
"STB_RESAcquireTuner(%u, %p, %u): Failed to acquire a tuner for owner %u", tuner_type,
383 transport, high_priority, owner));
387 STB_RES_DBG((
"STB_RESAcquireTuner(%u, %p, %u): Tuner %u acquired, usage_count=%u, high_count=%u, owner=%u",
388 tuner_type, transport, high_priority, tuner_id, tuner_status[tuner_id].usage_count,
389 tuner_status[tuner_id].high_count, owner));
410 ASSERT(tuner_id < num_tuners);
412 if (tuner_id < num_tuners)
414 STB_RES_DBG((
"STB_RESReleaseTuner(%u, %u, %u): usage_count=%u, high_count=%u, owner=%u",
415 tuner_id, high_priority, owner, tuner_status[tuner_id].usage_count,
416 tuner_status[tuner_id].high_count, tuner_status[tuner_id].owner));
420 tuner_status[tuner_id].high_count--;
423 if (tuner_status[tuner_id].usage_count != 0)
425 tuner_status[tuner_id].usage_count--;
426 if (tuner_status[tuner_id].usage_count == 0)
429 tuner_status[tuner_id].tuned_transport = NULL;
430 tuner_status[tuner_id].owner = RES_OWNER_NONE;
434 else if (tuner_status[tuner_id].owner == owner)
436 tuner_status[tuner_id].owner = RES_OWNER_NONE;
442 STB_RES_DBG((
"STB_RESReleaseTuner(%u): Tuner released too many times!", tuner_id));
463 ASSERT(tuner_id < num_tuners);
465 if (tuner_id < num_tuners)
467 tuner_status[tuner_id].disabled = disable;
489 ASSERT(tuner_id < num_tuners);
491 if (tuner_id < num_tuners)
493 disabled = tuner_status[tuner_id].disabled;
508 U8BIT id, enabled_tuners;
514 for (
id = 0;
id < num_tuners;
id++)
516 if (!tuner_status[
id].disabled)
524 return(enabled_tuners);
538 ASSERT(tuner_id < num_tuners);
540 if (tuner_id < num_tuners)
542 tuner_status[tuner_id].owner = owner;
556 E_STB_DP_SIGNAL_TYPE type;
564 ASSERT(tuner_id < num_tuners);
566 if (tuner_id < num_tuners)
568 type = tuner_status[tuner_id].tuner_type;
589 ASSERT(tuner_id < num_tuners);
592 if ((tuner_id < num_tuners) && (tuner_status[tuner_id].usage_count == 1))
594 tuner_status[tuner_id].tuned_transport = t_ptr;
614 ASSERT(tuner_id < num_tuners);
616 if (tuner_id < num_tuners)
618 t_ptr = tuner_status[tuner_id].tuned_transport;
643 for (i = 0; (i < num_tuners) && !can_tune; i++)
645 if (((tuner_status[i].usage_count > 0) && (tuner_status[i].tuned_transport == transport)) ||
646 (((tuner_status[i].tuner_type & tuner_type) != 0) && (tuner_status[i].high_count == 0)))
672 ASSERT(tuner_id < num_tuners);
674 if (tuner_id < num_tuners)
676 usage_count = tuner_status[tuner_id].usage_count;
710 STB_RES_DBG((
"STB_RESAcquireDemux(%u, %u)", demux_id, caps));
712 if (demux_id == INVALID_RES_ID)
714 for (i = 0; (i < num_demuxes) && (demux_id == INVALID_RES_ID); i++)
716 if ((demux_status[i].usage_count == 0) && ((demux_status[i].caps & caps) == caps))
718 demux_status[i].usage_count = 1;
723 if ((demux_id == INVALID_RES_ID) && (caps == DMX_CAPS_MONITOR_SI))
727 for (i = 0; (i < num_demuxes) && (demux_id == INVALID_RES_ID); i++)
729 if ((demux_status[i].usage_count == 0) && ((demux_status[i].caps & DMX_CAPS_LIVE) != 0))
731 demux_status[i].usage_count = 1;
740 demux_status[demux_id].usage_count++;
745 demux_id = INVALID_RES_ID;
749 if (demux_id == INVALID_RES_ID)
751 STB_RES_DBG((
"STB_RESAcquireDemux: Failed to acquire a demux"));
755 STB_RES_DBG((
"STB_RESAcquireDemux: Acquired %u, usage_count=%u", demux_id,
756 demux_status[demux_id].usage_count));
776 ASSERT(demux_id < num_demuxes);
778 if (demux_id < num_demuxes)
780 STB_RES_DBG((
"STB_RESReleaseDemux(%u): usage_count=%u", demux_id,
781 demux_status[demux_id].usage_count));
783 if (demux_status[demux_id].usage_count > 0)
785 demux_status[demux_id].usage_count--;
786 STB_RES_DBG((
"STB_RESReleaseDemux: Released demux %d", demux_id));
791 STB_RES_DBG((
"STB_RESReleaseDemux: Demux %d released too many times!", demux_id));
811 if (demux_id != INVALID_RES_ID)
813 caps = demux_status[demux_id].caps;
833 return(num_audio_decoders);
844 U8BIT decoder_id = INVALID_RES_ID;
848 for (i = 0; (i < num_audio_decoders) && (decoder_id == INVALID_RES_ID); i++)
850 if (!ad_decoder_status[i].is_acquired)
852 ad_decoder_status[i].is_acquired = TRUE;
854 STB_RES_DBG((
"STB_RESAcquireADDecoder: Decoder %d acquired", decoder_id));
859 if (decoder_id == INVALID_RES_ID)
861 STB_RES_DBG((
"STB_RESAcquireADDecoder: Failed to acquire a decoder"));
881 if (decoder_id < num_audio_decoders)
883 ad_decoder_status[decoder_id].is_acquired = FALSE;
884 STB_RES_DBG((
"STB_RESReleaseADDecoder: Released decoder %d", decoder_id));
899 U8BIT decoder_id = INVALID_RES_ID;
905 for (i = 0; (i < num_audio_decoders) && (decoder_id == INVALID_RES_ID); i++)
907 if (!audio_decoder_status[i].is_acquired)
909 audio_decoder_status[i].is_acquired = TRUE;
911 STB_RES_DBG((
"STB_RESAcquireAudioDecoder: Decoder %d acquired", decoder_id));
917 if (decoder_id == INVALID_RES_ID)
919 STB_RES_DBG((
"STB_RESAcquireAudioDecoder: Failed to acquire a decoder"));
939 ASSERT(decoder_id < num_audio_decoders);
941 if (decoder_id < num_audio_decoders)
943 audio_decoder_status[decoder_id].is_acquired = FALSE;
944 STB_RES_DBG((
"STB_RESReleaseAudioDecoder: Released decoder %d", decoder_id));
960 return(num_video_decoders);
971 U8BIT decoder_id = INVALID_RES_ID;
977 for (i = 0; (i < num_video_decoders) && (decoder_id == INVALID_RES_ID); i++)
979 if (!video_decoder_status[i].is_acquired)
981 video_decoder_status[i].is_acquired = TRUE;
983 STB_RES_DBG((
"STB_RESAcquireVideoDecoder: Decoder %d acquired", decoder_id));
989 if (decoder_id == INVALID_RES_ID)
991 STB_RES_DBG((
"STB_RESAcquireVideoDecoder: Failed to acquire a decoder"));
1009 if (res_initialised)
1011 ASSERT(decoder_id < num_video_decoders);
1013 if (decoder_id < num_video_decoders)
1015 video_decoder_status[decoder_id].is_acquired = FALSE;
1016 STB_RES_DBG((
"STB_RESReleaseVideoDecoder: Released decoder %d", decoder_id));
1031 return(num_ci_slots);
1034 #ifdef COMMON_INTERFACE 1042 U8BIT STB_RESAcquireCISlot(
void *service, U8BIT *pmt_data, U8BIT *ci_protection_desc)
1045 U8BIT slot_id = INVALID_RES_ID;
1047 FUNCTION_START(STB_RESAcquireCISlot);
1049 if (res_initialised)
1052 for (i = 0; (i < num_ci_slots) && (slot_id == INVALID_RES_ID); i++)
1054 if ((ci_slot_status[i].usage_count > 0) && (ci_slot_status[i].service == service))
1057 ci_slot_status[i].usage_count++;
1059 STB_RES_DBG((
"STB_RESAcquireCISlot: CI slot %u acquired, usage_count=%u", slot_id,
1060 ci_slot_status[i].usage_count));
1065 for (i = 0; (i < num_ci_slots) && (slot_id == INVALID_RES_ID); i++)
1067 if (ci_slot_status[i].usage_count == 0)
1071 ci_slot_status[i].usage_count = 1;
1072 ci_slot_status[i].service = service;
1074 STB_RES_DBG((
"STB_RESAcquireCISlot: CI slot %u acquired for service %p", slot_id, service));
1080 #ifdef STB_RES_DEBUG 1081 if (slot_id == INVALID_RES_ID)
1083 STB_RES_DBG((
"STB_RESAcquireCISlot: Failed to acquire a CI slot for service %p", service));
1087 FUNCTION_FINISH(STB_RESAcquireCISlot);
1097 BOOLEAN STB_RESUseCISlot(U8BIT slot_id)
1101 FUNCTION_START(STB_RESUseCISlot);
1105 if (res_initialised && (slot_id < num_ci_slots))
1107 STB_RES_DBG((
"STB_RESUseCISlot(%u): usage count=%u", slot_id,
1108 ci_slot_status[slot_id].usage_count));
1110 if (ci_slot_status[slot_id].usage_count == 0)
1112 ci_slot_status[slot_id].usage_count = 1;
1113 ci_slot_status[slot_id].service = NULL;
1118 FUNCTION_FINISH(STB_RESUseCISlot);
1138 if (res_initialised)
1140 ASSERT(slot_id < num_ci_slots);
1142 if (slot_id < num_ci_slots)
1144 retval = ci_slot_status[slot_id].usage_count;
1161 if (res_initialised)
1163 ASSERT(slot_id < num_ci_slots);
1165 if (slot_id < num_ci_slots)
1167 STB_RES_DBG((
"STB_RESReleaseCISlot(%u): usage_count=%u", slot_id,
1168 ci_slot_status[slot_id].usage_count));
1170 if (ci_slot_status[slot_id].usage_count > 0)
1172 ci_slot_status[slot_id].usage_count--;
1175 if (ci_slot_status[slot_id].usage_count == 0)
1177 ci_slot_status[slot_id].service = NULL;
U16BIT STB_TuneGetSignalType(U8BIT path)
Gets the signal types of the given tuner path. This will be a bitmask of supported types defined by E...
U8BIT STB_RESNumDemuxes(void)
Returns the number of demux paths under the control of the resource manager.
void * STB_GetMemory(U32BIT bytes)
Attempts to allocate memory from the heap.
void STB_RESReleaseAudioDecoder(U8BIT decoder_id)
Releases a previously acquired audio decoder.
U8BIT STB_HWGetTunerPaths(void)
Returns the number of front end (Tuner) paths on the platform.
void STB_RESSetTunerDisabled(U8BIT tuner_id, BOOLEAN disable)
Set the disable state for a tuner. When disabled, a tuner will be ignored when acquiring a new tuner ...
BOOLEAN STB_RESCanTuneToTransport(E_STB_DP_SIGNAL_TYPE tuner_type, void *transport)
Returns whether there's a tuner available to tune to the given transport.
BOOLEAN STB_RESInitialise(void)
Creates and initialises control structures for the resources to be managed.
Header file - macros and function prototypes for public use.
void STB_RESSetTunerOwner(U8BIT tuner_id, E_STB_DP_RES_OWNER owner)
Sets the owner of the tuner.
U8BIT STB_RESAcquireADDecoder(void)
Acquires an AD decoder and marks it as used.
U16BIT STB_DMXGetCapabilities(U8BIT path)
Returns the capability flags of the given demux.
U16BIT STB_RESGetDemuxCaps(U8BIT demux_id)
Returns the capability flags for the given demux.
U8BIT STB_RESAcquireDemux(U8BIT demux_id, U16BIT caps)
Acquires a demux path and marks it as being used.
void * STB_RESGetTunedTransport(U8BIT tuner_id)
Returns the transport record saved with the specified tuner.
E_STB_DP_SIGNAL_TYPE STB_RESGetTunerType(U8BIT tuner_id)
Returns the type of the given tuner.
BOOLEAN STB_RESIsTunerDisabled(U8BIT tuner_id)
Returns whether a tuner has been disabled or not.
U8BIT STB_RESNumVideoDecoders(void)
Returns the number of video decoders in the system.
U8BIT STB_HWGetVideoDecodePaths(void)
Returns the number of video decoding paths on the platform.
U8BIT STB_RESNumAudioDecoders(void)
Returns the number of audio decoders in the system.
Debug functions header file.
Header file - macros and function prototypes for public use.
U8BIT STB_RESAcquireAudioDecoder(void)
Acquires an audio decoder and marks it as used.
void STB_RESReleaseADDecoder(U8BIT decoder_id)
Releases a previously acquired AD decoder.
U8BIT STB_HWGetAudioDecodePaths(void)
Returns the number of audio decoding paths on the platform.
void STB_RESReleaseDemux(U8BIT demux_id)
Releases a previously acquired demux path.
System Wide Global Technical Data Type Definitions.
void STB_TuneSetSignalType(U8BIT path, E_STB_TUNE_SIGNAL_TYPE type)
This function is only relevant for tuners that support more than one signal type; for tuners that don...
STB middleware resource management module header file.
U8BIT STB_RESNumCISlots(void)
Returns the number of CI slots under the control of the resource manager.
U8BIT STB_RESAcquireVideoDecoder(void)
Acquires a video decoder and marks it as used.
Header file - Function prototypes for heap memory.
void STB_RESSetTunedTransport(U8BIT tuner_id, void *t_ptr)
Saves the transport pointer with the specified tuner.
U8BIT STB_RESNumEnabledTuners(void)
Returns the number of tuners that aren't disabled.
void STB_RESReleaseTuner(U8BIT tuner_id, BOOLEAN high_priority, E_STB_DP_RES_OWNER owner)
Releases a tuner that has previously been acquired.
Header file - Function prototypes for Demux control.
U8BIT STB_HWGetDemuxPaths(void)
Queries the number of demux paths available.
U8BIT STB_RESNumTuners(void)
Returns the number of tuners.
U8BIT STB_RESAcquireTuner(E_STB_DP_SIGNAL_TYPE tuner_type, void *transport, E_STB_DP_RES_OWNER owner, BOOLEAN high_priority, BOOLEAN *tuner_taken)
Acquires a tuner. Tuners will be reused if possible.
void STB_RESReleaseCISlot(U8BIT slot_id)
Releases a previously acquired CI slot.
U8BIT STB_RESTunerUsageCount(U8BIT tuner_id)
Returns the number of paths using the tuner.
BOOLEAN STB_CiCcIsServiceAllowed(U8BIT slot_id, U8BIT *ci_prot_desc)
Tell whether the service is allowed. This function checks whether the CI Protection Descriptor allows...
void STB_RESReleaseVideoDecoder(U8BIT decoder_id)
Releases a previously acquired video decoder.
U8BIT STB_RESGetCISlotUsageCount(U8BIT slot_id)
Returns the number of times the given slot is in use.
Header file - Function prototypes for tuner control.