Patch for the SDK RTSP sample: [auth]/[server] in rtsp.ini (Digest auth is built into librtsp_server), configurable enc_level, larger ring buffer for 8 Mbps. ak_record.c adds continuous + motion recording to MPEG-TS with configurable split, pre-roll and quotas, using the hardware motion grid. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
88 lines
3.9 KiB
Diff
88 lines
3.9 KiB
Diff
--- a/ak_rtsp_server_sample.c
|
|
+++ b/ak_rtsp_server_sample.c
|
|
@@ -257,9 +257,17 @@
|
|
* @void
|
|
* return: 0 - success; otherwise error code;
|
|
*/
|
|
+extern char g_rtsp_user[64], g_rtsp_pass[64];
|
|
+extern int g_rtsp_port;
|
|
+
|
|
int rtsp_server_init()
|
|
{
|
|
- rtsp_server_init_param(NULL);
|
|
+ rtsp_init_param ip;
|
|
+ memset(&ip, 0, sizeof ip); /* empty prefixes -> lib defaults (vs...) */
|
|
+ ip.iServerPort = g_rtsp_port;
|
|
+ snprintf(ip.cUserName, sizeof ip.cUserName, "%s", g_rtsp_user);
|
|
+ snprintf(ip.cPassword, sizeof ip.cPassword, "%s", g_rtsp_pass);
|
|
+ rtsp_server_init_param(&ip);
|
|
|
|
//设置网络信息
|
|
rtsp_server_set_dev_param_callback(rtsp_server_get_dev_param_cb);
|
|
--- a/ak_rtsp_stream.c
|
|
+++ b/ak_rtsp_stream.c
|
|
@@ -121,6 +121,9 @@
|
|
static char *pc_prog_name = NULL; //demo名称
|
|
|
|
static char *cfg_path = "/etc/config/rtsp.ini";
|
|
+/* [auth] user/password (empty user = no auth), [server] port */
|
|
+char g_rtsp_user[64] = "", g_rtsp_pass[64] = "";
|
|
+int g_rtsp_port = 554;
|
|
int audio_enable = 1;
|
|
|
|
//static ak_mutex_t refresh_flag_lock;
|
|
@@ -146,6 +149,7 @@
|
|
|
|
|
|
int rtsp_server_init();
|
|
+int record_start(const char *ini_path);
|
|
|
|
/*
|
|
* get_option_short: fill the stort option string.
|
|
@@ -548,7 +552,7 @@
|
|
vs->jpeg_qlevel = JPEG_QLEVEL_DEFAULT; //jpeg qlevel
|
|
vs->chroma_mode = CHROMA_4_2_0; //chroma mode
|
|
vs->max_picture_size = 0; //0 means default
|
|
- vs->enc_level = 30; //enc level
|
|
+ vs->enc_level = aas_ini_get_int(ini, "video0", "enc_level", 30); /* 50 = level 5.0, fits 2304x1296 */
|
|
vs->smart_mode = 0; //smart mode set
|
|
vs->smart_goplen = 100; //smart mode value
|
|
vs->smart_quality = 50; //quality
|
|
@@ -585,7 +589,7 @@
|
|
vs1->jpeg_qlevel = JPEG_QLEVEL_DEFAULT; //jpeg qlevel
|
|
vs1->chroma_mode = CHROMA_4_2_0; //chroma mode
|
|
vs1->max_picture_size = 0; //0 means default
|
|
- vs1->enc_level = 30; //enc level
|
|
+ vs1->enc_level = aas_ini_get_int(ini, "video1", "enc_level", 30);
|
|
vs1->smart_mode = 0; //smart mode set
|
|
vs1->smart_goplen = 100; //smart mode value
|
|
vs1->smart_quality = 50; //quality
|
|
@@ -613,6 +617,10 @@
|
|
rtsp_param.audio.sample_bits = 16;
|
|
printf("rtsp_param.audio.code_type=%d,rtsp_param.audio.sample_rate=%d,rtsp_param.audio.sample_bits=%d\n",
|
|
rtsp_param.audio.code_type,rtsp_param.audio.sample_rate,rtsp_param.audio.sample_bits);
|
|
+ snprintf(g_rtsp_user, sizeof g_rtsp_user, "%s", aas_ini_get_string(ini, "auth", "user", ""));
|
|
+ snprintf(g_rtsp_pass, sizeof g_rtsp_pass, "%s", aas_ini_get_string(ini, "auth", "password", ""));
|
|
+ g_rtsp_port = aas_ini_get_int(ini, "server", "port", 554);
|
|
+ printf("rtsp: port %d, auth %s\n", g_rtsp_port, g_rtsp_user[0] ? "ON (digest)" : "off");
|
|
aas_ini_free(ini);
|
|
printf("fun=%s line=%d debug here.\n",__FUNCTION__,__LINE__);
|
|
|
|
@@ -625,7 +633,7 @@
|
|
ak_thread_mutex_init(&rtsp_param.lock_buffer_video[0][1], NULL);
|
|
|
|
//main stream ring buffer
|
|
- rtsp_param.ring_buffer_video[0][0] = cirbuf_new(2* 1024 *1024);
|
|
+ rtsp_param.ring_buffer_video[0][0] = cirbuf_new(4* 1024 *1024); /* ~4 s at 8 Mbps */
|
|
|
|
//sub stream ring buffer
|
|
rtsp_param.ring_buffer_video[0][1] = cirbuf_new(512 *1024);
|
|
@@ -1764,6 +1772,7 @@
|
|
ak_thread_create(&(get_tid), audio_get_stream, (void*)chn, ANYKA_THREAD_MIN_STACK_SIZE, 19);
|
|
ak_thread_create(&(encode_tid), audio_get_frame_encode, NULL, ANYKA_THREAD_MIN_STACK_SIZE, 19);
|
|
rtsp_server_init();
|
|
+ record_start(cfg_path); /* SD recording, [record] in rtsp.ini (ak_record.c) */
|
|
|
|
|
|
/* WAITER for the thread exit */
|