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

                                 const AVFrame *frame, int *got_packet_ptr)

{

    int i, stereo, data_size, ret;

    const int16_t *in = frame ? (const int16_t *)frame->data[0] : NULL;

    uint8_t *out;

    ROQDPCMContext *context = avctx->priv_data;



    stereo = (avctx->channels == 2);



    if (!in && context->input_frames >= 8)

        return 0;



    if (in && context->input_frames < 8) {

        memcpy(&context->frame_buffer[context->buffered_samples * avctx->channels],

               in, avctx->frame_size * avctx->channels * sizeof(*in));

        context->buffered_samples += avctx->frame_size;

        if (context->input_frames == 0)

            context->first_pts = frame->pts;

        if (context->input_frames < 7) {

            context->input_frames++;

            return 0;




        in = context->frame_buffer;




    if (stereo) {

        context->lastSample[0] &= 0xFF00;

        context->lastSample[1] &= 0xFF00;




    if (context->input_frames == 7 || !in)

        data_size = avctx->channels * context->buffered_samples;

    else

        data_size = avctx->channels * avctx->frame_size;



    if ((ret = ff_alloc_packet2(avctx, avpkt, ROQ_HEADER_SIZE + data_size)))

        return ret;

    out = avpkt->data;



    bytestream_put_byte(&out, stereo ? 0x21 : 0x20);

    bytestream_put_byte(&out, 0x10);

    bytestream_put_le32(&out, data_size);



    if (stereo) {

        bytestream_put_byte(&out, (context->lastSample[1])>>8);

        bytestream_put_byte(&out, (context->lastSample[0])>>8);

    } else

        bytestream_put_le16(&out, context->lastSample[0]);



    /* Write the actual samples */

    for (i = 0; i < data_size; i++)

        *out++ = dpcm_predict(&context->lastSample[i & 1], *in++);



    avpkt->pts      = context->input_frames <= 7 ? context->first_pts : frame->pts;

    avpkt->duration = data_size / avctx->channels;



    context->input_frames++;

    if (!in)

        context->input_frames = FFMAX(context->input_frames, 8);



    *got_packet_ptr = 1;

    return 0;

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

                                 const AVFrame *frame, int *got_packet_ptr)

{

    int i, stereo, data_size, ret;

    const int16_t *in = frame ? (const int16_t *)frame->data[0] : NULL;

    uint8_t *out;

    ROQDPCMContext *context = avctx->priv_data;



    stereo = (avctx->channels == 2);



    if (!in && context->input_frames >= 8)

        return 0;



    if (in && context->input_frames < 8) {

        memcpy(&context->frame_buffer[context->buffered_samples * avctx->channels],

               in, avctx->frame_size * avctx->channels * sizeof(*in));

        context->buffered_samples += avctx->frame_size;

        if (context->input_frames == 0)

            context->first_pts = frame->pts;

        if (context->input_frames < 7) {

            context->input_frames++;

            return 0;




        in = context->frame_buffer;




    if (stereo) {

        context->lastSample[0] &= 0xFF00;

        context->lastSample[1] &= 0xFF00;




    if (context->input_frames == 7 || !in)

        data_size = avctx->channels * context->buffered_samples;

    else

        data_size = avctx->channels * avctx->frame_size;



    if ((ret = ff_alloc_packet2(avctx, avpkt, ROQ_HEADER_SIZE + data_size)))

        return ret;

    out = avpkt->data;



    bytestream_put_byte(&out, stereo ? 0x21 : 0x20);

    bytestream_put_byte(&out, 0x10);

    bytestream_put_le32(&out, data_size);



    if (stereo) {

        bytestream_put_byte(&out, (context->lastSample[1])>>8);

        bytestream_put_byte(&out, (context->lastSample[0])>>8);

    } else

        bytestream_put_le16(&out, context->lastSample[0]);



    

    for (i = 0; i < data_size; i++)

        *out++ = dpcm_predict(&context->lastSample[i & 1], *in++);



    avpkt->pts      = context->input_frames <= 7 ? context->first_pts : frame->pts;

    avpkt->duration = data_size / avctx->channels;



    context->input_frames++;

    if (!in)

        context->input_frames = FFMAX(context->input_frames, 8);



    *got_packet_ptr = 1;

    return 0;

static int FUNC_0(AVCodecContext *VAR_0, AVPacket *VAR_1,

                                 const AVFrame *VAR_2, int *VAR_3)

{

    int VAR_4, VAR_5, VAR_6, VAR_7;

    const int16_t *VAR_8 = VAR_2 ? (const int16_t *)VAR_2->data[0] : NULL;

    uint8_t *out;

    ROQDPCMContext *context = VAR_0->priv_data;



    VAR_5 = (VAR_0->channels == 2);



    if (!VAR_8 && context->input_frames >= 8)

        return 0;



    if (VAR_8 && context->input_frames < 8) {

        memcpy(&context->frame_buffer[context->buffered_samples * VAR_0->channels],

               VAR_8, VAR_0->frame_size * VAR_0->channels * sizeof(*VAR_8));

        context->buffered_samples += VAR_0->frame_size;

        if (context->input_frames == 0)

            context->first_pts = VAR_2->pts;

        if (context->input_frames < 7) {

            context->input_frames++;

            return 0;




        VAR_8 = context->frame_buffer;




    if (VAR_5) {

        context->lastSample[0] &= 0xFF00;

        context->lastSample[1] &= 0xFF00;




    if (context->input_frames == 7 || !VAR_8)

        VAR_6 = VAR_0->channels * context->buffered_samples;

    else

        VAR_6 = VAR_0->channels * VAR_0->frame_size;



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

        return VAR_7;

    out = VAR_1->data;



    bytestream_put_byte(&out, VAR_5 ? 0x21 : 0x20);

    bytestream_put_byte(&out, 0x10);

    bytestream_put_le32(&out, VAR_6);



    if (VAR_5) {

        bytestream_put_byte(&out, (context->lastSample[1])>>8);

        bytestream_put_byte(&out, (context->lastSample[0])>>8);

    } else

        bytestream_put_le16(&out, context->lastSample[0]);



    

    for (VAR_4 = 0; VAR_4 < VAR_6; VAR_4++)

        *out++ = dpcm_predict(&context->lastSample[VAR_4 & 1], *VAR_8++);



    VAR_1->pts      = context->input_frames <= 7 ? context->first_pts : VAR_2->pts;

    VAR_1->duration = VAR_6 / VAR_0->channels;



    context->input_frames++;

    if (!VAR_8)

        context->input_frames = FFMAX(context->input_frames, 8);



    *VAR_3 = 1;

    return 0;

static int FUNC_0(AVCodecContext *VAR_0, AVPacket *VAR_1,
const AVFrame *VAR_2, int *VAR_3)
{ int VAR_4, VAR_5, VAR_6, VAR_7; const int16_t *VAR_8 = VAR_2 ? (const int16_t *)VAR_2->data[0] : NULL; uint8_t *out; ROQDPCMContext *context = VAR_0->priv_data; VAR_5 = (VAR_0->channels == 2); if (!VAR_8 && context->input_frames >= 8)
return 0; if (VAR_8 && context->input_frames < 8) { memcpy(&context->frame_buffer[context->buffered_samples * VAR_0->channels],
VAR_8, VAR_0->frame_size * VAR_0->channels * sizeof(*VAR_8)); context->buffered_samples += VAR_0->frame_size; if (context->input_frames == 0)
context->first_pts = VAR_2->pts; if (context->input_frames < 7) { context->input_frames++; return 0; VAR_8 = context->frame_buffer; if (VAR_5) { context->lastSample[0] &= 0xFF00; context->lastSample[1] &= 0xFF00; if (context->input_frames == 7 || !VAR_8)
VAR_6 = VAR_0->channels * context->buffered_samples; else
VAR_6 = VAR_0->channels * VAR_0->frame_size; if ((VAR_7 = ff_alloc_packet2(VAR_0, VAR_1, ROQ_HEADER_SIZE + VAR_6)))
return VAR_7; out = VAR_1->data; bytestream_put_byte(&out, VAR_5 ? 0x21 : 0x20); bytestream_put_byte(&out, 0x10); bytestream_put_le32(&out, VAR_6); if (VAR_5) { bytestream_put_byte(&out, (context->lastSample[1])>>8); bytestream_put_byte(&out, (context->lastSample[0])>>8); } else bytestream_put_le16(&out, context->lastSample[0]); for (VAR_4 = 0; VAR_4 < VAR_6; VAR_4++) *out++ = dpcm_predict(&context->lastSample[VAR_4 & 1], *VAR_8++); VAR_1->pts      = context->input_frames <= 7 ? context->first_pts : VAR_2->pts; VAR_1->duration = VAR_6 / VAR_0->channels; context->input_frames++; if (!VAR_8)
context->input_frames = FFMAX(context->input_frames, 8); *VAR_3 = 1; return 0;