Changeset 4361:135e78128e19 in roaraudio


Ignore:
Timestamp:
09/14/10 17:02:58 (14 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added very basic mixer setup rutines

Location:
roard
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • roard/hwmixer.c

    r4360 r4361  
    2626#include "roard.h" 
    2727 
     28#define FLAG_NONE     0x0000 
     29#define FLAG_FHSEC    0x0001 
     30 
     31struct hwmixer; 
     32 
     33struct hwmixer_stream { 
     34 struct hwmixer * hwmixer; 
     35 int basestream; 
     36 int stream; 
     37 void * baseud; 
     38 void * ud; 
     39}; 
     40 
     41struct hwmixer { 
     42 const char * name; 
     43 const char * desc; 
     44 const char * devs; 
     45 int flags; 
     46 int (*open)(struct hwmixer_stream * stream, char * drv, char * dev, int fh, char * basename, struct roar_keyval * subnames, size_t subnamelen); 
     47 int (*close)(struct hwmixer_stream * stream); 
     48 int (*set_vol)(struct hwmixer_stream * stream, int channels, int mode, struct roar_mixer_settings * settings); 
     49 int (*get_vol)(struct hwmixer_stream * stream, int channels, int mode, struct roar_mixer_settings * settings); 
     50}; 
     51 
     52static int __true (void) { return 0; } 
     53 
     54struct hwmixer g_hwmixers[] = { 
     55 {"oss",  "OSS Mixer", "/dev/mixer*", FLAG_FHSEC, NULL, NULL, NULL, NULL}, 
     56 {"file", "Write to plain file", "/some/file", FLAG_FHSEC, NULL, NULL, NULL, NULL}, 
     57 {"dstr", "Write to DSTR",       "/some/file", FLAG_NONE,  NULL, NULL, NULL, NULL}, 
     58 {"null", "Null Mixer",          NULL, FLAG_NONE,  __true, __true, __true, __true}, 
     59 {NULL,   NULL, NULL, FLAG_NONE, NULL, NULL, NULL, NULL} 
     60}; 
     61 
    2862void print_hwmixerlist (void) { 
     63 struct hwmixer * mixer; 
     64 int i; 
     65 
    2966 printf("  Source   Flag Subsys - Description (devices)\n"); 
    3067 printf("------------------------------------------------------\n"); 
     68 
     69 for (i = 0; (mixer = &(g_hwmixers[i]))->name != NULL; i++) { 
     70  printf("  %-9s %c   Mixer  - %s (devices: %s)\n", 
     71         mixer->name, 
     72         mixer->flags & FLAG_FHSEC ? 's' : ' ', 
     73         mixer->desc, 
     74         mixer->devs == NULL ? "(none)" : mixer->devs 
     75        ); 
     76 } 
     77} 
     78 
     79void hwmixer_setup_info(struct hwmixer_stream * mstream) { 
     80 struct roar_stream_server * ss; 
     81 
     82 streams_get(mstream->stream, &ss); 
     83 
     84 memset(&(ROAR_STREAM(ss)->info), 0, sizeof(ROAR_STREAM(ss)->info)); 
     85 
     86 streams_set_dir(mstream->stream, ROAR_DIR_MIXING, 1); 
     87 
     88 streams_set_flag(mstream->stream, ROAR_FLAG_HWMIXER); 
    3189} 
    3290 
    3391int hwmixer_open(int basestream, char * drv, char * dev, int fh, char * basename, char * subnames) { 
    34  return -1; 
     92 struct roar_keyval * subnamekv = NULL; 
     93 struct hwmixer * mixer = NULL; 
     94 struct hwmixer_stream * stream; 
     95 ssize_t subnamekvlen = 0; 
     96 int i; 
     97 int ret; 
     98 
     99 for (i = 0; g_hwmixers[i].name != NULL; i++) { 
     100  if ( !strcmp(g_hwmixers[i].name, drv) ) { 
     101   mixer = &(g_hwmixers[i]); 
     102   break; 
     103  } 
     104 } 
     105 
     106 if ( mixer == NULL ) { 
     107  ROAR_WARN("hwmixer_open(basestream=%i, drv='%s', dev='%s', fh=%i, basename='%s', subnames='%s'): Driver not found.", basestream, drv, dev, fh, basename, subnames); 
     108  return -1; 
     109 } 
     110 
     111 if ( mixer->open == NULL ) { 
     112  return -1; 
     113 } 
     114 
     115 if ( fh != -1 && !(mixer->flags & FLAG_FHSEC) ) { 
     116  return -1; 
     117 } 
     118 
     119 stream = roar_mm_malloc(sizeof(struct hwmixer_stream)); 
     120 if ( stream == NULL ) 
     121  return -1; 
     122 
     123 memset(stream, 0, sizeof(struct hwmixer_stream)); 
     124 
     125 stream->hwmixer    = mixer; 
     126 stream->basestream = basestream; 
     127 stream->stream     = basestream; 
     128 stream->baseud     = NULL; 
     129 stream->ud         = NULL; 
     130 
     131 if ( basename == NULL ) { 
     132  streams_set_name(basestream, "Hardware Mixer"); 
     133 } else { 
     134  streams_set_name(basestream, basename); 
     135 } 
     136 
     137 ret = mixer->open(stream, drv, dev, fh, basename, subnamekv, subnamekvlen); 
     138 
     139 if ( ret == -1 ) { 
     140  roar_mm_free(stream); 
     141  return -1; 
     142 } 
     143 
     144 hwmixer_setup_info(stream); 
     145 
     146 streams_set_mixerstream(basestream, stream); 
     147 
     148 return 0; 
     149} 
     150 
     151int hwmixer_close(int stream) { 
     152 struct hwmixer_stream * mstream = streams_get_mixerstream(stream); 
     153 
     154 if ( mstream == NULL ) 
     155  return 0; 
     156 
     157 if ( mstream->hwmixer->close != NULL ) 
     158  mstream->hwmixer->close(mstream); 
     159 
     160 roar_mm_free(mstream); 
     161 
     162 return 0; 
    35163} 
    36164 
  • roard/include/hwmixer.h

    r4360 r4361  
    2929#include <roaraudio.h> 
    3030 
     31struct hwmixer_stream; 
     32 
    3133void print_hwmixerlist (void); 
    3234int hwmixer_open(int basestream, char * drv, char * dev, int fh, char * basename, char * subnames); 
    33  
     35int hwmixer_close(int stream); 
    3436#endif 
    3537 
  • roard/include/streams.h

    r4289 r4361  
    110110 int parent_stream; 
    111111 struct roar_stream_ltm ltm[MAX_LTM_WINDOWS_PER_STREAM]; 
     112 struct hwmixer_stream * mixerstream; 
    112113} * g_streams[ROAR_STREAMS_MAX]; 
    113114 
     
    168169struct roar_stream_ltm * streams_ltm_get(int id, int mt, int window); 
    169170 
     171struct hwmixer_stream * streams_get_mixerstream(int id); 
     172int streams_set_mixerstream(int id, struct hwmixer_stream * mstream); 
     173 
    170174int streams_ctl          (int id, int_least32_t cmd, void * data); 
    171175 
  • roard/streams.c

    r4346 r4361  
    150150   s->flags     =  ROAR_FLAG_NONE; 
    151151 
     152   s->mixerstream =  NULL; 
     153 
    152154   //roardsp_fchain_init(&(s->fc)); 
    153155 
     
    251253  s->driver_id = -1; 
    252254  no_vio_close =  1; 
     255 } 
     256 
     257 if ( s->mixerstream != NULL ) { 
     258  hwmixer_close(id); 
    253259 } 
    254260 
     
    11981204} 
    11991205 
     1206struct hwmixer_stream * streams_get_mixerstream(int id) { 
     1207 _CHECK_SID_RET(id, NULL); 
     1208 
     1209 return g_streams[id]->mixerstream; 
     1210} 
     1211 
     1212int streams_set_mixerstream(int id, struct hwmixer_stream * mstream) { 
     1213 _CHECK_SID(id); 
     1214 
     1215 g_streams[id]->mixerstream = mstream; 
     1216 
     1217 return 0; 
     1218} 
     1219 
    12001220 
    12011221int streams_ctl          (int id, int_least32_t cmd, void * data) { 
Note: See TracChangeset for help on using the changeset viewer.