The decoder initially read from the socket, decoded the video and sent
the decoded frames to the screen:
+---------+ +----------+
socket ---> | decoder | ---> | screen |
+---------+ +----------+
The design was simple, but the decoder had several responsabilities.
Then we added the recording feature, so we added a recorder, which
reused the packets received from the socket managed by the decoder:
+----------+
---> | screen |
+---------+ / +----------+
socket ---> | decoder | ----
+---------+ \ +----------+
---> | recorder |
+----------+
This lack of separation of concerns now have concrete implications: we
could not (properly) disable the decoder/display to only record the
video.
Therefore, split the decoder to extract the stream:
+----------+ +----------+
---> | decoder | ---> | screen |
+---------+ / +----------+ +----------+
socket ---> | stream | ----
+---------+ \ +----------+
---> | recorder |
+----------+
This will allow to record the stream without decoding the video.
36 lines
858 B
C
36 lines
858 B
C
#ifndef STREAM_H
|
|
#define STREAM_H
|
|
|
|
#include <SDL2/SDL_stdinc.h>
|
|
#include <SDL2/SDL_thread.h>
|
|
|
|
#include "net.h"
|
|
|
|
struct video_buffer;
|
|
|
|
struct frame_meta {
|
|
Uint64 pts;
|
|
struct frame_meta *next;
|
|
};
|
|
|
|
struct stream {
|
|
socket_t socket;
|
|
struct video_buffer *video_buffer;
|
|
SDL_Thread *thread;
|
|
struct decoder *decoder;
|
|
struct recorder *recorder;
|
|
struct receiver_state {
|
|
// meta (in order) for frames not consumed yet
|
|
struct frame_meta *frame_meta_queue;
|
|
size_t remaining; // remaining bytes to receive for the current frame
|
|
} receiver_state;
|
|
};
|
|
|
|
void stream_init(struct stream *stream, socket_t socket,
|
|
struct decoder *decoder, struct recorder *recorder);
|
|
SDL_bool stream_start(struct stream *stream);
|
|
void stream_stop(struct stream *stream);
|
|
void stream_join(struct stream *stream);
|
|
|
|
#endif
|