| 1 | /** |
| 2 | |
| 3 | \file as10x_cmd_stream.c |
| 4 | |
| 5 | \author: S. Martinelli |
| 6 | |
| 7 | ----------------------------------------------------------------------------\n |
| 8 | (c) Copyright Abilis Systems SARL 2005-2009 All rigths reserved \n |
| 9 | www.abilis.com \n |
| 10 | ----------------------------------------------------------------------------\n |
| 11 | |
| 12 | \brief AS10x CMD, stream services |
| 13 | |
| 14 | AS10x CMD management: build command buffer, send command through |
| 15 | selected port and wait for the response when required. |
| 16 | |
| 17 | */ |
| 18 | |
| 19 | |
| 20 | #if defined(LINUX) && defined(__KERNEL__) /* linux kernel implementation */ |
| 21 | #include <linux/kernel.h> |
| 22 | #include "as102_drv.h" |
| 23 | #elif defined(WIN32) |
| 24 | #if defined(DDK) /* win32 ddk implementation */ |
| 25 | #include "wdm.h" |
| 26 | #include "Device.h" |
| 27 | #include "endian_mgmt.h" /* FIXME */ |
| 28 | #else /* win32 sdk implementation */ |
| 29 | #include <windows.h> |
| 30 | #include "types.h" |
| 31 | #include "util.h" |
| 32 | #include "as10x_handle.h" |
| 33 | #include "endian_mgmt.h" |
| 34 | #endif |
| 35 | #else /* all other cases */ |
| 36 | #include <string.h> |
| 37 | #include "types.h" |
| 38 | #include "util.h" |
| 39 | #include "as10x_handle.h" |
| 40 | #include "endian_mgmt.h" /* FIXME */ |
| 41 | #endif /* __KERNEL__ */ |
| 42 | |
| 43 | #include "as10x_cmd.h" |
| 44 | |
| 45 | |
| 46 | /** |
| 47 | \brief send add filter command to AS10x |
| 48 | \param phandle: pointer to AS10x handle |
| 49 | \param filter: TSFilter filter for DVB-T |
| 50 | \param pfilter_handle: pointer where to store filter handle |
| 51 | \return 0 when no error, < 0 in case of error. |
| 52 | \callgraph |
| 53 | */ |
| 54 | int as10x_cmd_add_PID_filter(as10x_handle_t *phandle, |
| 55 | struct as10x_ts_filter *filter) |
| 56 | { |
| 57 | int error; |
| 58 | struct as10x_cmd_t *pcmd, *prsp; |
| 59 | |
| 60 | ENTER(); |
| 61 | |
| 62 | pcmd = phandle->cmd; |
| 63 | prsp = phandle->rsp; |
| 64 | |
| 65 | /* prepare command */ |
| 66 | as10x_cmd_build(pcmd, (++phandle->cmd_xid), |
| 67 | sizeof(pcmd->body.add_pid_filter.req)); |
| 68 | |
| 69 | /* fill command */ |
| 70 | pcmd->body.add_pid_filter.req.proc_id = |
| 71 | cpu_to_le16(CONTROL_PROC_SETFILTER); |
| 72 | pcmd->body.add_pid_filter.req.pid = cpu_to_le16(filter->pid); |
| 73 | pcmd->body.add_pid_filter.req.stream_type = filter->type; |
| 74 | |
| 75 | if (filter->idx < 16) |
| 76 | pcmd->body.add_pid_filter.req.idx = filter->idx; |
| 77 | else |
| 78 | pcmd->body.add_pid_filter.req.idx = 0xFF; |
| 79 | |
| 80 | /* send command */ |
| 81 | if (phandle->ops->xfer_cmd) { |
| 82 | error = phandle->ops->xfer_cmd(phandle, (uint8_t *) pcmd, |
| 83 | sizeof(pcmd->body.add_pid_filter.req) |
| 84 | + HEADER_SIZE, (uint8_t *) prsp, |
| 85 | sizeof(prsp->body.add_pid_filter.rsp) |
| 86 | + HEADER_SIZE); |
| 87 | } else { |
| 88 | error = AS10X_CMD_ERROR; |
| 89 | } |
| 90 | |
| 91 | if (error < 0) |
| 92 | goto out; |
| 93 | |
| 94 | /* parse response */ |
| 95 | error = as10x_rsp_parse(prsp, CONTROL_PROC_SETFILTER_RSP); |
| 96 | |
| 97 | if (error == 0) { |
| 98 | /* Response OK -> get response data */ |
| 99 | filter->idx = prsp->body.add_pid_filter.rsp.filter_id; |
| 100 | } |
| 101 | |
| 102 | out: |
| 103 | LEAVE(); |
| 104 | return error; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | \brief Send delete filter command to AS10x |
| 109 | \param phandle: pointer to AS10x handle |
| 110 | \param filter_handle: filter handle |
| 111 | \return 0 when no error, < 0 in case of error. |
| 112 | \callgraph |
| 113 | */ |
| 114 | int as10x_cmd_del_PID_filter(as10x_handle_t *phandle, |
| 115 | uint16_t pid_value) |
| 116 | { |
| 117 | int error; |
| 118 | struct as10x_cmd_t *pcmd, *prsp; |
| 119 | |
| 120 | ENTER(); |
| 121 | |
| 122 | pcmd = phandle->cmd; |
| 123 | prsp = phandle->rsp; |
| 124 | |
| 125 | /* prepare command */ |
| 126 | as10x_cmd_build(pcmd, (++phandle->cmd_xid), |
| 127 | sizeof(pcmd->body.del_pid_filter.req)); |
| 128 | |
| 129 | /* fill command */ |
| 130 | pcmd->body.del_pid_filter.req.proc_id = |
| 131 | cpu_to_le16(CONTROL_PROC_REMOVEFILTER); |
| 132 | pcmd->body.del_pid_filter.req.pid = cpu_to_le16(pid_value); |
| 133 | |
| 134 | /* send command */ |
| 135 | if (phandle->ops->xfer_cmd) { |
| 136 | error = phandle->ops->xfer_cmd(phandle, (uint8_t *) pcmd, |
| 137 | sizeof(pcmd->body.del_pid_filter.req) |
| 138 | + HEADER_SIZE, (uint8_t *) prsp, |
| 139 | sizeof(prsp->body.del_pid_filter.rsp) |
| 140 | + HEADER_SIZE); |
| 141 | } else { |
| 142 | error = AS10X_CMD_ERROR; |
| 143 | } |
| 144 | |
| 145 | if (error < 0) |
| 146 | goto out; |
| 147 | |
| 148 | /* parse response */ |
| 149 | error = as10x_rsp_parse(prsp, CONTROL_PROC_REMOVEFILTER_RSP); |
| 150 | |
| 151 | out: |
| 152 | LEAVE(); |
| 153 | return error; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | \brief Send start streaming command to AS10x |
| 158 | \param phandle: pointer to AS10x handle |
| 159 | \return 0 when no error, < 0 in case of error. |
| 160 | \callgraph |
| 161 | */ |
| 162 | int as10x_cmd_start_streaming(as10x_handle_t *phandle) |
| 163 | { |
| 164 | int error; |
| 165 | struct as10x_cmd_t *pcmd, *prsp; |
| 166 | |
| 167 | ENTER(); |
| 168 | |
| 169 | pcmd = phandle->cmd; |
| 170 | prsp = phandle->rsp; |
| 171 | |
| 172 | /* prepare command */ |
| 173 | as10x_cmd_build(pcmd, (++phandle->cmd_xid), |
| 174 | sizeof(pcmd->body.start_streaming.req)); |
| 175 | |
| 176 | /* fill command */ |
| 177 | pcmd->body.start_streaming.req.proc_id = |
| 178 | cpu_to_le16(CONTROL_PROC_START_STREAMING); |
| 179 | |
| 180 | /* send command */ |
| 181 | if (phandle->ops->xfer_cmd) { |
| 182 | error = phandle->ops->xfer_cmd(phandle, (uint8_t *) pcmd, |
| 183 | sizeof(pcmd->body.start_streaming.req) |
| 184 | + HEADER_SIZE, (uint8_t *) prsp, |
| 185 | sizeof(prsp->body.start_streaming.rsp) |
| 186 | + HEADER_SIZE); |
| 187 | } else { |
| 188 | error = AS10X_CMD_ERROR; |
| 189 | } |
| 190 | |
| 191 | if (error < 0) |
| 192 | goto out; |
| 193 | |
| 194 | /* parse response */ |
| 195 | error = as10x_rsp_parse(prsp, CONTROL_PROC_START_STREAMING_RSP); |
| 196 | |
| 197 | out: |
| 198 | LEAVE(); |
| 199 | return error; |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | \brief Send stop streaming command to AS10x |
| 204 | \param phandle: pointer to AS10x handle |
| 205 | \return 0 when no error, < 0 in case of error. |
| 206 | \callgraph |
| 207 | */ |
| 208 | int as10x_cmd_stop_streaming(as10x_handle_t *phandle) |
| 209 | { |
| 210 | int8_t error; |
| 211 | struct as10x_cmd_t *pcmd, *prsp; |
| 212 | |
| 213 | ENTER(); |
| 214 | |
| 215 | pcmd = phandle->cmd; |
| 216 | prsp = phandle->rsp; |
| 217 | |
| 218 | /* prepare command */ |
| 219 | as10x_cmd_build(pcmd, (++phandle->cmd_xid), |
| 220 | sizeof(pcmd->body.stop_streaming.req)); |
| 221 | |
| 222 | /* fill command */ |
| 223 | pcmd->body.stop_streaming.req.proc_id = |
| 224 | cpu_to_le16(CONTROL_PROC_STOP_STREAMING); |
| 225 | |
| 226 | /* send command */ |
| 227 | if (phandle->ops->xfer_cmd) { |
| 228 | error = phandle->ops->xfer_cmd(phandle, (uint8_t *) pcmd, |
| 229 | sizeof(pcmd->body.stop_streaming.req) |
| 230 | + HEADER_SIZE, (uint8_t *) prsp, |
| 231 | sizeof(prsp->body.stop_streaming.rsp) |
| 232 | + HEADER_SIZE); |
| 233 | } else { |
| 234 | error = AS10X_CMD_ERROR; |
| 235 | } |
| 236 | |
| 237 | if (error < 0) |
| 238 | goto out; |
| 239 | |
| 240 | /* parse response */ |
| 241 | error = as10x_rsp_parse(prsp, CONTROL_PROC_STOP_STREAMING_RSP); |
| 242 | |
| 243 | out: |
| 244 | LEAVE(); |
| 245 | return error; |
| 246 | } |
| 247 | |
| 248 | |