Пример #1
0
static int
x_vp8_write_frame(int ofd, vpx_image_t *img)
{
  int i;
  int j;
  int w = img->d_w;
  int h = img->d_h;
  int stride = img->stride[VPX_PLANE_Y];

  // write luminance
  for (j = 0; j < h; j++)
    {
      x_write(ofd, &img->planes[VPX_PLANE_Y][j * stride], w);
    }

  //write U plane
  stride = img->stride[VPX_PLANE_U];
  w = w >> 1;
  h = h >> 1;
  for (j = 0; j < h; j++)
    {
      x_write(ofd, &img->planes[VPX_PLANE_U][j * stride], w);
    }

  for (j = 0; j < h; j++)
    {
      x_write(ofd, &img->planes[VPX_PLANE_V][j * stride], w);
    }
  return 0;
}
Пример #2
0
int	my_put_error(char *str)
{
  int	i;

  i = 0;
  while (str[i] != '\0' && str != NULL)
    {
      x_write(write(2, &str[i], 1));
      i++;
    }
  return (0);
}
Пример #3
0
void	my_putchar(char c)
{
  x_write(write(1, &c, 1));
}
Пример #4
0
int main(void) {
  int in[2];
  int out[2];
  pid_t pid;

  printf("type 'quit' for exit\n\n");

  x_pipe(in);
  x_pipe(out);
  
  pid = x_fork();
  
  if(IS_CHILD(pid)) {
    x_dup2(in[READ], STDIN_FD);
    x_dup2(out[WRITE], STDOUT_FD);
    
    x_close(in[READ]);
    x_close(in[WRITE]);
    x_close(out[READ]);
    x_close(out[WRITE]);
    
    execl("/usr/bin/bc", "runbc", NULL);

    perror("execl");
    exit(1);
  } else if(IS_PARENT(pid)) {
    char buf[BUFSIZE + 1];
    fd_set rfds;
    int count;
    int flag = 1;

    x_close(in[READ]);
    x_close(out[WRITE]);
    
    while(13) {
      FD_ZERO(&rfds);
      FD_SET(STDIN_FD, &rfds);
      FD_SET(out[READ], &rfds);
      
      count = 0;

      x_select(out[READ] + 1, &rfds, NULL, NULL, NULL);

      if(FD_ISSET(out[READ], &rfds)) {
        // read messages from BC
        count = x_read(out[READ], buf, BUFSIZE);
        if(count) {
          x_write(STDOUT_FD, buf, count);
        } else {
          break;
        }
      }

      if(FD_ISSET(STDIN_FD, &rfds) && flag) {
        // send commands to BC
        count = x_read(STDIN_FD, buf, BUFSIZE);
        if(count) {
          x_write(in[WRITE], buf, count);
        } else {
          x_write(in[WRITE], "quit\n", 6);
          flag = 0;
        }
      }
    }

    x_waitpid(pid, NULL, 0);

    x_close(in[WRITE]);
    x_close(out[READ]);
  }

  return 0;
}
Пример #5
0
void
x_vpx_enc_run(unsigned char *pixels, int w, int h, int sock,
    struct sockaddr_in *cli)
{
  size_t len = 0;
  int p1x = 0;
  int p1y = 0;
  void *dat;
  vpx_codec_ctx_t _encoder;
  vpx_codec_ctx_t _decoder;
  vpx_image_t raw_yuv;
  const vpx_codec_cx_pkt_t *pkt;
  int frame_cnt = 0;
  int flags = 0;
  vpx_codec_iter_t iter;
  int outfd;
  int infd;
  int mem_fdmap;

  memset(&_encoder, 0, sizeof(_encoder));
  x_vpx_encoder_init(&_encoder, 1, w, h);

  memset(&_decoder, 0, sizeof(_decoder));
  x_vpx_decoder_init(&_decoder, 1);

  vpx_img_alloc(&raw_yuv, VPX_IMG_FMT_YV12, w, h, 0);
  memset(raw_yuv.planes[VPX_PLANE_Y], 0, raw_yuv.stride[VPX_PLANE_Y]
      * raw_yuv.d_h / 2);

  //  outfd = _P(open)("x_vp8_out.yuv",_P(O_CREAT) | _P(O_RDWR));
  infd = _P(open)("x_camera_in.yuv", _P(O_RDONLY));

  for (;;)
    {
#if 0
      raw_yuv.planes[VPX_PLANE_Y][p1y * w + p1x] = 0x0;
      p1x++;
      if (p1x > w)
        {
          p1x = 0;
          p1y++;
          if (p1y > h)
          p1y = 0;
        }
      raw_yuv.planes[VPX_PLANE_Y][p1y * w + p1x] = 0xff;
#endif
      //		int rbytes;
      //		int bufsiz = ycbcr[0].width*ycbcr[0].height
      //			+ ycbcr[1].width*ycbcr[1].height + ycbcr[2].width*ycbcr[2].height;

      /* read luminance */
      x_read(infd, raw_yuv.planes[VPX_PLANE_Y], raw_yuv.w * raw_yuv.h);
      /* read chroma U */
      x_read(infd, raw_yuv.planes[VPX_PLANE_U], (raw_yuv.w * raw_yuv.h) >> 2);
      /* read chroma V */
      x_read(infd, raw_yuv.planes[VPX_PLANE_V], (raw_yuv.w * raw_yuv.h) >> 2);

      //	x_vp8_write_frame(outfd,&raw_yuv);

      if (vpx_codec_encode(&_encoder, &raw_yuv, frame_cnt, 1, flags,
          VPX_DL_REALTIME ))
        {
          die_codec(&_encoder, "vpx_codec_enc_init()");
        }
      iter = NULL;
      while ((pkt = vpx_codec_get_cx_data(&_encoder, &iter)))
        {
          switch (pkt->kind)
            {
          case VPX_CODEC_CX_FRAME_PKT:
            // __decode_vp8_pkt(&_decoder, pkt->data.frame.buf, pkt->data.frame.sz, outfd);
            x_vp8_rtp_send((int) sock, (void *) pkt->data.frame.buf,
                (int) pkt->data.frame.sz, (struct sockaddr *) cli,
                (int) sizeof(*cli), seqno * 90);

            break;
          default:
            break;
            }
          x_write(1, (pkt->kind == VPX_CODEC_CX_FRAME_PKT)
              && (pkt->data.frame.flags & VPX_FRAME_IS_KEY) ? "K" : (pkt->kind
              == VPX_CODEC_CX_FRAME_PKT) && (pkt->data.frame.flags
              & VPX_FRAME_IS_INVISIBLE) ? "I" : (pkt->kind
              == VPX_CODEC_CX_FRAME_PKT) && (pkt->data.frame.flags
              & VPX_FRAME_IS_DROPPABLE) ? "D" : (pkt->kind
              == VPX_CODEC_CX_FRAME_PKT) && (pkt->data.frame.flags & 0x3) ? "B"
              : ".", 1);
#ifndef WIN32
          fsync(1);
#endif
        }
      frame_cnt++;
#ifdef WIN32
      Sleep(20);
#else
      usleep(56000);
#endif
    }
}