Skip to content

Commit

Permalink
Fix read_packet() return value on error or EOF
Browse files Browse the repository at this point in the history
Fix warning on error or EOF:

> Invalid return value 0 for stream protocol

See <http://git.videolan.org/?p=ffmpeg.git;a=commitdiff;h=a606f27f4c610708fa96e35eed7b7537d3d8f712>.

Fixes <#333>.
  • Loading branch information
rom1v committed Nov 12, 2018
1 parent 6dc6ec0 commit 2876463
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions app/src/decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,23 @@ static int read_packet_with_meta(void *opaque, uint8_t *buf, int buf_size) {
if (!state->remaining) {
#define HEADER_SIZE 12
uint8_t header[HEADER_SIZE];
ssize_t ret = net_recv_all(decoder->video_socket, header, HEADER_SIZE);
if (ret <= 0) {
return ret;
ssize_t r = net_recv_all(decoder->video_socket, header, HEADER_SIZE);
if (r == -1) {
return AVERROR(errno);
}
if (r == 0) {
return AVERROR_EOF;
}
// no partial read (net_recv_all())
SDL_assert_release(ret == HEADER_SIZE);
SDL_assert_release(r == HEADER_SIZE);

uint64_t pts = buffer_read64be(header);
state->remaining = buffer_read32be(&header[8]);

if (pts != NO_PTS && !receiver_state_push_meta(state, pts)) {
LOGE("Could not store PTS for recording");
// we cannot save the PTS, the recording would be broken
return -1;
return AVERROR(ENOMEM);
}
}

Expand All @@ -102,20 +105,30 @@ static int read_packet_with_meta(void *opaque, uint8_t *buf, int buf_size) {
if (buf_size > state->remaining)
buf_size = state->remaining;

ssize_t ret = net_recv(decoder->video_socket, buf, buf_size);
if (ret <= 0) {
return ret;
ssize_t r = net_recv(decoder->video_socket, buf, buf_size);
if (r == -1) {
return AVERROR(errno);
}
if (r == 0) {
return AVERROR_EOF;
}

SDL_assert(state->remaining >= ret);
state->remaining -= ret;
SDL_assert(state->remaining >= r);
state->remaining -= r;

return ret;
return r;
}

static int read_raw_packet(void *opaque, uint8_t *buf, int buf_size) {
struct decoder *decoder = opaque;
return net_recv(decoder->video_socket, buf, buf_size);
ssize_t r = net_recv(decoder->video_socket, buf, buf_size);
if (r == -1) {
return AVERROR(errno);
}
if (r == 0) {
return AVERROR_EOF;
}
return r;
}

// set the decoded frame as ready for rendering, and notify
Expand Down

0 comments on commit 2876463

Please sign in to comment.