Пример #1
0
void
reg_verify(void *buf, size_t count, void *reg_handle)
{
    struct reg_entry *rptr = 0;
    char *bufend = (char *) buf + count;
    int i = 0;
    int verified = 0;

    PRINT_TIME(NOFD, &tnow, &tprev, "reg_verify: buf = %p count = %d "
               "reg_handle = %p", buf, count, reg_handle);

    for (i = 0; i < MAX_REGIONS; i++) {
        rptr = &(reg_table[i]);
        PRINT_TIME(NOFD, &tnow, &tprev, "reg_verify: i = %d start = %p "
                   "end = %p handle = %p", i, rptr->start, rptr->end, rptr->handle);
        if (((char *) buf >= rptr->start) &&
                ((char *) bufend <= rptr->end) &&
                ((char *) reg_handle == rptr->handle)) {
            PRINT_TIME(NOFD, &tnow, &tprev, "reg_verify: found match\n");
            verified = 1;
            break;
        }
    }

    if (verified != 1) {
        ldbg("reg_table_verify : unable to verify specified region\n");
        ldbg("reg_table_verify : buf = %p count = %d bufend = %p "
             "reg_handle = %p\n", buf, count, bufend, reg_handle);
        reg_table_print();
        exit(1);
    }
}
Пример #2
0
void
reg_table_add(void *addr, size_t size, void **reg_handle)
{
    static char *cur_handle = (char *) 1;
    struct reg_entry *rptr = 0;
    int i;

    PRINT_TIME(NOFD, &tnow, &tprev, "reg_table_add: addr = %p size = %d "
               "handle addr = %p", addr, size, reg_handle);

    for (i = 0; i < MAX_REGIONS; i++) {
        if (reg_table[i].start == 0) {
            PRINT_TIME(NOFD, &tnow, &tprev, "reg_table_add: using entry = %d "
                       "start = %p ", i, reg_table[i].start);
            break;
        }
    }

    if (i == MAX_REGIONS) {
        printf("reg_table_add: no available regions MAX_REGIONS = %d\n",
               MAX_REGIONS);
        exit(1);
    } else {
        rptr = &(reg_table[i]);
        rptr->start = (char *) addr;
        rptr->end = (char *) addr + size;
        rptr->handle = cur_handle;
        *reg_handle = (void *) cur_handle;
        PRINT_TIME(NOFD, &tnow, &tprev, "reg_table_add: entry = %d start = %p "
                   "end = %p handle = %p", i, rptr->start, rptr->end, rptr->handle);
        cur_handle++;
    }
}
Пример #3
0
/* ---------------------------------------------------------------------- */
void
unblock_sigio(void)
{
  PRINT_TIME(NOFD, &tnow, &tprev, "unblock_sigio: entered sigio_blocked = %d",
    sigio_blocked);

  if (sigio_blocked == 0) {
    PRINT_TIME(NOFD, &tnow, &tprev,
      "unblock_sigio: is already unblocked returning");
    return;
  }

  num_unblock_sigio++;
  DEBG(MSG_INTR, "unblock_sigio: unblocked = %15d blocked = %15d\n",
    num_unblock_sigio, num_block_sigio);

  /* Set this before actually unblocking because we could get */
  /* after we're unblocked we could get interrupted before this gets set. */
  DEBG(MSG_INTR, "unblock_sigio: setting sigio_blocked = 0\n");
  sigio_blocked = 0;
  DEBG(MSG_INTR, "unblock_sigio: done setting sigio_blocked = 0\n");

  DEBG(MSG_INTR, "unblock_sigio: unblocking\n");
  do_unblock();

  PRINT_TIME(NOFD, &tnow, &tprev, "unblock_sigio: returning");
}
Пример #4
0
struct cacheinfo *
cache_add(char *uri)
{
  int fd, bytes;
  int len;
  struct cacheinfo *entry;
  struct stat stat;
  char *cur;
  char header_buf[MAX_HEADER_LEN];
  int header_len;
  int rc;
  char *rc_ptr;
  int trace_fd = 0;

  PRINT_TIME(NOFD, &tnow, &tprev, "cache_add: entered ");

  num_cache_add_calls++;

  if ((entry = cache_lookup(uri)) != 0) {
    num_cache_hits++;
    PRINT_TIME(NOFD, &tnow, &tprev, "cache_add: entry found - returning");
    return (entry);
  } else {
    PRINT_TIME(NOFD, &tnow, &tprev, "cache_add: entry not found ");
  }

  if (cur_entry < CACHE_MAX) {
    TRACE(EVT_OPEN_FILE, trace_fd = 0; rc = open(uri, O_RDONLY););
Пример #5
0
void introduction()
{
    prologue();
    PRINT_TIME("This test target DESFireEV1 cards.");

    PRINT_TIME("You will have 20 seconds to insert a card. Test log below");
    PRINT_TIME("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");

    LLA_SUBTEST_REGISTER("Authenticate");
    LLA_SUBTEST_REGISTER("ChangeKey");
    LLA_SUBTEST_REGISTER("WriteRead");
    LLA_SUBTEST_REGISTER("ReadFormat");
}
Пример #6
0
int
aio_sock_write(conn_t sd, void *buf, size_t count, void *reg_handle)
{
    char *tmp = (char *) buf;
    write_len = count;
    tmp[count] = '\0';
    PRINT_TIME(sd, &tnow, &tprev, "aio_sock_write: addr = %p count = %d "
               "handle = %p", buf, count, reg_handle);
    PRINT_TIME(sd, &tnow, &tprev, "aio_sock_write: writing [%s]", buf);

    reg_verify(buf, count, reg_handle);

    return 1;
}
Пример #7
0
int
aio_sock_create_compl_q(size_t len, int event_type)
{
    PRINT_TIME(NOFD, &tnow, &tprev, "aio_sock_create_compl_q: "
               "len = %d event_type = %d", len, event_type);
    return 1;
}
Пример #8
0
int
aio_sock_destroy(conn_t sd)
{
    PRINT_TIME(sd, &tnow, &tprev, "aio_sock_destroy: sd = %d", sd);

    return 1;
}
Пример #9
0
int main(int argc, char *argv[]){

  int res = 0;
  shrdPtr= (struct wonk*)malloc(sizeof(struct wonk));
  shrdPtr->a = 1;

  pthread_mutex_init(&lock,NULL);

	START_TIME();
  pthread_t acc[7],upd;
  pthread_create(&acc[0],NULL,accessorThread,(void*)shrdPtr);
  pthread_create(&acc[1],NULL,accessorThread,(void*)shrdPtr);
  pthread_create(&acc[2],NULL,accessorThread,(void*)shrdPtr);
  pthread_create(&acc[3],NULL,accessorThread,(void*)shrdPtr);
  pthread_create(&acc[4],NULL,accessorThread,(void*)shrdPtr);
  pthread_create(&acc[5],NULL,accessorThread,(void*)shrdPtr);
  pthread_create(&acc[6],NULL,accessorThread,(void*)shrdPtr);
  pthread_create(&upd,NULL,updaterThread,(void*)shrdPtr);

  pthread_join(upd,NULL);
  pthread_join(acc[0],(void*)&res);
  pthread_join(acc[1],(void*)&res);
  pthread_join(acc[2],(void*)&res);
  pthread_join(acc[3],(void*)&res);
  pthread_join(acc[4],(void*)&res);
  pthread_join(acc[5],(void*)&res);
  pthread_join(acc[6],(void*)&res);
	STOP_TIME();
  fprintf(stderr,"Final value of res was %d\n",res); 
	PRINT_TIME();
}
Пример #10
0
/* ---------------------------------------------------------------------- */
void
do_block(void)
{
  int flags = 0;
  sigset_t set, old;
  int rc;
  int trace_fd = 0;
  int i;

  switch (options.sigio_cntl) {
    case OPT_SIGIO_USE_PROCMASK:
#ifdef __CYGWIN__
      printf("do_block: option not supported in CYGWIN version\n");
      exit(1);
#else
      PRINT_TIME(NOFD, &tnow, &tprev, "do_block: changing procmask");
      if (in_handler) {
        DEBG(MSG_INTR, "do_block: in_handler = 1\n");
        /* printf("do_block - in handler - sigaddset\n"); */
        assert(uc != 0);
#ifdef MACROBUG
        print_mask("do_block: uc_sigmask was \n",
          (sigset_t *) & uc->uc_sigmask);
        TRACE(EVT_CHANGESET,
          trace_fd = 0;
          rc = sigaddset((sigset_t *) & (uc->uc_sigmask), SIGIO););
        print_mask("do_block: uc_sigmask is now\n",
          (sigset_t *) & uc->uc_sigmask);
#else
        print_mask("do_block: uc_sigmask was \n", &uc->uc_sigmask);
        TRACE(EVT_CHANGESET,
          trace_fd = 0; rc = sigaddset(&(uc->uc_sigmask), SIGIO););
        print_mask("do_block: uc_sigmask is now\n", &uc->uc_sigmask);
#endif /* MACROBUG */
      } else {
Пример #11
0
int
aio_sock_close(conn_t sd)
{
    PRINT_TIME(sd, &tnow, &tprev, "aio_sock_close: sd = %d", sd);

    return 1;
}
Пример #12
0
int
aio_sock_read(conn_t sd, void *buf, size_t count, void *reg_handle)
{
    char *tmp = (char *) buf;
    PRINT_TIME(sd, &tnow, &tprev,
               "aio_sock_read: addr = %p count = %d handle %p", buf, count, reg_handle);
    /* load up the buffer so we can later trigger an event */

    if (request_count < REQUESTS_PER_CONN) {

        ldbg("aio_sock_read: request_num = %d request = [%s]\n",
             request_num, fake_requests[request_num]);

        read_len = strlen(fake_requests[request_num]);
        strncpy((char *) buf, fake_requests[request_num], count);
        tmp[count] = '\0';

        reg_verify(buf, count, reg_handle);

        request_num++;
        if (request_num >= FAKE_REQUESTS) {
            request_num = 0;
        }
    } else {
        ldbg("aio_sock_read: will return zero bytes (EOF)\n");
        reg_verify(buf, count, reg_handle);
        read_len = 0;
    }

    return 1;
}
Пример #13
0
int
aio_sock_bind(conn_t s, struct sockaddr *my_addr, socklen_t addrlen)
{
    PRINT_TIME(NOFD, &tnow, &tprev, "aio_sock_bind: entered");

    return (0);
}
Пример #14
0
int
aio_sock_mem_dereg(void *addr, size_t size, void *reg_handle)
{
    PRINT_TIME(NOFD, &tnow, &tprev, "aio_sock_mem_dereg: addr = %p "
               "size = %d handle = %p", addr, size, reg_handle);
    reg_table_del(addr, size, reg_handle);
    return 1;
}
Пример #15
0
int
aio_sock_listen(conn_t s, int backlog)
{

    PRINT_TIME(NOFD, &tnow, &tprev, "aio_sock_listen: "
               "s = %d backlog = %d", s, backlog);

    return 1;
}
Пример #16
0
int
aio_sock_mem_reg(void *addr, size_t size, void **reg_handle)
{
    PRINT_TIME(NOFD, &tnow, &tprev, "aio_sock_mem_reg: addr = %p size = %d "
               "reg_handle = %p", addr, size, reg_handle);
    reg_table_add(addr, size, reg_handle);
    // reg_verify(addr, size, *reg_handle);
    // reg_table_print();
    return 1;
}
Пример #17
0
/**
  * Sets the STM32 internal time (RTC)
  * @param date Date in Julian calendar format
  */
void setTime(ptime_t date) {
	RTCDateTime timespec;
	timespec.year = date.year - 2000;
	timespec.month = date.month;
	timespec.day = date.day;
	timespec.millisecond = date.hour * 3600000 + date.minute * 60000 + date.second * 1000 + date.millisecond;

	TRACE_INFO("GPS  > Calibrate RTC");
	PRINT_TIME("RTC");
	rtcSetTime(&RTCD1, &timespec);
}
Пример #18
0
/* ---------------------------------------------------------------------- */
void
intr_enable(void)
{
  PRINT_TIME(NOFD, &tnow, &tprev, "intr_enable new_connections_on = %d",
    new_connections_on);
  /*
   * If interrupts are also used to control incoming connections
   * then we want to enable interrupts iff:
   *   num_idle >= 1 (actually >= options.thold)
   */
  if (options.conn_on == OPT_CONN_WITH_SIGIO) {
    if (new_connections_on) {
      PRINT_TIME(NOFD, &tnow, &tprev, "intr_enable: new connections are on");
      DEBG(MSG_INTR, "intr_enable: calling unblock_sigio()\n");
      unblock_sigio();
    } else {
      PRINT_TIME(NOFD, &tnow, &tprev, "intr_enable: should enable is false");
    }
  } else if (options.conn_on == OPT_CONN_WITH_SEND_EVTS) {
#ifdef SEND
    if (new_connections_on) {
      PRINT_TIME(NOFD, &tnow, &tprev, "intr_enable: new connections are on");
      DEBG(MSG_INTR, "intr_enable: calling unblock_send_events()\n");
      unblock_send_events();
    } else {
      PRINT_TIME(NOFD, &tnow, &tprev, "intr_enable: should enable is false");
    }
#endif /* SEND */
  } else {
    PRINT_TIME(NOFD, &tnow, &tprev,
      "intr_enable: enabling (not using SIGIO or SEND)");
  }
}
Пример #19
0
cv::Mat griddata(const std::vector<cv::Point2f> &xy,const std::vector<float> &v,
                 int left,int top,int width,int height,float defaultValue) {
    assert(width>0 && height>0);
    BEGIN_TIME;
    cv::Mat grid = cv::Mat::ones(height,width,CV_32F)*defaultValue;
    std::vector<cv::Vec3i> tris = trianglate(xy);
    for(uint i=0;i<tris.size();++i) {
        const cv::Vec3i &tri = tris[i];
        fill_tri(grid,tri,xy,v,left,top);
    }
    PRINT_TIME("griddata");
    return grid;
}
Пример #20
0
int
sock_is_special(int sd)
{
  int result = 0;

  if (sd > FD_SETSIZE && options.ignore_fd_setsize) {
    result = 0;
  } else {
    result = FD_ISSET(sd, &special_set);
  }

  PRINT_TIME(sd, &tnow, &tprev, "sock_is_special: returning %d", result);
  return (result);
}
Пример #21
0
void
block_sigio(void)
{
  PRINT_TIME(NOFD, &tnow, &tprev, "block_sigio: entered sigio_blocked = %d",
    sigio_blocked);

  if (sigio_blocked == 1) {
    PRINT_TIME(NOFD, &tnow, &tprev,
      "block_sigio: is already blocked returning");
    return;
  }

  DEBG(MSG_INTR, "block_sigio: blocking\n");
  do_block();

  num_block_sigio++;
  DEBG(MSG_INTR, "block_sigio: unblocked = %15d blocked = %15d\n",
    num_unblock_sigio, num_block_sigio);

  DEBG(MSG_INTR, "block_sigio: setting sigio_blocked = 1\n");
  sigio_blocked = 1;
  DEBG(MSG_INTR, "block_sigio: done setting sigio_blocked = 1\n");
  PRINT_TIME(NOFD, &tnow, &tprev, "block_sigio: returning");
}
Пример #22
0
int
aio_sock_writev(conn_t sd, struct aio_vec *vec, size_t count)
{
    char *tmp = 0;
    void *reg_handle = 0;
    void *base = 0;
    unsigned int len = 0;
    unsigned int i;

    for (i = 0; i < count; i++) {
        len = vec[i].len;
        base = vec[i].base;
        reg_handle = vec[i].reg_handle;
        PRINT_TIME(sd, &tnow, &tprev, "aio_sock_writev: entry = %d base = %p "
                   "len = %d handle = %p", i, base, len, reg_handle);
        if (len && base) {
            write_len += len;
            tmp = (char *) base;
            // tmp[len] = '\0';
            PRINT_TIME(sd, &tnow, &tprev, "aio_sock_writev: base = %p len = %d "
                       "handle = %p", base, len, reg_handle);
            PRINT_TIME(sd, &tnow, &tprev, "aio_sock_writev: writing [%s]", base);

            reg_verify(base, len, reg_handle);
        } else {
            printf("aio_sock_writev: invalid value for base or len\n");
            printf("aio_sock_writev: vec[%d].base = %p vec[%d].len = %d\n",
                   i, base, i, len);
            exit(1);
        }
    }

    PRINT_TIME(sd, &tnow, &tprev, "aio_sock_writev: returning 1");

    return 1;
}
Пример #23
0
int
aio_sock_init(int lowest_sd, int highest_sd)
{
    int i;
    PRINT_TIME(NOFD, &tnow, &tprev, "aio_sock_init: entered");
    printf("aio_sock_init: lowest_sd = %d highest_sd = %d\n",
           lowest_sd, highest_sd);
    reg_table_init();

    for (i = 0; i < FAKE_REQUESTS; i++) {
        printf("aio_sock_init: fake request[%d] = [%s]\n", i, fake_requests[i]);
    }

    return 1;
}
Пример #24
0
void
reg_table_del(void *addr, size_t size, void *reg_handle)
{
    struct reg_entry *rptr = 0;
    int entry = reg_table_find(addr, size, reg_handle);

    rptr = &(reg_table[entry]);

    PRINT_TIME(NOFD, &tnow, &tprev, "reg_table_del: start = %p end = %p "
               "handle = %p", rptr->start, rptr->end, rptr->handle);

    rptr->start = 0;
    rptr->end = 0;
    rptr->handle = 0;
}
Пример #25
0
// ManHunt "MatrixFile" "matrixSize" "numThreads"
int main(int argc, char ** argv){
  struct timeval tpStart,tpStop;
  gettimeofday(&tpStart,0);
#ifdef CALC_TIME
  int cpu_id = 0;
  cpu_set_t mask;
  CPU_ZERO(&mask);
  CPU_SET(cpu_id,&mask);
  sched_setaffinity(0,sizeof(mask),&mask);
  double freq = getCPUFreq();
  VAR_TIME;
  GET_START_TIME;
#endif
  switch(argc) {
  case 4:
    numThreads = atoi(argv[3]);
  case 3:
    matrixSize =  atoi(argv[2]);
  case 2:
    matrixFileName = (char*)malloc(strlen(argv[1])+1);
    strcpy(matrixFileName, argv[1]);
    break;
  case 1:
    matrixFileName = (char*)malloc(strlen("Matrix.in")+1);
    strcpy(matrixFileName, "Matrix.in");
    break;
  }
  printf("matrixFileName: \"%s\", matrixSize: %d, numThreads: %d\n\n", matrixFileName, matrixSize, numThreads);
  matrixFile = fopen(matrixFileName, "r");
  if ( !matrixFile ) { printf("opening matrix file failed.\n"); exit(-1); }
  free(matrixFileName);
  pthread_t threads[numThreads];
  if ( pthread_mutex_init(&matrixFileMutex, NULL) != 0 ) { printf("mutex creation failed.\n"); exit(-1); }
  int threadids[numThreads];
  for (int i=0; i < numThreads; i++) {
    threadids[i]=i;
    if( pthread_create(&threads[i], NULL, &threadFunction, &threadids[i]) != 0 ) { printf("thread creation failed.\n"); exit(-1); }
  }
  for (int i=0; i < numThreads; i++) {
    pthread_join(threads[i], NULL);
  }
  fclose(matrixFile);
#ifdef CALC_TIME
  GET_STOP_TIME;
  PRINT_TIME(stdout,freq);
#endif
  exit(0);
}
Пример #26
0
/* ---------------------------------------------------------------------- */
void
intr_disable(void)
{
  PRINT_TIME(NOFD, &tnow, &tprev, "intr_disable new_connections_on = %d",
    new_connections_on);
  /* Not true: could be blocked because there are no resources available */
  /* assert(!sigio_blocked); */
  if (options.conn_on == OPT_CONN_WITH_SIGIO) {
    DEBG(MSG_INTR, "intr_disable: calling block_sigio()\n");
    block_sigio();
  } else if (options.conn_on == OPT_CONN_WITH_SEND_EVTS) {
#ifdef SEND
    DEBG(MSG_INTR, "intr_disable: calling block_send_events()\n");
    block_send_events();
#endif /* SEND */
  }
}
Пример #27
0
void
do_kinfo_init(int zero_fd)
{
  int ret = 0;
  int alt_size;
  int size = (sizeof(struct kinfo_struct));
  assert(zero_fd > 2);

  DEBG(MSG_SEND, "do_kinfo_init: size = %d\n", size);

  DEBG(MSG_SEND, "do_kinfo_init: zero_fd = %d\n", zero_fd);

  /* round size to next highest page size */
  if (size % PAGE_SIZE != 0) {
    alt_size = ((size / PAGE_SIZE) * PAGE_SIZE) + PAGE_SIZE;
  }
  DEBG(MSG_SEND, "rounded up kinfo alt_size = %d\n", alt_size);
  assert(alt_size % PAGE_SIZE == 0);

  kinfo = (struct kinfo_struct *) mmap(0, alt_size,
    PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE, zero_fd, 0);

  if (kinfo == MAP_FAILED) {
    printf("do_kinfo_init: - no memory\n");
    close(zero_fd);
    exit(1);
  }

  printf("do_kinfo_init: kinfo = %p size = %d\n", kinfo, alt_size);

  ret = kinfo_init(kinfo, size, server_sd);
  PRINT_TIME(server_sd, &tnow, &tprev, "do_kinfo_init: kinfo_init "
    "returns %d", ret);
  if (ret < 0) {
    printf("do_kinfo_init: bad kinfo_init %i %s\n", errno, strerror(errno));
    printf("do_kinfo_init: ret = %d\n", ret);
    close(zero_fd);
    exit(-1);
  }
}
Пример #28
0
int
reg_table_find(void *addr, size_t size, void *reg_handle)
{
    struct reg_entry *rptr = 0;
    char *tmp_addr = (char *) addr;
    int i;

    PRINT_TIME(NOFD, &tnow, &tprev, "reg_table_find: addr = %p size = %p "
               "handle = %p", addr, size, reg_handle);
    for (i = 0; i < MAX_REGIONS; i++) {
        rptr = &(reg_table[i]);
        if (rptr->handle == reg_handle) {
            break;
        }
    }

    if (i == MAX_REGIONS) {
        printf("reg_table_find: can't find region = %p\n", reg_handle);
        exit(1);
    }

    if (tmp_addr != rptr->start) {
        printf("reg_table_find: reg_handle matches but start address does not\n");
        printf("reg_table_find: start = %p addr = %p\n", rptr->start, addr);
        exit(1);
    }

    if (tmp_addr + size != rptr->end) {
        printf("reg_table_find: reg_handle matches but end address does not\n");
        printf("reg_table_find: start = %p addr = %p\n", rptr->end,
               tmp_addr + size);
        exit(1);
    }

    return (i);
}
Пример #29
0
/*----------------------------------------------------------------------*/
void
process_sendfile_errors(int sd, int err)
{
    switch (err) {
    case EAGAIN:
        num_socket_sendfile_eagain++;
        PRINT_TIME(sd, &tnow, &tprev, "do_sendfile: EAGAIN would block");
        break;

    case ECONNRESET:
        PRINT_TIME(sd, &tnow, &tprev, "do_sendfile: ECONNRESET ");
        num_socket_sendfile_reset++;
        break;

#if defined(FreeBSD)
    case ENOTCONN:
        PRINT_TIME(sd, &tnow, &tprev, "do_sendfile: ENOTCONN ");
        num_socket_sendfile_enotconn++;
        break;
#endif

    case EPIPE:
        PRINT_TIME(sd, &tnow, &tprev, "do_sendfile: EPIPE ");
        num_socket_sendfile_epipe++;
        break;

    case EBUSY:
        PRINT_TIME(sd, &tnow, &tprev, "do_sendfile: EBUSY ");
        num_socket_sendfile_ebusy++;
        break;

    default:
        num_socket_sendfile_failed_others++;
        PRINT_TIME(sd, &tnow, &tprev, "do_sendfile: other failure ");
        DEBG(MSG_WRITEV, "do_sendfile: sendfile failed err = %d\n", err);
        printf("do_sendfile: sendfile failed errno = %d\n", err);
        break;
    } /* switch */
}
Пример #30
0
void SoftAVC::onQueueFilled(OMX_U32 portIndex) {
    UNUSED(portIndex);

    if (mSignalledError) {
        return;
    }
    if (mOutputPortSettingsChange != NONE) {
        return;
    }

    List<BufferInfo *> &inQueue = getPortQueue(kInputPortIndex);
    List<BufferInfo *> &outQueue = getPortQueue(kOutputPortIndex);

    /* If input EOS is seen and decoder is not in flush mode,
     * set the decoder in flush mode.
     * There can be a case where EOS is sent along with last picture data
     * In that case, only after decoding that input data, decoder has to be
     * put in flush. This case is handled here  */

    if (mReceivedEOS && !mIsInFlush) {
        setFlushMode();
    }

    while (!outQueue.empty()) {
        BufferInfo *inInfo;
        OMX_BUFFERHEADERTYPE *inHeader;

        BufferInfo *outInfo;
        OMX_BUFFERHEADERTYPE *outHeader;
        size_t timeStampIx;

        inInfo = NULL;
        inHeader = NULL;

        if (!mIsInFlush) {
            if (!inQueue.empty()) {
                inInfo = *inQueue.begin();
                inHeader = inInfo->mHeader;
                if (inHeader == NULL) {
                    inQueue.erase(inQueue.begin());
                    inInfo->mOwnedByUs = false;
                    continue;
                }
            } else {
                break;
            }
        }

        outInfo = *outQueue.begin();
        outHeader = outInfo->mHeader;
        outHeader->nFlags = 0;
        outHeader->nTimeStamp = 0;
        outHeader->nOffset = 0;

        if (inHeader != NULL) {
            if (inHeader->nFilledLen == 0) {
                inQueue.erase(inQueue.begin());
                inInfo->mOwnedByUs = false;
                notifyEmptyBufferDone(inHeader);

                if (!(inHeader->nFlags & OMX_BUFFERFLAG_EOS)) {
                    continue;
                }

                mReceivedEOS = true;
                inHeader = NULL;
                setFlushMode();
            } else if (inHeader->nFlags & OMX_BUFFERFLAG_EOS) {
                mReceivedEOS = true;
            }
        }

        // When there is an init required and the decoder is not in flush mode,
        // update output port's definition and reinitialize decoder.
        if (mInitNeeded && !mIsInFlush) {
            bool portWillReset = false;

            status_t err = reInitDecoder(mNewWidth, mNewHeight);
            if (err != OK) {
                notify(OMX_EventError, OMX_ErrorUnsupportedSetting, err, NULL);
                mSignalledError = true;
                return;
            }

            handlePortSettingsChange(&portWillReset, mNewWidth, mNewHeight);
            return;
        }

        /* Get a free slot in timestamp array to hold input timestamp */
        {
            size_t i;
            timeStampIx = 0;
            for (i = 0; i < MAX_TIME_STAMPS; i++) {
                if (!mTimeStampsValid[i]) {
                    timeStampIx = i;
                    break;
                }
            }
            if (inHeader != NULL) {
                mTimeStampsValid[timeStampIx] = true;
                mTimeStamps[timeStampIx] = inHeader->nTimeStamp;
            }
        }

        {
            ivd_video_decode_ip_t s_dec_ip;
            ivd_video_decode_op_t s_dec_op;
            WORD32 timeDelay, timeTaken;
            size_t sizeY, sizeUV;

            setDecodeArgs(&s_dec_ip, &s_dec_op, inHeader, outHeader, timeStampIx);
            // If input dump is enabled, then write to file
            DUMP_TO_FILE(mInFile, s_dec_ip.pv_stream_buffer, s_dec_ip.u4_num_Bytes);

            GETTIME(&mTimeStart, NULL);
            /* Compute time elapsed between end of previous decode()
             * to start of current decode() */
            TIME_DIFF(mTimeEnd, mTimeStart, timeDelay);

            IV_API_CALL_STATUS_T status;
            status = ivdec_api_function(mCodecCtx, (void *)&s_dec_ip, (void *)&s_dec_op);

            bool unsupportedDimensions =
                (IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED == (s_dec_op.u4_error_code & 0xFF));
            bool resChanged = (IVD_RES_CHANGED == (s_dec_op.u4_error_code & 0xFF));
            bool unsupportedLevel = (IH264D_UNSUPPORTED_LEVEL == (s_dec_op.u4_error_code & 0xFF));

            GETTIME(&mTimeEnd, NULL);
            /* Compute time taken for decode() */
            TIME_DIFF(mTimeStart, mTimeEnd, timeTaken);

            PRINT_TIME("timeTaken=%6d delay=%6d numBytes=%6d", timeTaken, timeDelay,
                   s_dec_op.u4_num_bytes_consumed);
            if (s_dec_op.u4_frame_decoded_flag && !mFlushNeeded) {
                mFlushNeeded = true;
            }

            if ((inHeader != NULL) && (1 != s_dec_op.u4_frame_decoded_flag)) {
                /* If the input did not contain picture data, then ignore
                 * the associated timestamp */
                mTimeStampsValid[timeStampIx] = false;
            }


            // This is needed to handle CTS DecoderTest testCodecResetsH264WithoutSurface,
            // which is not sending SPS/PPS after port reconfiguration and flush to the codec.
            if (unsupportedDimensions && !mFlushNeeded) {
                bool portWillReset = false;
                mNewWidth = s_dec_op.u4_pic_wd;
                mNewHeight = s_dec_op.u4_pic_ht;

                status_t err = reInitDecoder(mNewWidth, mNewHeight);
                if (err != OK) {
                    notify(OMX_EventError, OMX_ErrorUnsupportedSetting, err, NULL);
                    mSignalledError = true;
                    return;
                }

                handlePortSettingsChange(&portWillReset, mNewWidth, mNewHeight);

                setDecodeArgs(&s_dec_ip, &s_dec_op, inHeader, outHeader, timeStampIx);

                ivdec_api_function(mCodecCtx, (void *)&s_dec_ip, (void *)&s_dec_op);
                return;
            }

            if (unsupportedLevel && !mFlushNeeded) {

                mNewLevel = 51;

                status_t err = reInitDecoder(mNewWidth, mNewHeight);
                if (err != OK) {
                    notify(OMX_EventError, OMX_ErrorUnsupportedSetting, err, NULL);
                    mSignalledError = true;
                    return;
                }

                setDecodeArgs(&s_dec_ip, &s_dec_op, inHeader, outHeader, timeStampIx);

                ivdec_api_function(mCodecCtx, (void *)&s_dec_ip, (void *)&s_dec_op);
                return;
            }

            // If the decoder is in the changing resolution mode and there is no output present,
            // that means the switching is done and it's ready to reset the decoder and the plugin.
            if (mChangingResolution && !s_dec_op.u4_output_present) {
                mChangingResolution = false;
                resetDecoder();
                resetPlugin();
                continue;
            }

            if (unsupportedDimensions || resChanged) {
                mChangingResolution = true;
                if (mFlushNeeded) {
                    setFlushMode();
                }

                if (unsupportedDimensions) {
                    mNewWidth = s_dec_op.u4_pic_wd;
                    mNewHeight = s_dec_op.u4_pic_ht;
                    mInitNeeded = true;
                }
                continue;
            }

            if (unsupportedLevel) {

                if (mFlushNeeded) {
                    setFlushMode();
                }

                mNewLevel = 51;
                mInitNeeded = true;
                continue;
            }

            if ((0 < s_dec_op.u4_pic_wd) && (0 < s_dec_op.u4_pic_ht)) {
                uint32_t width = s_dec_op.u4_pic_wd;
                uint32_t height = s_dec_op.u4_pic_ht;
                bool portWillReset = false;
                handlePortSettingsChange(&portWillReset, width, height);

                if (portWillReset) {
                    resetDecoder();
                    return;
                }
            }

            if (s_dec_op.u4_output_present) {
                outHeader->nFilledLen = (outputBufferWidth() * outputBufferHeight() * 3) / 2;

                outHeader->nTimeStamp = mTimeStamps[s_dec_op.u4_ts];
                mTimeStampsValid[s_dec_op.u4_ts] = false;

                outInfo->mOwnedByUs = false;
                outQueue.erase(outQueue.begin());
                outInfo = NULL;
                notifyFillBufferDone(outHeader);
                outHeader = NULL;
            } else {
                /* If in flush mode and no output is returned by the codec,
                 * then come out of flush mode */
                mIsInFlush = false;

                /* If EOS was recieved on input port and there is no output
                 * from the codec, then signal EOS on output port */
                if (mReceivedEOS) {
                    outHeader->nFilledLen = 0;
                    outHeader->nFlags |= OMX_BUFFERFLAG_EOS;

                    outInfo->mOwnedByUs = false;
                    outQueue.erase(outQueue.begin());
                    outInfo = NULL;
                    notifyFillBufferDone(outHeader);
                    outHeader = NULL;
                    resetPlugin();
                }
            }
        }

        if (inHeader != NULL) {
            inInfo->mOwnedByUs = false;
            inQueue.erase(inQueue.begin());
            inInfo = NULL;
            notifyEmptyBufferDone(inHeader);
            inHeader = NULL;
        }
    }
}