Replace SDL_net by custom implementation
SDL_net is not very suitable for scrcpy. For example, SDLNet_TCP_Accept() is non-blocking, so we have to wrap it by calling many SDL_Net-specific functions to make it blocking. But above all, SDLNet_TCP_Open() is a server socket only when no IP is provided; otherwise, it's a client socket. Therefore, it is not possible to create a server socket bound to localhost, so it accepts connections from anywhere. This is a problem for scrcpy, because on start, the application listens for nearly 1 second until it accepts the first connection, supposedly from the device. If someone on the local network manages to connect to the server socket first, then they can stream arbitrary H.264 video. This may be troublesome, for example during a public presentation ;-) Provide our own simplified API (net.h) instead, implemented for the different platforms.
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#include "decoder.h"
|
||||
|
||||
#include <libavformat/avformat.h>
|
||||
#include <SDL2/SDL_events.h>
|
||||
#include <SDL2/SDL_mutex.h>
|
||||
#include <SDL2/SDL_net.h>
|
||||
#include <SDL2/SDL_thread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -11,13 +11,12 @@
|
||||
#include "frames.h"
|
||||
#include "lockutil.h"
|
||||
#include "log.h"
|
||||
#include "netutil.h"
|
||||
|
||||
#define BUFSIZE 0x10000
|
||||
|
||||
static int read_packet(void *opaque, uint8_t *buf, int buf_size) {
|
||||
struct decoder *decoder = opaque;
|
||||
return SDLNet_TCP_Recv(decoder->video_socket, buf, buf_size);
|
||||
return net_recv(decoder->video_socket, buf, buf_size);
|
||||
}
|
||||
|
||||
// set the decoded frame as ready for rendering, and notify
|
||||
@@ -147,7 +146,7 @@ run_finally_free_codec_ctx:
|
||||
return ret;
|
||||
}
|
||||
|
||||
void decoder_init(struct decoder *decoder, struct frames *frames, TCPsocket video_socket) {
|
||||
void decoder_init(struct decoder *decoder, struct frames *frames, socket_t video_socket) {
|
||||
decoder->frames = frames;
|
||||
decoder->video_socket = video_socket;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user