[Spice-commits] 3 commits - common/snd_codec.c common/snd_codec.h
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Jul 7 12:10:22 UTC 2020
common/snd_codec.c | 34 ++++++++++++++++++++--------------
common/snd_codec.h | 32 ++++++++++++++++++++------------
2 files changed, 40 insertions(+), 26 deletions(-)
New commits:
commit 35be203f42c899175a697c282007990543a1977e
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Fri Feb 7 10:31:37 2020 +0000
snd_codec: Use better type for snd_codec_create mode
Signed-off-by: Frediano Ziglio <freddy77 at gmail.com>
Acked-by: Julien Ropé <jrope at gmail.com>
diff --git a/common/snd_codec.c b/common/snd_codec.c
index b649e5d..5f5abcb 100644
--- a/common/snd_codec.c
+++ b/common/snd_codec.c
@@ -41,7 +41,7 @@
typedef struct SndCodecInternal
{
- int mode;
+ SpiceAudioDataMode mode;
int frequency;
#if HAVE_OPUS
@@ -168,7 +168,8 @@ bool snd_codec_is_capable(SpiceAudioDataMode mode, int frequency)
snd_codec_destroy is the obvious partner of snd_codec_create.
*/
-SndCodecResult snd_codec_create(SndCodec *codec, int mode, int frequency, int purpose)
+SndCodecResult
+snd_codec_create(SndCodec *codec, SpiceAudioDataMode mode, int frequency, int purpose)
{
SndCodecResult rc = SND_CODEC_UNAVAILABLE;
SndCodecInternal **c = codec;
@@ -262,7 +263,8 @@ snd_codec_encode(SndCodec codec, uint8_t *in_ptr, int in_size, uint8_t *out_ptr,
Returns:
SND_CODEC_OK if all went well
*/
-SndCodecResult 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;
diff --git a/common/snd_codec.h b/common/snd_codec.h
index 3dbac93..eee91cd 100644
--- a/common/snd_codec.h
+++ b/common/snd_codec.h
@@ -53,7 +53,8 @@ typedef struct SndCodecInternal * SndCodec;
bool snd_codec_is_capable(SpiceAudioDataMode mode, int frequency);
-SndCodecResult snd_codec_create(SndCodec *codec, int mode, int frequency, int purpose);
+SndCodecResult snd_codec_create(SndCodec *codec,
+ SpiceAudioDataMode mode, int frequency, int purpose);
void snd_codec_destroy(SndCodec *codec);
int snd_codec_frame_size(SndCodec codec);
commit 283d82b0a3b313525364e6da94644487bf218321
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Thu Nov 21 08:53:46 2019 +0000
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 at redhat.com>
Acked-by: Julien Ropé <jrope at gmail.com>
diff --git a/common/snd_codec.c b/common/snd_codec.c
index 4a617f4..b649e5d 100644
--- a/common/snd_codec.c
+++ b/common/snd_codec.c
@@ -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;
diff --git a/common/snd_codec.h b/common/snd_codec.h
index b58f758..3dbac93 100644
--- a/common/snd_codec.h
+++ b/common/snd_codec.h
@@ -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
commit 8d9a79dd7de0987395c1220d47afe759e3f88cff
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Thu Nov 21 08:52:28 2019 +0000
snd_codec: Use better types for snd_codec_is_capable
mode should be an enumeration value of SpiceAudioDataMode.
Return type is just a boolean.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Julien Ropé <jrope at gmail.com>
diff --git a/common/snd_codec.c b/common/snd_codec.c
index 2b55b91..4a617f4 100644
--- a/common/snd_codec.c
+++ b/common/snd_codec.c
@@ -134,11 +134,11 @@ static int snd_codec_decode_opus(SndCodecInternal *codec, uint8_t *in_ptr, int i
/*
snd_codec_is_capable
- Returns TRUE if the current spice implementation can
- use the given codec, FALSE otherwise.
+ Returns true if the current spice implementation can
+ use the given codec, false otherwise.
mode must be a SPICE_AUDIO_DATA_MODE_XXX enum from spice/enum.h
*/
-int snd_codec_is_capable(int mode, int frequency)
+bool snd_codec_is_capable(SpiceAudioDataMode mode, int frequency)
{
#if HAVE_OPUS
if (mode == SPICE_AUDIO_DATA_MODE_OPUS &&
@@ -146,10 +146,10 @@ int snd_codec_is_capable(int mode, int frequency)
frequency == 48000 || frequency == 24000 ||
frequency == 16000 || frequency == 12000 ||
frequency == 8000) )
- return TRUE;
+ return true;
#endif
- return FALSE;
+ return false;
}
/*
diff --git a/common/snd_codec.h b/common/snd_codec.h
index aaba867..b58f758 100644
--- a/common/snd_codec.h
+++ b/common/snd_codec.h
@@ -19,6 +19,9 @@
#ifndef H_SPICE_COMMON_SND_CODEC
#define H_SPICE_COMMON_SND_CODEC
+#include <stdbool.h>
+#include <spice/enums.h>
+
#define SND_CODEC_OPUS_FRAME_SIZE 480
#define SND_CODEC_OPUS_PLAYBACK_FREQ 48000
#define SND_CODEC_OPUS_COMPRESSED_FRAME_BYTES 480
@@ -46,7 +49,7 @@ SPICE_BEGIN_DECLS
typedef struct SndCodecInternal * SndCodec;
-int snd_codec_is_capable(int mode, int frequency);
+bool snd_codec_is_capable(SpiceAudioDataMode mode, int frequency);
int snd_codec_create(SndCodec *codec, int mode, int frequency, int purpose);
void snd_codec_destroy(SndCodec *codec);
More information about the Spice-commits
mailing list