Register buffer_lock as a global output

This commit is contained in:
Kamil Trzcinski
2022-09-03 11:04:37 +02:00
parent 3c818772d1
commit 5031cd99f6
12 changed files with 128 additions and 108 deletions

View File

@ -9,9 +9,6 @@
#include "device/buffer_list.h"
#include "device/device.h"
DEFINE_BUFFER_LOCK(http_h264, 0);
DEFINE_BUFFER_LOCK(http_h264_lowres, 0);
static const char *const VIDEO_HEADER =
"HTTP/1.0 200 OK\r\n"
"Access-Control-Allow-Origin: *\r\n"
@ -19,24 +16,9 @@ static const char *const VIDEO_HEADER =
"Content-Type: application/octet-stream\r\n"
"\r\n";
void http_h264_capture(buffer_t *buf)
{
buffer_lock_capture(&http_h264, buf);
}
void http_h264_lowres_capture(buffer_t *buf)
{
buffer_lock_capture(&http_h264_lowres, buf);
}
bool http_h264_needs_buffer()
{
return buffer_lock_needs_buffer(&http_h264) | buffer_lock_needs_buffer(&http_h264_lowres);
}
buffer_lock_t *http_h264_buffer_for_res(http_worker_t *worker)
{
if (strstr(worker->client_method, HTTP_LOW_RES_PARAM))
if (strstr(worker->client_method, HTTP_LOW_RES_PARAM) && http_jpeg_lowres.buf_list)
return &http_h264_lowres;
else
return &http_h264;

View File

@ -6,9 +6,6 @@
#include "device/buffer.h"
#include "device/buffer_lock.h"
DEFINE_BUFFER_LOCK(http_jpeg, 1000);
DEFINE_BUFFER_LOCK(http_jpeg_lowres, 1000);
#define PART_BOUNDARY "123456789000000000000987654321"
#define CONTENT_TYPE "image/jpeg"
#define CONTENT_LENGTH "Content-Length"
@ -23,24 +20,9 @@ static const char *const STREAM_PART = "Content-Type: " CONTENT_TYPE "\r\n" CONT
static const char *const STREAM_BOUNDARY = "\r\n"
"--" PART_BOUNDARY "\r\n";
bool http_jpeg_needs_buffer()
{
return buffer_lock_needs_buffer(&http_jpeg) | buffer_lock_needs_buffer(&http_jpeg_lowres);
}
void http_jpeg_capture(buffer_t *buf)
{
buffer_lock_capture(&http_jpeg, buf);
}
void http_jpeg_lowres_capture(buffer_t *buf)
{
buffer_lock_capture(&http_jpeg_lowres, buf);
}
buffer_lock_t *http_jpeg_buffer_for_res(http_worker_t *worker)
{
if (strstr(worker->client_method, HTTP_LOW_RES_PARAM))
if (strstr(worker->client_method, HTTP_LOW_RES_PARAM) && http_jpeg_lowres.buf_list)
return &http_jpeg_lowres;
else
return &http_jpeg;

7
output/output.c Normal file
View File

@ -0,0 +1,7 @@
#include "device/buffer_lock.h"
DEFINE_BUFFER_LOCK(http_h264, 0);
DEFINE_BUFFER_LOCK(http_h264_lowres, 0);
DEFINE_BUFFER_LOCK(http_jpeg, 1000);
DEFINE_BUFFER_LOCK(http_jpeg_lowres, 1000);

View File

@ -5,20 +5,20 @@
struct http_worker_s;
struct buffer_s;
extern struct buffer_lock_s http_h264;
extern struct buffer_lock_s http_h264_lowres;
extern struct buffer_lock_s http_jpeg;
extern struct buffer_lock_s http_jpeg_lowres;
// M-JPEG
void http_snapshot(struct http_worker_s *worker, FILE *stream);
void http_stream(struct http_worker_s *worker, FILE *stream);
void http_jpeg_capture(struct buffer_s *buf);
void http_jpeg_lowres_capture(struct buffer_s *buf);
bool http_jpeg_needs_buffer();
void http_option(struct http_worker_s *worker, FILE *stream);
// H264
bool http_h264_needs_buffer();
void http_h264_capture(struct buffer_s *buf);
void http_h264_lowres_capture(struct buffer_s *buf);
void http_h264_video(struct http_worker_s *worker, FILE *stream);
bool h264_is_key_frame(struct buffer_s *buf);
void http_h264_video(struct http_worker_s *worker, FILE *stream);
void http_mkv_video(struct http_worker_s *worker, FILE *stream);
void http_mp4_video(struct http_worker_s *worker, FILE *stream);
void http_mov_video(struct http_worker_s *worker, FILE *stream);

View File

@ -3,6 +3,7 @@ extern "C" {
#include "util/http/http.h"
#include "device/buffer.h"
#include "device/buffer_list.h"
#include "device/buffer_lock.h"
#include "device/device.h"
#include "util/opts/log.h"
#include "util/opts/fourcc.h"
@ -204,6 +205,33 @@ static void *rtsp_server_thread(void *opaque)
return NULL;
}
static bool rtsp_h264_needs_buffer(buffer_lock_t *buf_lock)
{
return rtsp_streams != NULL;
}
static void rtsp_h264_capture(buffer_lock_t *buf_lock, buffer_t *buf)
{
pthread_mutex_lock(&rtsp_lock);
for (DynamicH264Stream *stream = rtsp_streams; stream; stream = stream->pNextStream) {
stream->receiveData(buf, false);
if (!http_h264_lowres.buf_list) {
stream->receiveData(buf, true);
}
}
pthread_mutex_unlock(&rtsp_lock);
}
static void rtsp_h264_low_res_capture(buffer_lock_t *buf_lock, buffer_t *buf)
{
pthread_mutex_lock(&rtsp_lock);
for (DynamicH264Stream *stream = rtsp_streams; stream; stream = stream->pNextStream) {
stream->receiveData(buf, true);
}
pthread_mutex_unlock(&rtsp_lock);
}
extern "C" int rtsp_server(rtsp_options_t *options)
{
// Begin by setting up our usage environment:
@ -234,6 +262,11 @@ extern "C" int rtsp_server(rtsp_options_t *options)
// LOG_INFO(NULL, "The RTSP-over-HTTP is not available.");
// }
buffer_lock_register_check_streaming(&http_h264, rtsp_h264_needs_buffer);
buffer_lock_register_notify_buffer(&http_h264, rtsp_h264_capture);
buffer_lock_register_check_streaming(&http_h264_lowres, rtsp_h264_needs_buffer);
buffer_lock_register_notify_buffer(&http_h264_lowres, rtsp_h264_low_res_capture);
pthread_create(&rtsp_thread, NULL, rtsp_server_thread, env);
return 0;
@ -241,29 +274,6 @@ error:
return -1;
}
extern "C" bool rtsp_h264_needs_buffer()
{
return rtsp_streams != NULL;
}
extern "C" void rtsp_h264_capture(buffer_t *buf)
{
pthread_mutex_lock(&rtsp_lock);
for (DynamicH264Stream *stream = rtsp_streams; stream; stream = stream->pNextStream) {
stream->receiveData(buf, false);
}
pthread_mutex_unlock(&rtsp_lock);
}
extern "C" void rtsp_h264_low_res_capture(struct buffer_s *buf)
{
pthread_mutex_lock(&rtsp_lock);
for (DynamicH264Stream *stream = rtsp_streams; stream; stream = stream->pNextStream) {
stream->receiveData(buf, true);
}
pthread_mutex_unlock(&rtsp_lock);
}
#else // USE_RTSP
extern "C" int rtsp_server()
@ -271,17 +281,4 @@ extern "C" int rtsp_server()
return 0;
}
extern "C" bool rtsp_h264_needs_buffer()
{
return false;
}
extern "C" void rtsp_h264_capture(buffer_t *buf)
{
}
extern "C" void rtsp_h264_low_res_capture(struct buffer_s *buf)
{
}
#endif // USE_RTSP

View File

@ -5,6 +5,3 @@ typedef struct rtsp_options_s {
} rtsp_options_t;
int rtsp_server(rtsp_options_t *options);
bool rtsp_h264_needs_buffer();
void rtsp_h264_capture(struct buffer_s *buf);
void rtsp_h264_low_res_capture(struct buffer_s *buf);