Avoid partial header reads
Use net_recv_all() to avoid partial reads for the "meta" header (this would break the whole stream).
This commit is contained in:
parent
ebe998cf78
commit
e562837c0b
1 changed files with 5 additions and 2 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <libavformat/avformat.h>
|
#include <libavformat/avformat.h>
|
||||||
#include <libavutil/time.h>
|
#include <libavutil/time.h>
|
||||||
|
#include <SDL2/SDL_assert.h>
|
||||||
#include <SDL2/SDL_events.h>
|
#include <SDL2/SDL_events.h>
|
||||||
#include <SDL2/SDL_mutex.h>
|
#include <SDL2/SDL_mutex.h>
|
||||||
#include <SDL2/SDL_thread.h>
|
#include <SDL2/SDL_thread.h>
|
||||||
|
@ -30,11 +31,13 @@ static int read_packet(void *opaque, uint8_t *buf, int buf_size) {
|
||||||
// the previous PTS read is now for the current frame
|
// the previous PTS read is now for the current frame
|
||||||
decoder->pts = decoder->next_pts;
|
decoder->pts = decoder->next_pts;
|
||||||
|
|
||||||
// FIXME what if only part of the header is available?
|
ret = net_recv_all(decoder->video_socket, header, HEADER_SIZE);
|
||||||
ret = net_recv(decoder->video_socket, header, HEADER_SIZE);
|
|
||||||
if (ret <= 0)
|
if (ret <= 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
// no partial read (net_recv_all())
|
||||||
|
SDL_assert_release(ret == HEADER_SIZE);
|
||||||
|
|
||||||
// read the PTS for the next frame
|
// read the PTS for the next frame
|
||||||
decoder->next_pts = buffer_read64be(header);
|
decoder->next_pts = buffer_read64be(header);
|
||||||
remaining = buffer_read32be(&header[8]);
|
remaining = buffer_read32be(&header[8]);
|
||||||
|
|
Loading…
Reference in a new issue