1 /* Copyright 2015 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 #include <stdbool.h> 7 8 #include "cras_types.h" 9 #include "utlist.h" 10 11 struct cras_rclient; 12 struct cras_rstream; 13 struct cras_rstream_config; 14 struct cras_audio_format; 15 struct stream_list; 16 17 typedef int(stream_callback)(struct cras_rstream *rstream); 18 /* This function will mutably borrow stream_config. */ 19 typedef int(stream_create_func)(struct cras_rstream_config *stream_config, 20 struct cras_rstream **rstream); 21 typedef void(stream_destroy_func)(struct cras_rstream *rstream); 22 23 struct stream_list *stream_list_create(stream_callback *add_cb, 24 stream_callback *rm_cb, 25 stream_create_func *create_cb, 26 stream_destroy_func *destroy_cb, 27 struct cras_tm *timer_manager); 28 29 void stream_list_destroy(struct stream_list *list); 30 31 struct cras_rstream *stream_list_get(struct stream_list *list); 32 33 /* Creates a cras_rstream from cras_rstream_config and inserts the cras_rstream 34 * to stream_list in descending order by channel count. 35 * 36 * Args: 37 * list - stream_list to add streams. 38 * stream_config - A mutable borrow of cras_rstream_config. 39 * stream - A pointer to place created cras_rstream. 40 * 41 * Returns: 42 * 0 on success. Negative error code on failure. 43 */ 44 int stream_list_add(struct stream_list *list, 45 struct cras_rstream_config *stream_config, 46 struct cras_rstream **stream); 47 48 int stream_list_rm(struct stream_list *list, cras_stream_id_t id); 49 50 int stream_list_rm_all_client_streams(struct stream_list *list, 51 struct cras_rclient *rclient); 52 53 /* 54 * Checks if there is a stream pinned to the given device. 55 */ 56 bool stream_list_has_pinned_stream(struct stream_list *list, 57 unsigned int dev_idx); 58 59 /* 60 * Detects whether there is a RTC stream pair based on these rules: 61 * 1. The cb_threshold is 480. 62 * 2. The direction of two streams are opposite. 63 * 3. Two streams are from the same client. (Chrome or LaCrOS) 64 * 4. The start time of two streams are close enough. (shorter than 1s) 65 * If all rules are passed, set the stream type to the voice communication. 66 */ 67 void detect_rtc_stream_pair(struct stream_list *list, 68 struct cras_rstream *stream); 69