Skip to content

Commit

Permalink
Cleaning up the code a little, rethinking chips and families
Browse files Browse the repository at this point in the history
  • Loading branch information
wberube committed Aug 23, 2024
1 parent 88c0672 commit 013a76e
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 119 deletions.
4 changes: 2 additions & 2 deletions src/gpio.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "hal/macros.h"

#include <errno.h>
#include <fcntl.h>
#include <linux/version.h>
Expand All @@ -16,6 +14,8 @@
#include <string.h>
#endif

#include "hal/macros.h"

void gpio_deinit(void);
int gpio_init(void);
int gpio_read(char pin, bool *value);
Expand Down
57 changes: 34 additions & 23 deletions src/hal/support.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ void *vid_thread = NULL;

char chnCount = 0;
hal_chnstate *chnState = NULL;
char chipId[16] = "unknown";

char chip[16] = "unknown";
char family[32] = {0};
hal_platform plat = HAL_PLATFORM_UNK;
int series = 0;

Expand Down Expand Up @@ -69,24 +71,27 @@ void hal_identify(void) {
case 0xF1: // Pudding (6E)
case 0xF2: // Ispahan (6B0)
plat = HAL_PLATFORM_I6;
strcpy(chipId, series == 0xEF ?
strcpy(chip, series == 0xEF ?
"SSC32x" : "SSC33x");
strcpy(family, "infinity6(b/e0)");
chnCount = I6_VENC_CHN_NUM;
chnState = (hal_chnstate*)i6_state;
aud_thread = i6_audio_thread;
vid_thread = i6_video_thread;
return;
case 0xF9:
plat = HAL_PLATFORM_I6C;
strcpy(chipId, "SSC37x");
strcpy(chip, "SSC37x");
strcpy(family, "infinity6c");
chnCount = I6C_VENC_CHN_NUM;
chnState = (hal_chnstate*)i6c_state;
aud_thread = i6c_audio_thread;
vid_thread = i6c_video_thread;
return;
case 0xFB:
plat = HAL_PLATFORM_I6F;
strcpy(chipId, "SSC37x");
strcpy(chip, "SSC379G");
strcpy(family, "infinity6f");
chnCount = I6F_VENC_CHN_NUM;
chnState = (hal_chnstate*)i6f_state;
aud_thread = i6f_audio_thread;
Expand All @@ -96,10 +101,11 @@ void hal_identify(void) {

if (!access("/dev/vpd", 0)) {
plat = HAL_PLATFORM_GM;
strcpy(chipId, "GM813x");
strcpy(chip, "GM813x");
strcpy(family, "grainmedia");
if (file = fopen("/proc/pmu/chipver", "r")) {
fgets(line, 200, file);
sscanf(line, "%4s", chipId + 2);
sscanf(line, "%4s", chip + 2);
fclose(file);
}
chnCount = GM_VENC_CHN_NUM;
Expand All @@ -120,16 +126,17 @@ void hal_identify(void) {
case 0x31:
plat = HAL_PLATFORM_T31;
switch (type >> 16) {
case 0x2222: sprintf(chipId, "T31X"); break;
case 0x3333: sprintf(chipId, "T31L"); break;
case 0x4444: sprintf(chipId, "T31A"); break;
case 0x5555: sprintf(chipId, "T31ZL"); break;
case 0x6666: sprintf(chipId, "T31ZX"); break;
case 0xcccc: sprintf(chipId, "T31AL"); break;
case 0xdddd: sprintf(chipId, "T31ZC"); break;
case 0xeeee: sprintf(chipId, "T31LC"); break;
default: sprintf(chipId, "T31N"); break;
case 0x2222: sprintf(chip, "T31X"); break;
case 0x3333: sprintf(chip, "T31L"); break;
case 0x4444: sprintf(chip, "T31A"); break;
case 0x5555: sprintf(chip, "T31ZL"); break;
case 0x6666: sprintf(chip, "T31ZX"); break;
case 0xcccc: sprintf(chip, "T31AL"); break;
case 0xdddd: sprintf(chip, "T31ZC"); break;
case 0xeeee: sprintf(chip, "T31LC"); break;
default: sprintf(chip, "T31N"); break;
}
strcpy(family, "ingenic t31"); break;
chnCount = T31_VENC_CHN_NUM;
chnState = (hal_chnstate*)t31_state;
aud_thread = t31_audio_thread;
Expand Down Expand Up @@ -174,20 +181,21 @@ void hal_identify(void) {
out |= (SCSYSID[i] & 0xFF) << i * 8;
}

sprintf(chipId, "%s%X",
sprintf(chip, "%s%X",
((out >> 28) == 0x7) ? "GK" : "Hi", out);
if (chipId[6] == '0') {
chipId[6] = 'V';
if (chip[6] == '0') {
chip[6] = 'V';
} else {
chipId[8] = chipId[7];
chipId[7] = 'V';
chipId[9] = chipId[8];
chipId[10] = chipId[9];
chipId[11] = '\0';
chip[8] = chip[7];
chip[7] = 'V';
chip[9] = chip[8];
chip[10] = chip[9];
chip[11] = '\0';
}

if (out == 0x35180100) {
plat = HAL_PLATFORM_V1;
strcpy(family, "hisi-gen1");
chnCount = V1_VENC_CHN_NUM;
chnState = (hal_chnstate*)v1_state;
aud_thread = v1_audio_thread;
Expand All @@ -196,6 +204,7 @@ void hal_identify(void) {
return;
} else if (v2series) {
plat = HAL_PLATFORM_V2;
strcpy(family, "hisi-gen2");
chnCount = V2_VENC_CHN_NUM;
chnState = (hal_chnstate*)v2_state;
aud_thread = v2_audio_thread;
Expand All @@ -204,6 +213,7 @@ void hal_identify(void) {
return;
} else if (v3series) {
plat = HAL_PLATFORM_V3;
strcpy(family, "hisi-gen3");
chnCount = V3_VENC_CHN_NUM;
chnState = (hal_chnstate*)v3_state;
aud_thread = v3_audio_thread;
Expand All @@ -213,6 +223,7 @@ void hal_identify(void) {
}

plat = HAL_PLATFORM_V4;
strcpy(family, "hisi-gen4");
chnCount = V4_VENC_CHN_NUM;
chnState = (hal_chnstate*)v4_state;
aud_thread = v4_audio_thread;
Expand Down
3 changes: 2 additions & 1 deletion src/hal/support.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ extern void *vid_thread;
extern char chnCount;
extern hal_chnstate *chnState;

extern char chipId[16];
extern char chip[16];
extern char family[32];
extern hal_platform plat;
extern int series;

Expand Down
1 change: 1 addition & 0 deletions src/hal/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
typedef enum {
HAL_PLATFORM_UNK,
HAL_PLATFORM_GM,
HAL_PLATFORM_I3,
HAL_PLATFORM_I6,
HAL_PLATFORM_I6C,
HAL_PLATFORM_I6F,
Expand Down
10 changes: 7 additions & 3 deletions src/http_post.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "http_post.h"

pthread_t httpPostPid = 0;

int post_send(hal_jpegdata *jpeg) {
char *host_addr = app_config.http_post_host;

Expand Down Expand Up @@ -95,8 +97,6 @@ void *send_thread(void *vargp) {
}

void start_http_post_send() {
pthread_t http_post_thread_id = 0;

pthread_attr_t thread_attr;
pthread_attr_init(&thread_attr);
size_t stacksize;
Expand All @@ -105,9 +105,13 @@ void start_http_post_send() {
if (pthread_attr_setstacksize(&thread_attr, new_stacksize))
HAL_DANGER("http_post", "Can't set stack size %zu\n", new_stacksize);
if (pthread_create(
&http_post_thread_id, &thread_attr, send_thread, NULL))
&httpPostPid, &thread_attr, send_thread, NULL))
HAL_DANGER("http_post", "Starting the HTTP poster thread failed!\n");
if (pthread_attr_setstacksize(&thread_attr, stacksize))
HAL_DANGER("http_post", "Can't set stack size %zu\n", stacksize);
pthread_attr_destroy(&thread_attr);
}

void stop_http_post_send() {
pthread_join(httpPostPid, NULL);
}
17 changes: 5 additions & 12 deletions src/http_post.h
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
#pragma once

#include "hal/macros.h"
#include "hal/tools.h"
#include "jpeg.h"
#include "mp4/mp4.h"
#include "mp4/nal.h"

#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <signal.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <time.h>

#include <errno.h>
#include <pthread.h>
#include <regex.h>
#include <unistd.h>

#include "hal/macros.h"
#include "jpeg.h"

extern char keepRunning;

void start_http_post_send();
void stop_http_post_send();
44 changes: 10 additions & 34 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,14 @@ char graceful = 0;
int main(int argc, char *argv[]) {
hal_identify();

switch (plat) {
#if defined(__arm__)
case HAL_PLATFORM_GM:
fprintf(stderr, "Divinus for grainmedia\n"); break;
case HAL_PLATFORM_I6:
fprintf(stderr, "Divinus for infinity6(b0/e)\n"); break;
case HAL_PLATFORM_I6C:
fprintf(stderr, "Divinus for infinity6c\n"); break;
case HAL_PLATFORM_I6F:
fprintf(stderr, "Divinus for infinity6f\n"); break;
case HAL_PLATFORM_V1:
fprintf(stderr, "Divinus for hisi-gen1\n"); break;
case HAL_PLATFORM_V2:
fprintf(stderr, "Divinus for hisi-gen2\n"); break;
case HAL_PLATFORM_V3:
fprintf(stderr, "Divinus for hisi-gen3\n"); break;
case HAL_PLATFORM_V4:
fprintf(stderr, "Divinus for hisi-gen4\n"); break;
#elif defined(__mips__)
case HAL_PLATFORM_T31:
fprintf(stderr, "Divinus for ingenic t31\n"); break;
#endif
default:
fprintf(stderr, "Unsupported chip family! Quitting...\n");
return EXIT_FAILURE;
}
fprintf(stderr, "Chip ID: %s\n", chipId);
if (!*family)
HAL_ERROR("hal", "Unsupported chip family! Quitting...\n");

if (parse_app_config() != CONFIG_OK) {
fprintf(stderr, "Can't load app config 'divinus.yaml'\n");
return EXIT_FAILURE;
}
fprintf(stderr, "Divinus for %s\n", family);
fprintf(stderr, "Chip ID: %s\n", chip);

if (parse_app_config() != CONFIG_OK)
HAL_ERROR("hal", "Can't load app config 'divinus.yaml'\n");

if (app_config.mdns_enable)
start_mdns();
Expand All @@ -61,11 +37,11 @@ int main(int argc, char *argv[]) {

if (app_config.rtsp_enable) {
rtspHandle = rtsp_create(RTSP_MAXIMUM_CONNECTIONS, 2);
fprintf(stderr, "RTSP server started, listening for clients...\n");
HAL_INFO("rtsp", "Started listening for clients...\n");
}

if (start_sdk())
return EXIT_FAILURE;
HAL_ERROR("hal", "Failed to start SDK!\n");

if (app_config.night_mode_enable)
start_monitor_light_sensor();
Expand All @@ -83,7 +59,7 @@ int main(int argc, char *argv[]) {

if (app_config.rtsp_enable) {
rtsp_finish(rtspHandle);
fprintf(stderr, "RTSP server has closed!\n");
HAL_INFO("rtsp", "Server has closed!\n");
}

if (app_config.osd_enable)
Expand Down
16 changes: 8 additions & 8 deletions src/media.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#pragma once

#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <unistd.h>

#include "app_config.h"
#include "error.h"
#include "hal/types.h"
Expand All @@ -9,14 +17,6 @@
#include "rtsp/rtsp_server.h"
#include "server.h"

#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <unistd.h>

extern rtsp_handle rtspHandle;

int start_sdk(void);
Expand Down
6 changes: 3 additions & 3 deletions src/network.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#pragma once

#include "hal/support.h"
#include "lib/tinysvcmdns.h"

#include <ifaddrs.h>
#include <net/if.h>
#include <stdio.h>
Expand All @@ -12,5 +9,8 @@
extern int asprintf(char **restrict strp, const char *restrict fmt, ...);
#endif

#include "hal/support.h"
#include "lib/tinysvcmdns.h"

int start_mdns();
void stop_mdns();
10 changes: 5 additions & 5 deletions src/night.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#pragma once

#include "app_config.h"
#include "gpio.h"
#include "hal/macros.h"
#include "media.h"

#include <pthread.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <unistd.h>

#include "app_config.h"
#include "gpio.h"
#include "hal/macros.h"
#include "media.h"

void set_night_mode(bool night);
bool night_mode_is_enabled();
void *night_thread();
Expand Down
Loading

0 comments on commit 013a76e

Please sign in to comment.