Skip to content

Commit

Permalink
compress only lastest frame
Browse files Browse the repository at this point in the history
  • Loading branch information
mdevaev committed Mar 3, 2024
1 parent 36dd5d1 commit 8fe411a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/libs/queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ int us_queue_get(us_queue_s *queue, void **item, ldf timeout) {

#undef _WAIT_OR_UNLOCK

/*int us_queue_get_free(us_queue_s *queue) {
bool us_queue_is_empty(us_queue_s *queue) {
US_MUTEX_LOCK(queue->mutex);
const uint size = queue->size;
US_MUTEX_UNLOCK(queue->mutex);
return queue->capacity - size;
}*/
return (bool)(queue->capacity - size);
}
4 changes: 2 additions & 2 deletions src/libs/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ typedef struct {

#define US_QUEUE_DELETE_WITH_ITEMS(x_queue, x_free_item) { \
if (x_queue) { \
while (!us_queue_get_free(x_queue)) { \
while (!us_queue_is_empty(x_queue)) { \
void *m_ptr; \
if (!us_queue_get(x_queue, &m_ptr, 0)) { \
US_DELETE(m_ptr, x_free_item); \
Expand All @@ -61,4 +61,4 @@ void us_queue_destroy(us_queue_s *queue);

int us_queue_put(us_queue_s *queue, void *item, ldf timeout);
int us_queue_get(us_queue_s *queue, void **item, ldf timeout);
// int us_queue_get_free(us_queue_s *queue);
bool us_queue_is_empty(us_queue_s *queue);
9 changes: 9 additions & 0 deletions src/ustreamer/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <stdatomic.h>
#include <unistd.h>
#include <errno.h>
#include <assert.h>

#include <pthread.h>

Expand Down Expand Up @@ -303,6 +304,10 @@ static void *_jpeg_thread(void *v_ctx) {
if (us_queue_get(ctx->queue, (void**)&hw, 0.1) < 0) {
continue;
}
while (!us_queue_is_empty(ctx->queue)) { // Берем только самый свежий кадр
us_device_buffer_decref(hw);
assert(!us_queue_get(ctx->queue, (void**)&hw, 0));
}

if ( // Если никто не смотрит MJPEG - пропускаем кадр
!atomic_load(&stream->run->http_has_clients)
Expand Down Expand Up @@ -344,6 +349,10 @@ static void *_h264_thread(void *v_ctx) {
if (us_queue_get(ctx->queue, (void**)&hw, 0.1) < 0) {
continue;
}
while (!us_queue_is_empty(ctx->queue)) { // Берем только самый свежий кадр
us_device_buffer_decref(hw);
assert(!us_queue_get(ctx->queue, (void**)&hw, 0));
}

if (!us_memsink_server_check(ctx->h264->sink, NULL)) {
us_device_buffer_decref(hw);
Expand Down

0 comments on commit 8fe411a

Please sign in to comment.