obs-outputs: Check for recv error

master
jp9000 2015-11-16 13:49:34 -08:00
parent 2ee1d82860
commit 226337a6ca
1 changed files with 28 additions and 5 deletions

View File

@ -253,20 +253,41 @@ static inline bool get_next_packet(struct rtmp_stream *stream,
return new_packet; return new_packet;
} }
static void discard_recv_data(RTMP *rtmp, size_t size) static bool discard_recv_data(struct rtmp_stream *stream, size_t size)
{ {
RTMP *rtmp = &stream->rtmp;
uint8_t buf[512]; uint8_t buf[512];
#ifdef _WIN32
int ret;
#else
ssize_t ret;
#endif
do { do {
size_t bytes = size > 512 ? 512 : size; size_t bytes = size > 512 ? 512 : size;
size -= bytes; size -= bytes;
#ifdef _WIN32 #ifdef _WIN32
recv(rtmp->m_sb.sb_socket, buf, (int)bytes, 0); ret = recv(rtmp->m_sb.sb_socket, buf, (int)bytes, 0);
#else #else
recv(rtmp->m_sb.sb_socket, buf, bytes, 0); ret = recv(rtmp->m_sb.sb_socket, buf, bytes, 0);
#endif #endif
if (ret <= 0) {
#ifdef _WIN32
int error = WSAGetLastError();
#else
int error = errno;
#endif
if (ret < 0) {
do_log(LOG_ERROR, "recv error: %d (%d bytes)",
error, (int)size);
}
return false;
}
} while (size > 0); } while (size > 0);
return true;
} }
static int send_packet(struct rtmp_stream *stream, static int send_packet(struct rtmp_stream *stream,
@ -284,8 +305,10 @@ static int send_packet(struct rtmp_stream *stream,
ret = ioctl(stream->rtmp.m_sb.sb_socket, FIONREAD, &recv_size); ret = ioctl(stream->rtmp.m_sb.sb_socket, FIONREAD, &recv_size);
#endif #endif
if (ret >= 0 && recv_size > 0) if (ret >= 0 && recv_size > 0) {
discard_recv_data(&stream->rtmp, (size_t)recv_size); if (!discard_recv_data(stream, (size_t)recv_size))
return -1;
}
flv_packet_mux(packet, &data, &size, is_header); flv_packet_mux(packet, &data, &size, is_header);
#ifdef TEST_FRAMEDROPS #ifdef TEST_FRAMEDROPS