📄 pthread_trans.c
字号:
/* set tabstop=4 *//******************************************************************************** * * * Copyright(C) 2004 Penta-Micro * * * * ALL RIGHT RESERVED * * * * This software is the property of Penta-Micro and is furnished under * * license by Penta-Micro. This software may be used only in accordance * * with the terms of said license. This copyright notice may not be * * removed, modified or obliterated without the prior written permission * * of Penta-Micro. * * * * This software may not be copyed, transmitted, provided to or otherwise * * made available to any other person, company, corporation or other entity * * except as specified in the terms of said license. * * * * No right, title, ownership or other interest in the software is hereby * * granted or transferred. * * * * The information contained herein is subject to change without notice and * * should not be construed as a commitment by Penta-Micro. * * * ******************************************************************************** MODULE NAME: PTHREAD_TRANS.C REVISION HISTORY: Date Ver Name Description ---------- --- --------------------- ----------------------------------------- 06/28/2004 1.0 JiTaeHa(netbsd) Created 02/01/2005 1.1 JiGwanKang(xchannel) Modify(arrangement) ............................................................................... DESCRIPTION: This Module contains functions for Network Streaming. ...............................................................................*/ /** ************************************************************************* ** ** includes ** ************************************************************************* **/#include "stream_server.h"/** ************************************************************************* ** ** typedefs ** ************************************************************************* **/#define MAX_IRPT 64#define MAX_ITEM 8#define INIT_FLAG 0#define WRITE_FLAGS 1#define READ_FLAGS 2#define __WAITS__ 0/** ************************************************************************* ** ** globals ** ************************************************************************* **//** ************************************************************************* ** ** locals ** ************************************************************************* **/pthread_t dvr_threads;pthread_mutex_t dvr_mutexs;pthread_cond_t dvr_conds;int dvr_code_flags;unsigned char *send_buff_trans[MAX_CH];int trans_channel;int trans_send_signal(STRDATA *str_data, unsigned short *buf_data, int channel){ int flag_main=0; pthread_mutex_lock(&dvr_mutexs); dvr_code_flags=WRITE_FLAGS; trans_channel = channel; memcpy(send_buff_trans[channel], (STRDATA *)str_data , sizeof(STRDATA)); memcpy(send_buff_trans[channel]+sizeof(STRDATA), buf_data, str_data->frame_size); pthread_mutex_unlock(&dvr_mutexs); pthread_cond_signal(&dvr_conds); DEV_LEVEL2 ("S_I:%d " ,channel); flag_main=1; return flag_main;}int trans_read_signal(STRDATA *str_data, unsigned short *buf_data, int channel, int wait){ int flag_main=0; pthread_mutex_lock(&dvr_mutexs); if (wait==__WAITS__) pthread_cond_wait(&dvr_conds, &dvr_mutexs); if(dvr_code_flags==WRITE_FLAGS) { memcpy( (STRDATA *)str_data , send_buff_trans[channel], sizeof(STRDATA)); memcpy(buf_data, send_buff_trans[channel]+sizeof(STRDATA), str_data->frame_size); dvr_code_flags=READ_FLAGS; flag_main=1; } pthread_mutex_unlock(&dvr_mutexs); pthread_cond_signal(&dvr_conds); DEV_LEVEL2 ("R_I:%d " ,channel); return flag_main;}int create_shm_net_stream(void) //Create Shared Memory Segment Video Display and Video Data{ int cnt_main = 0;////////////////////// Video Shared Memory Segment ////////////////////////// for( cnt_main = 0 ; cnt_main < MAX_FRAME_IPB ; cnt_main++) { shm_key_0_ipb[cnt_main] = ftok(".",'0') + cnt_main; if( (shm_vid_0_ipb[cnt_main] = shmget(shm_key_0_ipb[cnt_main], BUFFER_LEN, IPC_CREAT|IPC_EXCL|0666)) == -1) { //fprintf(stdout,"\n[at2021_ioctl.c][CH-%d IPB-Shared buffer opening as client 0x%X]\n", 1, shm_key_0_ipb[cnt_main]); // Segment probably already exists - try as a client if( (shm_vid_0_ipb[cnt_main] = shmget(shm_key_0_ipb[cnt_main], BUFFER_LEN, 0)) == -1) { perror("shmget"); exit(1); } } //else fprintf(stdout,"\n[at2021_ioctl.c][CH-%d Creating new IPB-shared buffer segment 0x%X]\n", 1, shm_key_0_ipb[cnt_main]); if( (ch_buff_0_ipb[cnt_main] = shmat(shm_vid_0_ipb[cnt_main], 0, 0)) <0 ) { perror("shmat"); exit(1); } else memset(ch_buff_0_ipb[cnt_main], '\0' , BUFFER_LEN); } for( cnt_main = 0 ; cnt_main < MAX_FRAME_IPB ; cnt_main++) { shm_key_1_ipb[cnt_main] = ftok(".",'1') + cnt_main; if( (shm_vid_1_ipb[cnt_main] = shmget(shm_key_1_ipb[cnt_main], BUFFER_LEN, IPC_CREAT|IPC_EXCL|0666)) == -1) { //fprintf(stdout,"\n[at2021_ioctl.c][CH-%d IPB-Shared buffer opening as client 0x%X]\n", 2, shm_key_1_ipb[cnt_main]); // Segment probably already exists - try as a client if( (shm_vid_1_ipb[cnt_main] = shmget(shm_key_1_ipb[cnt_main], BUFFER_LEN, 0)) == -1) { perror("shmget"); exit(1); } } //else fprintf(stdout,"\n[at2021_ioctl.c][CH-%d Creating new IP-shared buffer segment 0x%X]\n", 2, shm_key_1_ipb[cnt_main]); if( (ch_buff_1_ipb[cnt_main] = shmat(shm_vid_1_ipb[cnt_main], 0, 0)) <0 ) { perror("shmat"); exit(1); } else memset(ch_buff_0_ipb[cnt_main], '\0' , BUFFER_LEN); } for( cnt_main = 0 ; cnt_main < MAX_FRAME_IPB ; cnt_main++) { shm_key_2_ipb[cnt_main] = ftok(".",'2') + cnt_main; if( (shm_vid_2_ipb[cnt_main] = shmget(shm_key_2_ipb[cnt_main], BUFFER_LEN, IPC_CREAT|IPC_EXCL|0666)) == -1) { //fprintf(stdout,"\n[at2021_ioctl.c][CH-%d IPB-Shared buffer opening as client 0x%X]\n", 3, shm_key_2_ipb[cnt_main]); // Segment probably already exists - try as a client if( (shm_vid_2_ipb[cnt_main] = shmget(shm_key_2_ipb[cnt_main], BUFFER_LEN, 0)) == -1) { perror("shmget"); exit(1); } } //else fprintf(stdout,"\n[at2021_ioctl.c][CH-%d Creating new IPB-shared buffer segment 0x%X]\n", 3, shm_key_2_ipb[cnt_main]); if( (ch_buff_2_ipb[cnt_main] = shmat(shm_vid_2_ipb[cnt_main], 0, 0)) <0 ) { perror("shmat"); exit(1); } else memset(ch_buff_0_ipb[cnt_main], '\0' , BUFFER_LEN); } for( cnt_main = 0 ; cnt_main < MAX_FRAME_IPB ; cnt_main++) { shm_key_3_ipb[cnt_main] = ftok(".",'3') + cnt_main; if( (shm_vid_3_ipb[cnt_main] = shmget(shm_key_3_ipb[cnt_main], BUFFER_LEN, IPC_CREAT|IPC_EXCL|0666)) == -1) { //fprintf(stdout,"\n[at2021_ioctl.c][CH-%d IP-Shared buffer opening as client 0x%X]\n", 4, shm_key_3_ipb[cnt_main]); // Segment probably already exists - try as a client if( (shm_vid_3_ipb[cnt_main] = shmget(shm_key_3_ipb[cnt_main], BUFFER_LEN, 0)) == -1) { perror("shmget"); exit(1); } } //else fprintf(stdout,"\n[at2021_ioctl.c][CH-%d Creating new IP-shared buffer segment 0x%X]\n", 4, shm_key_3_ipb[cnt_main]); if( (ch_buff_3_ipb[cnt_main] = shmat(shm_vid_3_ipb[cnt_main], 0, 0)) <0 ) { perror("shmat"); exit(1); } else memset(ch_buff_0_ipb[cnt_main], '\0' , BUFFER_LEN);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -