Skip to content

Commit

Permalink
Cleaning up the media exchanges
Browse files Browse the repository at this point in the history
  • Loading branch information
wberube committed Jun 18, 2024
1 parent 2ffb5c7 commit 78a202c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
7 changes: 3 additions & 4 deletions src/media.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ int save_audio_stream(hal_audframe *frame) {

int save_video_stream(char index, hal_vidstream *stream) {
int ret;
char isH265 = chnState[index].payload == HAL_VIDCODEC_H265 ? 1 : 0;

switch (chnState[index].payload) {
case HAL_VIDCODEC_H264:
case HAL_VIDCODEC_H265:
if (app_config.mp4_enable) {
send_mp4_to_client(index, stream,
chnState[index].payload == HAL_VIDCODEC_H265 ? 1 : 0);
send_mp4_to_client(index, stream, isH265);
send_h26x_to_client(index, stream);
}
if (app_config.rtsp_enable) {
Expand All @@ -40,8 +40,7 @@ int save_video_stream(char index, hal_vidstream *stream) {
.tv_sec = stream->pack[i].timestamp / 1000000,
.tv_usec = stream->pack[i].timestamp % 1000000 };
rtp_send_h26x(rtspHandle, stream->pack[i].data + stream->pack[i].offset,
stream->pack[i].length - stream->pack[i].offset, &tv,
chnState[index].payload == HAL_VIDCODEC_H265 ? 1 : 0);
stream->pack[i].length - stream->pack[i].offset, &tv, isH265);
}
}
break;
Expand Down
11 changes: 4 additions & 7 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ int send_to_client(int i, char *buf, ssize_t size) {
return 0;
}

void send_h26x_to_client(unsigned char index, const void *p) {
const hal_vidstream *stream = (const hal_vidstream *)p;

void send_h26x_to_client(char index, hal_vidstream *stream) {
for (unsigned int i = 0; i < stream->count; ++i) {
hal_vidpack *pack = &stream->pack[i];
unsigned int pack_len = pack->length - pack->offset;
Expand Down Expand Up @@ -105,8 +103,7 @@ void send_h26x_to_client(unsigned char index, const void *p) {
}
}

void send_mp4_to_client(unsigned char index, const void *p, char isH265) {
const hal_vidstream *stream = (const hal_vidstream *)p;
void send_mp4_to_client(char index, hal_vidstream *stream, char isH265) {

for (unsigned int i = 0; i < stream->count; ++i) {
hal_vidpack *pack = &stream->pack[i];
Expand Down Expand Up @@ -192,7 +189,7 @@ void send_mp4_to_client(unsigned char index, const void *p, char isH265) {
}
}

void send_mjpeg(unsigned char index, char *buf, ssize_t size) {
void send_mjpeg(char index, char *buf, ssize_t size) {
static char prefix_buf[128];
ssize_t prefix_size = sprintf(
prefix_buf,
Expand All @@ -216,7 +213,7 @@ void send_mjpeg(unsigned char index, char *buf, ssize_t size) {
pthread_mutex_unlock(&client_fds_mutex);
}

void send_jpeg(unsigned char index, char *buf, ssize_t size) {
void send_jpeg(char index, char *buf, ssize_t size) {
static char prefix_buf[128];
ssize_t prefix_size = sprintf(
prefix_buf,
Expand Down
8 changes: 4 additions & 4 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extern char keepRunning;
int start_server();
int stop_server();

void send_jpeg(unsigned char chn_index, char *buf, ssize_t size);
void send_mjpeg(unsigned char chn_index, char *buf, ssize_t size);
void send_h26x_to_client(unsigned char chn_index, const void *p);
void send_mp4_to_client(unsigned char chn_index, const void *p, char isH265);
void send_jpeg(char index, char *buf, ssize_t size);
void send_mjpeg(char index, char *buf, ssize_t size);
void send_h26x_to_client(char index, hal_vidstream *stream);
void send_mp4_to_client(char index, hal_vidstream *stream, char isH265);

0 comments on commit 78a202c

Please sign in to comment.