Changeset 4662:e9ff170a707b in roaraudio


Ignore:
Timestamp:
12/13/10 17:21:56 (11 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

some small improvments: moved over to VS, added support to set volume and mute

Location:
plugins/gstreamer0.10
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • plugins/gstreamer0.10/roarsink.c

    r4661 r4662  
    5757{ 
    5858  PROP_0, 
    59   PROP_HOST 
     59  PROP_HOST, 
     60  PROP_ROLE, 
     61  PROP_VOLUME, 
     62  PROP_MUTE 
    6063}; 
    6164 
     
    7477        "rate = (int) [ 1, MAX ], " 
    7578        "channels = (int) [ 1, " QM(ROAR_MAX_CHANNELS) " ]; " 
     79 
     80//        "audio/x-flac; " 
     81 
     82        "audio/x-gsm; " 
     83 
     84//        "application/ogg; " 
     85 
     86//        "audio/x-wav; " 
    7687 
    7788/* 
     
    175186  g_object_class_install_property(gobject_class, PROP_HOST, 
    176187      g_param_spec_string("host", "Host", 
    177           "The host running the RoarAudio daemon", NULL, G_PARAM_READWRITE)); 
     188          "The server/host running the RoarAudio daemon", NULL, G_PARAM_READWRITE)); 
     189  g_object_class_install_property(gobject_class, PROP_HOST, 
     190      g_param_spec_string("server", "Server", 
     191          "The server/host running the RoarAudio daemon", NULL, G_PARAM_READWRITE)); 
     192  g_object_class_install_property(gobject_class, PROP_ROLE, 
     193      g_param_spec_string("role", "Role", 
     194          "The stream role", NULL, G_PARAM_READWRITE)); 
     195  g_object_class_install_property(gobject_class, PROP_VOLUME, 
     196      g_param_spec_float("volume", "Volume", 
     197          "The stream volume (0.0 to 1.0)", 0.0, 1.0, 1.0, G_PARAM_READWRITE)); 
     198  g_object_class_install_property(gobject_class, PROP_MUTE, 
     199      g_param_spec_boolean("mute", "Mute", 
     200          "The mute state of the stream", FALSE, G_PARAM_READWRITE)); 
    178201} 
    179202 
    180203static void gst_roarsink_init (GstRoarSink * roarsink, GstRoarSinkClass * klass) { 
    181   memset(&(roarsink->con), 0, sizeof(roarsink->con)); 
    182   roar_connect_fh(&(roarsink->con), -1); 
    183   roarsink->fd     = -1; 
     204  roarsink->vss    = NULL; 
    184205  roarsink->host   = NULL; 
     206  roarsink->role   = NULL; 
     207  roarsink->volume = -1; 
     208  roarsink->mute   = ROAR_VS_ASK; 
    185209} 
    186210 
     
    191215  if ( roarsink->host != NULL ) 
    192216   g_free(roarsink->host); 
     217  if ( roarsink->role != NULL ) 
     218   g_free(roarsink->role); 
    193219 
    194220  G_OBJECT_CLASS(parent_class)->finalize(object); 
     
    201227 
    202228  /* no fd, we're done with the template caps */ 
    203   if (roar_get_connection_fh(&(roarsink->con)) < 0 || roarsink->cur_caps == NULL) { 
     229  if (roarsink->vss == NULL || roarsink->cur_caps == NULL) { 
    204230    GST_LOG_OBJECT(roarsink, "getcaps called, returning template caps"); 
    205231    return NULL; 
     
    222248 
    223249  /* now try to connect to any existing/running sound daemons */ 
    224   if ( roar_simple_connect(&(roarsink->con), roarsink->host, "gstreamer client") == -1 ) 
     250  if ( (roarsink->vss = roar_vs_new(roarsink->host, "gstreamer client", NULL)) == NULL ) 
    225251    goto couldnt_connect; 
    226252 
    227   /* get server info */ 
    228   if ( roar_server_oinfo(&(roarsink->con), &oinfo) == -1 ) 
     253  if ( roar_server_oinfo(roar_vs_connection_obj(roarsink->vss, NULL), &oinfo) == -1 ) 
    229254    goto no_server_info; 
    230255 
     
    269294  gst_caps_replace(&roarsink->cur_caps, NULL); 
    270295 
    271   roar_disconnect(&(roarsink->con)); 
    272  
    273   if ( roarsink->fd != -1 ) 
    274    close(roarsink->fd); 
     296  roar_vs_close(roarsink->vss, ROAR_VS_FALSE, NULL); 
     297  roarsink->vss = NULL; 
    275298 
    276299  return TRUE; 
     
    279302static gboolean gst_roarsink_prepare (GstAudioSink * asink, GstRingBufferSpec * spec) { 
    280303  GstRoarSink *roarsink = GST_ROARSINK(asink); 
    281   int codec = ROAR_CODEC_DEFAULT; 
    282   int bits  = spec->depth; 
     304  struct roar_audio_info info; 
     305 
     306  info.codec    = ROAR_CODEC_DEFAULT; 
     307  info.bits     = spec->depth; 
     308  info.rate     = spec->rate; 
     309  info.channels = spec->channels; 
    283310 
    284311  GST_DEBUG_OBJECT(roarsink, "prepare"); 
     
    292319      case TRUE: 
    293320        switch (spec->bigend) { 
    294          case TRUE:  codec = ROAR_CODEC_PCM_S_BE; break; 
    295          case FALSE: codec = ROAR_CODEC_PCM_S_LE; break; 
     321         case TRUE:  info.codec = ROAR_CODEC_PCM_S_BE; break; 
     322         case FALSE: info.codec = ROAR_CODEC_PCM_S_LE; break; 
    296323         default: return FALSE; break; 
    297324        } 
     
    299326      case FALSE: 
    300327        switch (spec->bigend) { 
    301          case TRUE:  codec = ROAR_CODEC_PCM_U_BE; break; 
    302          case FALSE: codec = ROAR_CODEC_PCM_U_LE; break; 
     328         case TRUE:  info.codec = ROAR_CODEC_PCM_U_BE; break; 
     329         case FALSE: info.codec = ROAR_CODEC_PCM_U_LE; break; 
    303330         default: return FALSE; break; 
    304331        } 
     
    308335    break; 
    309336   case GST_BUFTYPE_A_LAW: 
    310      codec = ROAR_CODEC_ALAW; 
    311      bits  = 8; 
     337     info.codec = ROAR_CODEC_ALAW; 
     338     info.bits  = 8; 
    312339    break; 
    313340   case GST_BUFTYPE_MU_LAW: 
    314      codec = ROAR_CODEC_MULAW; 
    315      bits  = 8; 
     341     info.codec = ROAR_CODEC_MULAW; 
     342     info.bits  = 8; 
     343    break; 
     344   case GST_BUFTYPE_GSM: 
     345     info.codec = ROAR_CODEC_GSM; 
     346     info.bits  = 0; 
    316347    break; 
    317348   default: 
     
    319350  } 
    320351 
    321   roarsink->fd = roar_simple_new_stream(&(roarsink->con), spec->rate, spec->channels, bits, 
    322                                         codec, ROAR_DIR_PLAY); 
    323  
    324   if ( roarsink->fd == -1 ) 
     352  if ( roar_vs_stream(roarsink->vss, &info, ROAR_DIR_PLAY, NULL) == -1 ) 
    325353    goto cannot_open; 
    326354 
    327   roarsink->rate = spec->rate; 
    328  
     355  // apply parameters: 
     356  if ( roarsink->mute != ROAR_VS_ASK && roar_vs_mute(roarsink->vss, roarsink->mute, NULL) == -1 ) { 
     357    goto cannot_open; 
     358  } 
     359  if ( roarsink->volume >= 0.0 && roar_vs_volume_mono(roarsink->vss, roarsink->volume, NULL) == -1 ) { 
     360    goto cannot_open; 
     361  } 
     362 
     363  /* get server info */ 
    329364  spec->segsize  = ROAR_BUF_SIZE; 
    330365  spec->segtotal = (ROAR_MAX_WRITE_SIZE / spec->segsize); 
     
    332367  /* FIXME: this is wrong for signed ints (and the 
    333368   * audioringbuffers should do it for us anyway) */ 
    334   spec->bytes_per_sample = spec->channels * bits / 8; 
     369  spec->bytes_per_sample = roar_info2framesize(&info) / 8; 
    335370  memset(&(spec->silence_sample), 0, sizeof(spec->silence_sample)); 
    336371 
     
    352387  GstRoarSink *roarsink = GST_ROARSINK(asink); 
    353388 
    354   if ((roarsink->fd == -1) && (roar_get_connection_fh(&(roarsink->con)) == -1)) 
     389  if (roarsink->vss == NULL) 
    355390    return TRUE; 
    356391 
    357   close(roarsink->fd); 
    358   roarsink->fd = -1; 
     392  roar_vs_close(roarsink->vss, ROAR_VS_FALSE, NULL); 
     393  roarsink->vss = NULL; 
    359394 
    360395  GST_INFO_OBJECT(roarsink, "closed sound device"); 
     
    371406 
    372407  while (to_write > 0) { 
    373     int done; 
    374  
    375     done = write(roarsink->fd, data, to_write); 
     408    ssize_t done; 
     409 
     410    done = roar_vs_write(roarsink->vss, data, to_write, NULL); 
    376411 
    377412    if (done < 0) 
     
    418453      roarsink->host = g_value_dup_string(value); 
    419454     break; 
     455    case PROP_ROLE: 
     456      if ( roarsink->role != NULL ) 
     457       g_free(roarsink->role); 
     458      roarsink->role = g_value_dup_string(value); 
     459     break; 
     460    case PROP_VOLUME: 
     461      roarsink->volume = (float)g_value_get_float(value); 
     462 
     463      if ( roarsink->vss == NULL ) 
     464       return; 
     465 
     466      roar_vs_volume_mono(roarsink->vss, roarsink->volume, NULL); 
     467     break; 
     468    case PROP_MUTE: 
     469      if ( g_value_get_boolean(value) ) { 
     470       roarsink->mute = ROAR_VS_TRUE; 
     471      } else { 
     472       roarsink->mute = ROAR_VS_FALSE; 
     473      } 
     474 
     475      if ( roarsink->vss == NULL ) 
     476       return; 
     477 
     478      roar_vs_mute(roarsink->vss, roarsink->mute, NULL); 
     479     break; 
    420480    default: 
    421481      break; 
     
    426486                                       GParamSpec * pspec) { 
    427487  GstRoarSink *roarsink = GST_ROARSINK(object); 
     488  float l, r; 
     489  int ret; 
    428490 
    429491  switch (prop_id) { 
    430492    case PROP_HOST: 
    431493      g_value_set_string(value, roarsink->host); 
     494     break; 
     495    case PROP_ROLE: 
     496      g_value_set_string(value, roarsink->role); 
     497     break; 
     498    case PROP_VOLUME: 
     499      if ( roarsink->vss == NULL || roar_vs_volume_get(roarsink->vss, &l, &r, NULL) == -1 ) { 
     500       l = roarsink->volume >= 0.0 ? roarsink->volume : 1.0; 
     501      } else { 
     502       l = (l + r)/2; 
     503       roarsink->volume = l; 
     504      } 
     505      g_value_set_float(value, l); 
     506     break; 
     507    case PROP_MUTE: 
     508      if ( roarsink->vss == NULL || (ret = roar_vs_mute(roarsink->vss, ROAR_VS_ASK, NULL)) == -1 ) { 
     509       ret = roarsink->mute != ROAR_VS_ASK ? roarsink->mute : ROAR_VS_FALSE; 
     510      } else { 
     511       roarsink->mute = ret; 
     512      } 
     513 
     514      g_value_set_boolean(value, ret == ROAR_VS_TRUE ? TRUE : FALSE); 
    432515     break; 
    433516    default: 
  • plugins/gstreamer0.10/roarsink.h

    r4023 r4662  
    5555  GstAudioSink   sink; 
    5656 
    57   struct roar_connection con; 
    58   int       fd; 
     57  roar_vs_t * vss; 
     58 
    5959  gchar    *host; 
     60  gchar    *role; 
    6061 
    61   guint     rate; 
     62  float     volume; 
     63  int       mute; 
     64 
    6265  GstCaps  *cur_caps; 
    6366}; 
Note: See TracChangeset for help on using the changeset viewer.