PebbleOS
Loading...
Searching...
No Matches
mic_manager.h File Reference
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <pbl/drivers/mic.h>
#include <kernel/pebble_tasks.h>

Typedefs

typedef void(* MicManagerPreemptedCb) (void *context)
 Called (without the manager lock held) when the client's mic is taken away.
 

Enumerations

enum  MicClient { MicClientNone = 0 , MicClientVoiceDictation , MicClientAppStream , MicClientAppCapture }
 Arbitrates the single microphone between kernel clients. More...
 
enum  MicManagerAppCheck { MicManagerAppOk = 0 , MicManagerAppNotForeground , MicManagerAppWatchface }
 

Functions

MicManagerAppCheck mic_manager_check_app (PebbleTask task)
 Whether task is a foreground app in focus, the only kind that may use the mic.
 
void mic_manager_init (void)
 
bool mic_manager_acquire (MicClient client, MicDataHandlerCB handler, void *context, int16_t *buffer, size_t buffer_len, MicManagerPreemptedCb on_preempted, void *preempt_context)
 Starts the microphone for a client.
 
bool mic_manager_reserve (MicClient client)
 Holds the idle mic for an app client whose start is pending, so other apps see it as busy.
 
void mic_manager_release (MicClient client)
 Stops the microphone if the client owns it and drops its reservation. No-op otherwise.
 
void mic_manager_set_dictation_active (bool active)
 Set for a whole dictation session, from before it takes the audio endpoint until it ends.
 
MicClient mic_manager_get_owner (void)
 
bool mic_manager_is_busy (void)
 

Typedef Documentation

◆ MicManagerPreemptedCb

typedef void(* MicManagerPreemptedCb) (void *context)

Called (without the manager lock held) when the client's mic is taken away.

The client must not call mic_manager_release() for the lost session; it is already released.

Enumeration Type Documentation

◆ MicClient

enum MicClient

Arbitrates the single microphone between kernel clients.

Dictation (the system voice UI) has priority over app capture: acquiring for dictation while an app owns the mic preempts the app, which is told through its preempted callback before the mic is restarted. An app cannot acquire the mic while dictation owns it. The OS mic banner is shown while an app client owns the running mic.

Enumerator
MicClientNone 
MicClientVoiceDictation 
MicClientAppStream 
MicClientAppCapture 

◆ MicManagerAppCheck

Enumerator
MicManagerAppOk 
MicManagerAppNotForeground 
MicManagerAppWatchface 

Function Documentation

◆ mic_manager_acquire()

bool mic_manager_acquire ( MicClient  client,
MicDataHandlerCB  handler,
void *  context,
int16_t *  buffer,
size_t  buffer_len,
MicManagerPreemptedCb  on_preempted,
void *  preempt_context 
)

Starts the microphone for a client.

See mic_start for the buffer semantics.

Returns
true if the client now owns the running microphone

◆ mic_manager_check_app()

MicManagerAppCheck mic_manager_check_app ( PebbleTask  task)

Whether task is a foreground app in focus, the only kind that may use the mic.

◆ mic_manager_get_owner()

MicClient mic_manager_get_owner ( void  )

◆ mic_manager_init()

void mic_manager_init ( void  )

◆ mic_manager_is_busy()

bool mic_manager_is_busy ( void  )
Returns
true while the mic is owned or reserved, or a dictation session runs

◆ mic_manager_release()

void mic_manager_release ( MicClient  client)

Stops the microphone if the client owns it and drops its reservation. No-op otherwise.

◆ mic_manager_reserve()

bool mic_manager_reserve ( MicClient  client)

Holds the idle mic for an app client whose start is pending, so other apps see it as busy.

Only that client or dictation may then acquire it. Cleared by acquire or release.

Returns
true if the mic was idle and unreserved

◆ mic_manager_set_dictation_active()

void mic_manager_set_dictation_active ( bool  active)

Set for a whole dictation session, from before it takes the audio endpoint until it ends.

Apps can neither reserve nor acquire the mic meanwhile.