void check_interupt() { if (q != NULL && q->type == CHECK_INT) { // Don't add another CHECK_INT if there's one pending // MI_register.mi_intr_reg is a bitmask so interupts can be combined return; } if (MI_register.mi_intr_reg & MI_register.mi_intr_mask_reg) { Cause = (Cause | 0x400) & 0xFFFFFF83; } else { Cause &= ~0x400; } if ((Status & 7) != 1) { return; } if (Status & Cause & 0xFF00) { if(q == NULL) { q = queue_malloc(sizeof(interupt_queue)); q->next = NULL; q->count = Count; q->type = CHECK_INT; } else { interupt_queue* aux = queue_malloc(sizeof(interupt_queue)); aux->next = q; aux->count = Count; aux->type = CHECK_INT; q = aux; } next_interupt = Count; } }
void check_interupt(void) { //DEBUG_PRINT("check_interupt\n"); if (MI_register.mi_intr_reg & MI_register.mi_intr_mask_reg) Cause = (Cause | 0x400) & 0xFFFFFF83; else Cause &= ~0x400; if ((Status & 7) != 1) return; #ifdef USE_CHECK if (Status & Cause & 0xFF00) { if(q == NULL) { q = (interupt_queue *) queue_malloc(sizeof(interupt_queue)); q->next = NULL; q->count = Count; q->type = CHECK_INT; } else { interupt_queue* aux = (interupt_queue *) queue_malloc(sizeof(interupt_queue)); aux->next = q; aux->count = Count; aux->type = CHECK_INT; q = aux; } next_interupt = Count; } #endif }
void add_interupt_event(int type, unsigned int delay) { unsigned int count = Count + delay/**2*/; int special = 0; interupt_queue *aux = q; if(type == SPECIAL_INT /*|| type == COMPARE_INT*/) special = 1; if(Count > 0x80000000) SPECIAL_done = 0; if (get_event(type)) { DebugMessage(M64MSG_WARNING, "two events of type 0x%x in interrupt queue", type); } if (q == NULL) { q = (interupt_queue *) queue_malloc(sizeof(interupt_queue)); q->next = NULL; q->count = count; q->type = type; next_interupt = q->count; //print_queue(); return; } if(before_event(count, q->count, q->type) && !special) { q = (interupt_queue *) queue_malloc(sizeof(interupt_queue)); q->next = aux; q->count = count; q->type = type; next_interupt = q->count; //print_queue(); return; } while (aux->next != NULL && (!before_event(count, aux->next->count, aux->next->type) || special)) aux = aux->next; if (aux->next == NULL) { aux->next = (interupt_queue *) queue_malloc(sizeof(interupt_queue)); aux = aux->next; aux->next = NULL; aux->count = count; aux->type = type; } else { interupt_queue *aux2; if (type != SPECIAL_INT) while(aux->next != NULL && aux->next->count == count) aux = aux->next; aux2 = aux->next; aux->next = (interupt_queue *) queue_malloc(sizeof(interupt_queue)); aux = aux->next; aux->next = aux2; aux->count = count; aux->type = type; } }
/****************************************************************************** **函数名称: rtrd_dsvr_dist_data_hdl **功 能: 数据分发处理 **输入参数: ** ctx: 全局信息 ** dsvr: 分发信息 **输出参数: NONE **返 回: 0:成功 !0:失败 **实现描述: **注意事项: WARNNING: 千万勿将共享变量参与MIN()三目运算, 否则可能出现严重错误!!!!且很难找出原因! ** 原因: MIN()不是原子运算, 使用共享变量可能导致判断成立后, 而返回时共 ** 享变量的值可能被其他进程或线程修改, 导致出现严重错误! **作 者: # Qifeng.zou # 2015.06.13 # ******************************************************************************/ static int rtrd_dsvr_dist_data_hdl(rtrd_cntx_t *ctx, rtrd_dsvr_t *dsvr) { #define RTRD_DISP_POP_NUM (1024) int idx, k, num, d; rtmq_frwd_t *frwd; void *data[RTRD_DISP_POP_NUM], *addr; for (d=0; d<ctx->conf.distq_num; ++d) { /* > 计算弹出个数(WARNNING: 勿将共享变量参与MIN()三目运算, 否则可能出现严重错误!!!) */ num = MIN(queue_used(ctx->distq[d]), RTRD_DISP_POP_NUM); if (0 == num) { continue; } /* > 弹出发送数据 */ num = queue_mpop(ctx->distq[d], data, num); if (0 == num) { continue; } log_trace(ctx->log, "Multi-pop num:%d!", num); /* > 放入发送队列 */ for (k=0; k<num; ++k) { /* > 获取发送队列 */ frwd = (rtmq_frwd_t *)data[k]; idx = rtrd_node_to_svr_map_rand(ctx, frwd->dest); if (idx < 0) { queue_dealloc(ctx->distq[d], data[k]); log_error(ctx->log, "Didn't find dev to svr map! nodeid:%d", frwd->dest); continue; } /* > 申请内存空间 */ addr = queue_malloc(ctx->sendq[idx], frwd->length+sizeof(rtmq_frwd_t)); if (NULL == addr) { queue_dealloc(ctx->distq[d], data[k]); log_error(ctx->log, "Alloc from queue failed! size:%d/%d", frwd->length, queue_size(ctx->sendq[idx])); continue; } memcpy(addr, data[k], frwd->length+sizeof(rtmq_frwd_t)); queue_push(ctx->sendq[idx], addr); queue_dealloc(ctx->distq[d], data[k]); /* > 发送分发请求 */ rtrd_dsvr_cmd_dist_req(ctx, dsvr, idx); } } return RTMQ_OK; }
int main(){ FILE * arquivo = NULL; long lSize; char * buffer; char caminho[256]; char ip[18]; int porta=0; queue_t * queue; netsend_struct_t * sender; int retorno; queue = queue_create(); sender = netsend_init(queue,NET_CONTENT_TYPE_VIDEO); netsend_packetSize(sender,1024,128); printf("CUIDADO - PROGRAMA CARREGA TODO O ARQUIVO PARA A MEMÓRIA RAM ANTES DE ENVIAR\n\n\n"); while(arquivo == NULL){ printf("Digite o caminho do arquivo a ser transferido para o servidor:\n"); scanf("%s",caminho); arquivo = fopen(caminho, "rb"); if(!arquivo) printf("Digite um caminho válido para o arquivo!\n\n"); } //tamanho fseek (arquivo, 0 , SEEK_END); lSize = ftell(arquivo); rewind (arquivo); buffer = (char *)queue_malloc(sizeof(char)*lSize); if(!buffer) printf("Seu sistema não possui memória livre sufiente para carregar o arquivo para memória!"); fread (buffer,1,lSize,arquivo); printf("Digite o IP do servidor:\n"); scanf("%s",ip); printf("Digite a porta do servidor:\n"); scanf("%d",&porta); netsend_setDest(sender, ip, porta); netsend_start(sender); retorno = queue_enqueue(queue,(uint8_t *)buffer,lSize,getTimestamp(),NULL); while(queue_length(queue)>0){ common_sleep(1000); }; netsend_stop(sender); netsend_end(sender); queue_appFinish(); printf("Arquivo enviado com sucesso!\n"); getchar(); return 0; };
int DecodeVideo::_PrepareFrame(AVFrame * inFrame, uint8_t ** buffer) { uint8_t *outbuf, *outbuf2; int outbufSize; AVFrame * frameTmp = avcodec_alloc_frame(); AVFrame * frameTmp2 = avcodec_alloc_frame(); // aloca buffer da queue e associa ao _tempFrame2 outbufSize = avpicture_get_size(_codecCtx->pix_fmt, _codecCtx->width, _codecCtx->height); if (outbufSize <= 0) return 0; outbuf = (uint8_t *) queue_malloc(outbufSize); if (!outbuf) return 0; avpicture_fill((AVPicture *)frameTmp, outbuf, _codecCtx->pix_fmt, _codecCtx->width, _codecCtx->height); // faz desentrelaçamento e coloca resultado no _tempFrame2 _Deinterlace(inFrame, frameTmp); // converte o pix_fmt se necessário if (_codecCtx->pix_fmt != _defaultPixFmt.toFfmpeg()) { outbuf2 = outbuf; // guarda ponteiro pro buffer temporário // novo buffer da queue para os dados finais outbufSize = avpicture_get_size(_defaultPixFmt.toFfmpeg(), _codecCtx->width, _codecCtx->height); outbuf = (uint8_t *) queue_malloc(outbufSize); avpicture_fill((AVPicture *)frameTmp2, outbuf, _defaultPixFmt.toFfmpeg(), _codecCtx->width, _codecCtx->height); _ConvertPixFmt(frameTmp, frameTmp2); queue_dealloc(outbuf2); } av_free(frameTmp); av_free(frameTmp2); *buffer = outbuf; return outbufSize; }
int DecodeVideo::_PrepareFrame(AVFrame * inFrame, uint8_t ** buffer) { uint8_t *outbuf; int outbufSize; AVFrame * frameTmp2 = avcodec_alloc_frame(); // novo buffer da queue para os dados finais outbufSize = avpicture_get_size(PIX_FMT_RGB565LE, _codecCtx->width, _codecCtx->height); outbuf = (uint8_t *) queue_malloc(outbufSize); avpicture_fill((AVPicture *)frameTmp2, outbuf, PIX_FMT_RGB565LE, _codecCtx->width, _codecCtx->height); _ConvertPixFmt(inFrame, frameTmp2); av_free(frameTmp2); *buffer = outbuf; return outbufSize; }
/****************************************************************************** **函数名称: rtrd_rsvr_exp_mesg_proc **功 能: 自定义消息处理 **输入参数: ** ctx: 全局对象 ** rsvr: 接收服务 ** sck: 套接字对象 **输出参数: NONE **返 回: 0:成功 !0:失败 **实现描述: ** 1. 是否在NULL空间: 直接丢弃 ** 2. 放入队列中 ** 3. 发送处理请求 **注意事项: **作 者: # Qifeng.zou # 2015.01.01 # ******************************************************************************/ static int rtrd_rsvr_exp_mesg_proc(rtrd_cntx_t *ctx, rtrd_rsvr_t *rsvr, rtrd_sck_t *sck, void *data) { int rqid, len; void *addr; rtmq_header_t *head = (rtmq_header_t *)data; ++rsvr->recv_total; /* 总数 */ len = sizeof(rtmq_header_t) + head->length; /* > 合法性验证 */ if (head->nodeid != sck->nodeid) { ++rsvr->drop_total; log_error(rsvr->log, "Devid isn't right! nodeid:%d/%d", head->nodeid, sck->nodeid); return RTMQ_ERR; } /* > 从队列申请空间 */ rqid = rand() % ctx->conf.recvq_num; addr = queue_malloc(ctx->recvq[rqid], len); if (NULL == addr) { ++rsvr->drop_total; /* 丢弃计数 */ rtrd_rsvr_cmd_proc_all_req(ctx, rsvr); log_error(rsvr->log, "Alloc from queue failed! recv:%llu drop:%llu error:%llu len:%d/%d", rsvr->recv_total, rsvr->drop_total, rsvr->err_total, len, queue_size(ctx->recvq[rqid])); return RTMQ_ERR; } /* > 进行数据拷贝 */ memcpy(addr, data, len); queue_push(ctx->recvq[rqid], addr); /* 放入处理队列 */ rtrd_rsvr_cmd_proc_req(ctx, rsvr, rqid); /* 发送处理请求 */ return RTMQ_OK; }
void add_interupt_event(int type, unsigned int delay) { #ifdef NEW_COUNT unsigned int count = ((Count + delay) & 0x0FFFFFFF); #else unsigned int count = Count + delay/**2*/; #endif #ifdef USE_SPECIAL int special = 0; #endif interupt_queue *aux = q; #ifdef USE_SPECIAL if(type == SPECIAL_INT /*|| type == COMPARE_INT*/) special = 1; if(Count > 0x80000000) SPECIAL_done = 0; #endif DEBUG_PRINT("add_interupt_event() type %d, at %u, Count %u\n",type,count, Count); if (get_event(type)) { DebugMessage(M64MSG_WARNING, "two events of type 0x%x in interrupt queue", type); } if (q == NULL) { q = (interupt_queue *) queue_malloc(sizeof(interupt_queue)); q->next = NULL; q->count = count; q->type = type; next_interupt = q->count; //print_queue(); return; } #ifdef USE_SPECIAL if(before_event(count, q->count, q->type) && !special) #else if(before_event(count, q->count, q->type)) #endif { q = (interupt_queue *) queue_malloc(sizeof(interupt_queue)); q->next = aux; q->count = count; q->type = type; next_interupt = q->count; //print_queue(); return; } //if not at end of list and (count is after next item of type or special) then get next #ifdef USE_SPECIAL while (aux->next != NULL && (!before_event(count, aux->next->count, aux->next->type) || special)) #else while (aux->next != NULL && (!before_event(count, aux->next->count, aux->next->type))) #endif { aux = aux->next; } if (aux->next == NULL) { aux->next = (interupt_queue *) queue_malloc(sizeof(interupt_queue)); aux = aux->next; aux->next = NULL; aux->count = count; aux->type = type; } else { interupt_queue *aux2; #ifdef USE_SPECIAL if (type != SPECIAL_INT) #endif while(aux->next != NULL && aux->next->count == count) aux = aux->next; aux2 = aux->next; aux->next = (interupt_queue *) queue_malloc(sizeof(interupt_queue)); aux = aux->next; aux->next = aux2; aux->count = count; aux->type = type; } }
void add_interupt_event(int type, unsigned long delay) { unsigned long count = Count + delay; int special = 0; if(type == SPECIAL_INT) { special = 1; } if(Count > 0x80000000) { SPECIAL_done = 0; } if (get_event(type)) { //printf("two events of type %x in queue\n", type); } interupt_queue *aux = q; if (q == NULL) { q = queue_malloc(sizeof(interupt_queue)); q->next = NULL; q->count = count; q->type = type; next_interupt = q->count; return; } if(before_event(count, q->count, q->type) && !special) { q = queue_malloc(sizeof(interupt_queue)); q->next = aux; q->count = count; q->type = type; next_interupt = q->count; return; } while (aux->next != NULL && (!before_event(count, aux->next->count, aux->next->type) || special)) { aux = aux->next; } if (aux->next == NULL) { aux->next = queue_malloc(sizeof(interupt_queue)); aux = aux->next; aux->next = NULL; aux->count = count; aux->type = type; } else { interupt_queue *aux2; if (type != SPECIAL_INT) { while(aux->next != NULL && aux->next->count == count) { aux = aux->next; } } aux2 = aux->next; aux->next = queue_malloc(sizeof(interupt_queue)); aux = aux->next; aux->next = aux2; aux->count = count; aux->type = type; } }