struct timeval tv; fd_set fds;  tv.tv_sec = 0; tv.tv_usec = 30 * 1000;   FD_ZERO(&fds); FD_SET(s->fd, &fds);   (void) select(s->fd + 1, &fds, 0, 0, &tv);
static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt){    AudioData *s = s1->priv_data;    int ret, bdelay;    int64_t cur_time;    struct audio_buf_info abufi;        if (av_new_packet(pkt, s->frame_size) < 0)        return -EIO;    for(;;) {        ret = read(s->fd, pkt->data, pkt->size);        if (ret > 0)            break;        if (ret == -1 && (errno == EAGAIN || errno == EINTR)) {            av_free_packet(pkt);            pkt->size = 0;            return 0;        }        if (!(ret == 0 || (ret == -1 && (errno == EAGAIN || errno == EINTR)))) {            av_free_packet(pkt);            return -EIO;        }    }    pkt->size = ret;    /* compute pts of the start of the packet */    cur_time = av_gettime();    bdelay = ret;    if (ioctl(s->fd, SNDCTL_DSP_GETISPACE, &abufi) == 0) {        bdelay += abufi.bytes;    }    /* substract time represented by the number of bytes in the audio fifo */    cur_time -= (bdelay * 1000000LL) / (s->sample_rate * s->channels);    /* convert to wanted units */    pkt->pts = cur_time & ((1LL << 48) - 1);    if (s->flip_left && s->channels == 2) {        int i;        short *p = (short *) pkt->data;        for (i = 0; i < ret; i += 4) {            *p = ~*p;            p += 2;        }    }    return 0;}