@@ -76,9 +76,12 @@ struct frames_st {
76
76
};
77
77
typedef int (* framecb )(struct frames_st * );
78
78
static int (* real_local_sdk_video_set_encode_frame_callback )(int ch , void * callback );
79
+ static int (* real_local_sdk_video_set_kbps )(int ch , int kbps );
79
80
static int video0_encode_capture (struct frames_st * frames );
80
81
static int video1_encode_capture (struct frames_st * frames );
81
82
static int video2_encode_capture (struct frames_st * frames );
83
+ static int userBitrate [4 ] = { 0 , 0 , 0 , 0 };
84
+ static int appBitrate [4 ] = { 240 , 180 , 0 , 160 };
82
85
83
86
struct video_capture_st {
84
87
framecb capture ;
@@ -313,6 +316,35 @@ static char *DGain(char *tokenPtr) {
313
316
return res ? "error" : "ok" ;
314
317
}
315
318
319
+ static char * Bitrate (char * tokenPtr ) {
320
+
321
+ char * p = strtok_r (NULL , " \t\r\n" , & tokenPtr );
322
+ if (!p ) return "error" ;
323
+ int ch = atoi (p );
324
+ if ((ch != 0 ) && (ch != 1 ) && (ch != 3 )) return "error" ;
325
+ p = strtok_r (NULL , " \t\r\n" , & tokenPtr );
326
+ if (!p ) {
327
+ if (userBitrate [ch ]) {
328
+ sprintf (videoResBuf , "%d\n" , userBitrate [ch ]);
329
+ } else {
330
+ sprintf (videoResBuf , "auto %d\n" , appBitrate [ch ]);
331
+ }
332
+ return videoResBuf ;
333
+ }
334
+ if (!strcmp (p , "auto" )) {
335
+ userBitrate [ch ] = 0 ;
336
+ fprintf (stderr , "video_set_kbps ch%d: %d\n" , ch , appBitrate [ch ]);
337
+ real_local_sdk_video_set_kbps (ch , appBitrate [ch ]);
338
+ } else {
339
+ int kbps = atoi (p );
340
+ if ((kbps < 10 ) || (kbps > 3000 )) return "error" ;
341
+ userBitrate [ch ] = kbps ;
342
+ fprintf (stderr , "video_set_kbps ch%d: %d\n" , ch , userBitrate [ch ]);
343
+ real_local_sdk_video_set_kbps (ch , userBitrate [ch ]);
344
+ }
345
+ return "ok" ;
346
+ }
347
+
316
348
struct CommandTableSt {
317
349
const char * cmd ;
318
350
char * (* func )(char * );
@@ -333,6 +365,7 @@ static struct CommandTableSt VideoCommandTable[] = {
333
365
{ "hilight" , & HiLight }, // hilight 0 - 10
334
366
{ "again" , & AGain }, // again 0 -
335
367
{ "dgain" , & DGain }, // dgain 0 -
368
+ { "bitrate" , & Bitrate }, // bitrate <ch> 10-3000(kbps)|auto
336
369
};
337
370
338
371
char * VideoCapture (int fd , char * tokenPtr ) {
@@ -416,6 +449,18 @@ int local_sdk_video_set_encode_frame_callback(int sch, void *callback) {
416
449
return real_local_sdk_video_set_encode_frame_callback (sch , callback );
417
450
}
418
451
452
+ int local_sdk_video_set_kbps (int ch , int kbps ) {
453
+
454
+ if ((ch == 0 ) || (ch == 1 ) || (ch == 3 )) {
455
+ appBitrate [ch ] = kbps ;
456
+ if (userBitrate [ch ]) {
457
+ kbps = userBitrate [ch ];
458
+ fprintf (stderr , "video_set_kbps ch%d: %d -> %d\n" , ch , appBitrate [ch ], kbps );
459
+ }
460
+ }
461
+ return real_local_sdk_video_set_kbps (ch , kbps );
462
+ }
463
+
419
464
static void __attribute ((constructor )) video_callback_init (void ) {
420
465
421
466
char * p = getenv ("RTSP_MAIN_FORMAT_HEVC" );
@@ -425,4 +470,5 @@ static void __attribute ((constructor)) video_callback_init(void) {
425
470
}
426
471
427
472
real_local_sdk_video_set_encode_frame_callback = dlsym (dlopen ("/system/lib/liblocalsdk.so" , RTLD_LAZY ), "local_sdk_video_set_encode_frame_callback" );
473
+ real_local_sdk_video_set_kbps = dlsym (dlopen ("/system/lib/liblocalsdk.so" , RTLD_LAZY ), "local_sdk_video_set_kbps" );
428
474
}
0 commit comments