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

{

    SMJPEGContext *sc = s->priv_data;

    uint32_t dtype, ret, size, timestamp;

    int64_t pos;



    if (s->pb->eof_reached)

        return AVERROR_EOF;

    pos   = avio_tell(s->pb);

    dtype = avio_rl32(s->pb);

    switch (dtype) {

    case SMJPEG_SNDD:

        timestamp = avio_rb32(s->pb);

        size = avio_rb32(s->pb);

        ret = av_get_packet(s->pb, pkt, size);

        pkt->stream_index = sc->audio_stream_index;

        pkt->pts = timestamp;

        pkt->pos = pos;

        break;

    case SMJPEG_VIDD:

        timestamp = avio_rb32(s->pb);

        size = avio_rb32(s->pb);

        ret = av_get_packet(s->pb, pkt, size);

        pkt->stream_index = sc->video_stream_index;

        pkt->pts = timestamp;

        pkt->pos = pos;

        break;

    case SMJPEG_DONE:

        ret = AVERROR_EOF;

        break;

    default:

        av_log(s, AV_LOG_ERROR, "unknown chunk %x\n", dtype);

        ret = AVERROR_INVALIDDATA;

        break;

    }

    return ret;

}

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

{

    SMJPEGContext *sc = s->priv_data;

    uint32_t dtype, ret, size, timestamp;

    int64_t pos;



    if (s->pb->eof_reached)

        return AVERROR_EOF;

    pos   = avio_tell(s->pb);

    dtype = avio_rl32(s->pb);

    switch (dtype) {

    case SMJPEG_SNDD:

        timestamp = avio_rb32(s->pb);

        size = avio_rb32(s->pb);

        ret = av_get_packet(s->pb, pkt, size);

        pkt->stream_index = sc->audio_stream_index;

        pkt->pts = timestamp;

        pkt->pos = pos;

        break;

    case SMJPEG_VIDD:

        timestamp = avio_rb32(s->pb);

        size = avio_rb32(s->pb);

        ret = av_get_packet(s->pb, pkt, size);

        pkt->stream_index = sc->video_stream_index;

        pkt->pts = timestamp;

        pkt->pos = pos;

        break;

    case SMJPEG_DONE:

        ret = AVERROR_EOF;

        break;

    default:

        av_log(s, AV_LOG_ERROR, "unknown chunk %x\n", dtype);

        ret = AVERROR_INVALIDDATA;

        break;

    }

    return ret;

}

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

{

    SMJPEGContext *sc = VAR_0->priv_data;

    uint32_t dtype, ret, size, timestamp;

    int64_t pos;



    if (VAR_0->pb->eof_reached)

        return AVERROR_EOF;

    pos   = avio_tell(VAR_0->pb);

    dtype = avio_rl32(VAR_0->pb);

    switch (dtype) {

    case SMJPEG_SNDD:

        timestamp = avio_rb32(VAR_0->pb);

        size = avio_rb32(VAR_0->pb);

        ret = av_get_packet(VAR_0->pb, VAR_1, size);

        VAR_1->stream_index = sc->audio_stream_index;

        VAR_1->pts = timestamp;

        VAR_1->pos = pos;

        break;

    case SMJPEG_VIDD:

        timestamp = avio_rb32(VAR_0->pb);

        size = avio_rb32(VAR_0->pb);

        ret = av_get_packet(VAR_0->pb, VAR_1, size);

        VAR_1->stream_index = sc->video_stream_index;

        VAR_1->pts = timestamp;

        VAR_1->pos = pos;

        break;

    case SMJPEG_DONE:

        ret = AVERROR_EOF;

        break;

    default:

        av_log(VAR_0, AV_LOG_ERROR, "unknown chunk %x\n", dtype);

        ret = AVERROR_INVALIDDATA;

        break;

    }

    return ret;

}

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)
{ SMJPEGContext *sc = VAR_0->priv_data; uint32_t dtype, ret, size, timestamp; int64_t pos; if (VAR_0->pb->eof_reached)
return AVERROR_EOF; pos   = avio_tell(VAR_0->pb); dtype = avio_rl32(VAR_0->pb); switch (dtype) { case SMJPEG_SNDD:
timestamp = avio_rb32(VAR_0->pb); size = avio_rb32(VAR_0->pb); ret = av_get_packet(VAR_0->pb, VAR_1, size); VAR_1->stream_index = sc->audio_stream_index; VAR_1->pts = timestamp; VAR_1->pos = pos; break; case SMJPEG_VIDD:
timestamp = avio_rb32(VAR_0->pb); size = avio_rb32(VAR_0->pb); ret = av_get_packet(VAR_0->pb, VAR_1, size); VAR_1->stream_index = sc->video_stream_index; VAR_1->pts = timestamp; VAR_1->pos = pos; break; case SMJPEG_DONE:
ret = AVERROR_EOF; break; default:
av_log(VAR_0, AV_LOG_ERROR, "unknown chunk %x\n", dtype); ret = AVERROR_INVALIDDATA; break; } return ret; }