Skip to content

Commit

Permalink
Removing StopReceiving checks (JPEG modes can fail), making it to enc…
Browse files Browse the repository at this point in the history
…oding on Ingenic
  • Loading branch information
wberube committed Jun 1, 2024
1 parent 965d702 commit e7f2393
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 14 deletions.
3 changes: 1 addition & 2 deletions src/hal/hisi/v4_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,7 @@ int v4_video_destroy(char index)

v4_state[index].payload = HAL_VIDCODEC_UNSPEC;

if (ret = v4_venc.fnStopReceiving(index))
return ret;
v4_venc.fnStopReceiving(index);

{
v4_sys_bind source = { .module = V4_SYS_MOD_VPSS,
Expand Down
115 changes: 109 additions & 6 deletions src/hal/inge/tx_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,12 @@ int tx_channel_create(char index, short width, short height, char framerate)

{
tx_fs_chn channel = {
.dest = { .width = _tx_snr_dim.width, .height = _tx_snr_dim.height },
.scale = { .enable = 1, .width = width, .height = height },
.fpsDen = framerate, .fpsNum = 1,
.pixFmt = TX_PIXFMT_NV12
.dest = { .width = width, .height = height }, .pixFmt = TX_PIXFMT_NV12,
.crop = { .enable = 1, .left = 0, .top = 0, .width = _tx_snr_dim.width,
.height = _tx_snr_dim.height },
.scale = { .enable = (_tx_snr_dim.width != width || _tx_snr_dim.height != height)
? 1 : 0, .width = width, .height = height },
.fpsDen = framerate, .fpsNum = 1, .bufCount = 2, .phyOrExtChn = 0,
};

if (ret = tx_fs.fnCreateChannel(index, &channel))
Expand Down Expand Up @@ -191,7 +193,7 @@ int tx_region_create(int *handle, hal_rect rect)
memset(&attrib, 0, sizeof(attrib));
attrib.show = 1;
attrib.alphaOn = 1;
attrib.fgAlpha = 255;
attrib.fgAlpha = 128;

tx_osd.fnRegisterRegion(*handle, _tx_osd_grp, &attrib);

Expand Down Expand Up @@ -272,6 +274,9 @@ int tx_video_create(char index, hal_vidconfig *config)
if (ret = tx_venc.fnCreateChannel(index, &channel))
return ret;

if (ret = tx_venc.fnRegisterChannel(index, index))
return ret;

{
int count = -1;
if (config->codec != HAL_VIDCODEC_JPG &&
Expand All @@ -290,7 +295,9 @@ int tx_video_destroy(char index)

tx_state[index].payload = HAL_VIDCODEC_UNSPEC;

if (ret = tx_venc.fnStopReceiving(index))
tx_venc.fnStopReceiving(index);

if (ret = tx_venc.fnUnregisterChannel(index))
return ret;

if (ret = tx_venc.fnDestroyChannel(index))
Expand All @@ -313,7 +320,103 @@ int tx_video_destroy_all(void)

void *tx_video_thread(void)
{
int ret;
int maxFd = 0;

for (int i = 0; i < TX_VENC_CHN_NUM; i++) {
if (!tx_state[i].enable) continue;
if (!tx_state[i].mainLoop) continue;

ret = tx_venc.fnGetDescriptor(i);
if (ret < 0) {
fprintf(stderr, "[tx_venc] Getting the encoder descriptor failed with %#x!\n", ret);
return NULL;
}
tx_state[i].fileDesc = ret;

if (maxFd <= tx_state[i].fileDesc)
maxFd = tx_state[i].fileDesc;
}

tx_venc_stat stat;
tx_venc_strm stream;
struct timeval timeout;
fd_set readFds;

while (keepRunning) {
FD_ZERO(&readFds);
for(int i = 0; i < TX_VENC_CHN_NUM; i++) {
if (!tx_state[i].enable) continue;
if (!tx_state[i].mainLoop) continue;
FD_SET(tx_state[i].fileDesc, &readFds);
}

timeout.tv_sec = 2;
timeout.tv_usec = 0;
ret = select(maxFd + 1, &readFds, NULL, NULL, &timeout);
if (ret < 0) {
fprintf(stderr, "[tx_venc] Select operation failed!\n");
break;
} else if (ret == 0) {
fprintf(stderr, "[tx_venc] Main stream loop timed out!\n");
continue;
} else {
for (int i = 0; i < TX_VENC_CHN_NUM; i++) {
if (!tx_state[i].enable) continue;
if (!tx_state[i].mainLoop) continue;
if (FD_ISSET(tx_state[i].fileDesc, &readFds)) {
memset(&stream, 0, sizeof(stream));

if (ret = tx_venc.fnQuery(i, &stat)) {
fprintf(stderr, "[tx_venc] Querying the encoder channel "
"%d failed with %#x!\n", i, ret);
break;
}

if (!stat.curPacks) {
fprintf(stderr, "[tx_venc] Current frame is empty, skipping it!\n");
continue;
}

stream.packet = (tx_venc_pack*)malloc(
sizeof(tx_venc_pack) * stat.curPacks);
if (!stream.packet) {
fprintf(stderr, "[tx_venc] Memory allocation on channel %d failed!\n", i);
break;
}
stream.count = stat.curPacks;

if (ret = tx_venc.fnGetStream(i, &stream, stat.curPacks)) {
fprintf(stderr, "[tx_venc] Getting the stream on "
"channel %d failed with %#x!\n", i, ret);
break;
}

if (tx_venc_cb) {
hal_vidstream outStrm;
hal_vidpack outPack[stat.curPacks];
outStrm.count = stream.count;
outStrm.seq = stream.sequence;
for (int j = 0; j < stat.curPacks; j++) {
outPack[j].data = (unsigned char*)stream.addr + stream.packet[j].offset;
outPack[j].length = stream.packet[j].length;
outPack[j].offset = stream.packet[j].offset;
}
outStrm.pack = outPack;
(*tx_venc_cb)(i, &outStrm);
}

if (ret = tx_venc.fnFreeStream(i, &stream)) {
fprintf(stderr, "[tx_venc] Releasing the stream on "
"channel %d failed with %#x!\n", i, ret);
}
free(stream.packet);
stream.packet = NULL;
}
}
}
}
fprintf(stderr, "[tx_venc] Shutting down encoding thread...\n");
}

void tx_system_deinit(void)
Expand Down
3 changes: 1 addition & 2 deletions src/hal/sstar/i6_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,7 @@ int i6_video_destroy(char index)

i6_state[index].payload = HAL_VIDCODEC_UNSPEC;

if (ret = i6_venc.fnStopReceiving(index))
return ret;
i6_venc.fnStopReceiving(index);

{
unsigned int device;
Expand Down
3 changes: 1 addition & 2 deletions src/hal/sstar/i6c_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,7 @@ int i6c_video_destroy(char index, char jpeg)

i6c_state[index].payload = HAL_VIDCODEC_UNSPEC;

if (ret = i6c_venc.fnStopReceiving(device, index))
return ret;
i6c_venc.fnStopReceiving(device, index);

{
i6c_sys_bind source = { .module = I6C_SYS_MOD_SCL,
Expand Down
3 changes: 1 addition & 2 deletions src/hal/sstar/i6f_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,7 @@ int i6f_video_destroy(char index, char jpeg)

i6f_state[index].payload = HAL_VIDCODEC_UNSPEC;

if (ret = i6f_venc.fnStopReceiving(device, index))
return ret;
i6f_venc.fnStopReceiving(device, index);

{
i6f_sys_bind source = { .module = I6F_SYS_MOD_SCL,
Expand Down

0 comments on commit e7f2393

Please sign in to comment.