• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2016 The Chromium OS Authors. All rights reserved.
2  * Use of this source code is governed by a BSD-style license that can be
3  * found in the LICENSE file.
4  */
5 
6 #ifndef CRAS_OBSERVER_H
7 #define CRAS_OBSERVER_H
8 
9 #include "cras_observer_ops.h"
10 
11 struct cras_observer_client;
12 
13 /* Add an observer.
14  * Args:
15  *    ops - Set callback function pointers in the operations that should be
16  *          called for state changes, or NULL otherwise.
17  *    context - Context pointer passed to the callbacks.
18  * Returns:
19  *    Valid pointer to the client reference, or NULL on memory allocation
20  *    error.
21  */
22 struct cras_observer_client *
23 cras_observer_add(const struct cras_observer_ops *ops, void *context);
24 
25 /* Retrieve the observed state changes.
26  * Args:
27  *    client - The client to query.
28  *    ops - Filled with the current values in the callback table.
29  */
30 void cras_observer_get_ops(const struct cras_observer_client *client,
31 			   struct cras_observer_ops *ops);
32 
33 /* Update the observed state changes.
34  * Args:
35  *    client - The client to modify.
36  *    ops - Set callback function pointers in the operations that should be
37  *          called for state changes, or NULL otherwise.
38  */
39 void cras_observer_set_ops(struct cras_observer_client *client,
40 			   const struct cras_observer_ops *ops);
41 
42 /* Returns non-zero if the given ops are empty. */
43 int cras_observer_ops_are_empty(const struct cras_observer_ops *ops);
44 
45 /* Remove this observer client.
46  * Args:
47  *    client - The client to remove.
48  */
49 void cras_observer_remove(struct cras_observer_client *client);
50 
51 /* Initialize the observer server. */
52 int cras_observer_server_init();
53 
54 /* Destroy the observer server. */
55 void cras_observer_server_free();
56 
57 /* Notify observers of output volume change. */
58 void cras_observer_notify_output_volume(int32_t volume);
59 
60 /* Notify observers of output mute change. */
61 void cras_observer_notify_output_mute(int muted, int user_muted,
62 				      int mute_locked);
63 
64 /* Notify observers of capture gain change. */
65 void cras_observer_notify_capture_gain(int32_t gain);
66 
67 /* Notify observers of capture mute change. */
68 void cras_observer_notify_capture_mute(int muted, int mute_locked);
69 
70 /* Notify observers of a nodes list change. */
71 void cras_observer_notify_nodes(void);
72 
73 /* Notify observers of active output node change. */
74 void cras_observer_notify_active_node(enum CRAS_STREAM_DIRECTION dir,
75 				      cras_node_id_t node_id);
76 
77 /* Notify observers of output node volume change. */
78 void cras_observer_notify_output_node_volume(cras_node_id_t node_id,
79 					     int32_t volume);
80 
81 /* Notify observers of node left-right swap change. */
82 void cras_observer_notify_node_left_right_swapped(cras_node_id_t node_id,
83 						  int swapped);
84 
85 /* Notify observers of input node gain change. */
86 void cras_observer_notify_input_node_gain(cras_node_id_t node_id, int32_t gain);
87 
88 /* Notify observers of suspend state changed. */
89 void cras_observer_notify_suspend_changed(int suspended);
90 
91 /* Notify observers of the number of active streams. */
92 void cras_observer_notify_num_active_streams(enum CRAS_STREAM_DIRECTION dir,
93 					     uint32_t num_active_streams);
94 
95 /* Notify observers of the timestamp when hotword triggered. */
96 void cras_observer_notify_hotword_triggered(int64_t tv_sec, int64_t tv_nsec);
97 
98 /* Notify observers the non-empty audio state changed. */
99 void cras_observer_notify_non_empty_audio_state_changed(int active);
100 
101 #endif /* CRAS_OBSERVER_H */
102