1 /* Copyright 2020 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 /* 7 * Remote Stream Configuration 8 */ 9 #ifndef CRAS_RSTREAM_CONFIG_H_ 10 #define CRAS_RSTREAM_CONFIG_H_ 11 12 #include "buffer_share.h" 13 #include "cras_shm.h" 14 #include "cras_types.h" 15 16 struct cras_connect_message; 17 struct dev_mix; 18 19 /* Config for creating an rstream. 20 * stream_type - CRAS_STREAM_TYPE. 21 * client_type - CRAS_CLIENT_TYPE. 22 * direction - CRAS_STREAM_OUTPUT or CRAS_STREAM_INPUT. 23 * dev_idx - Pin to this device if != NO_DEVICE. 24 * flags - Any special handling for this stream. 25 * effects - Bit map of effects to be enabled on this stream. 26 * format - The audio format the stream wishes to use. 27 * buffer_frames - Total number of audio frames to buffer. 28 * cb_threshold - # of frames when to request more from the client. 29 * audio_fd - The fd to read/write audio signals to. May be -1 for server 30 * stream. Some functions may mutably borrow the config and move 31 * the fd ownership. 32 * client_shm_fd - The shm fd to use to back the samples area. May be -1. 33 * Some functions may dup this fd while borrowing the config. 34 * client_shm_size - The size of shm area backed by client_shm_fd. 35 * buffer_offsets - Initial values for buffer_offset for a client shm stream. 36 * client - The client that owns this stream. 37 */ 38 struct cras_rstream_config { 39 cras_stream_id_t stream_id; 40 enum CRAS_STREAM_TYPE stream_type; 41 enum CRAS_CLIENT_TYPE client_type; 42 enum CRAS_STREAM_DIRECTION direction; 43 uint32_t dev_idx; 44 uint32_t flags; 45 uint32_t effects; 46 const struct cras_audio_format *format; 47 size_t buffer_frames; 48 size_t cb_threshold; 49 int audio_fd; 50 int client_shm_fd; 51 size_t client_shm_size; 52 uint32_t buffer_offsets[2]; 53 struct cras_rclient *client; 54 }; 55 56 /* Fills cras_rstream_config with given parameters. 57 * 58 * Args: 59 * audio_fd - The audio fd pointer from client. Its ownership will be moved to 60 * stream_config. 61 * client_shm_fd - The shared memory fd pointer for samples from client. Its 62 * ownership will be moved to stream_config. 63 * Other args - See comments in struct cras_rstream_config. 64 */ 65 void cras_rstream_config_init( 66 struct cras_rclient *client, cras_stream_id_t stream_id, 67 enum CRAS_STREAM_TYPE stream_type, enum CRAS_CLIENT_TYPE client_type, 68 enum CRAS_STREAM_DIRECTION direction, uint32_t dev_idx, uint32_t flags, 69 uint32_t effects, const struct cras_audio_format *format, 70 size_t buffer_frames, size_t cb_threshold, int *audio_fd, 71 int *client_shm_fd, size_t client_shm_size, 72 const uint64_t buffer_offsets[2], 73 struct cras_rstream_config *stream_config); 74 75 /* Fills cras_rstream_config with given parameters and a cras_connect_message. 76 * 77 * Args: 78 * client - The rclient which handles the connect message. 79 * msg - The cras_connect_message from client. 80 * aud_fd - The audio fd pointer from client. Its ownership will be moved to 81 * stream_config. 82 * client_shm_fd - The shared memory fd pointer for samples from client. Its 83 * ownership will be moved to stream_config. 84 * remote_format - The remote_format for the config. 85 * 86 * Returns a cras_rstream_config struct filled in with params from the message. 87 */ 88 struct cras_rstream_config cras_rstream_config_init_with_message( 89 struct cras_rclient *client, const struct cras_connect_message *msg, 90 int *aud_fd, int *client_shm_fd, 91 const struct cras_audio_format *remote_format); 92 93 /* Cleans up given cras_rstream_config. All fds inside the config will be 94 * closed. 95 * 96 * Args: 97 * stream_config - The config to be cleaned up. 98 */ 99 void cras_rstream_config_cleanup(struct cras_rstream_config *stream_config); 100 101 #endif /* CRAS_RSTREAM_CONFIG_H_ */ 102