Skip to content

Commit 547dc05

Browse files
committed
機能追加: video
- bitrate指定コマンドの追加
1 parent 95ebe66 commit 547dc05

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

libcallback/video_callback.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,12 @@ struct frames_st {
7676
};
7777
typedef int (* framecb)(struct frames_st *);
7878
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);
7980
static int video0_encode_capture(struct frames_st *frames);
8081
static int video1_encode_capture(struct frames_st *frames);
8182
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 };
8285

8386
struct video_capture_st {
8487
framecb capture;
@@ -313,6 +316,35 @@ static char *DGain(char *tokenPtr) {
313316
return res ? "error": "ok";
314317
}
315318

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+
316348
struct CommandTableSt {
317349
const char *cmd;
318350
char * (*func)(char *);
@@ -333,6 +365,7 @@ static struct CommandTableSt VideoCommandTable[] = {
333365
{ "hilight", &HiLight }, // hilight 0 - 10
334366
{ "again", &AGain }, // again 0 -
335367
{ "dgain", &DGain }, // dgain 0 -
368+
{ "bitrate", &Bitrate }, // bitrate <ch> 10-3000(kbps)|auto
336369
};
337370

338371
char *VideoCapture(int fd, char *tokenPtr) {
@@ -416,6 +449,18 @@ int local_sdk_video_set_encode_frame_callback(int sch, void *callback) {
416449
return real_local_sdk_video_set_encode_frame_callback(sch, callback);
417450
}
418451

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+
419464
static void __attribute ((constructor)) video_callback_init(void) {
420465

421466
char *p = getenv("RTSP_MAIN_FORMAT_HEVC");
@@ -425,4 +470,5 @@ static void __attribute ((constructor)) video_callback_init(void) {
425470
}
426471

427472
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");
428474
}

0 commit comments

Comments
 (0)