Skip to content

Commit

Permalink
Tons of changes, bugfixes
Browse files Browse the repository at this point in the history
- Typo that rendered hisi-v4 devices unusable, they were directed to the v3 platform
- Now passing the timestamps in the rewrapped video packets, maybe NAL units too?
- Integrated @ykst/librtsp, simple RTSP server that just works with no frills
  • Loading branch information
wberube committed Jun 4, 2024
1 parent e54dc37 commit 96fc52c
Show file tree
Hide file tree
Showing 38 changed files with 3,700 additions and 2,653 deletions.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ toolchain() {
}

if [ "$2" = "debug" ]; then
OPT="-gdwarf-3"
OPT="-DDEBUG -gdwarf-3"
else
OPT="-Os -s"
fi
Expand Down
1 change: 1 addition & 0 deletions src/hal/hisi/v3_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ void *v3_video_thread(void)
outPack[j].data = stream.packet[j].data;
outPack[j].length = stream.packet[j].length;
outPack[j].offset = stream.packet[j].offset;
outPack[j].timestamp = stream.packet[j].timestamp;
}
outStrm.pack = outPack;
(*v3_venc_cb)(i, &outStrm);
Expand Down
1 change: 1 addition & 0 deletions src/hal/hisi/v4_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,7 @@ void *v4_video_thread(void)
outPack[j].data = stream.packet[j].data;
outPack[j].length = stream.packet[j].length;
outPack[j].offset = stream.packet[j].offset;
outPack[j].timestamp = stream.packet[j].timestamp;
}
outStrm.pack = outPack;
(*v4_venc_cb)(i, &outStrm);
Expand Down
1 change: 1 addition & 0 deletions src/hal/inge/t31_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ void *t31_video_thread(void)
t31_venc_pack *pack = &stream.packet[j];
if (!pack->length) continue;
outPack[j].offset = 0;
outPack[j].timestamp = pack->timestamp;
unsigned int remain = stream.length - pack->offset;
if (remain < pack->length) {
outPack[j].data = (unsigned char*)(stream.addr);
Expand Down
1 change: 1 addition & 0 deletions src/hal/sstar/i6_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,7 @@ void *i6_video_thread(void)
outPack[j].data = stream.packet[j].data;
outPack[j].length = stream.packet[j].length;
outPack[j].offset = stream.packet[j].offset;
outPack[j].timestamp = stream.packet[j].timestamp;
}
outStrm.pack = outPack;
(*i6_venc_cb)(i, &outStrm);
Expand Down
1 change: 1 addition & 0 deletions src/hal/sstar/i6c_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,7 @@ void *i6c_video_thread(void)
outPack[j].data = stream.packet[j].data;
outPack[j].length = stream.packet[j].length;
outPack[j].offset = stream.packet[j].offset;
outPack[j].timestamp = stream.packet[j].timestamp;
}
outStrm.pack = outPack;
(*i6c_venc_cb)(i, &outStrm);
Expand Down
1 change: 1 addition & 0 deletions src/hal/sstar/i6f_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,7 @@ void *i6f_video_thread(void)
outPack[j].data = stream.packet[j].data;
outPack[j].length = stream.packet[j].length;
outPack[j].offset = stream.packet[j].offset;
outPack[j].timestamp = stream.packet[j].timestamp;
}
outStrm.pack = outPack;
(*i6f_venc_cb)(i, &outStrm);
Expand Down
2 changes: 1 addition & 1 deletion src/hal/support.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void hal_identify(void) {

switch (val) {
case 0x12040000:
case 0x120a0000:
case 0x120a0000: val = 0x12020000; break;
case 0x12100000:
val = 0x12020000;
v3series = 1;
Expand Down
1 change: 1 addition & 0 deletions src/hal/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ typedef struct {
unsigned char *data;
unsigned int length;
unsigned int offset;
unsigned long long timestamp;
} hal_vidpack;

typedef struct {
Expand Down
27 changes: 27 additions & 0 deletions src/lib/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,31 @@ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

---

The following software is included in this product: @ykst/librtsp.
A copy of the original source code may be downloaded from git+https://github.com/ykst/librtsp.
It contains the following license and notice below:

Copyright (c) 2014 Yohsuke YUKISHITA, https://github.com/ykst

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

---
249 changes: 249 additions & 0 deletions src/lib/rtsp/bufpool.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
#ifndef _RTSP_BUFFPOOL_H
#define _RTSP_BUFFPOOL_H

#include <pthread.h>
#include "common.h"
#include "list.h"
#include "hash.h"

#if defined (__cplusplus)
extern "C" {
#endif

/******************************************************************************
* DEFINITIONS
******************************************************************************/

/******************************************************************************
* DATA STRUCTURES
******************************************************************************/
struct __bufpool_elem_t {
unsigned int magic;
void *buf;
int ref_count;
int pos;
int (*reset)(void *buf);
struct list_t list_entry; // free list entry
};

struct __bufpool_t {
pthread_mutex_t mutex;
struct list_head_t free_list;
struct __bufpool_elem_t *elems;
hash_handle buf_table;
unsigned int num;
};

typedef struct __bufpool_t *bufpool_handle;

/******************************************************************************
* FUNCTION DECLARATIONS
******************************************************************************/
static inline bufpool_handle bufpool_create(int num, void * (*bufgetter_fxn)(int i), int (*reset)(void *buf), size_t each_size);
static void bufpool_delete(bufpool_handle h);

//static inline int bufpool_get_free(bufpool_handle h,void **p_buf);
static inline int __bufpool_ref_manipulate(bufpool_handle h, void * buf, int val);
static inline int bufpool_detach(bufpool_handle h, void *buf);
static inline int bufpool_attach(bufpool_handle h, void *buf);
static inline void bufpool_statistics(bufpool_handle h);

/******************************************************************************
* INLINE FUNCTIONS
******************************************************************************/
/* to use strict-aliase compiler optimization, we cannot use void **, so use macro : completely dependent of gcc-extension :p */
#define bufpool_get_free(__h,__p_buf) ({ \
__label__ __unlock;\
int __ret = FAILURE; \
struct list_t *__e; \
struct __bufpool_elem_t *__p; \
pthread_mutex_lock(&__h->mutex); \
ASSERT(__e = list_pop(&__h->free_list), goto __unlock); \
list_upcast(__p,__e); \
__p->ref_count += 1; \
*__p_buf = __p->buf; \
__ret = SUCCESS; \
__unlock: \
pthread_mutex_unlock(&__h->mutex); \
__ret; \
})


static inline int __bufpool_ref_manipulate(bufpool_handle h, void *buf, int val)
{
struct __bufpool_elem_t *p;

DASSERT(h->elems,return FAILURE);
DASSERT(h->num > 0,return FAILURE);

ASSERT(p = hash_lookup(h->buf_table,(hash_key_t) buf), return FAILURE);

DASSERT(CHECK_MAGIC(MAGIC_BUFPOOL_ELEM,&p), return FAILURE);

p->ref_count += val;

TEST(p->ref_count >= 0, ({
ERR("double detach at pointer %p: corrupted use of reference counting\n", buf);
return FAILURE;}));

if(p->ref_count == 0) {
if(p->reset) {
ASSERT(p->reset(buf) == SUCCESS,
return FAILURE);
}

ASSERT(list_push(&h->free_list,&p->list_entry) == SUCCESS,
return FAILURE);
}

//DBG("%p: %d\n", buf, p->ref_count);

return SUCCESS;
}


static inline void bufpool_statistics(bufpool_handle h)
{
//#ifdef __DEBUG
DASSERT(h, ERR("null pointer\n"));
int free_elems;
float free_elems_ratio;
int i;
int j = 0;
int max = 50;
char tmp[max+1];

pthread_mutex_lock(&h->mutex);

free_elems = list_length(&h->free_list);
free_elems_ratio = ((float)free_elems/(float)h->num) * max;

for(i = 0; i < free_elems_ratio; i++) {
tmp[j++] = '=';
}
for(; i < max; i++) {
tmp[j++] = '.';
}
tmp[j]=0;

printf("%p[%s]%d/%d\n",h,
tmp,free_elems,h->num);

pthread_mutex_unlock(&h->mutex);
//#endif
}

static inline int bufpool_attach(bufpool_handle h, void *buf)
{
int ret;
DASSERT(h,return FAILURE);

pthread_mutex_lock(&h->mutex);

ret = __bufpool_ref_manipulate(h,buf,1);

pthread_mutex_unlock(&h->mutex);

return ret;
}

static inline int bufpool_detach(bufpool_handle h, void *buf)
{
int ret;
DASSERT(h,return FAILURE);

pthread_mutex_lock(&h->mutex);

ret = __bufpool_ref_manipulate(h,buf,-1);

pthread_mutex_unlock(&h->mutex);

return ret;
}

static inline bufpool_handle bufpool_create(int num, void * (*bufgetter_fxn)(int i), int (*reset)(void *buf), size_t each_size)
{
int i;
bufpool_handle nh = NULL;


DASSERT(bufgetter_fxn, return NULL);


TALLOC(nh,return NULL);


pthread_mutex_init(&nh->mutex,NULL);


ASSERT(nh->elems = calloc(num,sizeof(struct __bufpool_elem_t)), goto error);


ASSERT(nh->buf_table = hash_create(num, each_size),
goto error);


for(i = 0; i< num; i++) {

nh->elems[i].magic = MAGIC_BUFPOOL_ELEM;

nh->elems[i].pos = i;
nh->elems[i].reset = reset;

ASSERT(nh->elems[i].buf = bufgetter_fxn(i),
goto error);

ASSERT(hash_add(nh->buf_table, (hash_key_t)nh->elems[i].buf,
&(nh->elems[i])) == SUCCESS,
goto error);

MUST(list_push(&nh->free_list, &(nh->elems[i].list_entry)) == SUCCESS,
goto error);

#ifdef __DEBUG
struct __bufpool_elem_t *p;

/* hash health check */
ASSERT(p = hash_lookup(nh->buf_table,(hash_key_t)(nh->elems[i].buf)), goto error);

ASSERT(CHECK_MAGIC(MAGIC_BUFPOOL_ELEM,&p),goto error);

ASSERT(p == &nh->elems[i], goto error);
#endif
}


nh->num = num;


return nh;
error:
bufpool_delete(nh);
return NULL;
}

static void bufpool_delete(bufpool_handle h)
{
int i;
if (h) {
if (h->elems) {
for(i = 0;i < h->num; i++) {
if(h->elems[i].reset) {
h->elems[i].reset(h->elems[i].buf);
}
}
FREE(h->elems);
}

hash_destroy(h->buf_table);

pthread_mutex_destroy(&h->mutex);
FREE(h);
}
}


#if defined (__cplusplus)
}
#endif
#endif
Loading

0 comments on commit 96fc52c

Please sign in to comment.