mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice-common
synced 2026-08-08 19:50:37 +00:00
snd_codec: Use better type for function result
Instead of just plain preprocessor macros use an enum. This is more type safe and could produce better debugging type information. Signed-off-by: Frediano Ziglio <fziglio@redhat.com> Acked-by: Julien Ropé <jrope@gmail.com>
This commit is contained in:
parent
8d9a79dd7d
commit
283d82b0a3
@ -51,7 +51,6 @@ typedef struct SndCodecInternal
|
||||
} SndCodecInternal;
|
||||
|
||||
|
||||
|
||||
/* Opus support routines */
|
||||
#if HAVE_OPUS
|
||||
static void snd_codec_destroy_opus(SndCodecInternal *codec)
|
||||
@ -68,7 +67,7 @@ static void snd_codec_destroy_opus(SndCodecInternal *codec)
|
||||
|
||||
}
|
||||
|
||||
static int snd_codec_create_opus(SndCodecInternal *codec, int purpose)
|
||||
static SndCodecResult snd_codec_create_opus(SndCodecInternal *codec, int purpose)
|
||||
{
|
||||
int opus_error;
|
||||
|
||||
@ -99,7 +98,9 @@ error:
|
||||
return SND_CODEC_UNAVAILABLE;
|
||||
}
|
||||
|
||||
static int snd_codec_encode_opus(SndCodecInternal *codec, uint8_t *in_ptr, int in_size, uint8_t *out_ptr, int *out_size)
|
||||
static SndCodecResult
|
||||
snd_codec_encode_opus(SndCodecInternal *codec, uint8_t *in_ptr, int in_size,
|
||||
uint8_t *out_ptr, int *out_size)
|
||||
{
|
||||
int n;
|
||||
if (in_size != SND_CODEC_OPUS_FRAME_SIZE * SND_CODEC_PLAYBACK_CHAN * 2)
|
||||
@ -113,7 +114,9 @@ static int snd_codec_encode_opus(SndCodecInternal *codec, uint8_t *in_ptr, int i
|
||||
return SND_CODEC_OK;
|
||||
}
|
||||
|
||||
static int snd_codec_decode_opus(SndCodecInternal *codec, uint8_t *in_ptr, int in_size, uint8_t *out_ptr, int *out_size)
|
||||
static SndCodecResult
|
||||
snd_codec_decode_opus(SndCodecInternal *codec, uint8_t *in_ptr, int in_size,
|
||||
uint8_t *out_ptr, int *out_size)
|
||||
{
|
||||
int n;
|
||||
n = opus_decode(codec->opus_decoder, in_ptr, in_size, (opus_int16 *) out_ptr,
|
||||
@ -165,9 +168,9 @@ bool snd_codec_is_capable(SpiceAudioDataMode mode, int frequency)
|
||||
|
||||
snd_codec_destroy is the obvious partner of snd_codec_create.
|
||||
*/
|
||||
int snd_codec_create(SndCodec *codec, int mode, int frequency, int purpose)
|
||||
SndCodecResult snd_codec_create(SndCodec *codec, int mode, int frequency, int purpose)
|
||||
{
|
||||
int rc = SND_CODEC_UNAVAILABLE;
|
||||
SndCodecResult rc = SND_CODEC_UNAVAILABLE;
|
||||
SndCodecInternal **c = codec;
|
||||
|
||||
*c = spice_new0(SndCodecInternal, 1);
|
||||
@ -231,7 +234,8 @@ int snd_codec_frame_size(SndCodec codec)
|
||||
Returns:
|
||||
SND_CODEC_OK if all went well
|
||||
*/
|
||||
int snd_codec_encode(SndCodec codec, uint8_t *in_ptr, int in_size, uint8_t *out_ptr, int *out_size)
|
||||
SndCodecResult
|
||||
snd_codec_encode(SndCodec codec, uint8_t *in_ptr, int in_size, uint8_t *out_ptr, int *out_size)
|
||||
{
|
||||
#if HAVE_OPUS
|
||||
SndCodecInternal *c = codec;
|
||||
@ -258,7 +262,7 @@ int snd_codec_encode(SndCodec codec, uint8_t *in_ptr, int in_size, uint8_t *out_
|
||||
Returns:
|
||||
SND_CODEC_OK if all went well
|
||||
*/
|
||||
int snd_codec_decode(SndCodec codec, uint8_t *in_ptr, int in_size, uint8_t *out_ptr, int *out_size)
|
||||
SndCodecResult snd_codec_decode(SndCodec codec, uint8_t *in_ptr, int in_size, uint8_t *out_ptr, int *out_size)
|
||||
{
|
||||
#if HAVE_OPUS
|
||||
SndCodecInternal *c = codec;
|
||||
|
||||
@ -34,30 +34,34 @@
|
||||
|
||||
#define SND_CODEC_ANY_FREQUENCY -1
|
||||
|
||||
#define SND_CODEC_OK 0
|
||||
#define SND_CODEC_UNAVAILABLE 1
|
||||
#define SND_CODEC_ENCODER_UNAVAILABLE 2
|
||||
#define SND_CODEC_DECODER_UNAVAILABLE 3
|
||||
#define SND_CODEC_ENCODE_FAILED 4
|
||||
#define SND_CODEC_DECODE_FAILED 5
|
||||
#define SND_CODEC_INVALID_ENCODE_SIZE 6
|
||||
|
||||
#define SND_CODEC_ENCODE 0x0001
|
||||
#define SND_CODEC_DECODE 0x0002
|
||||
|
||||
SPICE_BEGIN_DECLS
|
||||
|
||||
typedef enum {
|
||||
SND_CODEC_OK,
|
||||
SND_CODEC_UNAVAILABLE,
|
||||
SND_CODEC_ENCODER_UNAVAILABLE,
|
||||
SND_CODEC_DECODER_UNAVAILABLE,
|
||||
SND_CODEC_ENCODE_FAILED,
|
||||
SND_CODEC_DECODE_FAILED,
|
||||
SND_CODEC_INVALID_ENCODE_SIZE,
|
||||
} SndCodecResult;
|
||||
|
||||
typedef struct SndCodecInternal * SndCodec;
|
||||
|
||||
bool snd_codec_is_capable(SpiceAudioDataMode mode, int frequency);
|
||||
|
||||
int snd_codec_create(SndCodec *codec, int mode, int frequency, int purpose);
|
||||
SndCodecResult snd_codec_create(SndCodec *codec, int mode, int frequency, int purpose);
|
||||
void snd_codec_destroy(SndCodec *codec);
|
||||
|
||||
int snd_codec_frame_size(SndCodec codec);
|
||||
|
||||
int snd_codec_encode(SndCodec codec, uint8_t *in_ptr, int in_size, uint8_t *out_ptr, int *out_size);
|
||||
int snd_codec_decode(SndCodec codec, uint8_t *in_ptr, int in_size, uint8_t *out_ptr, int *out_size);
|
||||
SndCodecResult snd_codec_encode(SndCodec codec, uint8_t *in_ptr, int in_size,
|
||||
uint8_t *out_ptr, int *out_size);
|
||||
SndCodecResult snd_codec_decode(SndCodec codec, uint8_t *in_ptr, int in_size,
|
||||
uint8_t *out_ptr, int *out_size);
|
||||
|
||||
SPICE_END_DECLS
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user