* Decode a chunk of samples. * * The calls to this function must provide the samples that shall be * used by the protocol decoder * - in the correct order ([...]5, 6, 4, 7, 8[...] is a bug), * - starting from sample zero (2, 3, 4, 5, 6[...] is a bug), * - consecutively, with no gaps (0, 1, 2, 4, 5[...] is a bug). * * The start- and end-sample numbers are absolute sample numbers (relativ
| 1201 | * @private |
| 1202 | */ |
| 1203 | SRD_PRIV int srd_inst_decode(struct srd_decoder_inst *di, |
| 1204 | uint64_t abs_start_samplenum, uint64_t abs_end_samplenum, |
| 1205 | const uint8_t **inbuf, const uint8_t *inbuf_const, uint64_t inbuflen, |
| 1206 | char **error) |
| 1207 | { |
| 1208 | /* Return an error upon unusable input. */ |
| 1209 | if (!di) { |
| 1210 | *error = g_strdup("empty decoder instance"); |
| 1211 | return SRD_ERR_ARG; |
| 1212 | } |
| 1213 | if (!inbuf) { |
| 1214 | *error = g_strdup("NULL buffer pointer"); |
| 1215 | return SRD_ERR_ARG; |
| 1216 | } |
| 1217 | if (inbuflen == 0) { |
| 1218 | *error = g_strdup("empty buffer"); |
| 1219 | return SRD_ERR_ARG; |
| 1220 | } |
| 1221 | |
| 1222 | if (di->first_pos) { |
| 1223 | di->abs_cur_samplenum = abs_start_samplenum; |
| 1224 | } |
| 1225 | |
| 1226 | if (abs_start_samplenum != di->abs_cur_samplenum || |
| 1227 | abs_end_samplenum < abs_start_samplenum) { |
| 1228 | srd_dbg("Incorrect sample numbers: start=%" PRIu64 ", cur=%" |
| 1229 | PRIu64 ", end=%" PRIu64 ".", abs_start_samplenum, |
| 1230 | di->abs_cur_samplenum, abs_end_samplenum); |
| 1231 | return SRD_ERR_ARG; |
| 1232 | } |
| 1233 | |
| 1234 | srd_dbg("Decoding: abs start sample %" PRIu64 ", abs end sample %" |
| 1235 | PRIu64 " (%" PRIu64 " samples, %" PRIu64 " bytes), instance %s.", |
| 1236 | abs_start_samplenum, abs_end_samplenum, |
| 1237 | abs_end_samplenum - abs_start_samplenum, inbuflen, di->inst_id); |
| 1238 | |
| 1239 | /* |
| 1240 | If this is the first call, start the worker thread. |
| 1241 | One session may be have more decoder,so more thread will be created |
| 1242 | */ |
| 1243 | if (!di->thread_handle) { |
| 1244 | srd_dbg("No worker thread for this decoder stack " |
| 1245 | "exists yet, creating one: %s.", di->inst_id); |
| 1246 | |
| 1247 | di->thread_handle = g_thread_new(di->inst_id, |
| 1248 | di_thread, di); |
| 1249 | } |
| 1250 | |
| 1251 | /* Push the new sample chunk to the worker thread. */ |
| 1252 | g_mutex_lock(&di->data_mutex); |
| 1253 | di->abs_start_samplenum = abs_start_samplenum & ~7ULL; |
| 1254 | di->abs_end_samplenum = abs_end_samplenum; |
| 1255 | di->inbuf = inbuf; |
| 1256 | di->inbuf_const = inbuf_const; |
| 1257 | di->inbuflen = inbuflen; |
| 1258 | di->got_new_samples = TRUE; |
| 1259 | di->handled_all_samples = FALSE; |
| 1260 |