export h264 state

This commit is contained in:
Devaev Maxim
2021-01-12 15:28:42 +03:00
parent d0a5246580
commit 1a8dfb1f1b
3 changed files with 23 additions and 4 deletions

View File

@@ -29,6 +29,7 @@ h264_stream_s *h264_stream_init(memsink_s *sink, unsigned bitrate, unsigned gop)
h264->sink = sink;
h264->tmp_src = frame_init("h264_tmp_src");
h264->dest = frame_init("h264_dest");
atomic_init(&h264->online, false);
// FIXME: 30 or 0? https://github.com/6by9/yavta/blob/master/yavta.c#L210
if ((h264->enc = h264_encoder_init(bitrate, gop, 0)) == NULL) {
@@ -73,13 +74,17 @@ void h264_stream_process(h264_stream_s *h264, const frame_s *frame, int vcsm_han
LOG_VERBOSE("H264: Source copied; time=%.3Lf", get_now_monotonic() - now);
}
bool online = false;
if (!h264_encoder_is_prepared_for(h264->enc, frame, zero_copy)) {
h264_encoder_prepare(h264->enc, frame, zero_copy);
}
if (h264->enc->ready) {
if (h264_encoder_compress(h264->enc, frame, vcsm_handle, h264->dest, force_key) == 0) {
memsink_server_put(h264->sink, h264->dest);
online = !memsink_server_put(h264->sink, h264->dest);
}
}
atomic_store(&h264->online, online);
}

View File

@@ -23,6 +23,7 @@
#pragma once
#include <stdbool.h>
#include <stdatomic.h>
#include <assert.h>
#include "../../libs/tools.h"
@@ -39,6 +40,7 @@ typedef struct {
frame_s *tmp_src;
frame_s *dest;
h264_encoder_s *enc;
atomic_bool online;
} h264_stream_s;

View File

@@ -339,12 +339,24 @@ static void _http_callback_state(struct evhttp_request *request, void *v_server)
assert(evbuffer_add_printf(buf,
"{\"ok\": true, \"result\": {"
" \"encoder\": {\"type\": \"%s\", \"quality\": %u},"
" \"encoder\": {\"type\": \"%s\", \"quality\": %u},",
encoder_type_to_string(enc_type),
enc_quality
));
# ifdef WITH_OMX
if (STREAM(run->h264)) {
assert(evbuffer_add_printf(buf,
" \"h264\": {\"bitrate\": %u, \"gop\": %u, \"online\": %s},",
STREAM(h264_bitrate),
STREAM(h264_gop),
bool_to_string(atomic_load(&STREAM(run->h264->online)))
));
}
# endif
assert(evbuffer_add_printf(buf,
" \"source\": {\"resolution\": {\"width\": %u, \"height\": %u},"
" \"online\": %s, \"desired_fps\": %u, \"captured_fps\": %u},"
" \"stream\": {\"queued_fps\": %u, \"clients\": %u, \"clients_stat\": {",
encoder_type_to_string(enc_type),
enc_quality,
(server->fake_width ? server->fake_width : EX(frame->width)),
(server->fake_height ? server->fake_height : EX(frame->height)),
bool_to_string(EX(frame->online)),