Changeset 4656:5a99c25bbb0d in roaraudio


Ignore:
Timestamp:
12/12/10 20:49:45 (13 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

do no longer use wget for HTTP streams, first part of a set of patches.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • roarclients/roarvorbis.c

    r4014 r4656  
    5555 
    5656#ifdef ROAR_HAVE_LIBVORBISFILE 
    57 FILE * open_http (char * file) { 
    58 #ifdef ROAR_HAVE_BIN_WGET 
    59  char cmd[1024]; 
    60  
    61  snprintf(cmd, 1023, ROAR_HAVE_BIN_WGET " -qO - '%s'", file); 
    62  
    63  return popen(cmd, "r"); 
    64 #else 
    65  return NULL; 
    66 #endif 
    67 } 
     57int _g_cf_vorbis_vfvio_return_err (void) { 
     58 return -1; 
     59} 
     60 
     61size_t cf_vorbis_vfvio_read (void *ptr, size_t size, size_t nmemb, void *datasource) { 
     62 ssize_t r; 
     63 
     64 r = roar_vio_read(datasource, ptr, size*nmemb); 
     65 
     66 ROAR_DBG("cf_vorbis_vfvio_read(ptr=%p, size=%lu, nmemb=%lu, datasource=%p): r=%i", ptr, size, nmemb, datasource, r); 
     67 
     68 if ( r == -1 ) 
     69  return 0; 
     70 
     71 if ( r > 0 ) 
     72  errno = 0; 
     73 
     74 r /= size; 
     75 
     76 ROAR_DBG("cf_vorbis_vfvio_read(ptr=%p, size=%lu, nmemb=%lu, datasource=%p) = %i", ptr, size, nmemb, datasource, r); 
     77 return r; 
     78} 
     79 
     80 
     81ov_callbacks _g_cf_vorbis_vfvio = { 
     82  .read_func  = cf_vorbis_vfvio_read, 
     83  .seek_func  = (int    (*)(void *, ogg_int64_t, int      )) _g_cf_vorbis_vfvio_return_err, 
     84  .close_func = (int    (*)(void *                        )) _g_cf_vorbis_vfvio_return_err, 
     85  .tell_func  = (long   (*)(void *                        )) _g_cf_vorbis_vfvio_return_err 
     86}; 
     87 
    6888 
    6989int update_stream (struct roar_connection * con, 
     
    193213 return 1; 
    194214#else 
    195  struct roar_vio_calls vclt; 
     215 struct roar_vio_calls vclt, in; 
    196216 struct roar_vio_defaults def; 
    197217 char * server   = NULL; 
     
    200220 char * k; 
    201221 int    i; 
    202  FILE * in; 
    203222 struct roar_connection con; 
    204223 struct roar_stream     s; 
     
    238257 } 
    239258 
     259 if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_RDONLY, 0644) == -1 ) 
     260  return 1; 
     261 
     262 if ( roar_vio_open_dstr(&in, file, &def, 1) == -1 ) { 
     263  fprintf(stderr, "Error: can not open file: %s: %s\n", file, strerror(errno)); 
     264  return 1; 
     265 } 
     266 
    240267 if ( roar_simple_connect(&con, server, "roarvorbis") == -1 ) { 
    241268  ROAR_DBG("roar_simple_play(*): roar_simple_connect() faild!"); 
    242   return 1; 
    243  } 
    244  
    245  if ( strncmp(file, "http:", 5) == 0 ) { 
    246   in = open_http(file); 
    247  } else { 
    248   in = fopen(file, "rb"); 
    249  } 
    250  
    251  if ( in == NULL ) { 
    252   roar_disconnect(&con); 
    253   fclose(in); 
    254   return 1; 
    255  } 
    256  
    257 #ifdef _WIN32 
    258   _setmode(_fileno(in), _O_BINARY); 
    259 #endif 
    260  
    261  if( ov_open(in, &vf, NULL, 0) < 0 ) { 
     269  roar_vio_close(&in); 
     270  return 1; 
     271 } 
     272 
     273 if ( ov_open_callbacks((void*)&in, &vf, NULL, 0, _g_cf_vorbis_vfvio) < 0 ) { 
     274// if( ov_open(in, &vf, NULL, 0) < 0 ) { 
    262275  fprintf(stderr,"Input does not appear to be an Ogg bitstream.\n"); 
    263276  roar_disconnect(&con); 
    264   fclose(in); 
     277  roar_vio_close(&in); 
    265278  return 1; 
    266279 } 
     
    271284  if ( roar_vio_open_dstr(&vclt, vcltfile, &def, 1) == -1 ) { 
    272285   fprintf(stderr, "Error: can not open file: %s: %s\n", k, strerror(errno)); 
    273    fclose(in); 
     286   roar_disconnect(&con); 
     287   roar_vio_close(&in); 
    274288   return 1; 
    275289  } 
     
    284298  if ( last_section != current_section ) 
    285299   if ( update_stream(&con, &s, &vio, &vf, file, &info, vcltfile == NULL ? NULL : &vclt) == -1 ) { 
    286     fclose(in); 
     300    roar_vio_close(&in); 
     301    if ( vcltfile != NULL ) 
     302     roar_vio_close(&vclt); 
    287303    return 1; 
    288304   } 
     
    307323 roar_disconnect(&con); 
    308324 
    309  if ( vcltfile != NULL ) { 
     325 if ( vcltfile != NULL ) 
    310326  roar_vio_close(&vclt); 
    311  } 
    312  
    313  fclose(in); 
     327 
     328 roar_vio_close(&in); 
    314329 
    315330 return 0; 
Note: See TracChangeset for help on using the changeset viewer.