Changeset 82:395b9657ca85 in roaraudio


Ignore:
Timestamp:
07/12/08 18:49:34 (16 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added roar_simple_new_stream()

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • include/libroar/simple.h

    r0 r82  
    99 
    1010int roar_simple_stream  (int rate, int channels, int bits, int codec, char * server, int dir, char * name); 
     11 
     12int roar_simple_new_stream (struct roar_connection * con, int rate, int channels, int bits, int codec, int dir); 
    1113 
    1214int roar_simple_play    (int rate, int channels, int bits, int codec, char * server, char * name); 
  • include/libroar/stream.h

    r81 r82  
    1919int roar_stream_exec    (struct roar_connection * con, struct roar_stream * s); 
    2020int roar_stream_connect_to (struct roar_connection * con, struct roar_stream * s, int type, char * host, int port); 
     21int roar_stream_connect_to_ask (struct roar_connection * con, struct roar_stream * s, int type, char * host, int port); 
    2122 
    2223int roar_stream_add_data (struct roar_connection * con, struct roar_stream * s, char * data, size_t len); 
  • libroar/simple.c

    r54 r82  
    5858} 
    5959 
     60int roar_simple_new_stream (struct roar_connection * con, int rate, int channels, int bits, int codec, int dir) { 
     61 struct roar_stream     s; 
     62 struct roar_message    mes; 
     63 char file[80]; 
     64 int fh = -1, listen; 
     65 static int count = 0; 
     66 
     67 sprintf(file, "/tmp/.libroar-simple-stream.%i-%i", getpid(), count++); 
     68 
     69 if ( (listen = roar_socket_listen(ROAR_SOCKET_TYPE_UNIX, file, 0)) == -1 ) { 
     70  return -1; 
     71 } 
     72 
     73 if ( roar_stream_new(&s, rate, channels, bits, codec) == -1 ) { 
     74  return -1; 
     75 } 
     76 
     77 if ( roar_stream_connect(con, &s, dir) == -1 ) { 
     78  return -1; 
     79 } 
     80 
     81 if ( roar_stream_connect_to_ask(con, &s, ROAR_SOCKET_TYPE_UNIX, file, 0) != -1 ) { 
     82 
     83  if ( (fh = accept(listen, NULL, NULL)) != -1 ) { 
     84   if ( dir == ROAR_DIR_PLAY ) { 
     85    shutdown(fh, SHUT_RD); 
     86   } else if ( dir == ROAR_DIR_MONITOR || dir == ROAR_DIR_RECORD ) { 
     87    shutdown(fh, SHUT_WR); 
     88   } 
     89  } 
     90   if ( roar_recv_message(con, &mes, NULL) == -1 ) { 
     91    close(fh); 
     92    fh = -1; 
     93   } else if ( mes.cmd != ROAR_CMD_OK ) { 
     94    close(fh); 
     95    fh = -1; 
     96   } 
     97 } 
     98 
     99 close(listen); 
     100 unlink(file); 
     101 
     102 return fh; 
     103} 
     104 
    60105int roar_simple_play(int rate, int channels, int bits, int codec, char * server, char * name) { 
    61106 return roar_simple_stream(rate, channels, bits, codec, server, ROAR_DIR_PLAY, name); 
  • libroar/stream.c

    r81 r82  
    7575int roar_stream_connect_to (struct roar_connection * con, struct roar_stream * s, int type, char * host, int port) { 
    7676 struct roar_message m; 
     77 
     78 if ( roar_stream_connect_to_ask(con, s, type, host, port) == -1 ) 
     79  return -1; 
     80 
     81 if ( roar_recv_message(con, &m, NULL) == -1 ) 
     82  return -1; 
     83 
     84 if ( m.cmd == ROAR_CMD_OK ) 
     85  return 0; 
     86 return -1; 
     87} 
     88 
     89int roar_stream_connect_to_ask (struct roar_connection * con, struct roar_stream * s, int type, char * host, int port) { 
     90 struct roar_message m; 
    7791 int len = 0; 
    7892 
     
    97111 m.datalen = len + 4; 
    98112 
    99  if ( roar_req(con, &m, NULL) == -1 ) 
     113 if ( roar_send_message(con, &m, NULL) == -1 ) 
    100114  return -1; 
    101115 
    102  if ( m.cmd == ROAR_CMD_OK ) 
    103   return 0; 
    104  return -1; 
     116 return 0; 
    105117} 
    106118 
Note: See TracChangeset for help on using the changeset viewer.