static int libshine_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,

                                 const AVFrame *frame, int *got_packet_ptr)

{

    SHINEContext *s = avctx->priv_data;

    MPADecodeHeader hdr;

    unsigned char *data;

    long written;

    int ret, len;



    if (frame)

        data = shine_encode_buffer(s->shine, (int16_t **)frame->data, &written);

    else

        data = shine_flush(s->shine, &written);

    if (written < 0)

        return -1;

    if (written > 0) {

        if (s->buffer_index + written > BUFFER_SIZE) {

            av_log(avctx, AV_LOG_ERROR, "internal buffer too small\n");

            return AVERROR_BUG;

        }

        memcpy(s->buffer + s->buffer_index, data, written);

        s->buffer_index += written;

    }

    if (frame) {

        if ((ret = ff_af_queue_add(&s->afq, frame)) < 0)

            return ret;

    }



    if (s->buffer_index < 4 || !s->afq.frame_count)

        return 0;

    if (avpriv_mpegaudio_decode_header(&hdr, AV_RB32(s->buffer))) {

        av_log(avctx, AV_LOG_ERROR, "free format output not supported\n");

        return -1;

    }



    len = hdr.frame_size;

    if (len <= s->buffer_index) {

        if ((ret = ff_alloc_packet2(avctx, avpkt, len)))

            return ret;

        memcpy(avpkt->data, s->buffer, len);

        s->buffer_index -= len;

        memmove(s->buffer, s->buffer + len, s->buffer_index);



        ff_af_queue_remove(&s->afq, avctx->frame_size, &avpkt->pts,

                           &avpkt->duration);



        avpkt->size = len;

        *got_packet_ptr = 1;

    }

    return 0;

}

static int libshine_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,

                                 const AVFrame *frame, int *got_packet_ptr)

{

    SHINEContext *s = avctx->priv_data;

    MPADecodeHeader hdr;

    unsigned char *data;

    long written;

    int ret, len;



    if (frame)

        data = shine_encode_buffer(s->shine, (int16_t **)frame->data, &written);

    else

        data = shine_flush(s->shine, &written);

    if (written < 0)

        return -1;

    if (written > 0) {

        if (s->buffer_index + written > BUFFER_SIZE) {

            av_log(avctx, AV_LOG_ERROR, "internal buffer too small\n");

            return AVERROR_BUG;

        }

        memcpy(s->buffer + s->buffer_index, data, written);

        s->buffer_index += written;

    }

    if (frame) {

        if ((ret = ff_af_queue_add(&s->afq, frame)) < 0)

            return ret;

    }



    if (s->buffer_index < 4 || !s->afq.frame_count)

        return 0;

    if (avpriv_mpegaudio_decode_header(&hdr, AV_RB32(s->buffer))) {

        av_log(avctx, AV_LOG_ERROR, "free format output not supported\n");

        return -1;

    }



    len = hdr.frame_size;

    if (len <= s->buffer_index) {

        if ((ret = ff_alloc_packet2(avctx, avpkt, len)))

            return ret;

        memcpy(avpkt->data, s->buffer, len);

        s->buffer_index -= len;

        memmove(s->buffer, s->buffer + len, s->buffer_index);



        ff_af_queue_remove(&s->afq, avctx->frame_size, &avpkt->pts,

                           &avpkt->duration);



        avpkt->size = len;

        *got_packet_ptr = 1;

    }

    return 0;

}

    long written;
static int FUNC_0(AVCodecContext *VAR_0, AVPacket *VAR_1,

                                 const AVFrame *VAR_2, int *VAR_3)

{

    SHINEContext *s = VAR_0->priv_data;

    MPADecodeHeader hdr;

    unsigned char *VAR_4;

    long VAR_5;

    int VAR_6, VAR_7;



    if (VAR_2)

        VAR_4 = shine_encode_buffer(s->shine, (int16_t **)VAR_2->VAR_4, &VAR_5);

    else

        VAR_4 = shine_flush(s->shine, &VAR_5);

    if (VAR_5 < 0)

        return -1;

    if (VAR_5 > 0) {

        if (s->buffer_index + VAR_5 > BUFFER_SIZE) {

            av_log(VAR_0, AV_LOG_ERROR, "internal buffer too small\n");

            return AVERROR_BUG;

        }

        memcpy(s->buffer + s->buffer_index, VAR_4, VAR_5);

        s->buffer_index += VAR_5;

    }

    if (VAR_2) {

        if ((VAR_6 = ff_af_queue_add(&s->afq, VAR_2)) < 0)

            return VAR_6;

    }



    if (s->buffer_index < 4 || !s->afq.frame_count)

        return 0;

    if (avpriv_mpegaudio_decode_header(&hdr, AV_RB32(s->buffer))) {

        av_log(VAR_0, AV_LOG_ERROR, "free format output not supported\n");

        return -1;

    }



    VAR_7 = hdr.frame_size;

    if (VAR_7 <= s->buffer_index) {

        if ((VAR_6 = ff_alloc_packet2(VAR_0, VAR_1, VAR_7)))

            return VAR_6;

        memcpy(VAR_1->VAR_4, s->buffer, VAR_7);

        s->buffer_index -= VAR_7;

        memmove(s->buffer, s->buffer + VAR_7, s->buffer_index);



        ff_af_queue_remove(&s->afq, VAR_0->frame_size, &VAR_1->pts,

                           &VAR_1->duration);



        VAR_1->size = VAR_7;

        *VAR_3 = 1;

    }

    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, AVPacket *VAR_1,
const AVFrame *VAR_2, int *VAR_3)
{ SHINEContext *s = VAR_0->priv_data; MPADecodeHeader hdr; unsigned char *VAR_4; long VAR_5; int VAR_6, VAR_7; if (VAR_2)
VAR_4 = shine_encode_buffer(s->shine, (int16_t **)VAR_2->VAR_4, &VAR_5); else
VAR_4 = shine_flush(s->shine, &VAR_5); if (VAR_5 < 0)
return -1; if (VAR_5 > 0) { if (s->buffer_index + VAR_5 > BUFFER_SIZE) { av_log(VAR_0, AV_LOG_ERROR, "internal buffer too small\n"); return AVERROR_BUG; } memcpy(s->buffer + s->buffer_index, VAR_4, VAR_5); s->buffer_index += VAR_5; } if (VAR_2) { if ((VAR_6 = ff_af_queue_add(&s->afq, VAR_2)) < 0)
return VAR_6; } if (s->buffer_index < 4 || !s->afq.frame_count)
return 0; if (avpriv_mpegaudio_decode_header(&hdr, AV_RB32(s->buffer))) { av_log(VAR_0, AV_LOG_ERROR, "free format output not supported\n"); return -1; } VAR_7 = hdr.frame_size; if (VAR_7 <= s->buffer_index) { if ((VAR_6 = ff_alloc_packet2(VAR_0, VAR_1, VAR_7)))
return VAR_6; memcpy(VAR_1->VAR_4, s->buffer, VAR_7); s->buffer_index -= VAR_7; memmove(s->buffer, s->buffer + VAR_7, s->buffer_index); ff_af_queue_remove(&s->afq, VAR_0->frame_size, &VAR_1->pts,
&VAR_1->duration); VAR_1->size = VAR_7; *VAR_3 = 1; } return 0; }