Changeset 4716:617c3db2d14b in roaraudio


Ignore:
Timestamp:
01/09/11 18:44:03 (11 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added support for stream infos

File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/roard/protocol-gopher.c

    r4715 r4716  
    4141static int scb_streams    (int client, struct roar_vio_calls * vio, char * selector, char ** text, struct item * sitem); 
    4242static int scb_client_info(int client, struct roar_vio_calls * vio, char * selector, char ** text, struct item * sitem); 
     43static int scb_stream_info(int client, struct roar_vio_calls * vio, char * selector, char ** text, struct item * sitem); 
    4344 
    4445static struct roar_gopher_menu_item g_gopher_root_menu[] = { 
     
    7374 {.selector = "/clients/",   .type = _DIR,  .cb = scb_clients}, 
    7475 {.selector = "/streams/",   .type = _DIR,  .cb = scb_streams}, 
    75  {.selector = "/clients/*/", .type = _DIR,  .cb = scb_client_info} 
     76 {.selector = "/clients/*/", .type = _DIR,  .cb = scb_client_info}, 
     77 {.selector = "/streams/*/", .type = _DIR,  .cb = scb_stream_info} 
    7678}; 
    7779 
     
    254256 
    255257static int scb_client_info(int client, struct roar_vio_calls * vio, char * selector, char ** text, struct item * sitem) { 
    256 #define _MAX_ITEMS 8 
     258#define _MAX_ITEMS (16 + ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT) 
    257259 struct roar_gopher_menu_item items[_MAX_ITEMS]; 
    258260 struct roar_gopher_menu menu = {.flags = 0, .items = items, .items_len = 0}; 
     
    315317  } 
    316318 } 
     319 
     320 ret = send_menu(client, &menu, vio); 
     321 
     322 for (i = 0; i < menu.items_len; i++) { 
     323  if ( items[i].name != NULL ) 
     324   roar_mm_free((void*)items[i].name); 
     325  if ( items[i].selector != NULL ) 
     326   roar_mm_free((void*)items[i].selector); 
     327 } 
     328 
     329#undef _MAX_ITEMS 
     330 return ret; 
     331} 
     332 
     333static int scb_stream_info(int client, struct roar_vio_calls * vio, char * selector, char ** text, struct item * sitem) { 
     334#define _MAX_ITEMS 12 
     335 struct roar_gopher_menu_item items[_MAX_ITEMS]; 
     336 struct roar_gopher_menu menu = {.flags = 0, .items = items, .items_len = 0}; 
     337 struct roar_gopher_menu_item * item; 
     338 struct roar_stream_server * ss; 
     339 struct roar_stream        * s; 
     340 size_t i; 
     341 int ret; 
     342 ssize_t toks; 
     343 char * tok; 
     344 int id; 
     345 
     346 memset(items, 0, sizeof(items)); 
     347 
     348 toks = strseltok(sitem->selector, selector, &tok, 1); 
     349 if ( toks == -1 ) 
     350  return -1; 
     351 
     352 id = atoi(tok); 
     353 
     354 if ( streams_get(id, &ss) == -1 ) 
     355  return -1; 
     356 
     357 s = ROAR_STREAM(ss); 
     358 
     359 
     360 item = &(items[menu.items_len++]); 
     361 item->type = _INFO; 
     362 if ( ss->name != NULL && ss->name[0] != 0 ) { 
     363  item->name = _aprintf(64, "Stream %i: %s", id, ss->name); 
     364 } else { 
     365  item->name = _aprintf(64, "Stream %i", id); 
     366 } 
     367 
     368 item = &(items[menu.items_len++]); 
     369 item->type = _INFO; 
     370 item->name = _aprintf(64, "Stream state: %s", roar_streamstate2str(ss->state)); 
     371 
     372 item = &(items[menu.items_len++]); 
     373 item->type = _INFO; 
     374 item->name = _aprintf(64, "Stream direction: %s", roar_dir2str(s->dir)); 
     375 
     376 item = &(items[menu.items_len++]); 
     377 item->type = _INFO; 
     378 item->name = _aprintf(128, "Signal info: rate:%iHz bits:%i channels:%i codec:%s", 
     379                            s->info.rate, s->info.bits, s->info.channels, roar_codec2str(s->info.codec)); 
     380 
     381 if ( ss->codec_orgi != -1 && ss->codec_orgi != s->info.codec ) { 
     382  item = &(items[menu.items_len++]); 
     383  item->type = _INFO; 
     384  item->name = _aprintf(64, "Streamed codec: %s", roar_codec2str(ss->codec_orgi)); 
     385 } 
     386 
     387 if ( ss->role != -1 ) { 
     388  item = &(items[menu.items_len++]); 
     389  item->type = _INFO; 
     390  item->name = _aprintf(64, "Stream role: %s", roar_role2str(ss->role)); 
     391 } 
     392 
     393 item = &(items[menu.items_len++]); 
     394 item->type = _DIR; 
     395 item->name = _aprintf(64, "Client: %i", ss->client); 
     396 item->selector = _aprintf(64, "/clients/%i/", ss->client); 
    317397 
    318398 ret = send_menu(client, &menu, vio); 
Note: See TracChangeset for help on using the changeset viewer.