fn create_stream<'b, T: BufferDrop + CrasStreamData<'b>>(
        &mut self,
        device_index: Option<u32>,
        block_size: u32,
        direction: CRAS_STREAM_DIRECTION,
        rate: u32,
        channel_num: usize,
        format: SampleFormat,
    ) -> Result<CrasStream<'b, T>> {
        let stream_id = self.next_server_stream_id();

        // Prepares server message
        let audio_format =
            cras_audio_format_packed::new(format.into(), rate, channel_num, direction);
        let msg_header = cras_server_message {
            length: mem::size_of::<cras_connect_message>() as u32,
            id: CRAS_SERVER_MESSAGE_ID::CRAS_SERVER_CONNECT_STREAM,
        };
        let server_cmsg = cras_connect_message {
            header: msg_header,
            proto_version: CRAS_PROTO_VER,
            direction,
            stream_id,
            stream_type: CRAS_STREAM_TYPE::CRAS_STREAM_TYPE_DEFAULT,
            buffer_frames: block_size,
            cb_threshold: block_size,
            flags: 0,
            format: audio_format,
            dev_idx: device_index.unwrap_or(CRAS_SPECIAL_DEVICE::NO_DEVICE as u32),
            effects: 0,
            client_type: self.client_type,
            client_shm_size: 0,
            buffer_offsets: [0, 0],
        };

        // Creates AudioSocket pair
        let (sock1, sock2) = UnixStream::pair()?;

        // Sends `CRAS_SERVER_CONNECT_STREAM` message
        let socks = [sock2.as_raw_fd()];
        self.server_socket
            .send_server_message_with_fds(&server_cmsg, &socks)?;

        let audio_socket = AudioSocket::new(sock1);
        loop {
            let result = CrasClient::wait_for_message(&mut self.server_socket)?;
            if let ServerResult::StreamConnected(_stream_id, header_fd, samples_fd) = result {
                return CrasStream::try_new(
                    stream_id,
                    self.server_socket.try_clone()?,
                    block_size,
                    direction,
                    rate,
                    channel_num,
                    format.into(),
                    audio_socket,
                    header_fd,
                    samples_fd,
                )
                .map_err(Error::CrasStreamError);
            }
        }
    }
// Creates general stream with given parameters
Creates general stream with given parameters
Creates general stream with given parameters
fn create_stream<'b, T: BufferDrop + CrasStreamData<'b>>(
        &mut self,
        device_index: Option<u32>,
        block_size: u32,
        direction: CRAS_STREAM_DIRECTION,
        rate: u32,
        channel_num: usize,
        format: SampleFormat,
    ) -> Result<CrasStream<'b, T>> {
        let stream_id = self.next_server_stream_id();
        // Prepares server message
        let audio_format =
            cras_audio_format_packed::new(format.into(), rate, channel_num, direction);
        let msg_header = cras_server_message {
            length: mem::size_of::<cras_connect_message>() as u32,
            id: CRAS_SERVER_MESSAGE_ID::CRAS_SERVER_CONNECT_STREAM,
        };
        let server_cmsg = cras_connect_message {
            header: msg_header,
            proto_version: CRAS_PROTO_VER,
            direction,
            stream_id,
            stream_type: CRAS_STREAM_TYPE::CRAS_STREAM_TYPE_DEFAULT,
            buffer_frames: block_size,
            cb_threshold: block_size,
            flags: 0,
            format: audio_format,
            dev_idx: device_index.unwrap_or(CRAS_SPECIAL_DEVICE::NO_DEVICE as u32),
            effects: 0,
            client_type: self.client_type,
            client_shm_size: 0,
            buffer_offsets: [0, 0],
        };
        // Creates AudioSocket pair
        let (sock1, sock2) = UnixStream::pair()?;
        // Sends `CRAS_SERVER_CONNECT_STREAM` message
        let socks = [sock2.as_raw_fd()];
        self.server_socket
            .send_server_message_with_fds(&server_cmsg, &socks)?;
        let audio_socket = AudioSocket::new(sock1);
        loop {
            let result = CrasClient::wait_for_message(&mut self.server_socket)?;
            if let ServerResult::StreamConnected(_stream_id, header_fd, samples_fd) = result {
                return CrasStream::try_new(
                    stream_id,
                    self.server_socket.try_clone()?,
                    block_size,
                    direction,
                    rate,
                    channel_num,
                    format.into(),
                    audio_socket,
                    header_fd,
                    samples_fd,
                )
                .map_err(Error::CrasStreamError);
            }
        }
    }
fn create_stream < ' b , T : BufferDrop + CrasStreamData < ' b > > ( & mut self , device_index : Option < u32 > , block_size : u32 , direction : CRAS_STREAM_DIRECTION , rate : u32 , channel_num : usize , format : SampleFormat , ) -> Result < CrasStream < ' b , T > > { let stream_id = self . next_server_stream_id ( ) ; // Prepares server message let audio_format = cras_audio_format_packed :: new ( format . into ( ) , rate , channel_num , direction ) ; let msg_header = cras_server_message { length : mem :: size_of :: < cras_connect_message > ( ) as u32 , id : CRAS_SERVER_MESSAGE_ID :: CRAS_SERVER_CONNECT_STREAM , } ; let server_cmsg = cras_connect_message { header : msg_header , proto_version : CRAS_PROTO_VER , direction , stream_id , stream_type : CRAS_STREAM_TYPE :: CRAS_STREAM_TYPE_DEFAULT , buffer_frames : block_size , cb_threshold : block_size , flags : 0 , format : audio_format , dev_idx : device_index . unwrap_or ( CRAS_SPECIAL_DEVICE :: NO_DEVICE as u32 ) , effects : 0 , client_type : self . client_type , client_shm_size : 0 , buffer_offsets : [ 0 , 0 ] , } ; // Creates AudioSocket pair let ( sock1 , sock2 ) = UnixStream :: pair ( ) ? ; // Sends `CRAS_SERVER_CONNECT_STREAM` message let socks = [ sock2 . as_raw_fd ( ) ] ; self . server_socket . send_server_message_with_fds ( & server_cmsg , & socks ) ? ; let audio_socket = AudioSocket :: new ( sock1 ) ; loop { let result = CrasClient :: wait_for_message ( & mut self . server_socket ) ? ; if let ServerResult :: StreamConnected ( _stream_id , header_fd , samples_fd ) = result { return CrasStream :: try_new ( stream_id , self . server_socket . try_clone ( ) ? , block_size , direction , rate , channel_num , format . into ( ) , audio_socket , header_fd , samples_fd , ) . map_err ( Error :: CrasStreamError ) ; } } }
Creates general stream with given parameters
Creates general stream with given parameters
&mut self
device_index
Option<u32>
block_size
u32
direction
CRAS_STREAM_DIRECTION
rate
u32
channel_num
usize
format
SampleFormat
&mut self
device_index
Option<u32>
block_size
u32
direction
CRAS_STREAM_DIRECTION
rate
u32
channel_num
usize
format
SampleFormat