| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2003-2006, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: $ |
|---|
| 11 | * $brcm_Revision: $ |
|---|
| 12 | * $brcm_Date: $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: $ |
|---|
| 19 | * |
|---|
| 20 | ***************************************************************************/ |
|---|
| 21 | |
|---|
| 22 | #include "ch_map.h" |
|---|
| 23 | #include "bapp_task.h" |
|---|
| 24 | #include "bapp_util.h" |
|---|
| 25 | #if 0 |
|---|
| 26 | #include "ts_psi.h" |
|---|
| 27 | #include "ts_psi.h" |
|---|
| 28 | #include "ts_pat.h" |
|---|
| 29 | #include "ts_pmt.h" |
|---|
| 30 | #include "psip_ett.h" |
|---|
| 31 | #include "si.h" |
|---|
| 32 | #include "si_nit.h" |
|---|
| 33 | #include "si_ntt.h" |
|---|
| 34 | #include "si_stt.h" |
|---|
| 35 | #include "si_svct.h" |
|---|
| 36 | #endif |
|---|
| 37 | BDBG_MODULE(ch_map); /* Register software module with debug interface */ |
|---|
| 38 | |
|---|
| 39 | #define CH_MAP_MUTEX_TIMEOUT 500 |
|---|
| 40 | |
|---|
| 41 | /* |
|---|
| 42 | Summary: |
|---|
| 43 | Initialize channel map mgmt internals (structure may already be initialized). |
|---|
| 44 | Initialize mutex if it is 0. |
|---|
| 45 | */ |
|---|
| 46 | void ch_map_init(ch_map_t *p_ch_map,bapp_task_mutex_t p_mutex) |
|---|
| 47 | { |
|---|
| 48 | BDBG_ASSERT(p_ch_map); |
|---|
| 49 | BDBG_ASSERT(p_mutex); |
|---|
| 50 | p_ch_map->p_mutex = p_mutex; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | /* |
|---|
| 54 | Summary: |
|---|
| 55 | reset channel map mgmt internals. |
|---|
| 56 | */ |
|---|
| 57 | void ch_map_reset(ch_map_t *p_ch_map) |
|---|
| 58 | { |
|---|
| 59 | BDBG_ASSERT(p_ch_map); |
|---|
| 60 | BDBG_ASSERT(p_ch_map->p_mutex); |
|---|
| 61 | if (bapp_task_acquire_mutex(p_ch_map->p_mutex,CH_MAP_MUTEX_TIMEOUT) == b_ok) |
|---|
| 62 | { |
|---|
| 63 | p_ch_map->mms_map.num_mms = 0; |
|---|
| 64 | p_ch_map->freq_map.num_freq = 0; |
|---|
| 65 | p_ch_map->st_map.num_st = 0; |
|---|
| 66 | p_ch_map->vch_map.num_vch = 0; |
|---|
| 67 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 68 | } else |
|---|
| 69 | { |
|---|
| 70 | BDBG_WRN(("%s:%d mutex timeout\n", __FUNCTION__,__LINE__)); |
|---|
| 71 | } |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | /* |
|---|
| 75 | Summary: |
|---|
| 76 | copy channel map. |
|---|
| 77 | */ |
|---|
| 78 | void ch_map_copy(ch_map_t *p_ch_map_to,ch_map_t *p_ch_map_from,unsigned int flags) |
|---|
| 79 | { |
|---|
| 80 | BDBG_ASSERT(p_ch_map_to); |
|---|
| 81 | BDBG_ASSERT(p_ch_map_from); |
|---|
| 82 | BDBG_ASSERT(p_ch_map_to->p_mutex); |
|---|
| 83 | BDBG_ASSERT(p_ch_map_from->p_mutex); |
|---|
| 84 | if (bapp_task_acquire_mutex(p_ch_map_to->p_mutex,CH_MAP_MUTEX_TIMEOUT) == b_ok) |
|---|
| 85 | { |
|---|
| 86 | if (bapp_task_acquire_mutex(p_ch_map_from->p_mutex,CH_MAP_MUTEX_TIMEOUT) == b_ok) |
|---|
| 87 | { |
|---|
| 88 | p_ch_map_to->cur_ch = p_ch_map_from->cur_ch; /* current channel */ |
|---|
| 89 | |
|---|
| 90 | if (flags & 0x8) |
|---|
| 91 | bapp_util_memcpy(&p_ch_map_to->mms_map,&p_ch_map_from->mms_map,sizeof(mms_map_t)); |
|---|
| 92 | if (flags & 0x1) |
|---|
| 93 | bapp_util_memcpy(&p_ch_map_to->freq_map,&p_ch_map_from->freq_map,sizeof(freq_map_t)); |
|---|
| 94 | if (flags & 0x4) |
|---|
| 95 | bapp_util_memcpy(&p_ch_map_to->st_map,&p_ch_map_from->st_map,sizeof(st_map_t)); |
|---|
| 96 | if (flags & 0x2) |
|---|
| 97 | bapp_util_memcpy(&p_ch_map_to->vch_map,&p_ch_map_from->vch_map,sizeof(vch_map_t)); |
|---|
| 98 | bapp_task_release_mutex(p_ch_map_from->p_mutex); |
|---|
| 99 | } else |
|---|
| 100 | { |
|---|
| 101 | BDBG_WRN(("%s:%d mutex timeout\n", __FUNCTION__,__LINE__)); |
|---|
| 102 | } |
|---|
| 103 | bapp_task_release_mutex(p_ch_map_to->p_mutex); |
|---|
| 104 | } else |
|---|
| 105 | { |
|---|
| 106 | BDBG_WRN(("%s:%d mutex timeout\n", __FUNCTION__,__LINE__)); |
|---|
| 107 | } |
|---|
| 108 | } |
|---|
| 109 | /* |
|---|
| 110 | Summary: |
|---|
| 111 | compare mms maps. |
|---|
| 112 | */ |
|---|
| 113 | int ch_map_cmp_mms(mms_map_t *p_mms_map_to, mms_map_t *p_mms_map_from) |
|---|
| 114 | { |
|---|
| 115 | mms_t *p_mms_from; |
|---|
| 116 | mms_t *p_mms_to; |
|---|
| 117 | int i; |
|---|
| 118 | |
|---|
| 119 | if (p_mms_map_to->num_mms != p_mms_map_from->num_mms) |
|---|
| 120 | { |
|---|
| 121 | return -1; |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | for (i = 0; i < p_mms_map_to->num_mms; ++i) |
|---|
| 125 | { |
|---|
| 126 | p_mms_from = &(p_mms_map_from->mms[i]); |
|---|
| 127 | p_mms_to = &(p_mms_map_to->mms[i]); |
|---|
| 128 | |
|---|
| 129 | if (p_mms_from->code_rate != p_mms_to->code_rate) |
|---|
| 130 | return -1; |
|---|
| 131 | |
|---|
| 132 | if (p_mms_from->idx != p_mms_to->idx) |
|---|
| 133 | return -1; |
|---|
| 134 | |
|---|
| 135 | if (p_mms_from->modulation != p_mms_to->modulation) |
|---|
| 136 | return -1; |
|---|
| 137 | |
|---|
| 138 | if (p_mms_from->symbol_rate != p_mms_to->symbol_rate) |
|---|
| 139 | return -1; |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | return 0; |
|---|
| 143 | } |
|---|
| 144 | /* |
|---|
| 145 | Summary: |
|---|
| 146 | compare freq maps. |
|---|
| 147 | */ |
|---|
| 148 | int ch_map_cmp_freq(freq_map_t *p_freq_map_to, freq_map_t *p_freq_map_from) |
|---|
| 149 | { |
|---|
| 150 | freq_t *p_from; |
|---|
| 151 | freq_t *p_to; |
|---|
| 152 | int i; |
|---|
| 153 | |
|---|
| 154 | if (p_freq_map_to->num_freq != p_freq_map_from->num_freq) |
|---|
| 155 | { |
|---|
| 156 | return -1; |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | for (i = 0; i < p_freq_map_to->num_freq; ++i) |
|---|
| 160 | { |
|---|
| 161 | p_from = &(p_freq_map_from->freq[i]); |
|---|
| 162 | p_to = &(p_freq_map_to->freq[i]); |
|---|
| 163 | |
|---|
| 164 | if (p_from->freq_khz != p_to->freq_khz) |
|---|
| 165 | return -1; |
|---|
| 166 | |
|---|
| 167 | if (p_from->idx != p_to->idx) |
|---|
| 168 | return -1; |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | return 0; |
|---|
| 172 | } |
|---|
| 173 | /* |
|---|
| 174 | Summary: |
|---|
| 175 | compare freq maps. |
|---|
| 176 | */ |
|---|
| 177 | int ch_map_cmp_st(st_map_t *p_map_to, st_map_t *p_map_from) |
|---|
| 178 | { |
|---|
| 179 | st_t *p_from; |
|---|
| 180 | st_t *p_to; |
|---|
| 181 | int i; |
|---|
| 182 | |
|---|
| 183 | if (p_map_to->num_st != p_map_from->num_st) |
|---|
| 184 | { |
|---|
| 185 | return -1; |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | for (i = 0; i < p_map_to->num_st; ++i) |
|---|
| 189 | { |
|---|
| 190 | p_from = &(p_map_from->st[i]); |
|---|
| 191 | p_to = &(p_map_to->st[i]); |
|---|
| 192 | |
|---|
| 193 | if (p_from->source_id != p_to->source_id) |
|---|
| 194 | return -1; |
|---|
| 195 | |
|---|
| 196 | if (bapp_util_strcmp(p_from->name,p_to->name) != 0) |
|---|
| 197 | return -1; |
|---|
| 198 | } |
|---|
| 199 | |
|---|
| 200 | return 0; |
|---|
| 201 | } |
|---|
| 202 | /* |
|---|
| 203 | Summary: |
|---|
| 204 | compare vch maps. |
|---|
| 205 | */ |
|---|
| 206 | int ch_map_cmp_vch(vch_map_t *p_map_to, vch_map_t *p_map_from) |
|---|
| 207 | { |
|---|
| 208 | vch_t *p_from; |
|---|
| 209 | vch_t *p_to; |
|---|
| 210 | int i; |
|---|
| 211 | |
|---|
| 212 | if (p_map_to->num_vch != p_map_from->num_vch) |
|---|
| 213 | { |
|---|
| 214 | return -1; |
|---|
| 215 | } |
|---|
| 216 | |
|---|
| 217 | for (i = 0; i < p_map_to->num_vch; ++i) |
|---|
| 218 | { |
|---|
| 219 | p_from = &(p_map_from->vch[i]); |
|---|
| 220 | p_to = &(p_map_to->vch[i]); |
|---|
| 221 | |
|---|
| 222 | if (p_from->ch_num != p_to->ch_num) |
|---|
| 223 | return -1; |
|---|
| 224 | if (p_from->source_id != p_to->source_id) |
|---|
| 225 | return -1; |
|---|
| 226 | if (p_from->program_num != p_to->program_num) |
|---|
| 227 | return -1; |
|---|
| 228 | if (p_from->freq_idx != p_to->freq_idx) |
|---|
| 229 | return -1; |
|---|
| 230 | if (p_from->mms_idx != p_to->mms_idx) |
|---|
| 231 | return -1; |
|---|
| 232 | if (p_from->vchflags != p_to->vchflags) |
|---|
| 233 | return -1; |
|---|
| 234 | } |
|---|
| 235 | |
|---|
| 236 | return 0; |
|---|
| 237 | } |
|---|
| 238 | |
|---|
| 239 | /* |
|---|
| 240 | Summary: |
|---|
| 241 | check channel map for changes. |
|---|
| 242 | */ |
|---|
| 243 | unsigned int ch_map_cmp(ch_map_t *p_ch_map_to,ch_map_t *p_ch_map_from) |
|---|
| 244 | { |
|---|
| 245 | int cmp_result = 0; |
|---|
| 246 | BDBG_ASSERT(p_ch_map_to); |
|---|
| 247 | BDBG_ASSERT(p_ch_map_from); |
|---|
| 248 | BDBG_ASSERT(p_ch_map_to->p_mutex); |
|---|
| 249 | BDBG_ASSERT(p_ch_map_from->p_mutex); |
|---|
| 250 | if (bapp_task_acquire_mutex(p_ch_map_to->p_mutex,CH_MAP_MUTEX_TIMEOUT) == b_ok) |
|---|
| 251 | { |
|---|
| 252 | if (bapp_task_acquire_mutex(p_ch_map_from->p_mutex,CH_MAP_MUTEX_TIMEOUT) == b_ok) |
|---|
| 253 | { |
|---|
| 254 | if (p_ch_map_to->mms_map.num_mms != p_ch_map_from->mms_map.num_mms) |
|---|
| 255 | cmp_result |= 0x8; |
|---|
| 256 | if (p_ch_map_to->freq_map.num_freq != p_ch_map_from->freq_map.num_freq) |
|---|
| 257 | cmp_result |= 0x1; |
|---|
| 258 | if (p_ch_map_to->st_map.num_st != p_ch_map_from->st_map.num_st) |
|---|
| 259 | cmp_result |= 0x4; |
|---|
| 260 | if (p_ch_map_to->vch_map.num_vch != p_ch_map_from->vch_map.num_vch) |
|---|
| 261 | cmp_result |= 0x2; |
|---|
| 262 | if (ch_map_cmp_mms(&p_ch_map_to->mms_map,&p_ch_map_from->mms_map) != 0) |
|---|
| 263 | cmp_result |= 0x8; |
|---|
| 264 | if (ch_map_cmp_freq(&p_ch_map_to->freq_map,&p_ch_map_from->freq_map) != 0) |
|---|
| 265 | cmp_result |= 0x1; |
|---|
| 266 | if (ch_map_cmp_st(&p_ch_map_to->st_map,&p_ch_map_from->st_map) != 0) |
|---|
| 267 | cmp_result |= 0x4; |
|---|
| 268 | if (ch_map_cmp_vch(&p_ch_map_to->vch_map,&p_ch_map_from->vch_map) != 0) |
|---|
| 269 | cmp_result |= 0x2; |
|---|
| 270 | bapp_task_release_mutex(p_ch_map_from->p_mutex); |
|---|
| 271 | } else |
|---|
| 272 | { |
|---|
| 273 | BDBG_WRN(("%s:%d mutex timeout\n", __FUNCTION__,__LINE__)); |
|---|
| 274 | } |
|---|
| 275 | bapp_task_release_mutex(p_ch_map_to->p_mutex); |
|---|
| 276 | } else |
|---|
| 277 | { |
|---|
| 278 | BDBG_WRN(("%s:%d mutex timeout\n", __FUNCTION__,__LINE__)); |
|---|
| 279 | } |
|---|
| 280 | return cmp_result; |
|---|
| 281 | } |
|---|
| 282 | /* |
|---|
| 283 | Summary: |
|---|
| 284 | Check for matching entry. |
|---|
| 285 | */ |
|---|
| 286 | static bool ch_map_check_mms(ch_map_t *p_ch_map, mms_t *p_mms) |
|---|
| 287 | { |
|---|
| 288 | int i; |
|---|
| 289 | for (i = 0; i < p_ch_map->mms_map.num_mms; ++i) |
|---|
| 290 | { |
|---|
| 291 | if (p_ch_map->mms_map.mms[i].idx == p_mms->idx) |
|---|
| 292 | return true; |
|---|
| 293 | } |
|---|
| 294 | BDBG_MSG(("%s:%d no entry exists\n", __FUNCTION__,__LINE__)); |
|---|
| 295 | return false; |
|---|
| 296 | } |
|---|
| 297 | |
|---|
| 298 | /* |
|---|
| 299 | Summary: |
|---|
| 300 | Add an mms entry. |
|---|
| 301 | */ |
|---|
| 302 | void ch_map_add_mms(ch_map_t *p_ch_map, mms_t *p_mms) |
|---|
| 303 | { |
|---|
| 304 | BDBG_ASSERT(p_ch_map); |
|---|
| 305 | BDBG_ASSERT(p_ch_map->p_mutex); |
|---|
| 306 | if (bapp_task_acquire_mutex(p_ch_map->p_mutex,CH_MAP_MUTEX_TIMEOUT) == b_ok) |
|---|
| 307 | { |
|---|
| 308 | if (p_ch_map->mms_map.num_mms == MAX_FREQ_MAP) |
|---|
| 309 | { |
|---|
| 310 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 311 | BDBG_WRN(("%s:%d ENTRY LIMIT %d of %d\n", __FUNCTION__,__LINE__,p_ch_map->mms_map.num_mms,MAX_FREQ_MAP)); |
|---|
| 312 | return; |
|---|
| 313 | } |
|---|
| 314 | if (!ch_map_check_mms(p_ch_map,p_mms)) |
|---|
| 315 | { |
|---|
| 316 | p_ch_map->mms_map.mms[p_ch_map->mms_map.num_mms] = *p_mms; |
|---|
| 317 | p_ch_map->mms_map.num_mms++; |
|---|
| 318 | } |
|---|
| 319 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 320 | BDBG_MSG(("%s:%d num_mms = %d\n", __FUNCTION__,__LINE__,p_ch_map->mms_map.num_mms)); |
|---|
| 321 | } else |
|---|
| 322 | { |
|---|
| 323 | BDBG_WRN(("%s:%d mutex timeout\n", __FUNCTION__,__LINE__)); |
|---|
| 324 | } |
|---|
| 325 | } |
|---|
| 326 | /* |
|---|
| 327 | Summary: |
|---|
| 328 | Get mms for frequency idx. |
|---|
| 329 | */ |
|---|
| 330 | bool ch_map_get_mms(ch_map_t *p_ch_map, |
|---|
| 331 | unsigned char mms_idx, |
|---|
| 332 | mms_t *p_mms |
|---|
| 333 | ) |
|---|
| 334 | { |
|---|
| 335 | int idx; |
|---|
| 336 | bool result = false; |
|---|
| 337 | BDBG_ASSERT(p_ch_map); |
|---|
| 338 | BDBG_ASSERT(p_ch_map->p_mutex); |
|---|
| 339 | if (bapp_task_acquire_mutex(p_ch_map->p_mutex,CH_MAP_MUTEX_TIMEOUT) == b_ok) |
|---|
| 340 | { |
|---|
| 341 | for (idx = 0; idx < p_ch_map->mms_map.num_mms; ++idx) |
|---|
| 342 | { |
|---|
| 343 | if (mms_idx == p_ch_map->mms_map.mms[idx].idx) |
|---|
| 344 | { |
|---|
| 345 | *p_mms = p_ch_map->mms_map.mms[idx]; |
|---|
| 346 | result = true; |
|---|
| 347 | break; |
|---|
| 348 | } |
|---|
| 349 | } |
|---|
| 350 | |
|---|
| 351 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 352 | } |
|---|
| 353 | else |
|---|
| 354 | return false; |
|---|
| 355 | return result; |
|---|
| 356 | } |
|---|
| 357 | |
|---|
| 358 | /* |
|---|
| 359 | Summary: |
|---|
| 360 | Check for matching entry. |
|---|
| 361 | */ |
|---|
| 362 | static bool ch_map_check_freq(ch_map_t *p_ch_map, freq_t *p_freq) |
|---|
| 363 | { |
|---|
| 364 | int i; |
|---|
| 365 | for (i = 0; i < p_ch_map->freq_map.num_freq; ++i) |
|---|
| 366 | { |
|---|
| 367 | if (p_ch_map->freq_map.freq[i].idx == p_freq->idx) |
|---|
| 368 | return true; |
|---|
| 369 | } |
|---|
| 370 | BDBG_MSG(("%s:%d no entry exists\n", __FUNCTION__,__LINE__)); |
|---|
| 371 | return false; |
|---|
| 372 | } |
|---|
| 373 | |
|---|
| 374 | |
|---|
| 375 | /* |
|---|
| 376 | Summary: |
|---|
| 377 | Add a frequency entry. |
|---|
| 378 | */ |
|---|
| 379 | void ch_map_add_freq(ch_map_t *p_ch_map, freq_t *p_freq) |
|---|
| 380 | { |
|---|
| 381 | BDBG_ASSERT(p_ch_map); |
|---|
| 382 | BDBG_ASSERT(p_ch_map->p_mutex); |
|---|
| 383 | if (bapp_task_acquire_mutex(p_ch_map->p_mutex,CH_MAP_MUTEX_TIMEOUT) == b_ok) |
|---|
| 384 | { |
|---|
| 385 | if (p_ch_map->freq_map.num_freq == MAX_FREQ_MAP) |
|---|
| 386 | { |
|---|
| 387 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 388 | BDBG_WRN(("%s:%d ENTRY LIMIT %d of %d\n", __FUNCTION__,__LINE__,p_ch_map->freq_map.num_freq,MAX_FREQ_MAP)); |
|---|
| 389 | return; |
|---|
| 390 | } |
|---|
| 391 | if (!ch_map_check_freq(p_ch_map,p_freq)) |
|---|
| 392 | { |
|---|
| 393 | p_ch_map->freq_map.freq[p_ch_map->freq_map.num_freq] = *p_freq; |
|---|
| 394 | p_ch_map->freq_map.num_freq++; |
|---|
| 395 | } |
|---|
| 396 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 397 | BDBG_MSG(("%s:%d num_freq = %d\n", __FUNCTION__,__LINE__,p_ch_map->freq_map.num_freq)); |
|---|
| 398 | } else |
|---|
| 399 | { |
|---|
| 400 | BDBG_WRN(("%s:%d mutex timeout\n", __FUNCTION__,__LINE__)); |
|---|
| 401 | } |
|---|
| 402 | } |
|---|
| 403 | /* |
|---|
| 404 | Summary: |
|---|
| 405 | Check for matching entry. |
|---|
| 406 | */ |
|---|
| 407 | static bool ch_map_check_vch(ch_map_t *p_ch_map, vch_t *p_vch) |
|---|
| 408 | { |
|---|
| 409 | int i; |
|---|
| 410 | for (i = 0; i < p_ch_map->vch_map.num_vch; ++i) |
|---|
| 411 | { |
|---|
| 412 | if (p_ch_map->vch_map.vch[i].ch_num == p_vch->ch_num) |
|---|
| 413 | return true; |
|---|
| 414 | } |
|---|
| 415 | BDBG_MSG(("%s:%d no entry exists(%d,%d)\n", __FUNCTION__,__LINE__,p_vch->ch_num,p_vch->program_num)); |
|---|
| 416 | return false; |
|---|
| 417 | } |
|---|
| 418 | /* |
|---|
| 419 | Summary: |
|---|
| 420 | Add a virtual channel entry. |
|---|
| 421 | */ |
|---|
| 422 | void ch_map_add_vch(ch_map_t *p_ch_map, vch_t *p_vch) |
|---|
| 423 | { |
|---|
| 424 | BDBG_ASSERT(p_ch_map); |
|---|
| 425 | BDBG_ASSERT(p_ch_map->p_mutex); |
|---|
| 426 | if (bapp_task_acquire_mutex(p_ch_map->p_mutex,CH_MAP_MUTEX_TIMEOUT) == b_ok) |
|---|
| 427 | { |
|---|
| 428 | int idx,idx2, found_slot; |
|---|
| 429 | found_slot = 0; |
|---|
| 430 | |
|---|
| 431 | if (p_ch_map->vch_map.num_vch == MAX_VCH) |
|---|
| 432 | { |
|---|
| 433 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 434 | BDBG_WRN(("%s:%d ENTRY LIMIT, %d of %d\n", __FUNCTION__,__LINE__,p_ch_map->vch_map.num_vch,MAX_VCH)); |
|---|
| 435 | return; |
|---|
| 436 | } |
|---|
| 437 | |
|---|
| 438 | if (ch_map_check_vch(p_ch_map,p_vch)) |
|---|
| 439 | { |
|---|
| 440 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 441 | BDBG_MSG(("%s:%d entry exists(%d,%d)\n", __FUNCTION__,__LINE__,p_vch->ch_num,p_vch->program_num)); |
|---|
| 442 | return; |
|---|
| 443 | } |
|---|
| 444 | for (idx = 0; idx < p_ch_map->vch_map.num_vch; idx++) |
|---|
| 445 | { |
|---|
| 446 | if (p_vch->ch_num < p_ch_map->vch_map.vch[idx].ch_num) |
|---|
| 447 | { |
|---|
| 448 | for (idx2 = p_ch_map->vch_map.num_vch - 1; idx2 >= idx; idx2--) |
|---|
| 449 | { |
|---|
| 450 | BDBG_MSG(("move %d from %d to %d\n",p_ch_map->vch_map.vch[idx2].ch_num, idx2, idx2 + 1)); |
|---|
| 451 | bapp_util_memcpy(&p_ch_map->vch_map.vch[idx2 + 1],&p_ch_map->vch_map.vch[idx2], sizeof(vch_t)); |
|---|
| 452 | } |
|---|
| 453 | |
|---|
| 454 | bapp_util_memcpy(&p_ch_map->vch_map.vch[idx],p_vch, sizeof(vch_t)); |
|---|
| 455 | BDBG_MSG(("Add %d at %d\n",p_vch->ch_num, idx)); |
|---|
| 456 | found_slot = 1; |
|---|
| 457 | break; |
|---|
| 458 | } |
|---|
| 459 | } |
|---|
| 460 | if (!found_slot) |
|---|
| 461 | { |
|---|
| 462 | bapp_util_memcpy(&p_ch_map->vch_map.vch[p_ch_map->vch_map.num_vch],p_vch, sizeof(vch_t)); |
|---|
| 463 | BDBG_MSG(("Append %d at %d\n",p_vch->ch_num, p_ch_map->vch_map.num_vch)); |
|---|
| 464 | } |
|---|
| 465 | p_ch_map->vch_map.num_vch++; |
|---|
| 466 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 467 | } else |
|---|
| 468 | { |
|---|
| 469 | BDBG_WRN(("%s:%d mutex timeout\n", __FUNCTION__,__LINE__)); |
|---|
| 470 | } |
|---|
| 471 | } |
|---|
| 472 | |
|---|
| 473 | /* |
|---|
| 474 | Summary: |
|---|
| 475 | Check for matching entry. |
|---|
| 476 | */ |
|---|
| 477 | static bool ch_map_check_st(ch_map_t *p_ch_map, st_t *p_st) |
|---|
| 478 | { |
|---|
| 479 | int i; |
|---|
| 480 | for (i = 0; i < p_ch_map->st_map.num_st; ++i) |
|---|
| 481 | { |
|---|
| 482 | if (p_ch_map->st_map.st[i].source_id == p_st->source_id) |
|---|
| 483 | return true; |
|---|
| 484 | } |
|---|
| 485 | BDBG_MSG(("%s:%d no entry exists\n", __FUNCTION__,__LINE__)); |
|---|
| 486 | return false; |
|---|
| 487 | } |
|---|
| 488 | |
|---|
| 489 | /* |
|---|
| 490 | Summary: |
|---|
| 491 | Add a source text entry. |
|---|
| 492 | */ |
|---|
| 493 | void ch_map_add_st(ch_map_t *p_ch_map, st_t *p_st) |
|---|
| 494 | { |
|---|
| 495 | BDBG_ASSERT(p_ch_map); |
|---|
| 496 | BDBG_ASSERT(p_ch_map->p_mutex); |
|---|
| 497 | if (bapp_task_acquire_mutex(p_ch_map->p_mutex,CH_MAP_MUTEX_TIMEOUT) == b_ok) |
|---|
| 498 | { |
|---|
| 499 | if (p_ch_map->st_map.num_st == MAX_VCH) |
|---|
| 500 | { |
|---|
| 501 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 502 | BDBG_WRN(("%s:%d ENTRY LIMIT\n", __FUNCTION__,__LINE__)); |
|---|
| 503 | return; |
|---|
| 504 | } |
|---|
| 505 | |
|---|
| 506 | if (!ch_map_check_st(p_ch_map,p_st)) |
|---|
| 507 | { |
|---|
| 508 | p_ch_map->st_map.st[p_ch_map->st_map.num_st] = *p_st; |
|---|
| 509 | p_ch_map->st_map.num_st++; |
|---|
| 510 | } |
|---|
| 511 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 512 | } else |
|---|
| 513 | { |
|---|
| 514 | BDBG_WRN(("%s:%d mutex timeout\n", __FUNCTION__,__LINE__)); |
|---|
| 515 | } |
|---|
| 516 | } |
|---|
| 517 | |
|---|
| 518 | /* |
|---|
| 519 | Summary: |
|---|
| 520 | Get number of map entries. |
|---|
| 521 | */ |
|---|
| 522 | void ch_map_get_counts(ch_map_t *p_ch_map, |
|---|
| 523 | unsigned short *num_vch, |
|---|
| 524 | unsigned short *num_st, |
|---|
| 525 | unsigned char *num_freq |
|---|
| 526 | ) |
|---|
| 527 | { |
|---|
| 528 | BDBG_ASSERT(p_ch_map); |
|---|
| 529 | BDBG_ASSERT(p_ch_map->p_mutex); |
|---|
| 530 | if (bapp_task_acquire_mutex(p_ch_map->p_mutex,CH_MAP_MUTEX_TIMEOUT) == b_ok) |
|---|
| 531 | { |
|---|
| 532 | *num_vch = p_ch_map->vch_map.num_vch; |
|---|
| 533 | *num_st = p_ch_map->st_map.num_st; |
|---|
| 534 | *num_freq = p_ch_map->freq_map.num_freq; |
|---|
| 535 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 536 | } else |
|---|
| 537 | { |
|---|
| 538 | BDBG_WRN(("%s:%d mutex timeout\n", __FUNCTION__,__LINE__)); |
|---|
| 539 | } |
|---|
| 540 | } |
|---|
| 541 | |
|---|
| 542 | /* |
|---|
| 543 | Summary: |
|---|
| 544 | Get number of map entries. |
|---|
| 545 | */ |
|---|
| 546 | void ch_map_get_vch_num(ch_map_t *p_ch_map, |
|---|
| 547 | unsigned short *num_vch |
|---|
| 548 | ) |
|---|
| 549 | { |
|---|
| 550 | BDBG_ASSERT(p_ch_map); |
|---|
| 551 | BDBG_ASSERT(p_ch_map->p_mutex); |
|---|
| 552 | if (bapp_task_acquire_mutex(p_ch_map->p_mutex,CH_MAP_MUTEX_TIMEOUT) == b_ok) |
|---|
| 553 | { |
|---|
| 554 | *num_vch = p_ch_map->vch_map.num_vch; |
|---|
| 555 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 556 | } else |
|---|
| 557 | { |
|---|
| 558 | BDBG_WRN(("%s:%d mutex timeout\n", __FUNCTION__,__LINE__)); |
|---|
| 559 | } |
|---|
| 560 | } |
|---|
| 561 | /* |
|---|
| 562 | Summary: |
|---|
| 563 | Find the matching freqency info for the given the vch reference. |
|---|
| 564 | */ |
|---|
| 565 | bool ch_map_find_freq(ch_map_t *p_ch_map, vch_t *p_vch, freq_t *p_freq) |
|---|
| 566 | { |
|---|
| 567 | int idx; |
|---|
| 568 | for (idx = 0; idx < p_ch_map->freq_map.num_freq; ++idx) |
|---|
| 569 | { |
|---|
| 570 | if (p_vch->freq_idx == p_ch_map->freq_map.freq[idx].idx) |
|---|
| 571 | { |
|---|
| 572 | *p_freq = p_ch_map->freq_map.freq[idx]; |
|---|
| 573 | return true; |
|---|
| 574 | } |
|---|
| 575 | } |
|---|
| 576 | BDBG_MSG(("%s:%d frequncy %d not found\n", __FUNCTION__,__LINE__,p_vch->freq_idx)); |
|---|
| 577 | return false; |
|---|
| 578 | } |
|---|
| 579 | /* |
|---|
| 580 | Summary: |
|---|
| 581 | Find the matching source text for the given the vch reference. |
|---|
| 582 | */ |
|---|
| 583 | static bool ch_map_find_st(ch_map_t *p_ch_map, vch_t *p_vch, st_t *p_st) |
|---|
| 584 | { |
|---|
| 585 | int idx; |
|---|
| 586 | for (idx = 0; idx < p_ch_map->st_map.num_st; ++idx) |
|---|
| 587 | { |
|---|
| 588 | if (p_vch->source_id == p_ch_map->st_map.st[idx].source_id) |
|---|
| 589 | { |
|---|
| 590 | *p_st = p_ch_map->st_map.st[idx]; |
|---|
| 591 | return true; |
|---|
| 592 | } |
|---|
| 593 | } |
|---|
| 594 | return false; |
|---|
| 595 | } |
|---|
| 596 | |
|---|
| 597 | /* |
|---|
| 598 | Summary: |
|---|
| 599 | Get current channel information. |
|---|
| 600 | */ |
|---|
| 601 | bool ch_map_get_current(ch_map_t *p_ch_map, vch_t *p_vch, st_t *p_st, freq_t *p_freq) |
|---|
| 602 | { |
|---|
| 603 | bool result = false; |
|---|
| 604 | BDBG_ASSERT(p_ch_map); |
|---|
| 605 | BDBG_ASSERT(p_ch_map->p_mutex); |
|---|
| 606 | if (bapp_task_acquire_mutex(p_ch_map->p_mutex,CH_MAP_MUTEX_TIMEOUT) == b_ok) |
|---|
| 607 | { |
|---|
| 608 | if ((p_ch_map->freq_map.num_freq <= 0) || (p_ch_map->vch_map.num_vch <= 0)) |
|---|
| 609 | { |
|---|
| 610 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 611 | BDBG_MSG(("%s:%d channel map empty(%d,%d)\n", __FUNCTION__,__LINE__,p_ch_map->freq_map.num_freq,p_ch_map->vch_map.num_vch)); |
|---|
| 612 | return result; |
|---|
| 613 | } |
|---|
| 614 | |
|---|
| 615 | *p_vch = p_ch_map->vch_map.vch[p_ch_map->cur_ch]; |
|---|
| 616 | if (ch_map_find_freq(p_ch_map,p_vch,p_freq)) |
|---|
| 617 | { |
|---|
| 618 | result = true; |
|---|
| 619 | } |
|---|
| 620 | |
|---|
| 621 | if (!ch_map_find_st(p_ch_map,p_vch,p_st)) |
|---|
| 622 | { |
|---|
| 623 | p_st->name[0] = '\0'; |
|---|
| 624 | p_st->source_id = 0; |
|---|
| 625 | } |
|---|
| 626 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 627 | } else |
|---|
| 628 | { |
|---|
| 629 | BDBG_WRN(("%s:%d mutex timeout\n", __FUNCTION__,__LINE__)); |
|---|
| 630 | } |
|---|
| 631 | return result; |
|---|
| 632 | } |
|---|
| 633 | |
|---|
| 634 | /* |
|---|
| 635 | Summary: |
|---|
| 636 | Update current channel information. |
|---|
| 637 | */ |
|---|
| 638 | bool ch_map_vch_update(ch_map_t *p_ch_map, vch_t *p_vch) |
|---|
| 639 | { |
|---|
| 640 | bool result = false; |
|---|
| 641 | BDBG_ASSERT(p_ch_map); |
|---|
| 642 | BDBG_ASSERT(p_ch_map->p_mutex); |
|---|
| 643 | if (bapp_task_acquire_mutex(p_ch_map->p_mutex,CH_MAP_MUTEX_TIMEOUT) == b_ok) |
|---|
| 644 | { |
|---|
| 645 | if ((p_ch_map->freq_map.num_freq <= 0) || (p_ch_map->vch_map.num_vch <= 0)) |
|---|
| 646 | { |
|---|
| 647 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 648 | BDBG_MSG(("%s:%d channel map empty(%d,%d)\n", __FUNCTION__,__LINE__,p_ch_map->freq_map.num_freq,p_ch_map->vch_map.num_vch)); |
|---|
| 649 | return result; |
|---|
| 650 | } |
|---|
| 651 | |
|---|
| 652 | /* only update if this vch matches current vch */ |
|---|
| 653 | if ((p_ch_map->vch_map.vch[p_ch_map->cur_ch].freq_idx != p_vch->freq_idx) || |
|---|
| 654 | (p_ch_map->vch_map.vch[p_ch_map->cur_ch].source_id != p_vch->source_id) || |
|---|
| 655 | (p_ch_map->vch_map.vch[p_ch_map->cur_ch].ch_num != p_vch->ch_num) || |
|---|
| 656 | (p_ch_map->vch_map.vch[p_ch_map->cur_ch].program_num != p_vch->program_num)) |
|---|
| 657 | { |
|---|
| 658 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 659 | BDBG_WRN(("%s:%d current vch changed, abort update(%d,0x%04x,%d,%d) != (%d,0x%04x,%d,%d)\n", |
|---|
| 660 | __FUNCTION__,__LINE__, |
|---|
| 661 | p_ch_map->vch_map.vch[p_ch_map->cur_ch].freq_idx, |
|---|
| 662 | p_ch_map->vch_map.vch[p_ch_map->cur_ch].source_id, |
|---|
| 663 | p_ch_map->vch_map.vch[p_ch_map->cur_ch].ch_num, |
|---|
| 664 | p_ch_map->vch_map.vch[p_ch_map->cur_ch].program_num, |
|---|
| 665 | p_vch->freq_idx,p_vch->source_id,p_vch->ch_num,p_vch->program_num |
|---|
| 666 | )); |
|---|
| 667 | return result; |
|---|
| 668 | } |
|---|
| 669 | p_ch_map->vch_map.vch[p_ch_map->cur_ch] = *p_vch; |
|---|
| 670 | result = true; |
|---|
| 671 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 672 | } |
|---|
| 673 | else |
|---|
| 674 | { |
|---|
| 675 | BDBG_WRN(("%s:%d mutex timeout\n", __FUNCTION__,__LINE__)); |
|---|
| 676 | } |
|---|
| 677 | return result; |
|---|
| 678 | } |
|---|
| 679 | |
|---|
| 680 | /* |
|---|
| 681 | Summary: |
|---|
| 682 | Set next channel information. |
|---|
| 683 | */ |
|---|
| 684 | bool ch_map_set_next(ch_map_t *p_ch_map) |
|---|
| 685 | { |
|---|
| 686 | bool result = false; |
|---|
| 687 | int idx = 0; |
|---|
| 688 | BDBG_ASSERT(p_ch_map); |
|---|
| 689 | BDBG_ASSERT(p_ch_map->p_mutex); |
|---|
| 690 | if (bapp_task_acquire_mutex(p_ch_map->p_mutex,CH_MAP_MUTEX_TIMEOUT) == b_ok) |
|---|
| 691 | { |
|---|
| 692 | if ((p_ch_map->freq_map.num_freq <= 0) || (p_ch_map->vch_map.num_vch <= 0)) |
|---|
| 693 | { |
|---|
| 694 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 695 | return result; |
|---|
| 696 | } |
|---|
| 697 | |
|---|
| 698 | do |
|---|
| 699 | { |
|---|
| 700 | p_ch_map->cur_ch++; |
|---|
| 701 | |
|---|
| 702 | if (p_ch_map->cur_ch >= p_ch_map->vch_map.num_vch) |
|---|
| 703 | p_ch_map->cur_ch = 0; |
|---|
| 704 | |
|---|
| 705 | result = (p_ch_map->vch_map.vch[p_ch_map->cur_ch].vchflags == 0) ? true : false; |
|---|
| 706 | } while (!result && (idx++ < p_ch_map->vch_map.num_vch)); |
|---|
| 707 | |
|---|
| 708 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 709 | } else |
|---|
| 710 | { |
|---|
| 711 | BDBG_WRN(("%s:%d mutex timeout\n", __FUNCTION__,__LINE__)); |
|---|
| 712 | } |
|---|
| 713 | return result; |
|---|
| 714 | } |
|---|
| 715 | |
|---|
| 716 | |
|---|
| 717 | /* |
|---|
| 718 | Summary: |
|---|
| 719 | Set prev channel information. |
|---|
| 720 | */ |
|---|
| 721 | bool ch_map_set_prev(ch_map_t *p_ch_map) |
|---|
| 722 | { |
|---|
| 723 | bool result = false; |
|---|
| 724 | int idx = 0; |
|---|
| 725 | BDBG_ASSERT(p_ch_map); |
|---|
| 726 | BDBG_ASSERT(p_ch_map->p_mutex); |
|---|
| 727 | if (bapp_task_acquire_mutex(p_ch_map->p_mutex,CH_MAP_MUTEX_TIMEOUT) == b_ok) |
|---|
| 728 | { |
|---|
| 729 | if ((p_ch_map->freq_map.num_freq <= 0) || (p_ch_map->vch_map.num_vch <= 0)) |
|---|
| 730 | { |
|---|
| 731 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 732 | return result; |
|---|
| 733 | } |
|---|
| 734 | |
|---|
| 735 | do |
|---|
| 736 | { |
|---|
| 737 | if (p_ch_map->cur_ch == 0) |
|---|
| 738 | p_ch_map->cur_ch = p_ch_map->vch_map.num_vch - 1; |
|---|
| 739 | else |
|---|
| 740 | p_ch_map->cur_ch--; |
|---|
| 741 | result = (p_ch_map->vch_map.vch[p_ch_map->cur_ch].vchflags == 0) ? true : false; |
|---|
| 742 | } while (!result && (idx++ < p_ch_map->vch_map.num_vch)); |
|---|
| 743 | |
|---|
| 744 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 745 | } else |
|---|
| 746 | { |
|---|
| 747 | BDBG_WRN(("%s:%d mutex timeout\n", __FUNCTION__,__LINE__)); |
|---|
| 748 | } |
|---|
| 749 | return result; |
|---|
| 750 | } |
|---|
| 751 | |
|---|
| 752 | /*Summary: |
|---|
| 753 | determine if a given channel is visible (not hidden) in the channel map. |
|---|
| 754 | */ |
|---|
| 755 | bool ch_map_is_channel_visible(ch_map_t *p_ch_map, |
|---|
| 756 | unsigned short ch_num) |
|---|
| 757 | { |
|---|
| 758 | bool result = false; |
|---|
| 759 | int idx; |
|---|
| 760 | BDBG_ASSERT(p_ch_map); |
|---|
| 761 | BDBG_ASSERT(p_ch_map->p_mutex); |
|---|
| 762 | |
|---|
| 763 | if (bapp_task_acquire_mutex(p_ch_map->p_mutex,CH_MAP_MUTEX_TIMEOUT) == b_ok) |
|---|
| 764 | { |
|---|
| 765 | if ((p_ch_map->freq_map.num_freq <= 0) || (p_ch_map->vch_map.num_vch <= 0)) |
|---|
| 766 | { |
|---|
| 767 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 768 | return result; |
|---|
| 769 | } |
|---|
| 770 | |
|---|
| 771 | for (idx = 0; idx < p_ch_map->vch_map.num_vch; ++idx) |
|---|
| 772 | { |
|---|
| 773 | if (p_ch_map->vch_map.vch[idx].ch_num == ch_num) |
|---|
| 774 | { |
|---|
| 775 | if (p_ch_map->vch_map.vch[idx].vchflags == 0) |
|---|
| 776 | { |
|---|
| 777 | result = true; |
|---|
| 778 | } |
|---|
| 779 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 780 | return result;/* we are done looking, get out */ |
|---|
| 781 | } |
|---|
| 782 | } |
|---|
| 783 | |
|---|
| 784 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 785 | } else |
|---|
| 786 | { |
|---|
| 787 | BDBG_WRN(("%s:%d mutex timeout\n", __FUNCTION__,__LINE__)); |
|---|
| 788 | } |
|---|
| 789 | return result; |
|---|
| 790 | } |
|---|
| 791 | |
|---|
| 792 | |
|---|
| 793 | /* |
|---|
| 794 | Summary: |
|---|
| 795 | Set channel information by number. |
|---|
| 796 | */ |
|---|
| 797 | bool ch_map_set_ch(ch_map_t *p_ch_map, |
|---|
| 798 | unsigned short ch_num) |
|---|
| 799 | { |
|---|
| 800 | bool result = false; |
|---|
| 801 | int idx; |
|---|
| 802 | BDBG_ASSERT(p_ch_map); |
|---|
| 803 | BDBG_ASSERT(p_ch_map->p_mutex); |
|---|
| 804 | |
|---|
| 805 | if (bapp_task_acquire_mutex(p_ch_map->p_mutex,CH_MAP_MUTEX_TIMEOUT) == b_ok) |
|---|
| 806 | { |
|---|
| 807 | if ((p_ch_map->freq_map.num_freq <= 0) || (p_ch_map->vch_map.num_vch <= 0)) |
|---|
| 808 | { |
|---|
| 809 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 810 | return result; |
|---|
| 811 | } |
|---|
| 812 | |
|---|
| 813 | for (idx = 0; idx < p_ch_map->vch_map.num_vch; ++idx) |
|---|
| 814 | { |
|---|
| 815 | if (p_ch_map->vch_map.vch[idx].ch_num == ch_num) |
|---|
| 816 | { |
|---|
| 817 | p_ch_map->cur_ch = idx; |
|---|
| 818 | result = true; |
|---|
| 819 | break; |
|---|
| 820 | } |
|---|
| 821 | } |
|---|
| 822 | |
|---|
| 823 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 824 | } else |
|---|
| 825 | { |
|---|
| 826 | BDBG_WRN(("%s:%d mutex timeout\n", __FUNCTION__,__LINE__)); |
|---|
| 827 | } |
|---|
| 828 | return result; |
|---|
| 829 | } |
|---|
| 830 | |
|---|
| 831 | /* |
|---|
| 832 | Summary: |
|---|
| 833 | Set current channel given source ID. |
|---|
| 834 | */ |
|---|
| 835 | bool ch_map_set(ch_map_t *p_ch_map,unsigned short source_id) |
|---|
| 836 | { |
|---|
| 837 | bool result = false; |
|---|
| 838 | int idx; |
|---|
| 839 | BDBG_ASSERT(p_ch_map); |
|---|
| 840 | BDBG_ASSERT(p_ch_map->p_mutex); |
|---|
| 841 | |
|---|
| 842 | if (bapp_task_acquire_mutex(p_ch_map->p_mutex,CH_MAP_MUTEX_TIMEOUT) == b_ok) |
|---|
| 843 | { |
|---|
| 844 | if ((p_ch_map->freq_map.num_freq <= 0) || (p_ch_map->vch_map.num_vch <= 0)) |
|---|
| 845 | { |
|---|
| 846 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 847 | return result; |
|---|
| 848 | } |
|---|
| 849 | |
|---|
| 850 | for (idx = 0; idx < p_ch_map->vch_map.num_vch; ++idx) |
|---|
| 851 | { |
|---|
| 852 | if (p_ch_map->vch_map.vch[idx].source_id == source_id) |
|---|
| 853 | { |
|---|
| 854 | p_ch_map->cur_ch = idx; |
|---|
| 855 | result = true; |
|---|
| 856 | break; |
|---|
| 857 | } |
|---|
| 858 | } |
|---|
| 859 | |
|---|
| 860 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 861 | } else |
|---|
| 862 | { |
|---|
| 863 | BDBG_WRN(("%s:%d mutex timeout\n", __FUNCTION__,__LINE__)); |
|---|
| 864 | } |
|---|
| 865 | return result; |
|---|
| 866 | } |
|---|
| 867 | |
|---|
| 868 | /* |
|---|
| 869 | Summary: |
|---|
| 870 | try to find a source ID from the frequency vector and program number (for EAS major/minor ch#). |
|---|
| 871 | */ |
|---|
| 872 | bool ch_map_find_soure_id(ch_map_t *p_ch_map, |
|---|
| 873 | unsigned char freq_vec, |
|---|
| 874 | unsigned short prog_num, |
|---|
| 875 | unsigned short *p_source_id |
|---|
| 876 | ) |
|---|
| 877 | { |
|---|
| 878 | bool result = false; |
|---|
| 879 | int idx; |
|---|
| 880 | BDBG_ASSERT(p_ch_map); |
|---|
| 881 | BDBG_ASSERT(p_ch_map->p_mutex); |
|---|
| 882 | |
|---|
| 883 | if (bapp_task_acquire_mutex(p_ch_map->p_mutex,CH_MAP_MUTEX_TIMEOUT) == b_ok) |
|---|
| 884 | { |
|---|
| 885 | if ((p_ch_map->freq_map.num_freq <= 0) || (p_ch_map->vch_map.num_vch <= 0)) |
|---|
| 886 | { |
|---|
| 887 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 888 | return result; |
|---|
| 889 | } |
|---|
| 890 | |
|---|
| 891 | for (idx = 0; idx < p_ch_map->vch_map.num_vch; ++idx) |
|---|
| 892 | { |
|---|
| 893 | if ((p_ch_map->vch_map.vch[idx].freq_idx == freq_vec) && (p_ch_map->vch_map.vch[idx].program_num == prog_num)) |
|---|
| 894 | { |
|---|
| 895 | *p_source_id = p_ch_map->vch_map.vch[idx].source_id; |
|---|
| 896 | result = true; |
|---|
| 897 | break; |
|---|
| 898 | } |
|---|
| 899 | } |
|---|
| 900 | |
|---|
| 901 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 902 | } else |
|---|
| 903 | { |
|---|
| 904 | BDBG_WRN(("%s:%d mutex timeout\n", __FUNCTION__,__LINE__)); |
|---|
| 905 | } |
|---|
| 906 | return result; |
|---|
| 907 | } |
|---|
| 908 | |
|---|
| 909 | /* |
|---|
| 910 | Summary: |
|---|
| 911 | Output details to console. |
|---|
| 912 | */ |
|---|
| 913 | void ch_output(ch_map_t *p_ch_map) |
|---|
| 914 | { |
|---|
| 915 | int idx; |
|---|
| 916 | BDBG_ASSERT(p_ch_map); |
|---|
| 917 | BDBG_ASSERT(p_ch_map->p_mutex); |
|---|
| 918 | |
|---|
| 919 | if (bapp_task_acquire_mutex(p_ch_map->p_mutex,CH_MAP_MUTEX_TIMEOUT) == b_ok) |
|---|
| 920 | { |
|---|
| 921 | printf("const ch_map_t s_ch_map = \n{\n"); |
|---|
| 922 | printf("\t0x%08x,\n",0); |
|---|
| 923 | printf("\t%d,\n",p_ch_map->cur_ch); |
|---|
| 924 | printf("\t{ %d,\n",p_ch_map->mms_map.num_mms); |
|---|
| 925 | |
|---|
| 926 | for (idx = 0; idx < p_ch_map->mms_map.num_mms; ++idx) |
|---|
| 927 | { |
|---|
| 928 | printf("\t\t%c{ %d,%d,%d,%d }%c,\n",(idx == 0) ? '{' : ' ', |
|---|
| 929 | p_ch_map->mms_map.mms[idx].idx, p_ch_map->mms_map.mms[idx].code_rate,p_ch_map->mms_map.mms[idx].modulation,p_ch_map->mms_map.mms[idx].symbol_rate, |
|---|
| 930 | (idx == (p_ch_map->mms_map.num_mms - 1)) ? '}' : ' '); |
|---|
| 931 | } |
|---|
| 932 | printf("\t},\n"); |
|---|
| 933 | |
|---|
| 934 | printf("\t{ %d,\n",p_ch_map->freq_map.num_freq); |
|---|
| 935 | |
|---|
| 936 | for (idx = 0; idx < p_ch_map->freq_map.num_freq; ++idx) |
|---|
| 937 | { |
|---|
| 938 | printf("\t\t%c{ %d,%d }%c,\n",(idx == 0) ? '{' : ' ', |
|---|
| 939 | p_ch_map->freq_map.freq[idx].idx, p_ch_map->freq_map.freq[idx].freq_khz, |
|---|
| 940 | (idx == (p_ch_map->freq_map.num_freq - 1)) ? '}' : ' '); |
|---|
| 941 | } |
|---|
| 942 | printf("\t},\n"); |
|---|
| 943 | |
|---|
| 944 | printf("\t{ %d,\n",p_ch_map->st_map.num_st); |
|---|
| 945 | |
|---|
| 946 | for (idx = 0; idx < p_ch_map->st_map.num_st; ++idx) |
|---|
| 947 | { |
|---|
| 948 | printf("\t\t%c{ 0x%04x,\"%s\" }%c,\n",(idx == 0) ? '{' : ' ', |
|---|
| 949 | p_ch_map->st_map.st[idx].source_id, p_ch_map->st_map.st[idx].name, |
|---|
| 950 | (idx == (p_ch_map->st_map.num_st - 1)) ? '}' : ' '); |
|---|
| 951 | } |
|---|
| 952 | printf("\t},\n"); |
|---|
| 953 | |
|---|
| 954 | printf("\t{ %d,\n",p_ch_map->vch_map.num_vch); |
|---|
| 955 | |
|---|
| 956 | for (idx = 0; idx < p_ch_map->vch_map.num_vch; ++idx) |
|---|
| 957 | { |
|---|
| 958 | #if (MAX_AUDIO_PIDS == 8) |
|---|
| 959 | printf("\t\t%c{ %d,0x%04x,%d,%d,%d,%d,%d,0x%04x,0x%04x,0x%04x,0x%04x,0x%04x,0x%04x,0x%04x,0x%04x,0x%04x,0x%04x,0x%04x,0x%04x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,%c,%c,%c,%c,%c,%c,%c,%c,%c,%c,%c,%c,%c,%c,%c,%c,%c,%c,%c,%c,%c,%c,%c,%c, },\n",(idx == 0) ? '{' : ' ', |
|---|
| 960 | p_ch_map->vch_map.vch[idx].ch_num, p_ch_map->vch_map.vch[idx].source_id, |
|---|
| 961 | p_ch_map->vch_map.vch[idx].program_num, p_ch_map->vch_map.vch[idx].freq_idx, |
|---|
| 962 | p_ch_map->vch_map.vch[idx].flags, |
|---|
| 963 | p_ch_map->vch_map.vch[idx].num_audio, |
|---|
| 964 | p_ch_map->vch_map.vch[idx].cur_audio, |
|---|
| 965 | p_ch_map->vch_map.vch[idx].pcr_pid, |
|---|
| 966 | p_ch_map->vch_map.vch[idx].scte127_pid, |
|---|
| 967 | p_ch_map->vch_map.vch[idx].video_pid, |
|---|
| 968 | p_ch_map->vch_map.vch[idx].ca_pid, |
|---|
| 969 | p_ch_map->vch_map.vch[idx].audio_pid[0],p_ch_map->vch_map.vch[idx].audio_pid[1],p_ch_map->vch_map.vch[idx].audio_pid[2],p_ch_map->vch_map.vch[idx].audio_pid[3], |
|---|
| 970 | p_ch_map->vch_map.vch[idx].audio_pid[4],p_ch_map->vch_map.vch[idx].audio_pid[5],p_ch_map->vch_map.vch[idx].audio_pid[6],p_ch_map->vch_map.vch[idx].audio_pid[7], |
|---|
| 971 | p_ch_map->vch_map.vch[idx].audio_type[0],p_ch_map->vch_map.vch[idx].audio_type[1],p_ch_map->vch_map.vch[idx].audio_type[2],p_ch_map->vch_map.vch[idx].audio_type[3], |
|---|
| 972 | p_ch_map->vch_map.vch[idx].audio_type[4],p_ch_map->vch_map.vch[idx].audio_type[5],p_ch_map->vch_map.vch[idx].audio_type[6],p_ch_map->vch_map.vch[idx].audio_type[7], |
|---|
| 973 | p_ch_map->vch_map.vch[idx].audio_lang[0][0],p_ch_map->vch_map.vch[idx].audio_lang[0][1],p_ch_map->vch_map.vch[idx].audio_lang[0][2], |
|---|
| 974 | p_ch_map->vch_map.vch[idx].audio_lang[1][0],p_ch_map->vch_map.vch[idx].audio_lang[1][1],p_ch_map->vch_map.vch[idx].audio_lang[1][2], |
|---|
| 975 | p_ch_map->vch_map.vch[idx].audio_lang[2][0],p_ch_map->vch_map.vch[idx].audio_lang[2][1],p_ch_map->vch_map.vch[idx].audio_lang[2][2], |
|---|
| 976 | p_ch_map->vch_map.vch[idx].audio_lang[3][0],p_ch_map->vch_map.vch[idx].audio_lang[3][1],p_ch_map->vch_map.vch[idx].audio_lang[3][2], |
|---|
| 977 | p_ch_map->vch_map.vch[idx].audio_lang[4][0],p_ch_map->vch_map.vch[idx].audio_lang[4][1],p_ch_map->vch_map.vch[idx].audio_lang[4][2], |
|---|
| 978 | p_ch_map->vch_map.vch[idx].audio_lang[5][0],p_ch_map->vch_map.vch[idx].audio_lang[5][1],p_ch_map->vch_map.vch[idx].audio_lang[5][2], |
|---|
| 979 | p_ch_map->vch_map.vch[idx].audio_lang[6][0],p_ch_map->vch_map.vch[idx].audio_lang[6][1],p_ch_map->vch_map.vch[idx].audio_lang[6][2], |
|---|
| 980 | p_ch_map->vch_map.vch[idx].audio_lang[7][0],p_ch_map->vch_map.vch[idx].audio_lang[7][1],p_ch_map->vch_map.vch[idx].audio_lang[7][2], |
|---|
| 981 | (idx == (p_ch_map->vch_map.num_vch - 1)) ? '}' : ' '); |
|---|
| 982 | #else |
|---|
| 983 | printf("\t\t%c{ %d,0x%04x,%d,%d,%d,%d,%d,0x%04x,0x%04x,0x%04x,0x%04x,0x%04x,0x%04x,0x%04x,0x%02x,0x%02x,0x%02x,%c,%c,%c,%c,%c,%c,%c,%c,%c },\n",(idx == 0) ? '{' : ' ', |
|---|
| 984 | p_ch_map->vch_map.vch[idx].ch_num, p_ch_map->vch_map.vch[idx].source_id, |
|---|
| 985 | p_ch_map->vch_map.vch[idx].program_num, p_ch_map->vch_map.vch[idx].freq_idx, |
|---|
| 986 | p_ch_map->vch_map.vch[idx].vchflags, |
|---|
| 987 | p_ch_map->vch_map.vch[idx].num_audio, |
|---|
| 988 | p_ch_map->vch_map.vch[idx].cur_audio, |
|---|
| 989 | p_ch_map->vch_map.vch[idx].pcr_pid, |
|---|
| 990 | p_ch_map->vch_map.vch[idx].scte127_pid, |
|---|
| 991 | p_ch_map->vch_map.vch[idx].video_pid, |
|---|
| 992 | p_ch_map->vch_map.vch[idx].ca_pid, |
|---|
| 993 | p_ch_map->vch_map.vch[idx].audio_pid[0],p_ch_map->vch_map.vch[idx].audio_pid[1],p_ch_map->vch_map.vch[idx].audio_pid[2], |
|---|
| 994 | p_ch_map->vch_map.vch[idx].audio_type[0],p_ch_map->vch_map.vch[idx].audio_type[1],p_ch_map->vch_map.vch[idx].audio_type[2], |
|---|
| 995 | p_ch_map->vch_map.vch[idx].audio_lang[0][0],p_ch_map->vch_map.vch[idx].audio_lang[0][1],p_ch_map->vch_map.vch[idx].audio_lang[0][2], |
|---|
| 996 | p_ch_map->vch_map.vch[idx].audio_lang[1][0],p_ch_map->vch_map.vch[idx].audio_lang[1][1],p_ch_map->vch_map.vch[idx].audio_lang[1][2], |
|---|
| 997 | p_ch_map->vch_map.vch[idx].audio_lang[2][0],p_ch_map->vch_map.vch[idx].audio_lang[2][1],p_ch_map->vch_map.vch[idx].audio_lang[2][2], |
|---|
| 998 | (idx == (p_ch_map->vch_map.num_vch - 1)) ? '}' : ' '); |
|---|
| 999 | #endif |
|---|
| 1000 | } |
|---|
| 1001 | printf("\t},\n"); |
|---|
| 1002 | |
|---|
| 1003 | printf("};\n"); |
|---|
| 1004 | |
|---|
| 1005 | bapp_task_release_mutex(p_ch_map->p_mutex); |
|---|
| 1006 | } else |
|---|
| 1007 | { |
|---|
| 1008 | BDBG_WRN(("%s:%d mutex timeout\n", __FUNCTION__,__LINE__)); |
|---|
| 1009 | } |
|---|
| 1010 | return; |
|---|
| 1011 | } |
|---|
| 1012 | |
|---|
| 1013 | |
|---|