Ticket #1321: dialer-headset.patch

File dialer-headset.patch, 6.6 KB (added by sean_chiang@…, 11 years ago)

audio state control for headset in/out

  • src/phone-kit/moko-sound.h

     
    2323enum { SOUND_PROFILE_GSM_HANDSET, 
    2424SOUND_PROFILE_GSM_HEADSET, 
    2525SOUND_PROFILE_GSM_SPEAKER_OUT, 
    26 SOUND_PROFILE_STEREO_OUT }; 
     26SOUND_PROFILE_STEREO_OUT, 
     27SOUND_PROFILE_HEADSET}; 
    2728 
    2829void moko_sound_profile_set(int profile); 
    2930void moko_sound_profile_save(int profile); 
  • src/phone-kit/moko-dialer.c

     
    4040#include "moko-sound.h" 
    4141#include "moko-pin.h" 
    4242 
     43#include "moko-headset.h"  
     44 
    4345static void 
    4446listener_interface_init (gpointer g_iface, gpointer iface_data); 
    4547 
     
    435437  static int on_speaker = FALSE; 
    436438 
    437439  if (on_speaker) 
    438     moko_sound_profile_set(SOUND_PROFILE_GSM_HANDSET); 
     440  { 
     441    if ( HEADSET_STATUS_IN == moko_headset_status_get() )  
     442      moko_sound_profile_set(SOUND_PROFILE_GSM_HEADSET); 
     443    else 
     444      moko_sound_profile_set(SOUND_PROFILE_GSM_HANDSET); 
     445  }   
    439446  else 
    440447    moko_sound_profile_set(SOUND_PROFILE_GSM_SPEAKER_OUT); 
    441448 
  • src/phone-kit/dialer-main.c

     
    3131#include "moko-dialer.h" 
    3232#include "moko-sms.h" 
    3333#include "moko-pb.h" 
     34#include "moko-headset.h" 
    3435 
    3536#include "moko-contacts.h" 
    3637 
     
    340341    on_network_status_changed (network, status, pb); 
    341342} 
    342343 
     344static void 
     345headset_in_cb (DBusGProxy *proxy, const gchar *name, MokoDialer *dialer) 
     346{ 
     347        moko_headset_status_set(HEADSET_STATUS_IN); 
     348 
     349        if ( PK_DIALER_NORMAL == priv->status ) 
     350                moko_sound_profile_set(SOUND_PROFILE_HEADSET); 
     351        if ( PK_DIALER_INCOMING == priv->status ) 
     352                moko_sound_profile_set(SOUND_PROFILE_HEADSET); 
     353        if ( PK_DIALER_DIALING == priv->status ) 
     354                moko_sound_profile_set(SOUND_PROFILE_HEADSET); 
     355        if ( PK_DIALER_TALKING == priv->status ) 
     356                moko_sound_profile_set(SOUND_PROFILE_GSM_HEADSET); 
     357} 
     358 
     359static void 
     360headset_out_cb (DBusGProxy *proxy, const gchar *name, MokoDialer *dialer)  
     361{ 
     362        moko_headset_status_set(HEADSET_STATUS_OUT); 
     363 
     364        if ( PK_DIALER_NORMAL == priv->status ) 
     365                moko_sound_profile_set(SOUND_PROFILE_STEREO_OUT); 
     366        if ( PK_DIALER_INCOMING == priv->status ) 
     367                moko_sound_profile_set(SOUND_PROFILE_STEREO_OUT); 
     368        if ( PK_DIALER_DIALING == priv->status ) 
     369                moko_sound_profile_set(SOUND_PROFILE_STEREO_OUT); 
     370        if ( PK_DIALER_TALKING == priv->status ) 
     371                moko_sound_profile_set(SOUND_PROFILE_GSM_HANDSET); 
     372} 
     373 
    343374int 
    344375main (int argc, char **argv) 
    345376{ 
     
    349380  MokoPb *pb; 
    350381  DBusGConnection *connection; 
    351382  DBusGProxy *proxy; 
     383  DBusGProxy *headset_proxy; 
    352384  GError *error = NULL; 
    353385  guint32 ret; 
    354386 
     
    418450                                       SMS_PATH, 
    419451                                       G_OBJECT (sms)); 
    420452 
     453  headset_proxy = dbus_g_proxy_new_for_name (connection,                                                   
     454                  NULL, 
     455                  "/org/openmoko/PhoneKit/Headset", 
     456                  "org.openmoko.PhoneKit.Headset"); 
     457  dbus_g_proxy_add_signal (headset_proxy, 
     458                  "HeadsetIn", G_TYPE_INVALID); 
     459  dbus_g_proxy_connect_signal (headset_proxy, 
     460                  "HeadsetIn", G_CALLBACK (headset_in_cb), 
     461                  dialer, NULL); 
     462  dbus_g_proxy_add_signal (headset_proxy, 
     463                  "HeadsetOut", G_TYPE_INVALID); 
     464  dbus_g_proxy_connect_signal (headset_proxy, 
     465                  "HeadsetOut", G_CALLBACK (headset_out_cb), 
     466                  dialer, NULL); 
     467 
    421468  /* Sync phonebook */ 
    422469  /* XXX this is not the right place! */ 
    423470  pb_sync (pb, network); 
  • src/phone-kit/Makefile.am

     
    2121        moko-pb.c moko-pb.h \ 
    2222        moko-pin.c moko-pin.h \ 
    2323        moko-mcc-dc.h \ 
     24        moko-headset.c moko-headset.h \ 
    2425        $(BUILT_SOURCES) 
    2526 
    2627phone_kit_LDADD = @DIALER_LIBS@ @JANA_LIBS@ @NOTIFY_LIBS@ @ALSA_LIBS@ $(top_srcdir)/src/common/libdialer-common.a 
  • src/phone-kit/moko-sound.c

     
    2727  "/usr/share/openmoko/scenarios/gsmheadset.state", 
    2828  "/usr/share/openmoko/scenarios/gsmspeakerout.state", 
    2929  "/usr/share/openmoko/scenarios/stereoout.state" 
     30  "/usr/share/openmoko/scenarios/headset.state" 
    3031}; 
    3132 
    3233void moko_sound_profile_set(int profile) { 
  • src/phone-kit/moko-talking.c

     
    2626#include "moko-alsa-volume-control.h" 
    2727#include "moko-alsa-volume-scale.h" 
    2828 
     29#include "moko-headset.h" 
     30 
    2931G_DEFINE_TYPE (MokoTalking, moko_talking, GTK_TYPE_WIDGET) 
    3032 
    3133#define MOKO_TALKING_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE(obj, \ 
     
    216218  gtk_widget_hide (priv->incoming_bar); 
    217219  gtk_widget_show_all (priv->main_bar); 
    218220 
    219   moko_sound_profile_set(SOUND_PROFILE_GSM_HANDSET); 
     221  if ( HEADSET_STATUS_IN == moko_headset_status_get() )  
     222    moko_sound_profile_set(SOUND_PROFILE_GSM_HEADSET); 
     223  else 
     224    moko_sound_profile_set(SOUND_PROFILE_GSM_HANDSET); 
    220225 
    221226  if (entry) 
    222227    markup = g_strdup_printf ("<b>%s</b>\n%s", entry->contact->name, number); 
     
    296301  gtk_widget_hide (priv->incoming_bar); 
    297302  gtk_widget_show_all (priv->main_bar); 
    298303 
    299   moko_sound_profile_set(SOUND_PROFILE_GSM_HANDSET); 
     304  if ( HEADSET_STATUS_IN == moko_headset_status_get() )  
     305    moko_sound_profile_set(SOUND_PROFILE_GSM_HEADSET); 
     306  else 
     307    moko_sound_profile_set(SOUND_PROFILE_GSM_HANDSET); 
    300308 
    301309  if (entry) 
    302310    markup = g_strdup_printf ("<b>%s</b>\n%s", entry->contact->name, number); 
     
    334342  g_return_if_fail (MOKO_IS_TALKING (talking)); 
    335343  priv = talking->priv; 
    336344 
    337   moko_sound_profile_set(SOUND_PROFILE_STEREO_OUT); 
     345  if ( HEADSET_STATUS_IN == moko_headset_status_get() )  
     346    moko_sound_profile_set(SOUND_PROFILE_HEADSET); 
     347  else  
     348    moko_sound_profile_set(SOUND_PROFILE_STEREO_OUT); 
    338349 
    339350  if (priv->dtimer) 
    340351    g_timer_destroy(priv->dtimer); 
     
    392403  if (priv->timeout) 
    393404    g_source_remove (priv->timeout); 
    394405 
    395   moko_sound_profile_set(SOUND_PROFILE_STEREO_OUT); 
     406  if ( HEADSET_STATUS_IN == moko_headset_status_get() )  
     407    moko_sound_profile_set(SOUND_PROFILE_HEADSET); 
     408  else 
     409    moko_sound_profile_set(SOUND_PROFILE_STEREO_OUT); 
    396410  gtk_widget_hide (priv->window); 
    397411  g_signal_emit (G_OBJECT (talking), talking_signals[CANCEL_CALL], 0); 
    398412}