static void serial_set(char **arg, int opts) { struct serial_struct serinfo; int cmd; const char *word; int fd; fd = serial_open(*arg++, /*quiet:*/ false); if (fd < 0) exit(201); serial_ctl(fd, CTL_GET, &serinfo); if (opts & OPT_ZERO) serinfo.flags = 0; while (*arg) { int invert; word = *arg++; invert = (*word == '^'); word += invert; cmd = find_cmd(word); if (*arg == NULL && cmd_need_arg(cmd)) bb_error_msg_and_die(bb_msg_requires_arg, word); if (invert && !cmd_is_flag(cmd)) bb_error_msg_and_die("can't invert %s", word); switch (cmd) { case CMD_SPD_NORMAL: case CMD_SPD_HI: case CMD_SPD_VHI: case CMD_SPD_SHI: case CMD_SPD_WARP: case CMD_SPD_CUST: serinfo.flags &= ~ASYNC_SPD_MASK; /* fallthrough */ case CMD_FLAG_SAK: case CMD_FLAG_FOURPORT: case CMD_FLAG_NUP_NOTIFY: case CMD_FLAG_SKIP_TEST: case CMD_FLAG_AUTO_IRQ: case CMD_FLAG_SPLIT_TERMIOS: case CMD_FLAG_SESSION_LOCKOUT: case CMD_FLAG_PGRP_LOCKOUT: case CMD_FLAG_CALLOUT_NOHUP: case CMD_FLAG_LOW_LATENCY: if (invert) serinfo.flags &= ~setbits[cmd]; else serinfo.flags |= setbits[cmd]; break; case CMD_PORT: serinfo.port = get_numeric(*arg++); break; case CMD_IRQ: serinfo.irq = get_numeric(*arg++); break; case CMD_DIVISOR: serinfo.custom_divisor = get_numeric(*arg++); break; case CMD_UART: serinfo.type = get_uart(*arg++); break; case CMD_BASE: serinfo.baud_base = get_numeric(*arg++); break; case CMD_DELAY: serinfo.close_delay = get_numeric(*arg++); break; case CMD_WAIT: serinfo.closing_wait = get_wait(*arg++); break; case CMD_AUTOCONFIG: serial_ctl(fd, CTL_SET | CTL_CONFIG | CTL_GET, &serinfo); break; default: assert(0); } } serial_ctl(fd, CTL_SET | CTL_CLOSE, &serinfo); }
int encode_frame(Encoder *encoder, int type, uint8_t *frame, uint8_t *h264stream) { x264_picture_t pic_out; int num_Nal = -1; int result = 0; uint8_t *p_out = h264stream; uint i = 0; uint8_t *Y = encoder->picture->img.plane[0]; uint8_t *U = encoder->picture->img.plane[1]; uint8_t *V = encoder->picture->img.plane[2]; #ifdef _RealTime int YUV422_length = encoder->param->i_width * encoder->param->i_height * 2; int Y_index = 0, U_index = 0, V_index = 0, H_index = 0; for (i = 0; i < YUV422_length ; i = i + 4) { H_index = i / (encoder->param->i_width * 2); *(Y + Y_index++) = *(frame + i + 0); *(Y + Y_index++) = *(frame + i + 2); if(H_index % 2) { *(U + U_index++) = *(frame + i +1); } else { *(V + V_index++) = *(frame + i +3); } } #else int YUV420_length = encoder->param->i_width * encoder->param->i_height * 1.5; memcpy(Y, frame, YUV420_length); #endif //fwrite(encoder->picture->img.plane[0],1,640*480*1.5,H264_FP); //encoder->picture->i_pts ++; switch (type) { case 0: encoder->picture->i_type = X264_TYPE_P; break; case 1: encoder->picture->i_type = X264_TYPE_IDR; break; case 2: encoder->picture->i_type = X264_TYPE_I; break; default: encoder->picture->i_type = X264_TYPE_AUTO; break; } //encoder->picture->i_qpplus1 = 0; //Encode one frame if (is_IP == 0) { encoder->picture->i_type = X264_TYPE_I; } if (x264_encoder_encode(encoder->handle, &(encoder->nal), &num_Nal, encoder->picture, &pic_out) < 0) { return -1; } //Encoding Finish //Mark the Energy NAL_num = num_Nal; printf("ENCOD:%lu\t", (unsigned long)getCurrentTime()); #ifdef _ARM p = get_uart(); Energy_M = *p; #endif //Copy to for (i = 0; i < num_Nal; i++) { memcpy(p_out, encoder->nal[i].p_payload, encoder->nal[i].i_payload); RTP_send((char *)p_out, encoder->nal[i].i_payload); //Senddata by RTP p_out += encoder->nal[i].i_payload; result += encoder->nal[i].i_payload; } printf("TRANS:%lu\t", (unsigned long)getCurrentTime()); if (result > 0) { //fwrite(h264stream,result,1,H264_FP); //RTP_send((char *)h264stream,result); //Senddata by RTP } Frame_Size = result; //printf(" Size of Output:%d\n", result); return 0; }