summaryrefslogtreecommitdiff
path: root/cras/src/server/stream_list.h
blob: a527bc9798137f68e99f7a37a4140c072c6aafd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* Copyright 2015 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include <stdbool.h>

#include "cras_types.h"
#include "utlist.h"

struct cras_rclient;
struct cras_rstream;
struct cras_rstream_config;
struct cras_audio_format;
struct stream_list;

typedef int(stream_callback)(struct cras_rstream *rstream);
/* This function will mutably borrow stream_config. */
typedef int(stream_create_func)(struct cras_rstream_config *stream_config,
				struct cras_rstream **rstream);
typedef void(stream_destroy_func)(struct cras_rstream *rstream);

struct stream_list *stream_list_create(stream_callback *add_cb,
				       stream_callback *rm_cb,
				       stream_create_func *create_cb,
				       stream_destroy_func *destroy_cb,
				       struct cras_tm *timer_manager);

void stream_list_destroy(struct stream_list *list);

struct cras_rstream *stream_list_get(struct stream_list *list);

/* Creates a cras_rstream from cras_rstream_config and inserts the cras_rstream
 * to stream_list in descending order by channel count.
 *
 * Args:
 *   list - stream_list to add streams.
 *   stream_config - A mutable borrow of cras_rstream_config.
 *   stream - A pointer to place created cras_rstream.
 *
 * Returns:
 *   0 on success. Negative error code on failure.
 */
int stream_list_add(struct stream_list *list,
		    struct cras_rstream_config *stream_config,
		    struct cras_rstream **stream);

int stream_list_rm(struct stream_list *list, cras_stream_id_t id);

int stream_list_rm_all_client_streams(struct stream_list *list,
				      struct cras_rclient *rclient);

/*
 * Checks if there is a stream pinned to the given device.
 */
bool stream_list_has_pinned_stream(struct stream_list *list,
				   unsigned int dev_idx);

/*
 * Detects whether there is a RTC stream pair based on these rules:
 * 1. The cb_threshold is 480.
 * 2. The direction of two streams are opposite.
 * 3. Two streams are from the same client. (Chrome or LaCrOS)
 * 4. The start time of two streams are close enough. (shorter than 1s)
 * If all rules are passed, set the stream type to the voice communication.
 */
void detect_rtc_stream_pair(struct stream_list *list,
			    struct cras_rstream *stream);