Changeset 4275:2a5ba5fd0120 in roaraudio


Ignore:
Timestamp:
08/28/10 15:56:34 (14 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

corrected client site handling of ltm, should now be complet

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • include/libroar/ltm.h

    r4265 r4275  
    3939#include "libroar.h" 
    4040 
     41struct roar_ltm_result; 
     42 
    4143int roar_ltm_register(struct roar_connection * con, int mt, int window, int * streams, size_t slen); 
    4244int roar_ltm_unregister(struct roar_connection * con, int mt, int window, int * streams, size_t slen); 
    4345 
     46/* 
    4447ssize_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); 
    4548 
    4649int64_t roar_ltm_extract(int64_t * buf, size_t len, int mt, int req); 
    4750int64_t roar_ltm_extract1(int64_t * buf, size_t len, int mt, int req); 
     51*/ 
     52 
     53struct 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 
     57int roar_ltm_get_numstreams(struct roar_ltm_result * res); 
     58int roar_ltm_get_mt(struct roar_ltm_result * res); 
     59int roar_ltm_get_window(struct roar_ltm_result * res); 
     60 
     61int roar_ltm_get_numchans(struct roar_ltm_result * res, int streamidx); 
     62int64_t roar_ltm_extract(struct roar_ltm_result * res, int mt, int streamidx, int channel); 
    4863 
    4964#endif 
  • libroar/ltm.c

    r4269 r4275  
    3535 
    3636#include "libroar.h" 
     37 
     38struct 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}; 
    3746 
    3847static int roar_ltm_numbits(int f) { 
     
    140149} 
    141150 
     151/* 
    142152ssize_t roar_ltm_get_raw(struct roar_connection * con, 
    143153                         int mt, int window, 
     
    211221 return *buf; 
    212222} 
     223*/ 
     224 
     225struct 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 
     308int roar_ltm_get_numstreams(struct roar_ltm_result * res) { 
     309 _RETMEMBERCKED(res, streams); 
     310} 
     311int roar_ltm_get_mt(struct roar_ltm_result * res) { 
     312 _RETMEMBERCKED(res, mt); 
     313} 
     314int roar_ltm_get_window(struct roar_ltm_result * res) { 
     315 _RETMEMBERCKED(res, window); 
     316} 
     317 
     318static 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 
     337int 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 
     346int64_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} 
    213379 
    214380//ll 
Note: See TracChangeset for help on using the changeset viewer.