static int udp_read(URLContext *h, uint8_t *buf, int size)

{

    UDPContext *s = h->priv_data;

    int ret;

    int avail;



#if HAVE_PTHREADS

    if (s->fifo) {

        pthread_mutex_lock(&s->mutex);

        do {

            avail = av_fifo_size(s->fifo);

            if (avail) { // >=size) {

                uint8_t tmp[4];

                pthread_mutex_unlock(&s->mutex);



                av_fifo_generic_read(s->fifo, tmp, 4, NULL);

                avail= AV_RL32(tmp);

                if(avail > size){

                    av_log(h, AV_LOG_WARNING, "Part of datagram lost due to insufficient buffer size\n");

                    avail= size;

                }



                av_fifo_generic_read(s->fifo, buf, avail, NULL);

                av_fifo_drain(s->fifo, AV_RL32(tmp) - avail);

                return avail;

            } else if(s->circular_buffer_error){

                pthread_mutex_unlock(&s->mutex);

                return s->circular_buffer_error;

            } else if(h->flags & AVIO_FLAG_NONBLOCK) {

                pthread_mutex_unlock(&s->mutex);

                return AVERROR(EAGAIN);

            }

            else {

                pthread_cond_wait(&s->cond, &s->mutex);

            }

        } while( 1);

    }

#endif



    if (!(h->flags & AVIO_FLAG_NONBLOCK)) {

        ret = ff_network_wait_fd(s->udp_fd, 0);

        if (ret < 0)

            return ret;

    }

    ret = recv(s->udp_fd, buf, size, 0);



    return ret < 0 ? ff_neterrno() : ret;

}

static int udp_read(URLContext *h, uint8_t *buf, int size)

{

    UDPContext *s = h->priv_data;

    int ret;

    int avail;



#if HAVE_PTHREADS

    if (s->fifo) {

        pthread_mutex_lock(&s->mutex);

        do {

            avail = av_fifo_size(s->fifo);

            if (avail) { 

                uint8_t tmp[4];

                pthread_mutex_unlock(&s->mutex);



                av_fifo_generic_read(s->fifo, tmp, 4, NULL);

                avail= AV_RL32(tmp);

                if(avail > size){

                    av_log(h, AV_LOG_WARNING, "Part of datagram lost due to insufficient buffer size\n");

                    avail= size;

                }



                av_fifo_generic_read(s->fifo, buf, avail, NULL);

                av_fifo_drain(s->fifo, AV_RL32(tmp) - avail);

                return avail;

            } else if(s->circular_buffer_error){

                pthread_mutex_unlock(&s->mutex);

                return s->circular_buffer_error;

            } else if(h->flags & AVIO_FLAG_NONBLOCK) {

                pthread_mutex_unlock(&s->mutex);

                return AVERROR(EAGAIN);

            }

            else {

                pthread_cond_wait(&s->cond, &s->mutex);

            }

        } while( 1);

    }

#endif



    if (!(h->flags & AVIO_FLAG_NONBLOCK)) {

        ret = ff_network_wait_fd(s->udp_fd, 0);

        if (ret < 0)

            return ret;

    }

    ret = recv(s->udp_fd, buf, size, 0);



    return ret < 0 ? ff_neterrno() : ret;

}

static int FUNC_0(URLContext *VAR_0, uint8_t *VAR_1, int VAR_2)

{

    UDPContext *s = VAR_0->priv_data;

    int VAR_3;

    int VAR_4;



#if HAVE_PTHREADS

    if (s->fifo) {

        pthread_mutex_lock(&s->mutex);

        do {

            VAR_4 = av_fifo_size(s->fifo);

            if (VAR_4) { 

                uint8_t tmp[4];

                pthread_mutex_unlock(&s->mutex);



                av_fifo_generic_read(s->fifo, tmp, 4, NULL);

                VAR_4= AV_RL32(tmp);

                if(VAR_4 > VAR_2){

                    av_log(VAR_0, AV_LOG_WARNING, "Part of datagram lost due to insufficient buffer VAR_2\n");

                    VAR_4= VAR_2;

                }



                av_fifo_generic_read(s->fifo, VAR_1, VAR_4, NULL);

                av_fifo_drain(s->fifo, AV_RL32(tmp) - VAR_4);

                return VAR_4;

            } else if(s->circular_buffer_error){

                pthread_mutex_unlock(&s->mutex);

                return s->circular_buffer_error;

            } else if(VAR_0->flags & AVIO_FLAG_NONBLOCK) {

                pthread_mutex_unlock(&s->mutex);

                return AVERROR(EAGAIN);

            }

            else {

                pthread_cond_wait(&s->cond, &s->mutex);

            }

        } while( 1);

    }

#endif



    if (!(VAR_0->flags & AVIO_FLAG_NONBLOCK)) {

        VAR_3 = ff_network_wait_fd(s->udp_fd, 0);

        if (VAR_3 < 0)

            return VAR_3;

    }

    VAR_3 = recv(s->udp_fd, VAR_1, VAR_2, 0);



    return VAR_3 < 0 ? ff_neterrno() : VAR_3;

}

static int FUNC_0(URLContext *VAR_0, uint8_t *VAR_1, int VAR_2)
{ UDPContext *s = VAR_0->priv_data; int VAR_3; int VAR_4; #if HAVE_PTHREADS
if (s->fifo) { pthread_mutex_lock(&s->mutex); do { VAR_4 = av_fifo_size(s->fifo); if (VAR_4) { uint8_t tmp[4]; pthread_mutex_unlock(&s->mutex); av_fifo_generic_read(s->fifo, tmp, 4, NULL); VAR_4= AV_RL32(tmp); if(VAR_4 > VAR_2){ av_log(VAR_0, AV_LOG_WARNING, "Part of datagram lost due to insufficient buffer VAR_2\n"); VAR_4= VAR_2; } av_fifo_generic_read(s->fifo, VAR_1, VAR_4, NULL); av_fifo_drain(s->fifo, AV_RL32(tmp) - VAR_4); return VAR_4; } else if(s->circular_buffer_error){ pthread_mutex_unlock(&s->mutex); return s->circular_buffer_error; } else if(VAR_0->flags & AVIO_FLAG_NONBLOCK) { pthread_mutex_unlock(&s->mutex); return AVERROR(EAGAIN); } else { pthread_cond_wait(&s->cond, &s->mutex); } } while( 1); } #endif
if (!(VAR_0->flags & AVIO_FLAG_NONBLOCK)) { VAR_3 = ff_network_wait_fd(s->udp_fd, 0); if (VAR_3 < 0)
return VAR_3; } VAR_3 = recv(s->udp_fd, VAR_1, VAR_2, 0); return VAR_3 < 0 ? ff_neterrno() : VAR_3; }