mirror of https://github.com/Genymobile/scrcpy
Move device-related code to device.c
Move the code to read the initial device info from scrcpy.c to a separate file, device.c.hidpi
parent
28c5cc030b
commit
3b06e7d500
@ -0,0 +1,16 @@
|
|||||||
|
#include "device.h"
|
||||||
|
|
||||||
|
SDL_bool device_read_info(TCPsocket device_socket, char *device_name, struct size *size) {
|
||||||
|
unsigned char buf[DEVICE_NAME_FIELD_LENGTH + 4];
|
||||||
|
if (SDLNet_TCP_Recv(device_socket, buf, sizeof(buf)) <= 0) {
|
||||||
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not retrieve device information");
|
||||||
|
return SDL_FALSE;
|
||||||
|
}
|
||||||
|
buf[DEVICE_NAME_FIELD_LENGTH - 1] = '\0'; // in case the client sends garbage
|
||||||
|
// strcpy is safe here, since name contains at least DEVICE_NAME_FIELD_LENGTH bytes
|
||||||
|
// and strlen(buf) < DEVICE_NAME_FIELD_LENGTH
|
||||||
|
strcpy(device_name, (char *) buf);
|
||||||
|
size->width = (buf[DEVICE_NAME_FIELD_LENGTH] << 8) | buf[DEVICE_NAME_FIELD_LENGTH + 1];
|
||||||
|
size->height = (buf[DEVICE_NAME_FIELD_LENGTH + 2] << 8) | buf[DEVICE_NAME_FIELD_LENGTH + 3];
|
||||||
|
return SDL_TRUE;
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
#ifndef DEVICE_H
|
||||||
|
#define DEVICE_H
|
||||||
|
|
||||||
|
#include <SDL2/SDL_net.h>
|
||||||
|
#include <SDL2/SDL_stdinc.h>
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
#define DEVICE_NAME_FIELD_LENGTH 64
|
||||||
|
|
||||||
|
// name must be at least DEVICE_NAME_FIELD_LENGTH bytes
|
||||||
|
SDL_bool device_read_info(TCPsocket device_socket, char *name, struct size *frame_size);
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue