static void do_audio_out(AVFormatContext *s, 

                         AVOutputStream *ost, 

                         AVInputStream *ist,

                         unsigned char *buf, int size)

{

    uint8_t *buftmp;

    static uint8_t *audio_buf = NULL;

    static uint8_t *audio_out = NULL;

    const int audio_out_size= 4*MAX_AUDIO_PACKET_SIZE;



    int size_out, frame_bytes, ret;

    AVCodecContext *enc;



    /* SC: dynamic allocation of buffers */

    if (!audio_buf)

        audio_buf = av_malloc(2*MAX_AUDIO_PACKET_SIZE);

    if (!audio_out)

        audio_out = av_malloc(audio_out_size);

    if (!audio_buf || !audio_out)

        return;               /* Should signal an error ! */



    

    enc = &ost->st->codec;



    if (ost->audio_resample) {

        buftmp = audio_buf;

        size_out = audio_resample(ost->resample, 

                                  (short *)buftmp, (short *)buf,

                                  size / (ist->st->codec.channels * 2));

        size_out = size_out * enc->channels * 2;

    } else {

        buftmp = buf;

        size_out = size;

    }



    /* now encode as many frames as possible */

    if (enc->frame_size > 1) {

        /* output resampled raw samples */

        fifo_write(&ost->fifo, buftmp, size_out, 

                   &ost->fifo.wptr);



        frame_bytes = enc->frame_size * 2 * enc->channels;

        

        while (fifo_read(&ost->fifo, audio_buf, frame_bytes, 

                     &ost->fifo.rptr) == 0) {

            AVPacket pkt;

            av_init_packet(&pkt);



            ret = avcodec_encode_audio(enc, audio_out, audio_out_size, 

                                       (short *)audio_buf);

            audio_size += ret;

            pkt.stream_index= ost->index;

            pkt.data= audio_out;

            pkt.size= ret;

            if(enc->coded_frame)

                pkt.pts= enc->coded_frame->pts;

            pkt.flags |= PKT_FLAG_KEY;

            av_write_frame(s, &pkt);

        }

    } else {

        AVPacket pkt;

        av_init_packet(&pkt);

        /* output a pcm frame */

        /* XXX: change encoding codec API to avoid this ? */

        switch(enc->codec->id) {

        case CODEC_ID_PCM_S16LE:

        case CODEC_ID_PCM_S16BE:

        case CODEC_ID_PCM_U16LE:

        case CODEC_ID_PCM_U16BE:

            break;

        default:

            size_out = size_out >> 1;

            break;

        }

        ret = avcodec_encode_audio(enc, audio_out, size_out, 

				   (short *)buftmp);

        audio_size += ret;

        pkt.stream_index= ost->index;

        pkt.data= audio_out;

        pkt.size= ret;

        if(enc->coded_frame)

            pkt.pts= enc->coded_frame->pts;

        pkt.flags |= PKT_FLAG_KEY;

        av_write_frame(s, &pkt);

    }

}

static void do_audio_out(AVFormatContext *s, 

                         AVOutputStream *ost, 

                         AVInputStream *ist,

                         unsigned char *buf, int size)

{

    uint8_t *buftmp;

    static uint8_t *audio_buf = NULL;

    static uint8_t *audio_out = NULL;

    const int audio_out_size= 4*MAX_AUDIO_PACKET_SIZE;



    int size_out, frame_bytes, ret;

    AVCodecContext *enc;



    

    if (!audio_buf)

        audio_buf = av_malloc(2*MAX_AUDIO_PACKET_SIZE);

    if (!audio_out)

        audio_out = av_malloc(audio_out_size);

    if (!audio_buf || !audio_out)

        return;               



    

    enc = &ost->st->codec;



    if (ost->audio_resample) {

        buftmp = audio_buf;

        size_out = audio_resample(ost->resample, 

                                  (short *)buftmp, (short *)buf,

                                  size / (ist->st->codec.channels * 2));

        size_out = size_out * enc->channels * 2;

    } else {

        buftmp = buf;

        size_out = size;

    }



    

    if (enc->frame_size > 1) {

        

        fifo_write(&ost->fifo, buftmp, size_out, 

                   &ost->fifo.wptr);



        frame_bytes = enc->frame_size * 2 * enc->channels;

        

        while (fifo_read(&ost->fifo, audio_buf, frame_bytes, 

                     &ost->fifo.rptr) == 0) {

            AVPacket pkt;

            av_init_packet(&pkt);



            ret = avcodec_encode_audio(enc, audio_out, audio_out_size, 

                                       (short *)audio_buf);

            audio_size += ret;

            pkt.stream_index= ost->index;

            pkt.data= audio_out;

            pkt.size= ret;

            if(enc->coded_frame)

                pkt.pts= enc->coded_frame->pts;

            pkt.flags |= PKT_FLAG_KEY;

            av_write_frame(s, &pkt);

        }

    } else {

        AVPacket pkt;

        av_init_packet(&pkt);

        

        

        switch(enc->codec->id) {

        case CODEC_ID_PCM_S16LE:

        case CODEC_ID_PCM_S16BE:

        case CODEC_ID_PCM_U16LE:

        case CODEC_ID_PCM_U16BE:

            break;

        default:

            size_out = size_out >> 1;

            break;

        }

        ret = avcodec_encode_audio(enc, audio_out, size_out, 

				   (short *)buftmp);

        audio_size += ret;

        pkt.stream_index= ost->index;

        pkt.data= audio_out;

        pkt.size= ret;

        if(enc->coded_frame)

            pkt.pts= enc->coded_frame->pts;

        pkt.flags |= PKT_FLAG_KEY;

        av_write_frame(s, &pkt);

    }

}

static void FUNC_0(AVFormatContext *VAR_0, 

                         AVOutputStream *VAR_1, 

                         AVInputStream *VAR_2,

                         unsigned char *VAR_3, int VAR_4)

{

    uint8_t *buftmp;

    static uint8_t *VAR_5 = NULL;

    static uint8_t *VAR_6 = NULL;

    const int VAR_7= 4*MAX_AUDIO_PACKET_SIZE;



    int VAR_8, VAR_9, VAR_10;

    AVCodecContext *enc;



    

    if (!VAR_5)

        VAR_5 = av_malloc(2*MAX_AUDIO_PACKET_SIZE);

    if (!VAR_6)

        VAR_6 = av_malloc(VAR_7);

    if (!VAR_5 || !VAR_6)

        return;               



    

    enc = &VAR_1->st->codec;



    if (VAR_1->audio_resample) {

        buftmp = VAR_5;

        VAR_8 = audio_resample(VAR_1->resample, 

                                  (short *)buftmp, (short *)VAR_3,

                                  VAR_4 / (VAR_2->st->codec.channels * 2));

        VAR_8 = VAR_8 * enc->channels * 2;

    } else {

        buftmp = VAR_3;

        VAR_8 = VAR_4;

    }



    

    if (enc->frame_size > 1) {

        

        fifo_write(&VAR_1->fifo, buftmp, VAR_8, 

                   &VAR_1->fifo.wptr);



        VAR_9 = enc->frame_size * 2 * enc->channels;

        

        while (fifo_read(&VAR_1->fifo, VAR_5, VAR_9, 

                     &VAR_1->fifo.rptr) == 0) {

            AVPacket pkt;

            av_init_packet(&pkt);



            VAR_10 = avcodec_encode_audio(enc, VAR_6, VAR_7, 

                                       (short *)VAR_5);

            audio_size += VAR_10;

            pkt.stream_index= VAR_1->index;

            pkt.data= VAR_6;

            pkt.VAR_4= VAR_10;

            if(enc->coded_frame)

                pkt.pts= enc->coded_frame->pts;

            pkt.flags |= PKT_FLAG_KEY;

            av_write_frame(VAR_0, &pkt);

        }

    } else {

        AVPacket pkt;

        av_init_packet(&pkt);

        

        

        switch(enc->codec->id) {

        case CODEC_ID_PCM_S16LE:

        case CODEC_ID_PCM_S16BE:

        case CODEC_ID_PCM_U16LE:

        case CODEC_ID_PCM_U16BE:

            break;

        default:

            VAR_8 = VAR_8 >> 1;

            break;

        }

        VAR_10 = avcodec_encode_audio(enc, VAR_6, VAR_8, 

				   (short *)buftmp);

        audio_size += VAR_10;

        pkt.stream_index= VAR_1->index;

        pkt.data= VAR_6;

        pkt.VAR_4= VAR_10;

        if(enc->coded_frame)

            pkt.pts= enc->coded_frame->pts;

        pkt.flags |= PKT_FLAG_KEY;

        av_write_frame(VAR_0, &pkt);

    }

}

static void FUNC_0(AVFormatContext *VAR_0,
AVOutputStream *VAR_1,
AVInputStream *VAR_2,
unsigned char *VAR_3, int VAR_4)
{ uint8_t *buftmp; static uint8_t *VAR_5 = NULL; static uint8_t *VAR_6 = NULL; const int VAR_7= 4*MAX_AUDIO_PACKET_SIZE; int VAR_8, VAR_9, VAR_10; AVCodecContext *enc; if (!VAR_5)
VAR_5 = av_malloc(2*MAX_AUDIO_PACKET_SIZE); if (!VAR_6)
VAR_6 = av_malloc(VAR_7); if (!VAR_5 || !VAR_6)
return; enc = &VAR_1->st->codec; if (VAR_1->audio_resample) { buftmp = VAR_5; VAR_8 = audio_resample(VAR_1->resample,
(short *)buftmp, (short *)VAR_3,
VAR_4 / (VAR_2->st->codec.channels * 2)); VAR_8 = VAR_8 * enc->channels * 2; } else { buftmp = VAR_3; VAR_8 = VAR_4; } if (enc->frame_size > 1) { fifo_write(&VAR_1->fifo, buftmp, VAR_8,
&VAR_1->fifo.wptr); VAR_9 = enc->frame_size * 2 * enc->channels; while (fifo_read(&VAR_1->fifo, VAR_5, VAR_9,
&VAR_1->fifo.rptr) == 0) { AVPacket pkt; av_init_packet(&pkt); VAR_10 = avcodec_encode_audio(enc, VAR_6, VAR_7,
(short *)VAR_5); audio_size += VAR_10; pkt.stream_index= VAR_1->index; pkt.data= VAR_6; pkt.VAR_4= VAR_10; if(enc->coded_frame)
pkt.pts= enc->coded_frame->pts; pkt.flags |= PKT_FLAG_KEY; av_write_frame(VAR_0, &pkt); } } else { AVPacket pkt; av_init_packet(&pkt); switch(enc->codec->id) { case CODEC_ID_PCM_S16LE:
case CODEC_ID_PCM_S16BE:
case CODEC_ID_PCM_U16LE:
case CODEC_ID_PCM_U16BE:
break; default:
VAR_8 = VAR_8 >> 1; break; } VAR_10 = avcodec_encode_audio(enc, VAR_6, VAR_8,
(short *)buftmp); audio_size += VAR_10; pkt.stream_index= VAR_1->index; pkt.data= VAR_6; pkt.VAR_4= VAR_10; if(enc->coded_frame)
pkt.pts= enc->coded_frame->pts; pkt.flags |= PKT_FLAG_KEY; av_write_frame(VAR_0, &pkt); } }