@@ -25,8 +25,8 @@ static int queue_count;
2525static size_t queue_total_bytes ;
2626
2727static 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
3232static 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
143143static 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 */
341341int 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) {
422422int 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 */
526526int 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