#include #include #include #include #include #include #define SNDRV_SEQ_EVENT_LENGTH_MASK (3<<2) #define SNDRV_SEQ_QUEUE_DIRECT 253 #define SNDRV_SEQ_EVENT_LENGTH_VARIABLE (1<<2) #define SNDRV_SEQ_PORT_CAP_WRITE (1<<1) //int client; typedef int snd_seq_client_type_t; typedef unsigned int snd_seq_tick_time_t; typedef unsigned char snd_seq_event_type_t; struct snd_seq_real_time { unsigned int tv_sec; /* seconds */ unsigned int tv_nsec; /* nanoseconds */ }; struct snd_seq_ev_ext { unsigned int len; /* length of data */ void *ptr; /* pointer to data (note: maybe 64-bit) */ }; struct snd_seq_addr { unsigned char client; /**< Client number: 0..255, 255 = broadcast to all clients */ unsigned char port; /**< Port within client: 0..255, 255 = broadcast to all ports */ }; struct snd_seq_client_info { int client; /* client number to inquire */ snd_seq_client_type_t type; /* client type */ char name[64]; /* client name */ unsigned int filter; /* filter flags */ unsigned char multicast_filter[8]; /* multicast filter bitmap */ unsigned char event_filter[32]; /* event filter bitmap */ int num_ports; /* RO: number of ports */ int event_lost; /* number of lost events */ int card; /* RO: card number[kernel] */ int pid; /* RO: pid[user] */ char reserved[56]; /* for future use */ }; union snd_seq_timestamp { snd_seq_tick_time_t tick; struct snd_seq_real_time time; }; struct snd_seq_client_pool { int client; /* client number to inquire */ int output_pool; /* outgoing (write) pool size */ int input_pool; /* incoming (read) pool size */ int output_room; /* minimum free pool size for select/blocking mode */ int output_free; /* unused size */ int input_free; /* unused size */ char reserved[64]; }; struct snd_seq_port_info { struct snd_seq_addr addr; /* client/port numbers */ char name[64]; /* port name */ unsigned int capability; /* port capability bits */ unsigned int type; /* port type bits */ int midi_channels; /* channels per MIDI port */ int midi_voices; /* voices per MIDI port */ int synth_voices; /* voices per SYNTH port */ int read_use; /* R/O: subscribers for output (from this port) */ int write_use; /* R/O: subscribers for input (to this port) */ void *kernel; /* reserved for kernel use (must be NULL) */ unsigned int flags; /* misc. conditioning */ unsigned char time_queue; /* queue # for timestamping */ char reserved[59]; /* for future use */ }; struct snd_seq_queue_info { int queue; /* queue id */ /* * security settings, only owner of this queue can start/stop timer * etc. if the queue is locked for other clients */ int owner; /* client id for owner of the queue */ unsigned locked:1; /* timing queue locked for other queues */ char name[64]; /* name of this queue */ unsigned int flags; /* flags */ char reserved[60]; /* for future use */ }; struct snd_seq_event { snd_seq_event_type_t type; /* event type */ unsigned char flags; /* event flags */ char tag; unsigned char queue; /* schedule queue */ union snd_seq_timestamp time; /* schedule time */ struct snd_seq_addr source; /* source address */ struct snd_seq_addr dest; /* destination address */ union { /* event data... */ struct snd_seq_ev_ext ext; } data; }; //gcc competition.c -o competition -lpthread //./competition void *thread1(void *arg) { struct snd_seq_event event;//不能直接进去我要走 snd_seq_fifo_event_in char* buf; int num; int i; int ret=0; int fd=*(int*)arg; struct snd_seq_client_pool pool_info; buf=(char*)malloc(60000); event.flags=SNDRV_SEQ_EVENT_LENGTH_VARIABLE;//snd_seq_ev_is_variable event.data.ext.len=0xc0000770; event.data.ext.ptr=0xffffffff; ///////需要填充物 event.type=130; event.queue=0; event.dest.client=128;//get_event_dest_client 进2时候也要验证 还需要考虑 accept_input //需要动态获取 //printf("client %d\n",client); event.dest.port=0;//snd_seq_port_use_ptr port->capability可设置 没写好 num=2000/sizeof(event); for(i=0;i0) { printf("write 2000 ok num=%d\n",ret); } else { i++; printf("write fail"); pool_info.input_pool=100; pool_info.output_pool=i; pool_info.client=128;//需要动态获取 //printf("client %d\n",client); ret=ioctl(fd,1079530316,&pool_info); if(!(ret<0)) printf("thread1 ok snd_seq_ioctl_set_client_pool"); } } } void *thread2(void *arg) { struct snd_seq_event event; struct snd_seq_client_pool pool_info; int fd=*(int*)arg; int ret=0; int i=600; int num; char* buf; sleep(3); pool_info.input_pool=100; pool_info.output_pool=600; pool_info.client=128;//需要动态获取 //printf("client %d\n",client); printf("thread2 start"); event.flags=SNDRV_SEQ_EVENT_LENGTH_VARIABLE; buf=(char*)malloc(60000); event.data.ext.len=0xc0000770; event.data.ext.ptr=0xffffffff; num=2000/sizeof(event); ///////需要填充物 event.type=130; event.queue=0; event.dest.client=128;//get_event_dest_client 进2时候也要验证 还需要考虑 accept_input //需要动态获取 //printf("client %d\n",client); event.dest.port=0;//snd_seq_port_use_ptr port->capability可设置 没写好 for(i=0;iqueue ret=pthread_create( &th, NULL, thread1, (void*)&fd); if(ret!=0) { printf("create thread11111111111111111 error!\n"); return -1; } else { ret=pthread_create( &th, NULL, thread1, (void*)&fd); ret=pthread_create( &th, NULL, thread1, (void*)&fd); ret=pthread_create( &th, NULL, thread1, (void*)&fd); ret=pthread_create( &th, NULL, thread1, (void*)&fd); ret=pthread_create( &th, NULL, thread1, (void*)&fd); ret=pthread_create( &th, NULL, thread1, (void*)&fd); ret=pthread_create( &th, NULL, thread1, (void*)&fd); ret=pthread_create( &th, NULL, thread1, (void*)&fd); ret=pthread_create( &th, NULL, thread1, (void*)&fd); ret=pthread_create( &th, NULL, thread1, (void*)&fd); printf("create thread1 okokokokokokokokoko!\n"); } ret=pthread_create( &th, NULL, thread2, (void*)&fd); if(ret!=0) { printf("create thread2222222222 error!\n"); return -1; } else { printf("create thread2 okokokokokokokokoko!\n"); } //ret=pthread_create( &th, NULL, thread1, (void*)&fd); sleep(1800); return 0; }