Skip to content

Commit 73efc38

Browse files
committed
Getting rid of dead code
1 parent 44b8a97 commit 73efc38

3 files changed

Lines changed: 49 additions & 65 deletions

File tree

src/hal/tools.c

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ int base64_decode(char *decoded, const char *string, int maxLen) {
1010
while (*string && *string != '=' && i < maxLen) {
1111
const char *p = strchr(base64_table, *string++);
1212
if (!p) continue;
13-
13+
1414
v = p - base64_table;
1515
switch (buflen) {
1616
case 0:
@@ -86,34 +86,34 @@ int color_parse(const char *str) {
8686
char *remain = NULL;
8787
int len = strlen(str);
8888
int result = 0;
89-
89+
9090
// Ignore leading spaces
9191
while (*str == ' ' || *str == '\t') str++;
92-
92+
9393
// 4-bit hex format "#RGB"
9494
if (str[0] == '#' && len == 4) {
9595
int r = hex_to_int(str[1]);
9696
int g = hex_to_int(str[2]);
9797
int b = hex_to_int(str[3]);
98-
98+
9999
if (r >= 0 && g >= 0 && b >= 0)
100100
return (1 << 16) | (r << 11) | (g << 6) | (b << 1);
101101
}
102-
102+
103103
// 8-bit hex format "#RRGGBB"
104104
else if (str[0] == '#') {
105105
result = strtol(str + 1, &remain, 16);
106106
if (remain != str + 1 && *remain == '\0')
107107
return color_convert555(result);
108108
}
109-
109+
110110
// C standard format "0xRRGGBB"
111111
else if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) {
112112
result = strtol(str, &remain, 0);
113113
if (remain != str && *remain == '\0')
114114
return color_convert555(result);
115115
}
116-
116+
117117
// No prefix format "RRGGBB"
118118
else if (len >= 6) {
119119
result = strtol(str, &remain, 16);
@@ -143,10 +143,10 @@ int compile_regex(regex_t *r, const char *regex_text) {
143143
int escape_url(char *dst, const char *src, size_t maxlen) {
144144
static const char hex[] = "0123456789ABCDEF";
145145
int len = 0;
146-
146+
147147
if (!dst || !src || !maxlen)
148148
return 0;
149-
149+
150150
while (*src && len < maxlen - 1) {
151151
unsigned char c = *src;
152152

@@ -156,16 +156,16 @@ int escape_url(char *dst, const char *src, size_t maxlen) {
156156
} else {
157157
if (len + 3 > maxlen - 1)
158158
break;
159-
159+
160160
*dst++ = '%';
161161
*dst++ = hex[c >> 4];
162162
*dst++ = hex[c & 0xF];
163163
len += 3;
164164
}
165-
165+
166166
src++;
167167
}
168-
168+
169169
*dst = '\0';
170170
return len;
171171
}
@@ -301,7 +301,7 @@ int hex_to_int(char value) {
301301
unsigned int ip_to_int(const char *ip) {
302302
struct in_addr addr;
303303

304-
if (!inet_aton(ip, &addr))
304+
if (!inet_aton(ip, &addr))
305305
return 0;
306306

307307
return ntohl(addr.s_addr);
@@ -390,7 +390,7 @@ static void sha1_transform(unsigned int state[5], const unsigned char buffer[64]
390390
e = state[4];
391391

392392
for (i = 0; i < 20; i++) {
393-
unsigned int temp = ((a << 5) | (a >> 27)) +
393+
unsigned int temp = ((a << 5) | (a >> 27)) +
394394
((b & c) | ((~b) & d)) + e + w[i] + 0x5A827999;
395395
e = d;
396396
d = c;
@@ -482,18 +482,6 @@ char *split(char **input, char *sep) {
482482
return (curr);
483483
}
484484

485-
uint32_t time_get_ms(void) {
486-
struct timeval tv;
487-
gettimeofday(&tv, NULL);
488-
return (uint32_t)(tv.tv_sec * 1000 + tv.tv_usec / 1000);
489-
}
490-
491-
unsigned long long time_get_us(void) {
492-
struct timeval tv;
493-
gettimeofday(&tv, NULL);
494-
return (unsigned long long)tv.tv_sec * 1000000 + tv.tv_usec;
495-
}
496-
497485
void unescape_uri(char *uri) {
498486
char *src = uri;
499487
char *dst = uri;
@@ -525,4 +513,4 @@ void uuid_generate(char *uuid) {
525513
}
526514
}
527515
uuid[36] = '\0';
528-
}
516+
}

src/hal/tools.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ typedef struct {
3131
void *mmap64(void *start, size_t len, int prot, int flags, int fd, off_t off);
3232

3333
static inline int alt_isspace(int c) {
34-
return (c == ' ' || c == '\f' || c == '\n' ||
34+
return (c == ' ' || c == '\f' || c == '\n' ||
3535
c == '\r' || c == '\t' || c == '\v');
3636
}
3737

@@ -83,10 +83,6 @@ void sha1_final(unsigned char digest[20], sha1_context *context);
8383

8484
char *split(char **input, char *sep);
8585

86-
uint32_t time_get_ms(void);
87-
88-
unsigned long long time_get_us(void);
89-
9086
void unescape_uri(char *uri);
9187

92-
void uuid_generate(char *uuid);
88+
void uuid_generate(char *uuid);

src/rtmp.c

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ static int queue_count;
2525
static size_t queue_total_bytes;
2626

2727
static uint32_t get_rtmp_timestamp() {
28-
if (start_timestamp == 0) start_timestamp = time_get_ms();
29-
return time_get_ms() - start_timestamp;
28+
if (start_timestamp == 0) start_timestamp = millis();
29+
return millis() - start_timestamp;
3030
}
3131

3232
static int send_data(const void *buf, size_t len) {
@@ -142,13 +142,13 @@ static int rtmp_send_packet(int message_type, int stream_id, const void *data, i
142142

143143
static void queue_push(int type, int stream_id, int timestamp, const void *data, size_t len, bool force) {
144144
pthread_mutex_lock(&queue_mutex);
145-
145+
146146
if (!force && queue_total_bytes + len > MAX_QUEUE_BYTES) {
147147
HAL_WARNING("rtmp", "Queue full (%zu/%zu bytes), dropping packet!\n", queue_total_bytes, MAX_QUEUE_BYTES);
148148
pthread_mutex_unlock(&queue_mutex);
149149
return;
150150
}
151-
151+
152152
RtmpPacket *pkt = malloc(sizeof(RtmpPacket));
153153
if (!pkt) {
154154
pthread_mutex_unlock(&queue_mutex);
@@ -185,7 +185,7 @@ static void *send_thread(void *arg) {
185185
while (queue_head == NULL && keepRunning && is_connected) {
186186
pthread_cond_wait(&queue_cond, &queue_mutex);
187187
}
188-
188+
189189
if (!keepRunning || !is_connected) {
190190
pthread_mutex_unlock(&queue_mutex);
191191
break;
@@ -199,7 +199,7 @@ static void *send_thread(void *arg) {
199199
pthread_mutex_unlock(&queue_mutex);
200200

201201
rtmp_send_packet(pkt->type, pkt->stream_id, pkt->data, pkt->len, pkt->timestamp);
202-
202+
203203
free(pkt->data);
204204
free(pkt);
205205
}
@@ -261,29 +261,29 @@ static int rtmp_start_sequence(const char *url) {
261261
char *p = (char *)url;
262262
if (strncmp(p, "rtmp://", 7) != 0) return -1;
263263
p += 7;
264-
264+
265265
char *slash = strchr(p, '/');
266266
if (!slash) return -1;
267-
267+
268268
int host_len = slash - p;
269269
strncpy(host, p, host_len);
270270
host[host_len] = '\0';
271-
271+
272272
char *curr_host = host;
273273
char *colon = strchr(host, ':');
274274
if (colon) {
275275
*colon = '\0';
276276
port = atoi(colon + 1);
277277
}
278-
278+
279279
p = slash + 1;
280280
slash = strchr(p, '/');
281281
if (!slash) return -1;
282-
282+
283283
int app_len = slash - p;
284284
strncpy(app, p, app_len);
285285
app[app_len] = '\0';
286-
286+
287287
strcpy(stream, slash + 1);
288288

289289
struct hostent *he = gethostbyname(curr_host);
@@ -312,7 +312,7 @@ static int rtmp_start_sequence(const char *url) {
312312

313313
char tcurl[512];
314314
snprintf(tcurl, sizeof(tcurl), "rtmp://%s:%d/%s", curr_host, port, app);
315-
315+
316316
if (rtmp_connect(app, tcurl) < 0) return -1;
317317
if (rtmp_create_stream() < 0) return -1;
318318
if (rtmp_publish(stream) < 0) return -1;
@@ -340,14 +340,14 @@ static void *recv_thread(void *arg) {
340340
*/
341341
int rtmp_init(const char *url) {
342342
if (is_connected) rtmp_close();
343-
343+
344344
pthread_mutex_lock(&rtmp_mutex);
345345
memset(&flv_state, 0, sizeof(flv_state));
346346
seq_header_sent = false;
347347
metadata_sent = false;
348348
int ret = rtmp_start_sequence(url);
349349
if (ret == 0) {
350-
start_timestamp = time_get_ms();
350+
start_timestamp = millis();
351351
is_connected = true;
352352

353353
if (pthread_create(&recvPid, NULL, recv_thread, NULL)) {
@@ -396,7 +396,7 @@ void rtmp_close(void) {
396396
pthread_join(recvPid, NULL);
397397
pthread_join(sndPid, NULL);
398398
}
399-
399+
400400
pthread_mutex_lock(&queue_mutex);
401401
while (queue_head) {
402402
RtmpPacket *pkt = queue_head;
@@ -408,7 +408,7 @@ void rtmp_close(void) {
408408
queue_count = 0;
409409
queue_total_bytes = 0;
410410
pthread_mutex_unlock(&queue_mutex);
411-
411+
412412
pthread_mutex_unlock(&rtmp_mutex);
413413
HAL_INFO("rtmp", "RTMP has closed!\n");
414414
}
@@ -422,30 +422,30 @@ void rtmp_close(void) {
422422
int rtmp_ingest_video(hal_vidpack *packet, int is_h265) {
423423
if (!is_connected) return EXIT_FAILURE;
424424
if (!packet || !packet->data) return EXIT_FAILURE;
425-
425+
426426
pthread_mutex_lock(&rtmp_mutex);
427-
427+
428428
uint32_t now = get_rtmp_timestamp();
429429
flv_state.timestamp_ms = now;
430430
flv_state.audio_timestamp_ms = now;
431431

432432
int count = packet->naluCnt;
433433
if (count > 8) count = 8;
434-
434+
435435
for (int i = 0; i < count; i++) {
436436
hal_vidnalu *nalu = &packet->nalu[i];
437437
if (nalu->length == 0) continue;
438438

439439
if (nalu->offset + nalu->length > packet->length) {
440-
HAL_WARNING("rtmp", "NAL offset is out of bounds (off=%u len=%u total=%u)\n",
440+
HAL_WARNING("rtmp", "NAL offset is out of bounds (off=%u len=%u total=%u)\n",
441441
nalu->offset, nalu->length, packet->length);
442442
continue;
443443
}
444444

445445
uint8_t *nal_start = packet->data + nalu->offset;
446446
uint32_t nal_len = nalu->length;
447447
int type = nalu->type;
448-
448+
449449
bool is_slice = false;
450450
bool is_idr = false;
451451

@@ -473,7 +473,7 @@ int rtmp_ingest_video(hal_vidpack *packet, int is_h265) {
473473
meta.buf = meta_buf;
474474
meta.size = sizeof(meta_buf);
475475
meta.offset = 0;
476-
476+
477477
if (flv_get_metadata(&meta) == BUF_OK && meta.offset > 0) {
478478
queue_push(RTMP_MSG_AMF_META, 1, 0, meta.buf, meta.offset, true);
479479
metadata_sent = true;
@@ -482,16 +482,16 @@ int rtmp_ingest_video(hal_vidpack *packet, int is_h265) {
482482
}
483483

484484
if (!seq_header_sent) {
485-
if (!is_idr) continue;
486-
485+
if (!is_idr) continue;
486+
487487
struct BitBuf header;
488488
if (flv_get_header(&header) == BUF_OK && header.offset > 11) {
489489
queue_push(RTMP_MSG_VIDEO, 1, 0, header.buf + 11, header.offset - 15, true);
490490
seq_header_sent = true;
491491
HAL_INFO("rtmp", "Sent video sequence header (size=%d)\n", header.offset - 15);
492492
} else {
493493
HAL_WARNING("rtmp", "Waiting for header generation...\n");
494-
continue;
494+
continue;
495495
}
496496
}
497497

@@ -502,17 +502,17 @@ int rtmp_ingest_video(hal_vidpack *packet, int is_h265) {
502502
if (flv_get_tags(&tags) == BUF_OK && tags.offset > 15) {
503503
queue_push(RTMP_MSG_VIDEO, 1, flv_state.timestamp_ms, tags.buf + 11, tags.offset - 15, false);
504504
}
505-
505+
506506
if (flv_get_audio_tags(&tags) == BUF_OK && tags.offset > 15) {
507507
flv_set_state(&flv_state);
508-
508+
509509
queue_push(RTMP_MSG_AUDIO, 1, flv_state.audio_timestamp_ms, tags.buf + 11, tags.offset - 15, false);
510510
}
511511
}
512512
}
513513
}
514514
}
515-
515+
516516
pthread_mutex_unlock(&rtmp_mutex);
517517
return EXIT_SUCCESS;
518518
}
@@ -525,16 +525,16 @@ int rtmp_ingest_video(hal_vidpack *packet, int is_h265) {
525525
*/
526526
int rtmp_ingest_audio(void *data, int len) {
527527
if (!is_connected) return EXIT_FAILURE;
528-
528+
529529
if (!seq_header_sent) return EXIT_SUCCESS;
530530

531531
pthread_mutex_lock(&rtmp_mutex);
532-
532+
533533
if (flv_ingest_audio((char*)data, len) != BUF_OK) {
534534
pthread_mutex_unlock(&rtmp_mutex);
535535
return EXIT_FAILURE;
536536
}
537537

538538
pthread_mutex_unlock(&rtmp_mutex);
539539
return EXIT_SUCCESS;
540-
}
540+
}

0 commit comments

Comments
 (0)