Changeset 4275:2a5ba5fd0120 in roaraudio
- Timestamp:
- 08/28/10 15:56:34 (14 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
include/libroar/ltm.h
r4265 r4275 39 39 #include "libroar.h" 40 40 41 struct roar_ltm_result; 42 41 43 int roar_ltm_register(struct roar_connection * con, int mt, int window, int * streams, size_t slen); 42 44 int roar_ltm_unregister(struct roar_connection * con, int mt, int window, int * streams, size_t slen); 43 45 46 /* 44 47 ssize_t roar_ltm_get_raw(struct roar_connection * con, int mt, int window, int * streams, size_t slen, void * buf, size_t * buflen, int64_t ** array); 45 48 46 49 int64_t roar_ltm_extract(int64_t * buf, size_t len, int mt, int req); 47 50 int64_t roar_ltm_extract1(int64_t * buf, size_t len, int mt, int req); 51 */ 52 53 struct roar_ltm_result * roar_ltm_get(struct roar_connection * con, int mt, int window, int * streams, size_t slen, struct roar_ltm_result * oldresult); 54 55 #define roar_ltm_freeres(x) roar_mm_free((x)) 56 57 int roar_ltm_get_numstreams(struct roar_ltm_result * res); 58 int roar_ltm_get_mt(struct roar_ltm_result * res); 59 int roar_ltm_get_window(struct roar_ltm_result * res); 60 61 int roar_ltm_get_numchans(struct roar_ltm_result * res, int streamidx); 62 int64_t roar_ltm_extract(struct roar_ltm_result * res, int mt, int streamidx, int channel); 48 63 49 64 #endif -
libroar/ltm.c
r4269 r4275 35 35 36 36 #include "libroar.h" 37 38 struct roar_ltm_result { 39 int mt; 40 int window; 41 size_t streams; 42 size_t nummt; 43 size_t structlen; 44 int64_t data[1]; 45 }; 37 46 38 47 static int roar_ltm_numbits(int f) { … … 140 149 } 141 150 151 /* 142 152 ssize_t roar_ltm_get_raw(struct roar_connection * con, 143 153 int mt, int window, … … 211 221 return *buf; 212 222 } 223 */ 224 225 struct roar_ltm_result * roar_ltm_get(struct roar_connection * con, 226 int mt, int window, 227 int * streams, size_t slen, 228 struct roar_ltm_result * oldresult) { 229 struct roar_ltm_result * res = NULL; 230 struct roar_message mes; 231 size_t needed_structlen = 0; 232 uint16_t * d16; 233 int64_t * d64; 234 char * buf = NULL; 235 int ret; 236 int i; 237 238 if ( con == NULL ) 239 return NULL; 240 241 if ( streams == NULL || slen == 0 ) 242 return NULL; 243 244 if ( roar_ltm_pack_req(mt, window, streams, slen, &mes, &buf, ROAR_LTM_SST_GET_RAW) == -1 ) 245 return NULL; 246 247 ret = roar_req(con, &mes, &buf); 248 249 if ( ret == -1 || mes.cmd != ROAR_CMD_OK ) { 250 if ( buf != NULL ) 251 free(buf); 252 return NULL; 253 } 254 255 if ( buf == NULL ) { 256 d16 = (uint16_t*)&(mes.data); 257 d64 = ( int64_t*)&(mes.data); 258 } else { 259 d16 = (uint16_t*)buf; 260 d64 = ( int64_t*)buf; 261 } 262 263 for (i = 0; i < 8; i++) { 264 d16[i] = ROAR_NET2HOST64(d16[i]); 265 } 266 267 for (i = 2; i < mes.datalen/8; i++) { 268 d64[i] = ROAR_NET2HOST64(d64[i]); 269 } 270 271 needed_structlen = sizeof(struct roar_ltm_result) + mes.datalen - 16; 272 273 if ( oldresult != NULL ) { 274 if ( oldresult->structlen >= needed_structlen ) { 275 res = oldresult; 276 needed_structlen = oldresult->structlen; 277 } else { 278 roar_ltm_freeres(oldresult); 279 } 280 } else { 281 res = roar_mm_malloc(needed_structlen); 282 } 283 284 if ( res == NULL ) { 285 if ( buf != NULL ) 286 free(buf); 287 return NULL; 288 } 289 290 memset(res, 0, needed_structlen); 291 res->structlen = needed_structlen; 292 293 res->mt = mt; 294 res->window = window; 295 res->streams = slen; 296 res->nummt = roar_ltm_numbits(mt); 297 298 memcpy(res->data, &(d64[2]), mes.datalen - 16); 299 300 if ( buf != NULL ) 301 free(buf); 302 return res; 303 } 304 305 #define _CKNULL(x) if ( (x) == NULL ) return -1 306 #define _RETMEMBERCKED(x,m) _CKNULL(x); return (x)->m 307 308 int roar_ltm_get_numstreams(struct roar_ltm_result * res) { 309 _RETMEMBERCKED(res, streams); 310 } 311 int roar_ltm_get_mt(struct roar_ltm_result * res) { 312 _RETMEMBERCKED(res, mt); 313 } 314 int roar_ltm_get_window(struct roar_ltm_result * res) { 315 _RETMEMBERCKED(res, window); 316 } 317 318 static int64_t * roar_ltm_get_streamptr(struct roar_ltm_result * res, int streamidx) { 319 int64_t * ptr; 320 int numchans; 321 int i; 322 323 if ( res == NULL || streamidx < 0 || streamidx >= res->streams ) 324 return NULL; 325 326 ptr = res->data; 327 328 for (i = 0; i < streamidx; i++) { 329 numchans = *ptr & 0xFFFF; 330 ptr += res->nummt * numchans; 331 ptr++; 332 } 333 334 return ptr; 335 } 336 337 int roar_ltm_get_numchans(struct roar_ltm_result * res, int streamidx) { 338 int64_t * ptr = roar_ltm_get_streamptr(res, streamidx); 339 340 if ( ptr == NULL ) 341 return -1; 342 343 return *ptr & 0xFFFF; 344 } 345 346 int64_t roar_ltm_extract(struct roar_ltm_result * res, int mt, int streamidx, int channel) { 347 int64_t * ptr = roar_ltm_get_streamptr(res, streamidx); 348 int numchans; 349 int resmt; 350 351 if ( roar_ltm_numbits(mt) != 1 ) 352 return -1; 353 354 if ( ptr == NULL ) 355 return -1; 356 357 numchans = *ptr & 0xFFFF; 358 359 if ( channel >= numchans ) 360 return -1; 361 362 ptr++; 363 364 ptr += res->nummt * channel; 365 366 // now ptr points to the first mt for the given channel. 367 368 resmt = res->mt; 369 370 while (!(mt & 0x1)) { 371 if ( resmt & 0x1 ) 372 ptr++; 373 mt >>= 1; 374 resmt >>= 1; 375 } 376 377 return *ptr; 378 } 213 379 214 380 //ll
Note: See TracChangeset
for help on using the changeset viewer.