Support lowres capture

This commit is contained in:
Kamil Trzcinski
2022-04-08 09:48:52 +02:00
parent a816336de5
commit 50f2a9eb87
7 changed files with 83 additions and 38 deletions

View File

@ -47,12 +47,16 @@ void http_404(http_worker_t *worker, FILE *stream);
void http_snapshot(http_worker_t *worker, FILE *stream);
void http_stream(http_worker_t *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();
// H264
bool http_h264_needs_buffer();
void http_h264_capture(buffer_t *buf);
void http_h264_lowres_capture(buffer_t *buf);
void http_h264_video(http_worker_t *worker, FILE *stream);
void http_mkv_video(http_worker_t *worker, FILE *stream);
void http_mp4_video(http_worker_t *worker, FILE *stream);
void http_mov_video(http_worker_t *worker, FILE *stream);
#define HTTP_LOW_RES_PARAM "res=low"

View File

@ -13,7 +13,7 @@
#include <libavformat/avio.h>
#include <libavformat/avformat.h>
DECLARE_BUFFER_LOCK(http_h264);
buffer_lock_t *http_h264_buffer_for_res(http_worker_t *worker);
static const char *const VIDEO_HEADER =
"HTTP/1.0 200 OK\r\n"
@ -307,7 +307,7 @@ static void http_ffmpeg_video(http_worker_t *worker, FILE *stream, const char *c
av_dict_set_int(&status.output_opts, "nobuffer", 1, 0);
av_dict_set_int(&status.output_opts, "flush_packets", 1, 0);
int n = buffer_lock_write_loop(&http_h264, 0, (buffer_write_fn)http_ffmpeg_video_buf_part, &status);
int n = buffer_lock_write_loop(http_h264_buffer_for_res(worker), 0, (buffer_write_fn)http_ffmpeg_video_buf_part, &status);
http_ffmpeg_close_status(&status);
if (status.wrote_header) {

View File

@ -8,6 +8,7 @@
#include "hw/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"
@ -21,9 +22,22 @@ 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);
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))
return &http_h264_lowres;
else
return &http_h264;
}
typedef struct {
@ -67,7 +81,7 @@ void http_h264_video(http_worker_t *worker, FILE *stream)
{
http_video_status_t status = { stream };
int n = buffer_lock_write_loop(&http_h264, 0, (buffer_write_fn)http_video_buf_part, &status);
int n = buffer_lock_write_loop(http_h264_buffer_for_res(worker), 0, (buffer_write_fn)http_video_buf_part, &status);
if (status.wrote_header) {
return;

View File

@ -6,6 +6,7 @@
#include "hw/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"
@ -31,7 +32,7 @@ static const char *const STREAM_BOUNDARY = "\r\n"
bool http_jpeg_needs_buffer()
{
return buffer_lock_needs_buffer(&http_jpeg);
return buffer_lock_needs_buffer(&http_jpeg) | buffer_lock_needs_buffer(&http_jpeg_lowres);
}
void http_jpeg_capture(buffer_t *buf)
@ -39,6 +40,19 @@ 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))
return &http_jpeg_lowres;
else
return &http_jpeg;
}
int http_snapshot_buf_part(buffer_lock_t *buf_lock, buffer_t *buf, int frame, FILE *stream)
{
fprintf(stream, "HTTP/1.1 200 OK\r\n");
@ -51,7 +65,7 @@ int http_snapshot_buf_part(buffer_lock_t *buf_lock, buffer_t *buf, int frame, FI
void http_snapshot(http_worker_t *worker, FILE *stream)
{
int n = buffer_lock_write_loop(&http_jpeg, 1, (buffer_write_fn)http_snapshot_buf_part, stream);
int n = buffer_lock_write_loop(http_jpeg_buffer_for_res(worker), 1, (buffer_write_fn)http_snapshot_buf_part, stream);
if (n <= 0) {
http_500_header(stream);
@ -79,7 +93,7 @@ int http_stream_buf_part(buffer_lock_t *buf_lock, buffer_t *buf, int frame, FILE
void http_stream(http_worker_t *worker, FILE *stream)
{
int n = buffer_lock_write_loop(&http_jpeg, 0, (buffer_write_fn)http_stream_buf_part, stream);
int n = buffer_lock_write_loop(http_jpeg_buffer_for_res(worker), 0, (buffer_write_fn)http_stream_buf_part, stream);
if (n == 0) {
http_500_header(stream);