Ticket #1321: dialer-headset.2.patch

File dialer-headset.2.patch, 7.1 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" 
     35#include "moko-sound.h" 
    3436 
    3537#include "moko-contacts.h" 
    3638 
     
    340342    on_network_status_changed (network, status, pb); 
    341343} 
    342344 
     345static void 
     346headset_in_cb (DBusGProxy *proxy, const gchar *name, void *data) 
     347{ 
     348    PhoneKitDialerStatus status; 
     349    MokoNetwork *network; 
     350    MokoDialer *dialer; 
     351 
     352    network = moko_network_get_default (); 
     353    dialer = moko_dialer_get_default (network); 
     354     
     355    status = moko_dialer_get_status(dialer);   
     356 
     357    moko_headset_status_set(HEADSET_STATUS_IN); 
     358 
     359    if ( PK_DIALER_NORMAL == status ) 
     360        moko_sound_profile_set(SOUND_PROFILE_HEADSET); 
     361    if ( PK_DIALER_INCOMING == status ) 
     362        moko_sound_profile_set(SOUND_PROFILE_HEADSET); 
     363    if ( PK_DIALER_DIALING == status ) 
     364        moko_sound_profile_set(SOUND_PROFILE_HEADSET); 
     365    if ( PK_DIALER_TALKING == status ) 
     366        moko_sound_profile_set(SOUND_PROFILE_GSM_HEADSET); 
     367} 
     368 
     369static void 
     370headset_out_cb (DBusGProxy *proxy, const gchar *name, void *data)  
     371{ 
     372    PhoneKitDialerStatus status; 
     373    MokoNetwork *network; 
     374    MokoDialer *dialer; 
     375 
     376    network = moko_network_get_default (); 
     377    dialer = moko_dialer_get_default (network); 
     378     
     379    status = moko_dialer_get_status(dialer);   
     380     
     381    moko_headset_status_set(HEADSET_STATUS_OUT); 
     382 
     383    if ( PK_DIALER_NORMAL == status ) 
     384        moko_sound_profile_set(SOUND_PROFILE_STEREO_OUT); 
     385    if ( PK_DIALER_INCOMING == status ) 
     386        moko_sound_profile_set(SOUND_PROFILE_STEREO_OUT); 
     387    if ( PK_DIALER_DIALING == status ) 
     388        moko_sound_profile_set(SOUND_PROFILE_STEREO_OUT); 
     389    if ( PK_DIALER_TALKING == status ) 
     390        moko_sound_profile_set(SOUND_PROFILE_GSM_HANDSET); 
     391} 
     392 
    343393int 
    344394main (int argc, char **argv) 
    345395{ 
     
    349399  MokoPb *pb; 
    350400  DBusGConnection *connection; 
    351401  DBusGProxy *proxy; 
     402  DBusGProxy *headset_proxy; 
    352403  GError *error = NULL; 
    353404  guint32 ret; 
    354405 
     
    418469                                       SMS_PATH, 
    419470                                       G_OBJECT (sms)); 
    420471 
     472  headset_proxy = dbus_g_proxy_new_for_name (connection,                                                   
     473                  NULL, 
     474                  "/org/openmoko/PhoneKit/Headset", 
     475                  "org.openmoko.PhoneKit.Headset"); 
     476  dbus_g_proxy_add_signal (headset_proxy, 
     477                  "HeadsetIn", G_TYPE_INVALID); 
     478  dbus_g_proxy_connect_signal (headset_proxy, 
     479                  "HeadsetIn", G_CALLBACK (headset_in_cb), 
     480                  NULL, NULL); 
     481  dbus_g_proxy_add_signal (headset_proxy, 
     482                  "HeadsetOut", G_TYPE_INVALID); 
     483  dbus_g_proxy_connect_signal (headset_proxy, 
     484                  "HeadsetOut", G_CALLBACK (headset_out_cb), 
     485                  NULL, NULL); 
     486 
    421487  /* Sync phonebook */ 
    422488  /* XXX this is not the right place! */ 
    423489  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}