2017-12-12 22:12:07 +08:00
|
|
|
#ifndef DECODER_H
|
|
|
|
#define DECODER_H
|
|
|
|
|
2017-12-16 00:34:16 +08:00
|
|
|
#include <SDL2/SDL_stdinc.h>
|
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.
2018-02-16 05:59:21 +08:00
|
|
|
#include <SDL2/SDL_thread.h>
|
|
|
|
|
2018-10-11 13:12:36 +08:00
|
|
|
#include "common.h"
|
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.
2018-02-16 05:59:21 +08:00
|
|
|
#include "net.h"
|
2017-12-12 22:12:07 +08:00
|
|
|
|
2019-03-02 22:16:55 +08:00
|
|
|
struct video_buffer;
|
2017-12-12 22:12:07 +08:00
|
|
|
|
2018-11-11 22:27:52 +08:00
|
|
|
struct frame_meta {
|
|
|
|
uint64_t pts;
|
|
|
|
struct frame_meta *next;
|
|
|
|
};
|
|
|
|
|
2017-12-12 22:12:07 +08:00
|
|
|
struct decoder {
|
2019-03-02 22:16:55 +08:00
|
|
|
struct video_buffer *video_buffer;
|
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.
2018-02-16 05:59:21 +08:00
|
|
|
socket_t video_socket;
|
2017-12-12 22:12:07 +08:00
|
|
|
SDL_Thread *thread;
|
2018-11-09 19:21:17 +08:00
|
|
|
struct recorder *recorder;
|
2018-11-11 19:36:08 +08:00
|
|
|
struct receiver_state {
|
2018-11-11 22:27:52 +08:00
|
|
|
// meta (in order) for frames not consumed yet
|
|
|
|
struct frame_meta *frame_meta_queue;
|
2018-11-11 19:36:08 +08:00
|
|
|
size_t remaining; // remaining bytes to receive for the current frame
|
|
|
|
} receiver_state;
|
2017-12-12 22:12:07 +08:00
|
|
|
};
|
|
|
|
|
2019-03-02 22:16:55 +08:00
|
|
|
void decoder_init(struct decoder *decoder, struct video_buffer *vb,
|
2018-11-09 19:21:17 +08:00
|
|
|
socket_t video_socket, struct recorder *recoder);
|
|
|
|
SDL_bool decoder_start(struct decoder *decoder);
|
2018-02-09 15:42:39 +08:00
|
|
|
void decoder_stop(struct decoder *decoder);
|
2017-12-12 22:12:07 +08:00
|
|
|
void decoder_join(struct decoder *decoder);
|
|
|
|
|
|
|
|
#endif
|