Fix buffer leaking on connection disconnect
This commit is contained in:
parent
aad601d575
commit
899204916f
@ -5,4 +5,4 @@ cd "$SCRIPT_DIR"
|
|||||||
|
|
||||||
set -xeo pipefail
|
set -xeo pipefail
|
||||||
make
|
make
|
||||||
./camera_stream -camera-path=$(echo /dev/v4l/by-path/*.csi-video-index0) "$@"
|
$GDB ./camera_stream -camera-path=$(echo /dev/v4l/by-path/*.csi-video-index0) "$@"
|
||||||
|
@ -30,12 +30,13 @@ void http_video(http_worker_t *worker, FILE *stream)
|
|||||||
bool had_key_frame = false;
|
bool had_key_frame = false;
|
||||||
bool requested_key_frame = false;
|
bool requested_key_frame = false;
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
buffer_t *buf = NULL;
|
||||||
fprintf(stream, VIDEO_HEADER);
|
fprintf(stream, VIDEO_HEADER);
|
||||||
|
|
||||||
buffer_lock_use(&http_h264, 1);
|
buffer_lock_use(&http_h264, 1);
|
||||||
|
|
||||||
while (!feof(stream)) {
|
while (!feof(stream)) {
|
||||||
buffer_t *buf = buffer_lock_get(&http_h264, 0, &counter);
|
buf = buffer_lock_get(&http_h264, 0, &counter);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -59,8 +60,10 @@ void http_video(http_worker_t *worker, FILE *stream)
|
|||||||
requested_key_frame = true;
|
requested_key_frame = true;
|
||||||
}
|
}
|
||||||
buffer_consumed(buf, "h264-stream");
|
buffer_consumed(buf, "h264-stream");
|
||||||
|
buf = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
buffer_consumed(buf, "error");
|
||||||
buffer_lock_use(&http_h264, -1);
|
buffer_lock_use(&http_h264, -1);
|
||||||
}
|
}
|
||||||
|
@ -64,11 +64,12 @@ error:
|
|||||||
void http_stream(http_worker_t *worker, FILE *stream)
|
void http_stream(http_worker_t *worker, FILE *stream)
|
||||||
{
|
{
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
buffer_t *buf = NULL;
|
||||||
fprintf(stream, STREAM_HEADER);
|
fprintf(stream, STREAM_HEADER);
|
||||||
buffer_lock_use(&http_jpeg, 1);
|
buffer_lock_use(&http_jpeg, 1);
|
||||||
|
|
||||||
while (!feof(stream)) {
|
while (!feof(stream)) {
|
||||||
buffer_t *buf = buffer_lock_get(&http_jpeg, 0, &counter);
|
buf = buffer_lock_get(&http_jpeg, 0, &counter);
|
||||||
|
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
fprintf(stream, STREAM_ERROR, -1, "No frames.");
|
fprintf(stream, STREAM_ERROR, -1, "No frames.");
|
||||||
@ -86,8 +87,10 @@ void http_stream(http_worker_t *worker, FILE *stream)
|
|||||||
}
|
}
|
||||||
|
|
||||||
buffer_consumed(buf, "jpeg-stream");
|
buffer_consumed(buf, "jpeg-stream");
|
||||||
|
buf = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
buffer_consumed(buf, "error");
|
||||||
buffer_lock_use(&http_jpeg, -1);
|
buffer_lock_use(&http_jpeg, -1);
|
||||||
}
|
}
|
||||||
|
@ -65,9 +65,11 @@ int _build_fds(link_t *all_links, struct pollfd *fds, link_t **links, buffer_lis
|
|||||||
source->device->output_device->paused = paused;
|
source->device->output_device->paused = paused;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int count_enqueued = buffer_list_count_enqueued(source);
|
||||||
|
|
||||||
fds[n].fd = source->device->fd;
|
fds[n].fd = source->device->fd;
|
||||||
fds[n].events = POLLHUP;
|
fds[n].events = POLLHUP;
|
||||||
if (!source->device->paused)
|
if (!source->device->paused && count_enqueued > 0)
|
||||||
fds[n].events |= POLLIN;
|
fds[n].events |= POLLIN;
|
||||||
fds[n].revents = 0;
|
fds[n].revents = 0;
|
||||||
buf_lists[n] = source;
|
buf_lists[n] = source;
|
||||||
|
@ -5,4 +5,4 @@ cd "$SCRIPT_DIR"
|
|||||||
|
|
||||||
set -xeo pipefail
|
set -xeo pipefail
|
||||||
make
|
make
|
||||||
./camera_stream -camera-path=$(echo /dev/v4l/by-id/usb-*-video-index0 ) "$@"
|
$GDB ./camera_stream -camera-path=$(echo /dev/v4l/by-id/usb-*-video-index0 ) "$@"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user