static int sap_fetch_packet(AVFormatContext *s, AVPacket *pkt)

{

    struct SAPState *sap = s->priv_data;

    int fd = url_get_file_handle(sap->ann_fd);

    int n, ret;

    fd_set rfds;

    struct timeval tv;

    uint8_t recvbuf[1500];



    if (sap->eof)

        return AVERROR_EOF;



    while (1) {

        FD_ZERO(&rfds);

        FD_SET(fd, &rfds);

        tv.tv_sec = tv.tv_usec = 0;

        n = select(fd + 1, &rfds, NULL, NULL, &tv);

        if (n <= 0 || !FD_ISSET(fd, &rfds))

            break;

        ret = url_read(sap->ann_fd, recvbuf, sizeof(recvbuf));

        if (ret >= 8) {

            uint16_t hash = AV_RB16(&recvbuf[2]);

            /* Should ideally check the source IP address, too */

            if (recvbuf[0] & 0x04 && hash == sap->hash) {

                /* Stream deletion */

                sap->eof = 1;

                return AVERROR_EOF;

            }

        }

    }

    ret = av_read_frame(sap->sdp_ctx, pkt);

    if (ret < 0)

        return ret;

    if (s->ctx_flags & AVFMTCTX_NOHEADER) {

        while (sap->sdp_ctx->nb_streams > s->nb_streams) {

            int i = s->nb_streams;

            AVStream *st = av_new_stream(s, i);

            if (!st) {

                av_free_packet(pkt);

                return AVERROR(ENOMEM);

            }

            avcodec_copy_context(st->codec, sap->sdp_ctx->streams[i]->codec);

            st->time_base = sap->sdp_ctx->streams[i]->time_base;

        }

    }

    return ret;

}

static int sap_fetch_packet(AVFormatContext *s, AVPacket *pkt)

{

    struct SAPState *sap = s->priv_data;

    int fd = url_get_file_handle(sap->ann_fd);

    int n, ret;

    fd_set rfds;

    struct timeval tv;

    uint8_t recvbuf[1500];



    if (sap->eof)

        return AVERROR_EOF;



    while (1) {

        FD_ZERO(&rfds);

        FD_SET(fd, &rfds);

        tv.tv_sec = tv.tv_usec = 0;

        n = select(fd + 1, &rfds, NULL, NULL, &tv);

        if (n <= 0 || !FD_ISSET(fd, &rfds))

            break;

        ret = url_read(sap->ann_fd, recvbuf, sizeof(recvbuf));

        if (ret >= 8) {

            uint16_t hash = AV_RB16(&recvbuf[2]);

            

            if (recvbuf[0] & 0x04 && hash == sap->hash) {

                

                sap->eof = 1;

                return AVERROR_EOF;

            }

        }

    }

    ret = av_read_frame(sap->sdp_ctx, pkt);

    if (ret < 0)

        return ret;

    if (s->ctx_flags & AVFMTCTX_NOHEADER) {

        while (sap->sdp_ctx->nb_streams > s->nb_streams) {

            int i = s->nb_streams;

            AVStream *st = av_new_stream(s, i);

            if (!st) {

                av_free_packet(pkt);

                return AVERROR(ENOMEM);

            }

            avcodec_copy_context(st->codec, sap->sdp_ctx->streams[i]->codec);

            st->time_base = sap->sdp_ctx->streams[i]->time_base;

        }

    }

    return ret;

}

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)

{

    struct SAPState *VAR_2 = VAR_0->priv_data;

    int VAR_3 = url_get_file_handle(VAR_2->ann_fd);

    int VAR_4, VAR_5;

    fd_set rfds;

    struct timeval VAR_6;

    uint8_t recvbuf[1500];



    if (VAR_2->eof)

        return AVERROR_EOF;



    while (1) {

        FD_ZERO(&rfds);

        FD_SET(VAR_3, &rfds);

        VAR_6.tv_sec = VAR_6.tv_usec = 0;

        VAR_4 = select(VAR_3 + 1, &rfds, NULL, NULL, &VAR_6);

        if (VAR_4 <= 0 || !FD_ISSET(VAR_3, &rfds))

            break;

        VAR_5 = url_read(VAR_2->ann_fd, recvbuf, sizeof(recvbuf));

        if (VAR_5 >= 8) {

            uint16_t hash = AV_RB16(&recvbuf[2]);

            

            if (recvbuf[0] & 0x04 && hash == VAR_2->hash) {

                

                VAR_2->eof = 1;

                return AVERROR_EOF;

            }

        }

    }

    VAR_5 = av_read_frame(VAR_2->sdp_ctx, VAR_1);

    if (VAR_5 < 0)

        return VAR_5;

    if (VAR_0->ctx_flags & AVFMTCTX_NOHEADER) {

        while (VAR_2->sdp_ctx->nb_streams > VAR_0->nb_streams) {

            int VAR_7 = VAR_0->nb_streams;

            AVStream *st = av_new_stream(VAR_0, VAR_7);

            if (!st) {

                av_free_packet(VAR_1);

                return AVERROR(ENOMEM);

            }

            avcodec_copy_context(st->codec, VAR_2->sdp_ctx->streams[VAR_7]->codec);

            st->time_base = VAR_2->sdp_ctx->streams[VAR_7]->time_base;

        }

    }

    return VAR_5;

}

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)
{ struct SAPState *VAR_2 = VAR_0->priv_data; int VAR_3 = url_get_file_handle(VAR_2->ann_fd); int VAR_4, VAR_5; fd_set rfds; struct timeval VAR_6; uint8_t recvbuf[1500]; if (VAR_2->eof)
return AVERROR_EOF; while (1) { FD_ZERO(&rfds); FD_SET(VAR_3, &rfds); VAR_6.tv_sec = VAR_6.tv_usec = 0; VAR_4 = select(VAR_3 + 1, &rfds, NULL, NULL, &VAR_6); if (VAR_4 <= 0 || !FD_ISSET(VAR_3, &rfds))
break; VAR_5 = url_read(VAR_2->ann_fd, recvbuf, sizeof(recvbuf)); if (VAR_5 >= 8) { uint16_t hash = AV_RB16(&recvbuf[2]); if (recvbuf[0] & 0x04 && hash == VAR_2->hash) { VAR_2->eof = 1; return AVERROR_EOF; } } } VAR_5 = av_read_frame(VAR_2->sdp_ctx, VAR_1); if (VAR_5 < 0)
return VAR_5; if (VAR_0->ctx_flags & AVFMTCTX_NOHEADER) { while (VAR_2->sdp_ctx->nb_streams > VAR_0->nb_streams) { int VAR_7 = VAR_0->nb_streams; AVStream *st = av_new_stream(VAR_0, VAR_7); if (!st) { av_free_packet(VAR_1); return AVERROR(ENOMEM); } avcodec_copy_context(st->codec, VAR_2->sdp_ctx->streams[VAR_7]->codec); st->time_base = VAR_2->sdp_ctx->streams[VAR_7]->time_base; } } return VAR_5; }