mirror of
https://github.com/X11Libre/xserver.git
synced 2026-04-14 17:18:09 +00:00
Xext: xv: ProcXvQueryEncodings() collect payload in buffer before writing
The payload lengths is already known, so we can easily collect the data in a stack buffer and only need one WriteToClient() operation. This also clears the road for further simplification/unification of the reply sending code, coming with follow-up commits. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
@@ -180,9 +180,7 @@ ProcXvQueryAdaptors(ClientPtr client)
|
||||
static int
|
||||
ProcXvQueryEncodings(ClientPtr client)
|
||||
{
|
||||
xvEncodingInfo einfo;
|
||||
int totalSize;
|
||||
int nameSize;
|
||||
XvPortPtr pPort;
|
||||
int ne;
|
||||
XvEncodingPtr pe;
|
||||
@@ -202,6 +200,12 @@ ProcXvQueryEncodings(ClientPtr client)
|
||||
pe++;
|
||||
}
|
||||
|
||||
char *buf = calloc(1, totalSize);
|
||||
if (!buf)
|
||||
return BadAlloc;
|
||||
|
||||
char *walk = buf;
|
||||
|
||||
xvQueryEncodingsReply rep = {
|
||||
.type = X_Reply,
|
||||
.sequenceNumber = client->sequence,
|
||||
@@ -215,31 +219,38 @@ ProcXvQueryEncodings(ClientPtr client)
|
||||
swaps(&rep.num_encodings);
|
||||
}
|
||||
|
||||
WriteToClient(client, sizeof(rep), &rep);
|
||||
|
||||
ne = pPort->pAdaptor->nEncodings;
|
||||
pe = pPort->pAdaptor->pEncodings;
|
||||
while (ne--) {
|
||||
einfo.encoding = pe->id;
|
||||
einfo.name_size = nameSize = strlen(pe->name);
|
||||
einfo.width = pe->width;
|
||||
einfo.height = pe->height;
|
||||
einfo.rate.numerator = pe->rate.numerator;
|
||||
einfo.rate.denominator = pe->rate.denominator;
|
||||
int nameSize;
|
||||
xvEncodingInfo *einfo = (xvEncodingInfo*)walk;
|
||||
|
||||
einfo->encoding = pe->id;
|
||||
einfo->name_size = nameSize = strlen(pe->name);
|
||||
einfo->width = pe->width;
|
||||
einfo->height = pe->height;
|
||||
einfo->rate.numerator = pe->rate.numerator;
|
||||
einfo->rate.denominator = pe->rate.denominator;
|
||||
|
||||
if (client->swapped) {
|
||||
swapl(&einfo.encoding);
|
||||
swaps(&einfo.name_size);
|
||||
swaps(&einfo.width);
|
||||
swaps(&einfo.height);
|
||||
swapl(&einfo.rate.numerator);
|
||||
swapl(&einfo.rate.denominator);
|
||||
swapl(&einfo->encoding);
|
||||
swaps(&einfo->name_size);
|
||||
swaps(&einfo->width);
|
||||
swaps(&einfo->height);
|
||||
swapl(&einfo->rate.numerator);
|
||||
swapl(&einfo->rate.denominator);
|
||||
}
|
||||
WriteToClient(client, sizeof(einfo), &einfo);
|
||||
WriteToClient(client, nameSize, pe->name);
|
||||
|
||||
walk += sizeof(xvEncodingInfo);
|
||||
memcpy(walk, pe->name, nameSize);
|
||||
walk += pad_to_int32(nameSize);
|
||||
|
||||
pe++;
|
||||
}
|
||||
|
||||
WriteToClient(client, sizeof(rep), &rep);
|
||||
WriteToClient(client, totalSize, buf);
|
||||
free(buf);
|
||||
return Success;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user