mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2026-01-01 11:08:43 -05:00
Rework serialization
Move serialization to the protocol, we now just send blocks of bytes over the connection and let the protocol deserialize them.
This commit is contained in:
parent
842d73ca4b
commit
41399b0b25
26 changed files with 1617 additions and 2501 deletions
|
|
@ -231,8 +231,8 @@ struct _SpaNode {
|
|||
* #SPA_RESULT_INVALID_COMMAND @command is an invalid command
|
||||
* #SPA_RESULT_ASYNC @command is executed asynchronously
|
||||
*/
|
||||
SpaResult (*send_command) (SpaNode *node,
|
||||
SpaNodeCommand *command);
|
||||
SpaResult (*send_command) (SpaNode *node,
|
||||
SpaNodeCommand *command);
|
||||
/**
|
||||
* SpaNode::set_event_callback:
|
||||
* @node: a #SpaNode
|
||||
|
|
|
|||
|
|
@ -211,7 +211,7 @@ spa_pod_builder_double (SpaPODBuilder *builder, double val)
|
|||
}
|
||||
|
||||
static inline off_t
|
||||
spa_pod_builder_string (SpaPODBuilder *builder, const char *str, uint32_t len)
|
||||
spa_pod_builder_string_len (SpaPODBuilder *builder, const char *str, uint32_t len)
|
||||
{
|
||||
const SpaPODString p = { { len + 1, SPA_POD_TYPE_STRING } };
|
||||
off_t out = spa_pod_builder_raw (builder, &p, sizeof (p) , false);
|
||||
|
|
@ -220,6 +220,23 @@ spa_pod_builder_string (SpaPODBuilder *builder, const char *str, uint32_t len)
|
|||
return out;
|
||||
}
|
||||
|
||||
static inline off_t
|
||||
spa_pod_builder_string (SpaPODBuilder *builder, const char *str)
|
||||
{
|
||||
uint32_t len = str ? strlen (str) : 0;
|
||||
return spa_pod_builder_string_len (builder, str ? str : "", len);
|
||||
}
|
||||
|
||||
static inline off_t
|
||||
spa_pod_builder_bytes (SpaPODBuilder *builder, const void *bytes, uint32_t len)
|
||||
{
|
||||
const SpaPODBytes p = { { len, SPA_POD_TYPE_BYTES } };
|
||||
off_t out = spa_pod_builder_raw (builder, &p, sizeof (p) , false);
|
||||
if (spa_pod_builder_raw (builder, bytes, len, true) == -1)
|
||||
out = -1;
|
||||
return out;
|
||||
}
|
||||
|
||||
static inline off_t
|
||||
spa_pod_builder_rectangle (SpaPODBuilder *builder, uint32_t width, uint32_t height)
|
||||
{
|
||||
|
|
@ -334,7 +351,7 @@ spa_pod_builder_propv (SpaPODBuilder *builder,
|
|||
{
|
||||
const char *str = va_arg (args, char *);
|
||||
uint32_t len = va_arg (args, uint32_t);
|
||||
spa_pod_builder_string (builder, str, len);
|
||||
spa_pod_builder_string_len (builder, str, len);
|
||||
break;
|
||||
}
|
||||
case SPA_POD_TYPE_RECTANGLE:
|
||||
|
|
|
|||
|
|
@ -70,6 +70,16 @@ typedef struct {
|
|||
int32_t value;
|
||||
} SpaPODInt;
|
||||
|
||||
static inline bool
|
||||
spa_pod_get_int (SpaPOD **pod, int32_t *val)
|
||||
{
|
||||
if (*pod == NULL || (*pod)->type != SPA_POD_TYPE_INT)
|
||||
return false;
|
||||
*val = ((SpaPODInt *)(*pod))->value;
|
||||
*pod = SPA_MEMBER (*pod, SPA_ROUND_UP_N (SPA_POD_SIZE (*pod), 8), SpaPOD);
|
||||
return true;
|
||||
}
|
||||
|
||||
typedef SpaPODInt SpaPODBool;
|
||||
typedef SpaPODInt SpaPODURI;
|
||||
|
||||
|
|
@ -78,6 +88,16 @@ typedef struct {
|
|||
int64_t value;
|
||||
} SpaPODLong;
|
||||
|
||||
static inline bool
|
||||
spa_pod_get_long (SpaPOD **pod, int64_t *val)
|
||||
{
|
||||
if (*pod == NULL || (*pod)->type != SPA_POD_TYPE_LONG)
|
||||
return false;
|
||||
*val = ((SpaPODLong *)*pod)->value;
|
||||
*pod = SPA_MEMBER (*pod, SPA_ROUND_UP_N (SPA_POD_SIZE (*pod), 8), SpaPOD);
|
||||
return true;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
SpaPOD pod;
|
||||
float value;
|
||||
|
|
@ -93,6 +113,21 @@ typedef struct {
|
|||
/* value here */
|
||||
} SpaPODString;
|
||||
|
||||
static inline bool
|
||||
spa_pod_get_string (SpaPOD **pod, const char **val)
|
||||
{
|
||||
if (*pod == NULL || (*pod)->type != SPA_POD_TYPE_STRING)
|
||||
return false;
|
||||
*val = SPA_POD_CONTENTS (SpaPODString, *pod);
|
||||
*pod = SPA_MEMBER (*pod, SPA_ROUND_UP_N (SPA_POD_SIZE (*pod), 8), SpaPOD);
|
||||
return true;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
SpaPOD pod;
|
||||
/* value here */
|
||||
} SpaPODBytes;
|
||||
|
||||
typedef struct {
|
||||
SpaPOD pod;
|
||||
SpaRectangle value;
|
||||
|
|
@ -123,6 +158,16 @@ typedef struct {
|
|||
/* one or more SpaPOD follow */
|
||||
} SpaPODStruct;
|
||||
|
||||
static inline bool
|
||||
spa_pod_get_struct (SpaPOD **pod, SpaPOD **val)
|
||||
{
|
||||
if (*pod == NULL || (*pod)->type != SPA_POD_TYPE_STRUCT)
|
||||
return false;
|
||||
*val = *pod;
|
||||
*pod = SPA_MEMBER (*pod, SPA_ROUND_UP_N (SPA_POD_SIZE (*pod), 8), SpaPOD);
|
||||
return true;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
uint32_t key;
|
||||
#define SPA_POD_PROP_RANGE_NONE 0
|
||||
|
|
@ -161,6 +206,28 @@ typedef struct {
|
|||
SpaPODObjectBody body;
|
||||
} SpaPODObject;
|
||||
|
||||
static inline bool
|
||||
spa_pod_get_object (SpaPOD **pod, const SpaPOD **val)
|
||||
{
|
||||
if (*pod == NULL || (*pod)->type != SPA_POD_TYPE_OBJECT)
|
||||
return false;
|
||||
*val = *pod;
|
||||
*pod = SPA_MEMBER (*pod, SPA_ROUND_UP_N (SPA_POD_SIZE (*pod), 8), SpaPOD);
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
spa_pod_get_bytes (SpaPOD **pod, const void **val, uint32_t *size)
|
||||
{
|
||||
if (*pod == NULL || (*pod)->type != SPA_POD_TYPE_BYTES)
|
||||
return false;
|
||||
*val = SPA_POD_CONTENTS (SpaPODBytes, *pod);
|
||||
*size = SPA_POD_SIZE (*pod);
|
||||
*pod = SPA_MEMBER (*pod, SPA_ROUND_UP_N (SPA_POD_SIZE (*pod), 8), SpaPOD);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#define SPA_POD_ARRAY_BODY_FOREACH(body, size, iter) \
|
||||
for ((iter) = SPA_MEMBER (body, sizeof(SpaPODArrayBody), __typeof__(*iter)); \
|
||||
(iter) < SPA_MEMBER (body, (size), __typeof__(*iter)); \
|
||||
|
|
@ -204,6 +271,7 @@ spa_pod_object_find_prop (const SpaPODObject *obj, uint32_t key)
|
|||
return spa_pod_contents_find_prop (&obj->pod, sizeof (SpaPODObject), key);
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -424,6 +424,10 @@ print_pod_value (uint32_t size, uint32_t type, void *body, int prefix)
|
|||
}
|
||||
break;
|
||||
}
|
||||
case SPA_POD_TYPE_BYTES:
|
||||
printf ("%-*sBytes\n", prefix, "");
|
||||
spa_debug_dump_mem (body, size);
|
||||
break;
|
||||
default:
|
||||
printf ("unhandled prop type %d\n", type);
|
||||
break;
|
||||
|
|
@ -477,6 +481,9 @@ print_format_value (uint32_t size, uint32_t type, void *body)
|
|||
case SPA_POD_TYPE_BITMASK:
|
||||
fprintf (stderr, "Bitmask");
|
||||
break;
|
||||
case SPA_POD_TYPE_BYTES:
|
||||
fprintf (stderr, "Bytes");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ main (int argc, char *argv[])
|
|||
spa_pod_builder_long (&b, 6000);
|
||||
spa_pod_builder_float (&b, 4.0);
|
||||
spa_pod_builder_double (&b, 3.14);
|
||||
spa_pod_builder_string (&b, "test123", strlen ("test123"));
|
||||
spa_pod_builder_string (&b, "test123");
|
||||
spa_pod_builder_rectangle (&b, 320, 240);
|
||||
spa_pod_builder_fraction (&b, 25, 1);
|
||||
spa_pod_builder_push_array (&b, &frame[3]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue