Changeset 4388:2de43be17c40 in roaraudio


Ignore:
Timestamp:
09/15/10 01:13:41 (14 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

changed a lot internals of the OSS hwmixer.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • roard/hwmixer_oss.c

    r4380 r4388  
    3434}; 
    3535 
     36static struct subdev_map { 
     37 const char * name; 
     38 struct subdev subdev; 
     39} g_subdevs[] = { 
     40 {"Volume", {.bit = SOUND_MASK_VOLUME, .cmd_read = SOUND_MIXER_READ_VOLUME, .cmd_write = SOUND_MIXER_WRITE_VOLUME}}, 
     41 {NULL} 
     42}; 
     43 
     44static int hwmixer_oss_open_stream(struct hwmixer_stream * stream, int devmask, int sdevmask, char * basename, struct roar_keyval * subname) { 
     45 struct subdev * subdev; 
     46 struct subdev * source_subdev = NULL; 
     47 struct roar_stream_server * ss; 
     48 int i; 
     49 
     50 for (i = 0; g_subdevs[i].name != NULL; i++) { 
     51  if ( !strcasecmp(subname->key, g_subdevs[i].name) ) { 
     52   source_subdev = &(g_subdevs[i].subdev); 
     53   break; 
     54  } 
     55 } 
     56 
     57 if ( source_subdev == NULL ) 
     58  return -1; 
     59 
     60 if ( !(devmask & source_subdev->bit) ) 
     61  return -1; 
     62 
     63 subdev = roar_mm_malloc(sizeof(struct subdev)); 
     64 
     65 if ( subdev == NULL ) 
     66  return -1; 
     67 
     68 memcpy(subdev, source_subdev, sizeof(struct subdev)); 
     69 
     70 subdev->channels = sdevmask & subdev->bit ? 2 : 1; 
     71 
     72 stream->ud     = subdev; 
     73 
     74 if (streams_get(stream->stream, &ss) != -1) { 
     75  ROAR_STREAM(ss)->info.channels = subdev->channels; 
     76 } else { 
     77  ROAR_WARN("hwmixer_dstr_open(*): can not get object for stream %i", stream->stream); 
     78 } 
     79 
     80 return 0; 
     81} 
     82 
    3683int hwmixer_oss_open(struct hwmixer_stream * stream, char * drv, char * dev, int fh, char * basename, struct roar_keyval * subnames, size_t subnamelen) { 
    3784 struct roar_vio_calls * vio = roar_mm_malloc(sizeof(struct roar_vio_calls)); 
    3885 struct roar_vio_defaults def; 
    39  struct roar_stream_server * ss; 
    4086 struct roar_vio_sysio_ioctl ctl; 
     87 struct roar_keyval kv; 
    4188 int devmask, sdevmask; 
    42  struct subdev * subdev = roar_mm_malloc(sizeof(struct subdev)); 
    43  
    44  if ( vio == NULL || subdev == NULL ) { 
    45   if ( vio != NULL ) 
    46    roar_mm_free(vio); 
    47   if ( subdev != NULL ) 
    48    roar_mm_free(subdev); 
     89 
     90 if ( vio == NULL ) { 
    4991  return -1; 
    5092 } 
     
    59101  if ( dev == NULL ) { 
    60102   roar_mm_free(vio); 
    61    roar_mm_free(subdev); 
    62103   return -1; 
    63104  } 
     
    65106  if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_FILE, O_RDWR, 0644) == -1 ) { 
    66107   roar_mm_free(vio); 
    67    roar_mm_free(subdev); 
    68108   return -1; 
    69109  } 
     
    71111  if ( roar_vio_open_dstr(vio, dev, &def, 1) == -1 ) { 
    72112   roar_mm_free(vio); 
    73    roar_mm_free(subdev); 
    74113   return -1; 
    75114  } 
     
    77116  if ( roar_vio_open_fh(vio, fh) == -1 ) { 
    78117   roar_mm_free(vio); 
    79    roar_mm_free(subdev); 
    80118   return -1; 
    81119  } 
     
    83121 
    84122 stream->baseud = vio; 
    85  stream->ud     = subdev; 
    86123 
    87124 ctl.cmd  = SOUND_MIXER_READ_DEVMASK; 
     
    91128  roar_vio_close(vio); 
    92129  roar_mm_free(vio); 
    93   roar_mm_free(subdev); 
    94130  return -1; 
    95131 } 
     
    102138 } 
    103139 
    104  memset(subdev, 0, sizeof(struct subdev)); 
    105  
    106  if ( devmask & SOUND_MASK_VOLUME ) { 
    107   subdev->bit       = SOUND_MASK_VOLUME; 
    108   subdev->channels  = sdevmask & SOUND_MASK_VOLUME ? 2 : 1; 
    109   subdev->cmd_read  = SOUND_MIXER_READ_VOLUME; 
    110   subdev->cmd_write = SOUND_MIXER_WRITE_VOLUME; 
    111  } else { 
     140 kv.key   = "Volume"; 
     141 kv.value = NULL; 
     142 
     143 if ( hwmixer_oss_open_stream(stream, devmask, sdevmask, basename, &kv) == -1 ) { 
    112144  roar_vio_close(vio); 
    113145  roar_mm_free(vio); 
    114   roar_mm_free(subdev); 
    115   return -1; 
    116  } 
    117  
    118  if (streams_get(stream->basestream, &ss) != -1) { 
    119   ROAR_STREAM(ss)->info.channels = 2; 
    120  } else { 
    121   ROAR_WARN("hwmixer_dstr_open(*): can not get object for basestream %i", stream->basestream); 
    122  } 
     146  return -1; 
     147 } 
     148 
    123149 
    124150#ifdef TEST_HWMIXER_SUBSTREAMS 
Note: See TracChangeset for help on using the changeset viewer.