cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

audio.h (7235B)


      1/*
      2 * Licensed to the Apache Software Foundation (ASF) under one
      3 * or more contributor license agreements.  See the NOTICE file
      4 * distributed with this work for additional information
      5 * regarding copyright ownership.  The ASF licenses this file
      6 * to you under the Apache License, Version 2.0 (the
      7 * "License"); you may not use this file except in compliance
      8 * with the License.  You may obtain a copy of the License at
      9 *
     10 *   http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing,
     13 * software distributed under the License is distributed on an
     14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     15 * KIND, either express or implied.  See the License for the
     16 * specific language governing permissions and limitations
     17 * under the License.
     18 */
     19
     20
     21#ifndef __GUAC_AUDIO_H
     22#define __GUAC_AUDIO_H
     23
     24/**
     25 * Provides functions and structures used for providing simple streaming audio.
     26 *
     27 * @file audio.h
     28 */
     29
     30#include "audio-fntypes.h"
     31#include "audio-types.h"
     32#include "client-types.h"
     33#include "stream-types.h"
     34
     35struct guac_audio_encoder {
     36
     37    /**
     38     * The mimetype of the audio data encoded by this audio
     39     * encoder.
     40     */
     41    const char* mimetype;
     42
     43    /**
     44     * Handler which will be called when the audio stream is first created.
     45     */
     46    guac_audio_encoder_begin_handler* begin_handler;
     47
     48    /**
     49     * Handler which will be called when PCM data is written to the audio
     50     * stream for encoding.
     51     */
     52    guac_audio_encoder_write_handler* write_handler;
     53
     54    /**
     55     * Handler which will be called when the audio stream is flushed.
     56     */
     57    guac_audio_encoder_flush_handler* flush_handler;
     58
     59    /**
     60     * Handler which will be called when the audio stream is closed.
     61     */
     62    guac_audio_encoder_end_handler* end_handler;
     63
     64    /**
     65     * Handler which will be called when a new user joins the Guacamole
     66     * connection associated with an audio stream.
     67     */
     68    guac_audio_encoder_join_handler* join_handler;
     69
     70};
     71
     72struct guac_audio_stream {
     73
     74    /**
     75     * Arbitrary codec encoder which will receive raw PCM data.
     76     */
     77    guac_audio_encoder* encoder;
     78
     79    /**
     80     * The client associated with this audio stream.
     81     */
     82    guac_client* client;
     83
     84    /**
     85     * The actual stream associated with this audio stream.
     86     */
     87    guac_stream* stream;
     88
     89    /**
     90     * The number of samples per second of PCM data sent to this stream.
     91     */
     92    int rate;
     93
     94    /**
     95     * The number of audio channels per sample of PCM data. Legal values are
     96     * 1 or 2.
     97     */
     98    int channels;
     99
    100    /**
    101     * The number of bits per sample per channel for PCM data. Legal values are
    102     * 8 or 16.
    103     */
    104    int bps;
    105
    106    /**
    107     * Encoder-specific state data.
    108     */
    109    void* data;
    110
    111};
    112
    113/**
    114 * Allocates a new audio stream at the client level which encodes audio data
    115 * using the given encoder. If NULL is specified for the encoder, an
    116 * appropriate encoder will be selected based on the encoders built into
    117 * libguac and the level of support declared by users associated with the
    118 * given guac_client. The PCM format specified here (via rate, channels, and
    119 * bps) must be the format used for all PCM data provided to the audio stream.
    120 * The format may only be changed using guac_audio_stream_reset().
    121 *
    122 * If a new user joins the connection after the audio stream is created, that
    123 * user will not be aware of the existence of the audio stream, and
    124 * guac_audio_stream_add_user() will need to be invoked to recreate the stream
    125 * for the new user.
    126 *
    127 * @param client
    128 *     The guac_client for which this audio stream is being allocated. The
    129 *     connection owner is given priority when determining the level of audio
    130 *     support. It is currently assumed that all other joining users on the
    131 *     connection will have the same level of audio support.
    132 *
    133 * @param encoder
    134 *     The guac_audio_encoder to use when encoding audio, or NULL if libguac
    135 *     should select an appropriate built-in encoder on its own.
    136 *
    137 * @param rate
    138 *     The number of samples per second of PCM data sent to this stream.
    139 *
    140 * @param channels
    141 *     The number of audio channels per sample of PCM data. Legal values are
    142 *     1 or 2.
    143 *
    144 * @param bps
    145 *     The number of bits per sample per channel for PCM data. Legal values are
    146 *     8 or 16.
    147 *
    148 * @return
    149 *     The newly allocated guac_audio_stream, or NULL if no audio stream could
    150 *     be allocated due to lack of support on the part of the connecting
    151 *     Guacamole client or due to reaching the maximum number of active
    152 *     streams.
    153 */
    154guac_audio_stream* guac_audio_stream_alloc(guac_client* client,
    155        guac_audio_encoder* encoder, int rate, int channels, int bps);
    156
    157/**
    158 * Resets the given audio stream, switching to the given encoder, rate,
    159 * channels, and bits per sample. If NULL is specified for the encoder, the
    160 * encoder is left unchanged. If the encoder, rate, channels, and bits per
    161 * sample are all identical to the current settings, this function has no
    162 * effect.
    163 *
    164 * @param audio
    165 *     The guac_audio_stream to reset.
    166 *
    167 * @param encoder
    168 *     The guac_audio_encoder to use when encoding audio, or NULL to leave this
    169 *     unchanged.
    170 *
    171 * @param rate
    172 *     The number of samples per second of PCM data sent to this stream.
    173 *
    174 * @param channels
    175 *     The number of audio channels per sample of PCM data. Legal values are
    176 *     1 or 2.
    177 *
    178 * @param bps
    179 *     The number of bits per sample per channel for PCM data. Legal values are
    180 *     8 or 16.
    181 */
    182void guac_audio_stream_reset(guac_audio_stream* audio,
    183        guac_audio_encoder* encoder, int rate, int channels, int bps);
    184
    185/**
    186 * Notifies the given audio stream that a user has joined the connection. The
    187 * audio stream itself may need to be restarted. and the audio stream will need
    188 * to be created for the new user to ensure they can properly handle future
    189 * data received along the stream.
    190 *
    191 * @param audio
    192 *     The guac_audio_stream associated with the Guacamole connection being
    193 *     joined.
    194 *
    195 * @param user
    196 *     The user that has joined the Guacamole connection.
    197 */
    198void guac_audio_stream_add_user(guac_audio_stream* audio, guac_user* user);
    199
    200/**
    201 * Closes and frees the given audio stream.
    202 *
    203 * @param stream
    204 *     The guac_audio_stream to free.
    205 */
    206void guac_audio_stream_free(guac_audio_stream* stream);
    207
    208/**
    209 * Writes PCM data to the given audio stream. This PCM data will be
    210 * automatically encoded by the audio encoder associated with this stream. The
    211 * PCM data must be 2-channel, 44100 Hz, with signed 16-bit samples.
    212 *
    213 * @param stream
    214 *     The guac_audio_stream to write PCM data through.
    215 *
    216 * @param data
    217 *     The PCM data to write.
    218 *
    219 * @param length
    220 *     The number of bytes of PCM data provided.
    221 */
    222void guac_audio_stream_write_pcm(guac_audio_stream* stream,
    223        const unsigned char* data, int length);
    224
    225/**
    226 * Flushes the underlying audio buffer, if any, ensuring that all audio
    227 * previously written via guac_audio_stream_write_pcm() has been encoded and
    228 * sent to the client.
    229 *
    230 * @param stream
    231 *     The guac_audio_stream whose audio buffers should be flushed.
    232 */
    233void guac_audio_stream_flush(guac_audio_stream* stream);
    234
    235#endif
    236