| 1 | /* |
|---|
| 2 | Summary: |
|---|
| 3 | Callback function normally called when a complete message has |
|---|
| 4 | * been received and passed the filter criteria. |
|---|
| 5 | */ |
|---|
| 6 | #ifdef DEBUG_RRT |
|---|
| 7 | static void chm_output_rrt(chm_mgr_t *p_chm); |
|---|
| 8 | #endif |
|---|
| 9 | static void * chm_smessage_rrt_callback(void * context, size_t size) |
|---|
| 10 | { |
|---|
| 11 | chm_mgr_t * p_chm = (chm_mgr_t*)context; |
|---|
| 12 | PSIP_RRT_header header; |
|---|
| 13 | bapp_t *p_app = (bapp_t*)p_chm->p_app; |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | p_chm->rrt_cnt++; |
|---|
| 17 | |
|---|
| 18 | PSIP_RRT_getHeader(p_chm->rrt_buf, &header); |
|---|
| 19 | |
|---|
| 20 | if ((header.rating_region == 1) || ((size == p_app->settings.rrt_settings.rrt_size) && (memcmp(p_chm->rrt_buf,p_app->settings.rrt_settings.rrt, size) == 0))) |
|---|
| 21 | { |
|---|
| 22 | BDBG_WRN(("RRTs region 1 or they match so don't update\n")); |
|---|
| 23 | return(void*)p_chm->rrt_buf; |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | #ifdef DEBUG_RRT |
|---|
| 27 | chm_output_rrt(p_chm); /* DEBUG ONLY */ |
|---|
| 28 | #endif |
|---|
| 29 | p_chm->rrt_evt.type = eCHM_EVT_RRT; |
|---|
| 30 | p_chm->rrt_evt.size = size; |
|---|
| 31 | memcpy(p_chm->rrt_evt.rrt,p_chm->rrt_buf,size); |
|---|
| 32 | |
|---|
| 33 | chm_post_app_event_cb(p_chm,(chm_event_t*)&p_chm->rrt_evt); |
|---|
| 34 | |
|---|
| 35 | return(void*)p_chm->rrt_buf; |
|---|
| 36 | } |
|---|
| 37 | /* |
|---|
| 38 | Summary: |
|---|
| 39 | Get the RRT. return non-zero on failure |
|---|
| 40 | */ |
|---|
| 41 | |
|---|
| 42 | static int chm_rrt_start(chm_mgr_t *p_chm, /* Channel manager reference */ |
|---|
| 43 | unsigned short network_pid) |
|---|
| 44 | { |
|---|
| 45 | int cerr; |
|---|
| 46 | smessage_stream_params_t params; |
|---|
| 47 | |
|---|
| 48 | cerr = eCHM_ERR_OK; |
|---|
| 49 | BDBG_MSG(("%s:%d (0x%04x)",__FUNCTION__, __LINE__,network_pid)); |
|---|
| 50 | |
|---|
| 51 | chm_rrt_stop(p_chm); |
|---|
| 52 | |
|---|
| 53 | p_chm->rrt_msg = smessage_open(smessage_format_psi); |
|---|
| 54 | if (NULL == p_chm->rrt_msg) |
|---|
| 55 | { |
|---|
| 56 | BDBG_ERR(("%s:%d",__FILE__, __LINE__)); |
|---|
| 57 | cerr = eCHM_ERR_FAILED; |
|---|
| 58 | goto ExitFunc; |
|---|
| 59 | } |
|---|
| 60 | smessage_stream_params_init(¶ms, p_chm->rrt_msg); |
|---|
| 61 | params.band = p_chm->band; |
|---|
| 62 | params.pid = (uint16_t)network_pid; |
|---|
| 63 | params.filter.coef[0] = 0xCA; |
|---|
| 64 | params.filter.mask[0] = 0x00; |
|---|
| 65 | params.buffer = p_chm->rrt_buf; |
|---|
| 66 | params.buffer_size = RRT_BUF_LEN; |
|---|
| 67 | /* processing is done in callback */ |
|---|
| 68 | params.data_ready_callback = chm_smessage_rrt_callback; |
|---|
| 69 | params.overflow = NULL; |
|---|
| 70 | params.callback_context = (void *)p_chm; |
|---|
| 71 | BDBG_WRN(("%s\n",__FUNCTION__)); |
|---|
| 72 | if (b_ok != smessage_start(¶ms, p_chm->rrt_msg)) |
|---|
| 73 | { |
|---|
| 74 | BDBG_ERR(("%s:%d",__FILE__, __LINE__)); |
|---|
| 75 | cerr = eCHM_ERR_FAILED; |
|---|
| 76 | } |
|---|
| 77 | ExitFunc: |
|---|
| 78 | return cerr; |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | /* |
|---|
| 82 | Summary: |
|---|
| 83 | Stop the RRT. return non-zero on failure |
|---|
| 84 | */ |
|---|
| 85 | static void chm_rrt_stop(chm_mgr_t *p_chm) |
|---|
| 86 | { |
|---|
| 87 | if (NULL != p_chm->rrt_msg) |
|---|
| 88 | { |
|---|
| 89 | BDBG_WRN(("%s\n",__FUNCTION__)); |
|---|
| 90 | if (b_ok != smessage_stop(p_chm->rrt_msg)) |
|---|
| 91 | { |
|---|
| 92 | BDBG_ERR(("%s:%d",__FUNCTION__, __LINE__)); |
|---|
| 93 | return; |
|---|
| 94 | } |
|---|
| 95 | smessage_close(p_chm->rrt_msg); |
|---|
| 96 | p_chm->rrt_msg = NULL; |
|---|
| 97 | } |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | #ifdef DEBUG_RRT |
|---|
| 101 | static void chm_output_rrt(chm_mgr_t *p_chm) |
|---|
| 102 | { |
|---|
| 103 | PSIP_RRT_header header; |
|---|
| 104 | PSIP_RRT_dimension dim; |
|---|
| 105 | PSIP_RRT_value val; |
|---|
| 106 | int dim_idx,val_idx; |
|---|
| 107 | char tmp_str[64]; |
|---|
| 108 | |
|---|
| 109 | if (p_chm->rrt_cnt <= 0) |
|---|
| 110 | return; |
|---|
| 111 | |
|---|
| 112 | PSIP_RRT_getHeader(p_chm->rrt_buf, &header); |
|---|
| 113 | if (chm_process_mss(p_chm,header.p_rating_region_name_text,tmp_str,64) == 0) |
|---|
| 114 | { |
|---|
| 115 | BDBG_WRN(("RRT %8s",tmp_str)); |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | for (dim_idx = 0; dim_idx < header.dimensions_defined; ++dim_idx) |
|---|
| 119 | { |
|---|
| 120 | if (PSIP_RRT_getDimension(p_chm->rrt_buf,dim_idx,&dim) != BERR_SUCCESS) |
|---|
| 121 | continue; |
|---|
| 122 | |
|---|
| 123 | if (chm_process_mss(p_chm,dim.p_dimension_name_text,tmp_str,sizeof(tmp_str)) == 0) |
|---|
| 124 | { |
|---|
| 125 | BDBG_WRN((" RRT[%d] %8s(%d)",dim_idx,tmp_str,dim.graduated_scale)); |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | for (val_idx = 0; val_idx < dim.values_defined; ++val_idx) |
|---|
| 129 | { |
|---|
| 130 | if (PSIP_RRT_getValue(p_chm->rrt_buf,dim_idx,val_idx,&val) != BERR_SUCCESS) |
|---|
| 131 | continue; |
|---|
| 132 | |
|---|
| 133 | if (chm_process_mss(p_chm,val.p_rating_value_text,tmp_str,sizeof(tmp_str)) == 0) |
|---|
| 134 | { |
|---|
| 135 | BDBG_WRN((" RRT[%d,%d] %8s",dim_idx,val_idx,tmp_str)); |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | if (chm_process_mss(p_chm,val.p_abbrev_rating_value_text,tmp_str,sizeof(tmp_str)) == 0) |
|---|
| 139 | { |
|---|
| 140 | BDBG_WRN((" RRT[%d,%d] %8s",dim_idx,val_idx,tmp_str)); |
|---|
| 141 | } |
|---|
| 142 | } |
|---|
| 143 | } |
|---|
| 144 | } |
|---|
| 145 | #endif |
|---|