Changeset 4960:60cdebcb83ef in roaraudio for libroarpulse


Ignore:
Timestamp:
05/14/11 04:46:29 (13 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

some updates for pulseaudio emulation, converted libroarpulse-simple fully to VS API

Location:
libroarpulse
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • libroarpulse/error.c

    r4708 r4960  
    4343static const struct { 
    4444 int error; 
     45 int ra_error; 
    4546 const char * name; 
    4647} _roar_pa_errors[] = { 
    47  {PA_OK,                       "OK"                             }, 
    48  {PA_ERR_ACCESS,               "Access denied"                  }, 
    49  {PA_ERR_COMMAND,              "Unknown command"                }, 
    50  {PA_ERR_INVALID,              "Invalid argument"               }, 
    51  {PA_ERR_EXIST,                "Entity exists"                  }, 
    52  {PA_ERR_NOENTITY,             "No such entity"                 }, 
    53  {PA_ERR_CONNECTIONREFUSED,    "Connection refused"             }, 
    54  {PA_ERR_PROTOCOL,             "Protocol error"                 }, 
    55  {PA_ERR_TIMEOUT,              "Timeout"                        }, 
    56  {PA_ERR_AUTHKEY,              "No authorization key"           }, 
    57  {PA_ERR_INTERNAL,             "Internal error"                 }, 
    58  {PA_ERR_CONNECTIONTERMINATED, "Connection terminated"          }, 
    59  {PA_ERR_KILLED,               "Entity killed"                  }, 
    60  {PA_ERR_INVALIDSERVER,        "Invalid server"                 }, 
    61  {PA_ERR_MODINITFAILED,        "Module initalization failed"    }, 
    62  {PA_ERR_BADSTATE,             "Bad state"                      }, 
    63  {PA_ERR_NODATA,               "No data"                        }, 
    64  {PA_ERR_VERSION,              "Incompatible protocol version"  }, 
    65  {PA_ERR_TOOLARGE,             "Too large"                      }, 
    66  {PA_ERR_MAX,                  "MAX"                            }, 
    67  {-1, NULL} 
     48 {PA_OK,                       ROAR_ERROR_NONE,   "OK"                             }, 
     49 {PA_ERR_ACCESS,               ROAR_ERROR_PERM,   "Access denied"                  }, 
     50 {PA_ERR_COMMAND,              ROAR_ERROR_BADRQC, "Unknown command"                }, 
     51 {PA_ERR_INVALID,              ROAR_ERROR_INVAL,  "Invalid argument"               }, 
     52 {PA_ERR_EXIST,                ROAR_ERROR_EXIST,  "Entity exists"                  }, 
     53 {PA_ERR_NOENTITY,             ROAR_ERROR_NOENT,  "No such entity"                 }, 
     54 {PA_ERR_CONNECTIONREFUSED,    ROAR_ERROR_CONNREFUSED, "Connection refused"             }, 
     55 {PA_ERR_PROTOCOL,             ROAR_ERROR_PROTO,  "Protocol error"                 }, 
     56 {PA_ERR_TIMEOUT,              ROAR_ERROR_TIMEDOUT, "Timeout"                        }, 
     57 {PA_ERR_AUTHKEY,              ROAR_ERROR_PERM,   "No authorization key"           }, 
     58 {PA_ERR_INTERNAL,             ROAR_ERROR_UNKNOWN, "Internal error"                 }, 
     59 {PA_ERR_CONNECTIONTERMINATED, ROAR_ERROR_IO,     "Connection terminated"          }, 
     60 {PA_ERR_KILLED,               ROAR_ERROR_IO,     "Entity killed"                  }, 
     61 {PA_ERR_INVALIDSERVER,        ROAR_ERROR_INVAL,  "Invalid server"                 }, 
     62 {PA_ERR_MODINITFAILED,        ROAR_ERROR_BADLIB, "Module initalization failed"    }, 
     63 {PA_ERR_BADSTATE,             ROAR_ERROR_INVAL,  "Bad state"                      }, 
     64 {PA_ERR_NODATA,               ROAR_ERROR_NODATA, "No data"                        }, 
     65 {PA_ERR_VERSION,              ROAR_ERROR_NSVERSION, "Incompatible protocol version"  }, 
     66 {PA_ERR_TOOLARGE,             ROAR_ERROR_RANGE,  "Too large"                      }, 
     67#ifdef PA_ERR_NOTSUPPORTED 
     68 {PA_ERR_NOTSUPPORTED,         ROAR_ERROR_NOTSUP, "Not supported"}, 
     69#endif 
     70#ifdef PA_ERR_UNKNOWN 
     71 {PA_ERR_UNKNOWN,              ROAR_ERROR_UNKNOWN, "Unknown error code"}, 
     72#endif 
     73#ifdef PA_ERR_NOEXTENSION 
     74 {PA_ERR_UNKNOWN,              ROAR_ERROR_NOENT,  "No such extension"}, 
     75#endif 
     76#ifdef PA_ERR_OBSOLETE 
     77 {PA_ERR_OBSOLETE,             ROAR_ERROR_NOSYS,  "Obsolete functionality"}, 
     78#endif 
     79#ifdef PA_ERR_NOTIMPLEMENTED 
     80 {PA_ERR_NOTIMPLEMENTED,       ROAR_ERROR_NOSYS,  "Missing implementation"}, 
     81#endif 
     82#ifdef PA_ERR_FORKED 
     83 {PA_ERR_FORKED,               ROAR_ERROR_INVAL,  "Client forked"}, 
     84#endif 
     85#ifdef PA_ERR_IO 
     86 {PA_ERR_IO,                   ROAR_ERROR_IO,     "Input/Output error"}, 
     87#endif 
     88#ifdef PA_ERR_BUSY 
     89 {PA_ERR_BUSY,                 ROAR_ERROR_BUSY,   "Device or resource busy"}, 
     90#endif 
     91 {PA_ERR_MAX,                  ROAR_ERROR_UNKNOWN, "MAX"                            }, 
     92 {-1, ROAR_ERROR_UNKNOWN, NULL} 
    6893}; 
    6994 
     
    78103} 
    79104 
     105int roar_pa_raerror2paerror(int error) { 
     106 int i; 
     107 
     108 for (i = 0; _roar_pa_errors[i].name != NULL; i++) 
     109  if ( _roar_pa_errors[i].ra_error == error ) 
     110   return _roar_pa_errors[i].error; 
     111 
     112 return PA_ERR_INVALID; 
     113} 
     114 
    80115//ll 
  • libroarpulse/sample.c

    r4708 r4960  
    4141 
    4242/** Return the amount of bytes playback of a second of audio with the specified sample type takes */ 
    43 size_t pa_bytes_per_second(const pa_sample_spec *spec); 
     43size_t pa_bytes_per_second(const pa_sample_spec *spec) { 
     44 return pa_sample_size(spec) * spec->channels * spec->rate; 
     45} 
    4446 
    4547/** Return the size of a frame with the specific sample type */ 
     
    6668    return 2; 
    6769   break; 
     70#ifdef PA_SAMPLE_S24LE 
     71  case PA_SAMPLE_S24LE: 
     72  case PA_SAMPLE_S24BE: 
     73    return 3; 
     74   break; 
     75#endif 
     76#ifdef PA_SAMPLE_S32LE 
     77  case PA_SAMPLE_S32LE: 
     78  case PA_SAMPLE_S32BE: 
     79  case PA_SAMPLE_S24_32LE: 
     80  case PA_SAMPLE_S24_32BE: 
     81    return 4; 
     82   break; 
     83#endif 
    6884  default: 
    6985    return 0; 
  • libroarpulse/simple.c

    r4708 r4960  
    4040#include <libroarpulse/libroarpulse.h> 
    4141 
     42#define _seterr() if ( error != NULL ) { *error = roar_pa_raerror2paerror(err); } 
     43 
    4244/** Create a new connection to the server */ 
    4345pa_simple* pa_simple_new( 
     
    5254    int *error                          /**< A pointer where the error code is stored when the routine returns NULL. It is OK to pass NULL here. */ 
    5355    ) { 
    54  struct roarpulse_simple * s; 
     56 struct roar_keyval kv[1]; 
     57 roar_vs_t * vss = NULL; 
    5558 struct roar_audio_info info; 
    5659 int roar_dir; 
    57  struct roar_meta meta; 
     60 int err = ROAR_ERROR_NONE; 
    5861 
    5962 if ( dir == PA_STREAM_PLAYBACK ) { 
     
    6972 } 
    7073 
    71  if ( (s = roar_mm_malloc(sizeof(struct roarpulse_simple))) == NULL ) 
    72   return NULL; 
    73  
    7474 server = roar_pa_find_server((char*)server); 
    7575 
    76  if ( roar_simple_connect(&(s->con), (char*)server, (char*)name) == -1 ) { 
    77   roar_mm_free(s); 
     76 vss = roar_vs_new(server, name, &err); 
     77 if ( vss == NULL ) { 
     78  _seterr(); 
    7879  return NULL; 
    7980 } 
    8081 
    81  if ( roar_vio_simple_new_stream_obj(&(s->vio), &(s->con), &(s->stream), 
    82                                      info.rate, info.channels, 
    83                                      info.bits, info.codec, roar_dir) == -1 ) { 
    84   roar_disconnect(&(s->con)); 
    85   roar_mm_free(s); 
     82 if ( roar_vs_stream(vss, &info, roar_dir, &err) == -1 ) { 
     83  roar_vs_close(vss, ROAR_VS_TRUE, NULL); 
     84  _seterr(); 
    8685  return NULL; 
    8786 } 
    8887 
    8988 if ( stream_name != NULL && stream_name[0] != 0 ) { 
    90   meta.value  = (char*)stream_name; 
    91   meta.key[0] = 0; 
    92   meta.type   = ROAR_META_TYPE_DESCRIPTION; 
     89  kv[0].key   = "DESCRIPTION"; 
     90  kv[1].value = (char*)stream_name; 
    9391 
    94   roar_stream_meta_set(&(s->con), &(s->stream), ROAR_META_MODE_SET, &meta); 
     92  roar_vs_meta(vss, kv, 1, NULL); 
    9593 } 
    9694 
    97  return (pa_simple*) s; 
     95 return (pa_simple*) vss; 
    9896} 
    9997 
    10098/** Close and free the connection to the server. The connection objects becomes invalid when this is called. */ 
    10199void pa_simple_free(pa_simple *s) { 
    102  struct roarpulse_simple * ss = (struct roarpulse_simple*) s; 
    103  
    104100 if ( s == NULL ) 
    105101  return; 
    106102 
    107  roar_vio_close(&(ss->vio)); 
    108  roar_disconnect(&(ss->con)); 
    109  
    110  roar_mm_free(s); 
     103 roar_vs_close((roar_vs_t*)s, ROAR_VS_FALSE, NULL); 
    111104} 
    112105 
    113106/** Write some data to the server */ 
    114107int pa_simple_write(pa_simple *s, const void*data, size_t length, int *error) { 
    115  struct roarpulse_simple * ss = (struct roarpulse_simple*) s; 
     108 int ret; 
     109 int err = ROAR_ERROR_NONE; 
    116110 
    117111 if ( s == NULL ) 
    118112  return -1; 
    119113 
    120  return roar_vio_write(&(ss->vio), (char*) data, length); 
     114 ret = roar_vs_write((roar_vs_t*)s, data, length, &err); 
     115 
     116 _seterr(); 
     117 
     118 return ret; 
    121119} 
    122120 
    123121/** Wait until all data already written is played by the daemon */ 
    124122int pa_simple_drain(pa_simple *s, int *error) { 
    125 // struct roarpulse_simple * ss = (struct roarpulse_simple*) s; 
     123 int ret; 
     124 int err = ROAR_ERROR_NONE; 
    126125 
    127126 if ( s == NULL ) 
    128127  return -1; 
    129128 
    130  pa_simple_flush(s, error); 
     129 ret = roar_vs_sync((roar_vs_t*)s, ROAR_VS_WAIT, &err); 
    131130 
    132  return -1; 
     131 _seterr(); 
     132 
     133 return ret; 
    133134} 
    134135 
    135136/** Read some data from the server */ 
    136137int pa_simple_read(pa_simple *s, void*data, size_t length, int *error) { 
    137  struct roarpulse_simple * ss = (struct roarpulse_simple*) s; 
     138 int ret; 
     139 int err = ROAR_ERROR_NONE; 
    138140 
    139141 if ( s == NULL ) 
    140142  return -1; 
    141143 
    142  return roar_vio_read(&(ss->vio), data, length); 
     144 ret = roar_vs_read((roar_vs_t*)s, data, length, &err); 
     145 
     146 _seterr(); 
     147 
     148 return ret; 
    143149} 
    144150 
    145151/** Return the playback latency. \since 0.5 */ 
    146152pa_usec_t pa_simple_get_latency(pa_simple *s, int *error) { 
    147  struct roarpulse_simple * ss = (struct roarpulse_simple*) s; 
     153 roar_mus_t ret; 
     154 int err = ROAR_ERROR_NONE; 
    148155 
    149156 if ( s == NULL ) 
    150157  return -1; 
    151158 
    152  return -1; 
     159 ret = roar_vs_latency((roar_vs_t*)s, ROAR_VS_BACKEND_DEFAULT, &err); 
     160 
     161 if ( ret < 0 ) 
     162  ret *= -1; 
     163 
     164 if ( ret == 0 && err != ROAR_ERROR_NONE ) { 
     165  _seterr(); 
     166  return -1; 
     167 } 
     168 
     169 return ret; 
    153170} 
    154171 
    155172/** Flush the playback buffer. \since 0.5 */ 
    156173int pa_simple_flush(pa_simple *s, int *error) { 
    157  struct roarpulse_simple * ss = (struct roarpulse_simple*) s; 
     174 int ret; 
     175 int err = ROAR_ERROR_NONE; 
    158176 
    159177 if ( s == NULL ) 
    160178  return -1; 
    161179 
    162  return roar_vio_sync(&(ss->vio)); 
     180 ret = roar_vs_sync((roar_vs_t*)s, ROAR_VS_NOWAIT, &err); 
     181 
     182 _seterr(); 
     183 
     184 return ret; 
    163185} 
    164186 
  • libroarpulse/util.c

    r4896 r4960  
    7272 
    7373/** Return the current username in the specified string buffer. */ 
    74 char *pa_get_user_name(char *s, size_t l); 
     74char *pa_get_user_name(char *s, size_t l) { 
     75 char * user = NULL; 
     76 
     77 if ( s == NULL ) { 
     78  roar_err_set(ROAR_ERROR_FAULT); 
     79  roar_err_to_errno(); 
     80  return NULL; 
     81 } 
     82 
     83 if ( user == NULL ) 
     84  user = getenv("USER"); 
     85 if ( user == NULL ) 
     86  user = getenv("LOGNAME"); 
     87 if ( user == NULL ) 
     88  user = getenv("USERNAME"); 
     89 
     90#ifdef ROAR_HAVE_GETUID 
     91 if ( user == NULL ) 
     92  if ( getuid() == 0 ) 
     93   user = "root"; 
     94#endif 
     95 
     96 if ( user == NULL ) { 
     97  roar_err_set(ROAR_ERROR_NOENT); 
     98  roar_err_to_errno(); 
     99  return NULL; 
     100 } 
     101 
     102 strncpy(s, user, l); 
     103 s[l-1] = 0; 
     104 
     105 return s; 
     106} 
    75107 
    76108/** Return the current hostname in the specified buffer. */ 
    77 char *pa_get_host_name(char *s, size_t l); 
     109char *pa_get_host_name(char *s, size_t l) { 
     110#ifdef ROAR_HAVE_GETHOSTNAME 
     111 if (gethostname(s, l) == -1) 
     112  return NULL; 
     113 
     114 s[l-1] = 0; 
     115 return s; 
     116#else 
     117 roar_err_set(ROAR_ERROR_NOSYS); 
     118 roar_err_to_errno(); 
     119 return NULL; 
     120#endif 
     121} 
    78122 
    79123/** Return the fully qualified domain name in s */ 
Note: See TracChangeset for help on using the changeset viewer.