static void compare_refcounts(BlockDriverState *bs, BdrvCheckResult *res,

                              BdrvCheckMode fix, bool *rebuild,

                              int64_t *highest_cluster,

                              uint16_t *refcount_table, int64_t nb_clusters)

{

    BDRVQcowState *s = bs->opaque;

    int64_t i;

    uint64_t refcount1, refcount2;

    int ret;

    for (i = 0, *highest_cluster = 0; i < nb_clusters; i++) {

        ret = qcow2_get_refcount(bs, i, &refcount1);

        if (ret < 0) {

            fprintf(stderr, "Can't get refcount for cluster %" PRId64 ": %s\n",

                    i, strerror(-ret));

            res->check_errors++;

            continue;

        }

        refcount2 = refcount_table[i];

        if (refcount1 > 0 || refcount2 > 0) {

            *highest_cluster = i;

        }

        if (refcount1 != refcount2) {

            /* Check if we're allowed to fix the mismatch */

            int *num_fixed = NULL;

            if (refcount1 == 0) {

                *rebuild = true;

            } else if (refcount1 > refcount2 && (fix & BDRV_FIX_LEAKS)) {

                num_fixed = &res->leaks_fixed;

            } else if (refcount1 < refcount2 && (fix & BDRV_FIX_ERRORS)) {

                num_fixed = &res->corruptions_fixed;

            }

            fprintf(stderr, "%s cluster %" PRId64 " refcount=%" PRIu64

                    " reference=%" PRIu64 "\n",

                   num_fixed != NULL     ? "Repairing" :

                   refcount1 < refcount2 ? "ERROR" :

                                           "Leaked",

                   i, refcount1, refcount2);

            if (num_fixed) {

                ret = update_refcount(bs, i << s->cluster_bits, 1,

                                      refcount_diff(refcount1, refcount2),

                                      refcount1 > refcount2,

                                      QCOW2_DISCARD_ALWAYS);

                if (ret >= 0) {

                    (*num_fixed)++;

                    continue;

                }

            }

            /* And if we couldn't, print an error */

            if (refcount1 < refcount2) {

                res->corruptions++;

            } else {

                res->leaks++;

            }

        }

    }

}


static void xilinx_spips_realize(DeviceState *dev, Error **errp)

{

    XilinxSPIPS *s = XILINX_SPIPS(dev);

    SysBusDevice *sbd = SYS_BUS_DEVICE(dev);

    XilinxSPIPSClass *xsc = XILINX_SPIPS_GET_CLASS(s);

    int i;

    DB_PRINT_L(0, "realized spips\n");

    s->spi = g_new(SSIBus *, s->num_busses);

    for (i = 0; i < s->num_busses; ++i) {

        char bus_name[16];

        snprintf(bus_name, 16, "spi%d", i);

        s->spi[i] = ssi_create_bus(dev, bus_name);

    }

    s->cs_lines = g_new0(qemu_irq, s->num_cs * s->num_busses);

    ssi_auto_connect_slaves(DEVICE(s), s->cs_lines, s->spi[0]);

    ssi_auto_connect_slaves(DEVICE(s), s->cs_lines, s->spi[1]);

    sysbus_init_irq(sbd, &s->irq);

    for (i = 0; i < s->num_cs * s->num_busses; ++i) {

        sysbus_init_irq(sbd, &s->cs_lines[i]);

    }

    memory_region_init_io(&s->iomem, OBJECT(s), xsc->reg_ops, s,

                          "spi", XLNX_SPIPS_R_MAX * 4);

    sysbus_init_mmio(sbd, &s->iomem);

    s->irqline = -1;

    fifo8_create(&s->rx_fifo, xsc->rx_fifo_size);

    fifo8_create(&s->tx_fifo, xsc->tx_fifo_size);

}


int32_t HELPER(sdiv)(int32_t num, int32_t den)

{

    if (den == 0)

      return 0;

    return num / den;

}


static void bdrv_move_feature_fields(BlockDriverState *bs_dest,

                                     BlockDriverState *bs_src)

{

    /* move some fields that need to stay attached to the device */

    bs_dest->open_flags         = bs_src->open_flags;

    /* dev info */

    bs_dest->dev_ops            = bs_src->dev_ops;

    bs_dest->dev_opaque         = bs_src->dev_opaque;

    bs_dest->dev                = bs_src->dev;

    bs_dest->guest_block_size   = bs_src->guest_block_size;

    bs_dest->copy_on_read       = bs_src->copy_on_read;

    bs_dest->enable_write_cache = bs_src->enable_write_cache;

    /* i/o throttled req */

    memcpy(&bs_dest->throttle_state,

           &bs_src->throttle_state,

           sizeof(ThrottleState));

    bs_dest->throttled_reqs[0]  = bs_src->throttled_reqs[0];

    bs_dest->throttled_reqs[1]  = bs_src->throttled_reqs[1];

    bs_dest->io_limits_enabled  = bs_src->io_limits_enabled;

    /* r/w error */

    bs_dest->on_read_error      = bs_src->on_read_error;

    bs_dest->on_write_error     = bs_src->on_write_error;

    /* i/o status */

    bs_dest->iostatus_enabled   = bs_src->iostatus_enabled;

    bs_dest->iostatus           = bs_src->iostatus;

    /* dirty bitmap */

    bs_dest->dirty_bitmaps      = bs_src->dirty_bitmaps;

    /* reference count */

    bs_dest->refcnt             = bs_src->refcnt;

    /* job */

    bs_dest->in_use             = bs_src->in_use;

    bs_dest->job                = bs_src->job;

    /* keep the same entry in bdrv_states */

    pstrcpy(bs_dest->device_name, sizeof(bs_dest->device_name),

            bs_src->device_name);

    bs_dest->device_list = bs_src->device_list;

    /* keep the same entry in graph_bdrv_states

     * We do want to swap name but don't want to swap linked list entries

     */

    bs_dest->node_list   = bs_src->node_list;

}


int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame,

                              const void *pp, unsigned pp_size,

                              const void *qm, unsigned qm_size,

                              int (*commit_bs_si)(AVCodecContext *,

                                                  DECODER_BUFFER_DESC *bs,

                                                  DECODER_BUFFER_DESC *slice))

{

    AVDXVAContext *ctx = avctx->hwaccel_context;

    unsigned               buffer_count = 0;

#if CONFIG_D3D11VA

    D3D11_VIDEO_DECODER_BUFFER_DESC buffer11[4];

#endif

#if CONFIG_DXVA2

    DXVA2_DecodeBufferDesc          buffer2[4];

#endif

    DECODER_BUFFER_DESC             *buffer,*buffer_slice;

    int result, runs = 0;

    HRESULT hr;

    unsigned type;

    do {

#if CONFIG_D3D11VA

        if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) {

            if (D3D11VA_CONTEXT(ctx)->context_mutex != INVALID_HANDLE_VALUE)

                WaitForSingleObjectEx(D3D11VA_CONTEXT(ctx)->context_mutex, INFINITE, FALSE);

            hr = ID3D11VideoContext_DecoderBeginFrame(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder,

                                                      ff_dxva2_get_surface(frame),

                                                      0, NULL);

        }

#endif

#if CONFIG_DXVA2

        if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD)

            hr = IDirectXVideoDecoder_BeginFrame(DXVA2_CONTEXT(ctx)->decoder,

                                                 ff_dxva2_get_surface(frame),

                                                 NULL);

#endif

        if (hr == E_PENDING)

            av_usleep(2000);

    } while (hr == E_PENDING && ++runs < 50);

    if (FAILED(hr)) {

        av_log(avctx, AV_LOG_ERROR, "Failed to begin frame: 0x%lx\n", hr);

#if CONFIG_D3D11VA

        if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD)

            if (D3D11VA_CONTEXT(ctx)->context_mutex != INVALID_HANDLE_VALUE)

                ReleaseMutex(D3D11VA_CONTEXT(ctx)->context_mutex);

#endif

        return -1;

    }

#if CONFIG_D3D11VA

    if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) {

        buffer = &buffer11[buffer_count];

        type = D3D11_VIDEO_DECODER_BUFFER_PICTURE_PARAMETERS;

    }

#endif

#if CONFIG_DXVA2

    if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) {

        buffer = &buffer2[buffer_count];

        type = DXVA2_PictureParametersBufferType;

    }

#endif

    result = ff_dxva2_commit_buffer(avctx, ctx, buffer,

                                    type,

                                    pp, pp_size, 0);

    if (result) {

        av_log(avctx, AV_LOG_ERROR,

               "Failed to add picture parameter buffer\n");

        goto end;

    }

    buffer_count++;

    if (qm_size > 0) {

#if CONFIG_D3D11VA

        if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) {

            buffer = &buffer11[buffer_count];

            type = D3D11_VIDEO_DECODER_BUFFER_INVERSE_QUANTIZATION_MATRIX;

        }

#endif

#if CONFIG_DXVA2

        if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) {

            buffer = &buffer2[buffer_count];

            type = DXVA2_InverseQuantizationMatrixBufferType;

        }

#endif

        result = ff_dxva2_commit_buffer(avctx, ctx, buffer,

                                        type,

                                        qm, qm_size, 0);

        if (result) {

            av_log(avctx, AV_LOG_ERROR,

                   "Failed to add inverse quantization matrix buffer\n");

            goto end;

        }

        buffer_count++;

    }

#if CONFIG_D3D11VA

    if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) {

        buffer       = &buffer11[buffer_count + 0];

        buffer_slice = &buffer11[buffer_count + 1];

    }

#endif

#if CONFIG_DXVA2

    if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) {

        buffer       = &buffer2[buffer_count + 0];

        buffer_slice = &buffer2[buffer_count + 1];

    }

#endif

    result = commit_bs_si(avctx,

                          buffer,

                          buffer_slice);

    if (result) {

        av_log(avctx, AV_LOG_ERROR,

               "Failed to add bitstream or slice control buffer\n");

        goto end;

    }

    buffer_count += 2;

    /* TODO Film Grain when possible */

    assert(buffer_count == 1 + (qm_size > 0) + 2);

#if CONFIG_D3D11VA

    if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD)

        hr = ID3D11VideoContext_SubmitDecoderBuffers(D3D11VA_CONTEXT(ctx)->video_context,

                                                     D3D11VA_CONTEXT(ctx)->decoder,

                                                     buffer_count, buffer11);

#endif

#if CONFIG_DXVA2

    if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) {

        DXVA2_DecodeExecuteParams exec = {

            .NumCompBuffers     = buffer_count,

            .pCompressedBuffers = buffer2,

            .pExtensionData     = NULL,

        };

        hr = IDirectXVideoDecoder_Execute(DXVA2_CONTEXT(ctx)->decoder, &exec);

    }

#endif

    if (FAILED(hr)) {

        av_log(avctx, AV_LOG_ERROR, "Failed to execute: 0x%lx\n", hr);

        result = -1;

    }

end:

#if CONFIG_D3D11VA

    if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) {

        hr = ID3D11VideoContext_DecoderEndFrame(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder);

        if (D3D11VA_CONTEXT(ctx)->context_mutex != INVALID_HANDLE_VALUE)

            ReleaseMutex(D3D11VA_CONTEXT(ctx)->context_mutex);

    }

#endif

#if CONFIG_DXVA2

    if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD)

        hr = IDirectXVideoDecoder_EndFrame(DXVA2_CONTEXT(ctx)->decoder, NULL);

#endif

    if (FAILED(hr)) {

        av_log(avctx, AV_LOG_ERROR, "Failed to end frame: 0x%lx\n", hr);

        result = -1;

    }

    return result;

}


static int xsub_encode(AVCodecContext *avctx, unsigned char *buf,

                       int bufsize, void *data)

{

    AVSubtitle *h = data;

    uint64_t startTime = h->pts / 1000; // FIXME: need better solution...

    uint64_t endTime = startTime + h->end_display_time - h->start_display_time;

    int start_tc[4], end_tc[4];

    uint8_t *hdr = buf + 27; // Point behind the timestamp

    uint8_t *rlelenptr;

    uint16_t width, height;

    int i;

    PutBitContext pb;

    if (bufsize < 27 + 7*2 + 4*3) {

        av_log(avctx, AV_LOG_ERROR, "Buffer too small for XSUB header.\n");

        return -1;

    }

    // TODO: support multiple rects

    if (h->num_rects > 1)

        av_log(avctx, AV_LOG_WARNING, "Only single rects supported (%d in subtitle.)\n", h->num_rects);

    // TODO: render text-based subtitles into bitmaps

    if (!h->rects[0]->pict.data[0] || !h->rects[0]->pict.data[1]) {

        av_log(avctx, AV_LOG_WARNING, "No subtitle bitmap available.\n");

        return -1;

    }

    // TODO: color reduction, similar to dvdsub encoder

    if (h->rects[0]->nb_colors > 4)

        av_log(avctx, AV_LOG_WARNING, "No more than 4 subtitle colors supported (%d found.)\n", h->rects[0]->nb_colors);

    // TODO: Palette swapping if color zero is not transparent

    if (((uint32_t *)h->rects[0]->pict.data[1])[0] & 0xff)

        av_log(avctx, AV_LOG_WARNING, "Color index 0 is not transparent. Transparency will be messed up.\n");

    if (make_tc(startTime, start_tc) || make_tc(endTime, end_tc)) {

        av_log(avctx, AV_LOG_WARNING, "Time code >= 100 hours.\n");

        return -1;

    }

    snprintf(buf, 28,

        "[%02d:%02d:%02d.%03d-%02d:%02d:%02d.%03d]",

        start_tc[3], start_tc[2], start_tc[1], start_tc[0],

        end_tc[3],   end_tc[2],   end_tc[1],   end_tc[0]);

    // Width and height must probably be multiples of 2.

    // 2 pixels required on either side of subtitle.

    // Possibly due to limitations of hardware renderers.

    // TODO: check if the bitmap is already padded

    width  = FFALIGN(h->rects[0]->w, 2) + PADDING * 2;

    height = FFALIGN(h->rects[0]->h, 2);

    bytestream_put_le16(&hdr, width);

    bytestream_put_le16(&hdr, height);

    bytestream_put_le16(&hdr, h->rects[0]->x);

    bytestream_put_le16(&hdr, h->rects[0]->y);

    bytestream_put_le16(&hdr, h->rects[0]->x + width);

    bytestream_put_le16(&hdr, h->rects[0]->y + height);

    rlelenptr = hdr; // Will store length of first field here later.

    hdr+=2;

    // Palette

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

        bytestream_put_be24(&hdr, ((uint32_t *)h->rects[0]->pict.data[1])[i]);

    // Bitmap

    // RLE buffer. Reserve 2 bytes for possible padding after the last row.

    init_put_bits(&pb, hdr, bufsize - (hdr - buf) - 2);

    if (xsub_encode_rle(&pb, h->rects[0]->pict.data[0],

                        h->rects[0]->pict.linesize[0]*2,

                        h->rects[0]->w, (h->rects[0]->h + 1) >> 1))

        return -1;

    bytestream_put_le16(&rlelenptr, put_bits_count(&pb) >> 3); // Length of first field

    if (xsub_encode_rle(&pb, h->rects[0]->pict.data[0] + h->rects[0]->pict.linesize[0],

                        h->rects[0]->pict.linesize[0]*2,

                        h->rects[0]->w, h->rects[0]->h >> 1))

        return -1;

    // Enforce total height to be be multiple of 2

    if (h->rects[0]->h & 1) {

        put_xsub_rle(&pb, h->rects[0]->w, PADDING_COLOR);

        align_put_bits(&pb);

    }

    flush_put_bits(&pb);

    return hdr - buf + put_bits_count(&pb)/8;

}


void avcodec_register_all(void)

{

    static int initialized;

    if (initialized)

        return;

    initialized = 1;

    /* hardware accelerators */

    REGISTER_HWACCEL(H263_CUVID,        h263_cuvid);

    REGISTER_HWACCEL(H263_VAAPI,        h263_vaapi);

    REGISTER_HWACCEL(H263_VIDEOTOOLBOX, h263_videotoolbox);

    REGISTER_HWACCEL(H264_CUVID,        h264_cuvid);

    REGISTER_HWACCEL(H264_D3D11VA,      h264_d3d11va);

    REGISTER_HWACCEL(H264_DXVA2,        h264_dxva2);

    REGISTER_HWACCEL(H264_MEDIACODEC,   h264_mediacodec);

    REGISTER_HWACCEL(H264_MMAL,         h264_mmal);

    REGISTER_HWACCEL(H264_QSV,          h264_qsv);

    REGISTER_HWACCEL(H264_VAAPI,        h264_vaapi);

    REGISTER_HWACCEL(H264_VDA,          h264_vda);

    REGISTER_HWACCEL(H264_VDA_OLD,      h264_vda_old);

    REGISTER_HWACCEL(H264_VDPAU,        h264_vdpau);

    REGISTER_HWACCEL(H264_VIDEOTOOLBOX, h264_videotoolbox);

    REGISTER_HWACCEL(HEVC_CUVID,        hevc_cuvid);

    REGISTER_HWACCEL(HEVC_D3D11VA,      hevc_d3d11va);

    REGISTER_HWACCEL(HEVC_DXVA2,        hevc_dxva2);

    REGISTER_HWACCEL(HEVC_QSV,          hevc_qsv);

    REGISTER_HWACCEL(HEVC_VAAPI,        hevc_vaapi);

    REGISTER_HWACCEL(HEVC_VDPAU,        hevc_vdpau);

    REGISTER_HWACCEL(MPEG1_XVMC,        mpeg1_xvmc);

    REGISTER_HWACCEL(MPEG1_VDPAU,       mpeg1_vdpau);

    REGISTER_HWACCEL(MPEG1_VIDEOTOOLBOX, mpeg1_videotoolbox);

    REGISTER_HWACCEL(MPEG2_XVMC,        mpeg2_xvmc);

    REGISTER_HWACCEL(MPEG2_D3D11VA,     mpeg2_d3d11va);

    REGISTER_HWACCEL(MPEG2_DXVA2,       mpeg2_dxva2);

    REGISTER_HWACCEL(MPEG2_MMAL,        mpeg2_mmal);

    REGISTER_HWACCEL(MPEG2_QSV,         mpeg2_qsv);

    REGISTER_HWACCEL(MPEG2_VAAPI,       mpeg2_vaapi);

    REGISTER_HWACCEL(MPEG2_VDPAU,       mpeg2_vdpau);

    REGISTER_HWACCEL(MPEG2_VIDEOTOOLBOX, mpeg2_videotoolbox);

    REGISTER_HWACCEL(MPEG4_CUVID,       mpeg4_cuvid);

    REGISTER_HWACCEL(MPEG4_MMAL,        mpeg4_mmal);

    REGISTER_HWACCEL(MPEG4_VAAPI,       mpeg4_vaapi);

    REGISTER_HWACCEL(MPEG4_VDPAU,       mpeg4_vdpau);

    REGISTER_HWACCEL(MPEG4_VIDEOTOOLBOX, mpeg4_videotoolbox);

    REGISTER_HWACCEL(VC1_CUVID,         vc1_cuvid);

    REGISTER_HWACCEL(VC1_D3D11VA,       vc1_d3d11va);

    REGISTER_HWACCEL(VC1_DXVA2,         vc1_dxva2);

    REGISTER_HWACCEL(VC1_VAAPI,         vc1_vaapi);

    REGISTER_HWACCEL(VC1_VDPAU,         vc1_vdpau);

    REGISTER_HWACCEL(VC1_MMAL,          vc1_mmal);

    REGISTER_HWACCEL(VC1_QSV,           vc1_qsv);

    REGISTER_HWACCEL(VP8_CUVID,         vp8_cuvid);

    REGISTER_HWACCEL(VP9_CUVID,         vp9_cuvid);

    REGISTER_HWACCEL(VP9_D3D11VA,       vp9_d3d11va);

    REGISTER_HWACCEL(VP9_DXVA2,         vp9_dxva2);

    REGISTER_HWACCEL(VP9_VAAPI,         vp9_vaapi);

    REGISTER_HWACCEL(WMV3_D3D11VA,      wmv3_d3d11va);

    REGISTER_HWACCEL(WMV3_DXVA2,        wmv3_dxva2);

    REGISTER_HWACCEL(WMV3_VAAPI,        wmv3_vaapi);

    REGISTER_HWACCEL(WMV3_VDPAU,        wmv3_vdpau);

    /* video codecs */

    REGISTER_ENCODER(A64MULTI,          a64multi);

    REGISTER_ENCODER(A64MULTI5,         a64multi5);

    REGISTER_DECODER(AASC,              aasc);

    REGISTER_DECODER(AIC,               aic);

    REGISTER_ENCDEC (ALIAS_PIX,         alias_pix);

    REGISTER_ENCDEC (AMV,               amv);

    REGISTER_DECODER(ANM,               anm);

    REGISTER_DECODER(ANSI,              ansi);

    REGISTER_ENCDEC (APNG,              apng);

    REGISTER_ENCDEC (ASV1,              asv1);

    REGISTER_ENCDEC (ASV2,              asv2);

    REGISTER_DECODER(AURA,              aura);

    REGISTER_DECODER(AURA2,             aura2);

    REGISTER_ENCDEC (AVRP,              avrp);

    REGISTER_DECODER(AVRN,              avrn);

    REGISTER_DECODER(AVS,               avs);

    REGISTER_ENCDEC (AVUI,              avui);

    REGISTER_ENCDEC (AYUV,              ayuv);

    REGISTER_DECODER(BETHSOFTVID,       bethsoftvid);

    REGISTER_DECODER(BFI,               bfi);

    REGISTER_DECODER(BINK,              bink);

    REGISTER_ENCDEC (BMP,               bmp);

    REGISTER_DECODER(BMV_VIDEO,         bmv_video);

    REGISTER_DECODER(BRENDER_PIX,       brender_pix);

    REGISTER_DECODER(C93,               c93);

    REGISTER_DECODER(CAVS,              cavs);

    REGISTER_DECODER(CDGRAPHICS,        cdgraphics);

    REGISTER_DECODER(CDXL,              cdxl);

    REGISTER_DECODER(CFHD,              cfhd);

    REGISTER_ENCDEC (CINEPAK,           cinepak);

    REGISTER_ENCDEC (CLJR,              cljr);

    REGISTER_DECODER(CLLC,              cllc);

    REGISTER_ENCDEC (COMFORTNOISE,      comfortnoise);

    REGISTER_DECODER(CPIA,              cpia);

    REGISTER_DECODER(CSCD,              cscd);

    REGISTER_DECODER(CYUV,              cyuv);

    REGISTER_DECODER(DDS,               dds);

    REGISTER_DECODER(DFA,               dfa);

    REGISTER_DECODER(DIRAC,             dirac);

    REGISTER_ENCDEC (DNXHD,             dnxhd);

    REGISTER_ENCDEC (DPX,               dpx);

    REGISTER_DECODER(DSICINVIDEO,       dsicinvideo);

    REGISTER_DECODER(DVAUDIO,           dvaudio);

    REGISTER_ENCDEC (DVVIDEO,           dvvideo);

    REGISTER_DECODER(DXA,               dxa);

    REGISTER_DECODER(DXTORY,            dxtory);

    REGISTER_DECODER(DXV,               dxv);

    REGISTER_DECODER(EACMV,             eacmv);

    REGISTER_DECODER(EAMAD,             eamad);

    REGISTER_DECODER(EATGQ,             eatgq);

    REGISTER_DECODER(EATGV,             eatgv);

    REGISTER_DECODER(EATQI,             eatqi);

    REGISTER_DECODER(EIGHTBPS,          eightbps);

    REGISTER_DECODER(EIGHTSVX_EXP,      eightsvx_exp);

    REGISTER_DECODER(EIGHTSVX_FIB,      eightsvx_fib);

    REGISTER_DECODER(ESCAPE124,         escape124);

    REGISTER_DECODER(ESCAPE130,         escape130);

    REGISTER_DECODER(EXR,               exr);

    REGISTER_ENCDEC (FFV1,              ffv1);

    REGISTER_ENCDEC (FFVHUFF,           ffvhuff);

    REGISTER_DECODER(FIC,               fic);

    REGISTER_ENCDEC (FLASHSV,           flashsv);

    REGISTER_ENCDEC (FLASHSV2,          flashsv2);

    REGISTER_DECODER(FLIC,              flic);

    REGISTER_ENCDEC (FLV,               flv);

    REGISTER_DECODER(FOURXM,            fourxm);

    REGISTER_DECODER(FRAPS,             fraps);

    REGISTER_DECODER(FRWU,              frwu);

    REGISTER_DECODER(G2M,               g2m);

    REGISTER_ENCDEC (GIF,               gif);

    REGISTER_ENCDEC (H261,              h261);

    REGISTER_ENCDEC (H263,              h263);

    REGISTER_DECODER(H263I,             h263i);

    REGISTER_ENCDEC (H263P,             h263p);

    REGISTER_DECODER(H264,              h264);

    REGISTER_DECODER(H264_CRYSTALHD,    h264_crystalhd);

    REGISTER_DECODER(H264_MEDIACODEC,   h264_mediacodec);

    REGISTER_DECODER(H264_MMAL,         h264_mmal);

    REGISTER_DECODER(H264_QSV,          h264_qsv);

    REGISTER_DECODER(H264_VDA,          h264_vda);

#if FF_API_VDPAU

    REGISTER_DECODER(H264_VDPAU,        h264_vdpau);

#endif

    REGISTER_ENCDEC (HAP,               hap);

    REGISTER_DECODER(HEVC,              hevc);

    REGISTER_DECODER(HEVC_QSV,          hevc_qsv);

    REGISTER_DECODER(HNM4_VIDEO,        hnm4_video);

    REGISTER_DECODER(HQ_HQA,            hq_hqa);

    REGISTER_DECODER(HQX,               hqx);

    REGISTER_ENCDEC (HUFFYUV,           huffyuv);

    REGISTER_DECODER(IDCIN,             idcin);

    REGISTER_DECODER(IFF_ILBM,          iff_ilbm);

    REGISTER_DECODER(INDEO2,            indeo2);

    REGISTER_DECODER(INDEO3,            indeo3);

    REGISTER_DECODER(INDEO4,            indeo4);

    REGISTER_DECODER(INDEO5,            indeo5);

    REGISTER_DECODER(INTERPLAY_VIDEO,   interplay_video);

    REGISTER_ENCDEC (JPEG2000,          jpeg2000);

    REGISTER_ENCDEC (JPEGLS,            jpegls);

    REGISTER_DECODER(JV,                jv);

    REGISTER_DECODER(KGV1,              kgv1);

    REGISTER_DECODER(KMVC,              kmvc);

    REGISTER_DECODER(LAGARITH,          lagarith);

    REGISTER_ENCODER(LJPEG,             ljpeg);

    REGISTER_DECODER(LOCO,              loco);

    REGISTER_DECODER(M101,              m101);

    REGISTER_DECODER(MAGICYUV,          magicyuv);

    REGISTER_DECODER(MDEC,              mdec);

    REGISTER_DECODER(MIMIC,             mimic);

    REGISTER_ENCDEC (MJPEG,             mjpeg);

    REGISTER_DECODER(MJPEGB,            mjpegb);

    REGISTER_DECODER(MMVIDEO,           mmvideo);

    REGISTER_DECODER(MOTIONPIXELS,      motionpixels);

#if FF_API_XVMC

    REGISTER_DECODER(MPEG_XVMC,         mpeg_xvmc);

#endif /* FF_API_XVMC */

    REGISTER_ENCDEC (MPEG1VIDEO,        mpeg1video);

    REGISTER_ENCDEC (MPEG2VIDEO,        mpeg2video);

    REGISTER_ENCDEC (MPEG4,             mpeg4);

    REGISTER_DECODER(MPEG4_CRYSTALHD,   mpeg4_crystalhd);

    REGISTER_DECODER(MPEG4_MMAL,        mpeg4_mmal);

#if FF_API_VDPAU

    REGISTER_DECODER(MPEG4_VDPAU,       mpeg4_vdpau);

#endif

    REGISTER_DECODER(MPEGVIDEO,         mpegvideo);

#if FF_API_VDPAU

    REGISTER_DECODER(MPEG_VDPAU,        mpeg_vdpau);

    REGISTER_DECODER(MPEG1_VDPAU,       mpeg1_vdpau);

#endif

    REGISTER_DECODER(MPEG2_MMAL,        mpeg2_mmal);

    REGISTER_DECODER(MPEG2_CRYSTALHD,   mpeg2_crystalhd);

    REGISTER_DECODER(MPEG2_QSV,         mpeg2_qsv);

    REGISTER_DECODER(MSA1,              msa1);

    REGISTER_DECODER(MSMPEG4_CRYSTALHD, msmpeg4_crystalhd);

    REGISTER_DECODER(MSMPEG4V1,         msmpeg4v1);

    REGISTER_ENCDEC (MSMPEG4V2,         msmpeg4v2);

    REGISTER_ENCDEC (MSMPEG4V3,         msmpeg4v3);

    REGISTER_DECODER(MSRLE,             msrle);

    REGISTER_DECODER(MSS1,              mss1);

    REGISTER_DECODER(MSS2,              mss2);

    REGISTER_ENCDEC (MSVIDEO1,          msvideo1);

    REGISTER_DECODER(MSZH,              mszh);

    REGISTER_DECODER(MTS2,              mts2);

    REGISTER_DECODER(MVC1,              mvc1);

    REGISTER_DECODER(MVC2,              mvc2);

    REGISTER_DECODER(MXPEG,             mxpeg);

    REGISTER_DECODER(NUV,               nuv);

    REGISTER_DECODER(PAF_VIDEO,         paf_video);

    REGISTER_ENCDEC (PAM,               pam);

    REGISTER_ENCDEC (PBM,               pbm);

    REGISTER_ENCDEC (PCX,               pcx);

    REGISTER_ENCDEC (PGM,               pgm);

    REGISTER_ENCDEC (PGMYUV,            pgmyuv);

    REGISTER_DECODER(PICTOR,            pictor);

    REGISTER_ENCDEC (PNG,               png);

    REGISTER_ENCDEC (PPM,               ppm);

    REGISTER_ENCDEC (PRORES,            prores);

    REGISTER_ENCODER(PRORES_AW,         prores_aw);

    REGISTER_ENCODER(PRORES_KS,         prores_ks);

    REGISTER_DECODER(PRORES_LGPL,       prores_lgpl);

    REGISTER_DECODER(PTX,               ptx);

    REGISTER_DECODER(QDRAW,             qdraw);

    REGISTER_DECODER(QPEG,              qpeg);

    REGISTER_ENCDEC (QTRLE,             qtrle);

    REGISTER_ENCDEC (R10K,              r10k);

    REGISTER_ENCDEC (R210,              r210);

    REGISTER_ENCDEC (RAWVIDEO,          rawvideo);

    REGISTER_DECODER(RL2,               rl2);

    REGISTER_ENCDEC (ROQ,               roq);

    REGISTER_DECODER(RPZA,              rpza);

    REGISTER_DECODER(RSCC,              rscc);

    REGISTER_ENCDEC (RV10,              rv10);

    REGISTER_ENCDEC (RV20,              rv20);

    REGISTER_DECODER(RV30,              rv30);

    REGISTER_DECODER(RV40,              rv40);

    REGISTER_ENCDEC (S302M,             s302m);

    REGISTER_DECODER(SANM,              sanm);

    REGISTER_DECODER(SCREENPRESSO,      screenpresso);

    REGISTER_DECODER(SDX2_DPCM,         sdx2_dpcm);

    REGISTER_ENCDEC (SGI,               sgi);

    REGISTER_DECODER(SGIRLE,            sgirle);

    REGISTER_DECODER(SHEERVIDEO,        sheervideo);

    REGISTER_DECODER(SMACKER,           smacker);

    REGISTER_DECODER(SMC,               smc);

    REGISTER_DECODER(SMVJPEG,           smvjpeg);

    REGISTER_ENCDEC (SNOW,              snow);

    REGISTER_DECODER(SP5X,              sp5x);

    REGISTER_ENCDEC (SUNRAST,           sunrast);

    REGISTER_ENCDEC (SVQ1,              svq1);

    REGISTER_DECODER(SVQ3,              svq3);

    REGISTER_ENCDEC (TARGA,             targa);

    REGISTER_DECODER(TARGA_Y216,        targa_y216);

    REGISTER_DECODER(TDSC,              tdsc);

    REGISTER_DECODER(THEORA,            theora);

    REGISTER_DECODER(THP,               thp);

    REGISTER_DECODER(TIERTEXSEQVIDEO,   tiertexseqvideo);

    REGISTER_ENCDEC (TIFF,              tiff);

    REGISTER_DECODER(TMV,               tmv);

    REGISTER_DECODER(TRUEMOTION1,       truemotion1);

    REGISTER_DECODER(TRUEMOTION2,       truemotion2);

    REGISTER_DECODER(TRUEMOTION2RT,     truemotion2rt);

    REGISTER_DECODER(TSCC,              tscc);

    REGISTER_DECODER(TSCC2,             tscc2);

    REGISTER_DECODER(TXD,               txd);

    REGISTER_DECODER(ULTI,              ulti);

    REGISTER_ENCDEC (UTVIDEO,           utvideo);

    REGISTER_ENCDEC (V210,              v210);

    REGISTER_DECODER(V210X,             v210x);

    REGISTER_ENCDEC (V308,              v308);

    REGISTER_ENCDEC (V408,              v408);

    REGISTER_ENCDEC (V410,              v410);

    REGISTER_DECODER(VB,                vb);

    REGISTER_DECODER(VBLE,              vble);

    REGISTER_DECODER(VC1,               vc1);

    REGISTER_DECODER(VC1_CRYSTALHD,     vc1_crystalhd);

#if FF_API_VDPAU

    REGISTER_DECODER(VC1_VDPAU,         vc1_vdpau);

#endif

    REGISTER_DECODER(VC1IMAGE,          vc1image);

    REGISTER_DECODER(VC1_MMAL,          vc1_mmal);

    REGISTER_DECODER(VC1_QSV,           vc1_qsv);

    REGISTER_ENCODER(VC2,               vc2);

    REGISTER_DECODER(VCR1,              vcr1);

    REGISTER_DECODER(VMDVIDEO,          vmdvideo);

    REGISTER_DECODER(VMNC,              vmnc);

    REGISTER_DECODER(VP3,               vp3);

    REGISTER_DECODER(VP5,               vp5);

    REGISTER_DECODER(VP6,               vp6);

    REGISTER_DECODER(VP6A,              vp6a);

    REGISTER_DECODER(VP6F,              vp6f);

    REGISTER_DECODER(VP7,               vp7);

    REGISTER_DECODER(VP8,               vp8);

    REGISTER_DECODER(VP9,               vp9);

    REGISTER_DECODER(VQA,               vqa);

    REGISTER_DECODER(WEBP,              webp);

    REGISTER_ENCODER(WRAPPED_AVFRAME,   wrapped_avframe);

    REGISTER_ENCDEC (WMV1,              wmv1);

    REGISTER_ENCDEC (WMV2,              wmv2);

    REGISTER_DECODER(WMV3,              wmv3);

    REGISTER_DECODER(WMV3_CRYSTALHD,    wmv3_crystalhd);

#if FF_API_VDPAU

    REGISTER_DECODER(WMV3_VDPAU,        wmv3_vdpau);

#endif

    REGISTER_DECODER(WMV3IMAGE,         wmv3image);

    REGISTER_DECODER(WNV1,              wnv1);

    REGISTER_DECODER(XAN_WC3,           xan_wc3);

    REGISTER_DECODER(XAN_WC4,           xan_wc4);

    REGISTER_ENCDEC (XBM,               xbm);

    REGISTER_ENCDEC (XFACE,             xface);

    REGISTER_DECODER(XL,                xl);

    REGISTER_ENCDEC (XWD,               xwd);

    REGISTER_ENCDEC (Y41P,              y41p);

    REGISTER_DECODER(YLC,               ylc);

    REGISTER_DECODER(YOP,               yop);

    REGISTER_ENCDEC (YUV4,              yuv4);

    REGISTER_DECODER(ZERO12V,           zero12v);

    REGISTER_DECODER(ZEROCODEC,         zerocodec);

    REGISTER_ENCDEC (ZLIB,              zlib);

    REGISTER_ENCDEC (ZMBV,              zmbv);

    /* audio codecs */

    REGISTER_ENCDEC (AAC,               aac);

    REGISTER_DECODER(AAC_FIXED,         aac_fixed);

    REGISTER_DECODER(AAC_LATM,          aac_latm);

    REGISTER_ENCDEC (AC3,               ac3);

    REGISTER_ENCDEC (AC3_FIXED,         ac3_fixed);

    REGISTER_ENCDEC (ALAC,              alac);

    REGISTER_DECODER(ALS,               als);

    REGISTER_DECODER(AMRNB,             amrnb);

    REGISTER_DECODER(AMRWB,             amrwb);

    REGISTER_DECODER(APE,               ape);

    REGISTER_DECODER(ATRAC1,            atrac1);

    REGISTER_DECODER(ATRAC3,            atrac3);

    REGISTER_DECODER(ATRAC3P,           atrac3p);

    REGISTER_DECODER(BINKAUDIO_DCT,     binkaudio_dct);

    REGISTER_DECODER(BINKAUDIO_RDFT,    binkaudio_rdft);

    REGISTER_DECODER(BMV_AUDIO,         bmv_audio);

    REGISTER_DECODER(COOK,              cook);

    REGISTER_ENCDEC (DCA,               dca);

    REGISTER_DECODER(DSD_LSBF,          dsd_lsbf);

    REGISTER_DECODER(DSD_MSBF,          dsd_msbf);

    REGISTER_DECODER(DSD_LSBF_PLANAR,   dsd_lsbf_planar);

    REGISTER_DECODER(DSD_MSBF_PLANAR,   dsd_msbf_planar);

    REGISTER_DECODER(DSICINAUDIO,       dsicinaudio);

    REGISTER_DECODER(DSS_SP,            dss_sp);

    REGISTER_DECODER(DST,               dst);

    REGISTER_ENCDEC (EAC3,              eac3);

    REGISTER_DECODER(EVRC,              evrc);

    REGISTER_DECODER(FFWAVESYNTH,       ffwavesynth);

    REGISTER_ENCDEC (FLAC,              flac);

    REGISTER_ENCDEC (G723_1,            g723_1);

    REGISTER_DECODER(G729,              g729);

    REGISTER_DECODER(GSM,               gsm);

    REGISTER_DECODER(GSM_MS,            gsm_ms);

    REGISTER_DECODER(IAC,               iac);

    REGISTER_DECODER(IMC,               imc);

    REGISTER_DECODER(INTERPLAY_ACM,     interplay_acm);

    REGISTER_DECODER(MACE3,             mace3);

    REGISTER_DECODER(MACE6,             mace6);

    REGISTER_DECODER(METASOUND,         metasound);

    REGISTER_DECODER(MLP,               mlp);

    REGISTER_DECODER(MP1,               mp1);

    REGISTER_DECODER(MP1FLOAT,          mp1float);

    REGISTER_ENCDEC (MP2,               mp2);

    REGISTER_DECODER(MP2FLOAT,          mp2float);

    REGISTER_ENCODER(MP2FIXED,          mp2fixed);

    REGISTER_DECODER(MP3,               mp3);

    REGISTER_DECODER(MP3FLOAT,          mp3float);

    REGISTER_DECODER(MP3ADU,            mp3adu);

    REGISTER_DECODER(MP3ADUFLOAT,       mp3adufloat);

    REGISTER_DECODER(MP3ON4,            mp3on4);

    REGISTER_DECODER(MP3ON4FLOAT,       mp3on4float);

    REGISTER_DECODER(MPC7,              mpc7);

    REGISTER_DECODER(MPC8,              mpc8);

    REGISTER_ENCDEC (NELLYMOSER,        nellymoser);

    REGISTER_DECODER(ON2AVC,            on2avc);

    REGISTER_DECODER(OPUS,              opus);

    REGISTER_DECODER(PAF_AUDIO,         paf_audio);

    REGISTER_DECODER(QCELP,             qcelp);

    REGISTER_DECODER(QDM2,              qdm2);

    REGISTER_ENCDEC (RA_144,            ra_144);

    REGISTER_DECODER(RA_288,            ra_288);

    REGISTER_DECODER(RALF,              ralf);

    REGISTER_DECODER(SHORTEN,           shorten);

    REGISTER_DECODER(SIPR,              sipr);

    REGISTER_DECODER(SMACKAUD,          smackaud);

    REGISTER_ENCDEC (SONIC,             sonic);

    REGISTER_ENCODER(SONIC_LS,          sonic_ls);

    REGISTER_DECODER(TAK,               tak);

    REGISTER_DECODER(TRUEHD,            truehd);

    REGISTER_DECODER(TRUESPEECH,        truespeech);

    REGISTER_ENCDEC (TTA,               tta);

    REGISTER_DECODER(TWINVQ,            twinvq);

    REGISTER_DECODER(VMDAUDIO,          vmdaudio);

    REGISTER_ENCDEC (VORBIS,            vorbis);

    REGISTER_ENCDEC (WAVPACK,           wavpack);

    REGISTER_DECODER(WMALOSSLESS,       wmalossless);

    REGISTER_DECODER(WMAPRO,            wmapro);

    REGISTER_ENCDEC (WMAV1,             wmav1);

    REGISTER_ENCDEC (WMAV2,             wmav2);

    REGISTER_DECODER(WMAVOICE,          wmavoice);

    REGISTER_DECODER(WS_SND1,           ws_snd1);

    REGISTER_DECODER(XMA1,              xma1);

    REGISTER_DECODER(XMA2,              xma2);

    /* PCM codecs */

    REGISTER_ENCDEC (PCM_ALAW,          pcm_alaw);

    REGISTER_DECODER(PCM_BLURAY,        pcm_bluray);

    REGISTER_DECODER(PCM_DVD,           pcm_dvd);

    REGISTER_ENCDEC (PCM_F32BE,         pcm_f32be);

    REGISTER_ENCDEC (PCM_F32LE,         pcm_f32le);

    REGISTER_ENCDEC (PCM_F64BE,         pcm_f64be);

    REGISTER_ENCDEC (PCM_F64LE,         pcm_f64le);

    REGISTER_DECODER(PCM_LXF,           pcm_lxf);

    REGISTER_ENCDEC (PCM_MULAW,         pcm_mulaw);

    REGISTER_ENCDEC (PCM_S8,            pcm_s8);

    REGISTER_ENCDEC (PCM_S8_PLANAR,     pcm_s8_planar);

    REGISTER_ENCDEC (PCM_S16BE,         pcm_s16be);

    REGISTER_ENCDEC (PCM_S16BE_PLANAR,  pcm_s16be_planar);

    REGISTER_ENCDEC (PCM_S16LE,         pcm_s16le);

    REGISTER_ENCDEC (PCM_S16LE_PLANAR,  pcm_s16le_planar);

    REGISTER_ENCDEC (PCM_S24BE,         pcm_s24be);

    REGISTER_ENCDEC (PCM_S24DAUD,       pcm_s24daud);

    REGISTER_ENCDEC (PCM_S24LE,         pcm_s24le);

    REGISTER_ENCDEC (PCM_S24LE_PLANAR,  pcm_s24le_planar);

    REGISTER_ENCDEC (PCM_S32BE,         pcm_s32be);

    REGISTER_ENCDEC (PCM_S32LE,         pcm_s32le);

    REGISTER_ENCDEC (PCM_S32LE_PLANAR,  pcm_s32le_planar);

    REGISTER_ENCDEC (PCM_S64BE,         pcm_s64be);

    REGISTER_ENCDEC (PCM_S64LE,         pcm_s64le);

    REGISTER_ENCDEC (PCM_U8,            pcm_u8);

    REGISTER_ENCDEC (PCM_U16BE,         pcm_u16be);

    REGISTER_ENCDEC (PCM_U16LE,         pcm_u16le);

    REGISTER_ENCDEC (PCM_U24BE,         pcm_u24be);

    REGISTER_ENCDEC (PCM_U24LE,         pcm_u24le);

    REGISTER_ENCDEC (PCM_U32BE,         pcm_u32be);

    REGISTER_ENCDEC (PCM_U32LE,         pcm_u32le);

    REGISTER_DECODER(PCM_ZORK,          pcm_zork);

    /* DPCM codecs */

    REGISTER_DECODER(INTERPLAY_DPCM,    interplay_dpcm);

    REGISTER_ENCDEC (ROQ_DPCM,          roq_dpcm);

    REGISTER_DECODER(SOL_DPCM,          sol_dpcm);

    REGISTER_DECODER(XAN_DPCM,          xan_dpcm);

    /* ADPCM codecs */

    REGISTER_DECODER(ADPCM_4XM,         adpcm_4xm);

    REGISTER_ENCDEC (ADPCM_ADX,         adpcm_adx);

    REGISTER_DECODER(ADPCM_AFC,         adpcm_afc);

    REGISTER_DECODER(ADPCM_AICA,        adpcm_aica);

    REGISTER_DECODER(ADPCM_CT,          adpcm_ct);

    REGISTER_DECODER(ADPCM_DTK,         adpcm_dtk);

    REGISTER_DECODER(ADPCM_EA,          adpcm_ea);

    REGISTER_DECODER(ADPCM_EA_MAXIS_XA, adpcm_ea_maxis_xa);

    REGISTER_DECODER(ADPCM_EA_R1,       adpcm_ea_r1);

    REGISTER_DECODER(ADPCM_EA_R2,       adpcm_ea_r2);

    REGISTER_DECODER(ADPCM_EA_R3,       adpcm_ea_r3);

    REGISTER_DECODER(ADPCM_EA_XAS,      adpcm_ea_xas);

    REGISTER_ENCDEC (ADPCM_G722,        adpcm_g722);

    REGISTER_ENCDEC (ADPCM_G726,        adpcm_g726);

    REGISTER_DECODER(ADPCM_G726LE,      adpcm_g726le);

    REGISTER_DECODER(ADPCM_IMA_AMV,     adpcm_ima_amv);

    REGISTER_DECODER(ADPCM_IMA_APC,     adpcm_ima_apc);

    REGISTER_DECODER(ADPCM_IMA_DAT4,    adpcm_ima_dat4);

    REGISTER_DECODER(ADPCM_IMA_DK3,     adpcm_ima_dk3);

    REGISTER_DECODER(ADPCM_IMA_DK4,     adpcm_ima_dk4);

    REGISTER_DECODER(ADPCM_IMA_EA_EACS, adpcm_ima_ea_eacs);

    REGISTER_DECODER(ADPCM_IMA_EA_SEAD, adpcm_ima_ea_sead);

    REGISTER_DECODER(ADPCM_IMA_ISS,     adpcm_ima_iss);

    REGISTER_DECODER(ADPCM_IMA_OKI,     adpcm_ima_oki);

    REGISTER_ENCDEC (ADPCM_IMA_QT,      adpcm_ima_qt);

    REGISTER_DECODER(ADPCM_IMA_RAD,     adpcm_ima_rad);

    REGISTER_DECODER(ADPCM_IMA_SMJPEG,  adpcm_ima_smjpeg);

    REGISTER_ENCDEC (ADPCM_IMA_WAV,     adpcm_ima_wav);

    REGISTER_DECODER(ADPCM_IMA_WS,      adpcm_ima_ws);

    REGISTER_ENCDEC (ADPCM_MS,          adpcm_ms);

    REGISTER_DECODER(ADPCM_MTAF,        adpcm_mtaf);

    REGISTER_DECODER(ADPCM_PSX,         adpcm_psx);

    REGISTER_DECODER(ADPCM_SBPRO_2,     adpcm_sbpro_2);

    REGISTER_DECODER(ADPCM_SBPRO_3,     adpcm_sbpro_3);

    REGISTER_DECODER(ADPCM_SBPRO_4,     adpcm_sbpro_4);

    REGISTER_ENCDEC (ADPCM_SWF,         adpcm_swf);

    REGISTER_DECODER(ADPCM_THP,         adpcm_thp);

    REGISTER_DECODER(ADPCM_THP_LE,      adpcm_thp_le);

    REGISTER_DECODER(ADPCM_VIMA,        adpcm_vima);

    REGISTER_DECODER(ADPCM_XA,          adpcm_xa);

    REGISTER_ENCDEC (ADPCM_YAMAHA,      adpcm_yamaha);

    /* subtitles */

    REGISTER_ENCDEC (SSA,               ssa);

    REGISTER_ENCDEC (ASS,               ass);

    REGISTER_DECODER(CCAPTION,          ccaption);

    REGISTER_ENCDEC (DVBSUB,            dvbsub);

    REGISTER_ENCDEC (DVDSUB,            dvdsub);

    REGISTER_DECODER(JACOSUB,           jacosub);

    REGISTER_DECODER(MICRODVD,          microdvd);

    REGISTER_ENCDEC (MOVTEXT,           movtext);

    REGISTER_DECODER(MPL2,              mpl2);

    REGISTER_DECODER(PGSSUB,            pgssub);

    REGISTER_DECODER(PJS,               pjs);

    REGISTER_DECODER(REALTEXT,          realtext);

    REGISTER_DECODER(SAMI,              sami);

    REGISTER_ENCDEC (SRT,               srt);

    REGISTER_DECODER(STL,               stl);

    REGISTER_ENCDEC (SUBRIP,            subrip);

    REGISTER_DECODER(SUBVIEWER,         subviewer);

    REGISTER_DECODER(SUBVIEWER1,        subviewer1);

    REGISTER_ENCDEC (TEXT,              text);

    REGISTER_DECODER(VPLAYER,           vplayer);

    REGISTER_ENCDEC (WEBVTT,            webvtt);

    REGISTER_ENCDEC (XSUB,              xsub);

    /* external libraries */

    REGISTER_ENCDEC (AAC_AT,            aac_at);

    REGISTER_DECODER(AC3_AT,            ac3_at);

    REGISTER_DECODER(ADPCM_IMA_QT_AT,   adpcm_ima_qt_at);

    REGISTER_ENCDEC (ALAC_AT,           alac_at);

    REGISTER_DECODER(AMR_NB_AT,         amr_nb_at);

    REGISTER_DECODER(EAC3_AT,           eac3_at);

    REGISTER_DECODER(GSM_MS_AT,         gsm_ms_at);

    REGISTER_ENCDEC (ILBC_AT,           ilbc_at);

    REGISTER_DECODER(MP1_AT,            mp1_at);

    REGISTER_DECODER(MP2_AT,            mp2_at);

    REGISTER_DECODER(MP3_AT,            mp3_at);

    REGISTER_ENCDEC (PCM_ALAW_AT,       pcm_alaw_at);

    REGISTER_ENCDEC (PCM_MULAW_AT,      pcm_mulaw_at);

    REGISTER_DECODER(QDMC_AT,           qdmc_at);

    REGISTER_DECODER(QDM2_AT,           qdm2_at);

    REGISTER_DECODER(LIBCELT,           libcelt);

    REGISTER_ENCODER(LIBFAAC,           libfaac);

    REGISTER_ENCDEC (LIBFDK_AAC,        libfdk_aac);

    REGISTER_ENCDEC (LIBGSM,            libgsm);

    REGISTER_ENCDEC (LIBGSM_MS,         libgsm_ms);

    REGISTER_ENCDEC (LIBILBC,           libilbc);

    REGISTER_ENCODER(LIBMP3LAME,        libmp3lame);

    REGISTER_ENCDEC (LIBOPENCORE_AMRNB, libopencore_amrnb);

    REGISTER_DECODER(LIBOPENCORE_AMRWB, libopencore_amrwb);

    REGISTER_ENCDEC (LIBOPENJPEG,       libopenjpeg);

    REGISTER_ENCDEC (LIBOPUS,           libopus);

    REGISTER_ENCDEC (LIBSCHROEDINGER,   libschroedinger);

    REGISTER_ENCODER(LIBSHINE,          libshine);

    REGISTER_ENCDEC (LIBSPEEX,          libspeex);

    REGISTER_ENCODER(LIBTHEORA,         libtheora);

    REGISTER_ENCODER(LIBTWOLAME,        libtwolame);

    REGISTER_ENCODER(LIBVO_AMRWBENC,    libvo_amrwbenc);

    REGISTER_ENCDEC (LIBVORBIS,         libvorbis);

    REGISTER_ENCDEC (LIBVPX_VP8,        libvpx_vp8);

    REGISTER_ENCDEC (LIBVPX_VP9,        libvpx_vp9);

    REGISTER_ENCODER(LIBWAVPACK,        libwavpack);

    REGISTER_ENCODER(LIBWEBP_ANIM,      libwebp_anim);  /* preferred over libwebp */

    REGISTER_ENCODER(LIBWEBP,           libwebp);

    REGISTER_ENCODER(LIBX262,           libx262);

    REGISTER_ENCODER(LIBX264,           libx264);

    REGISTER_ENCODER(LIBX264RGB,        libx264rgb);

    REGISTER_ENCODER(LIBX265,           libx265);

    REGISTER_ENCODER(LIBXAVS,           libxavs);

    REGISTER_ENCODER(LIBXVID,           libxvid);

    REGISTER_DECODER(LIBZVBI_TELETEXT,  libzvbi_teletext);

    /* text */

    REGISTER_DECODER(BINTEXT,           bintext);

    REGISTER_DECODER(XBIN,              xbin);

    REGISTER_DECODER(IDF,               idf);

    /* external libraries, that shouldn't be used by default if one of the

     * above is available */

    REGISTER_ENCDEC (LIBOPENH264,       libopenh264);

    REGISTER_DECODER(H263_CUVID,        h263_cuvid);

    REGISTER_DECODER(H264_CUVID,        h264_cuvid);

    REGISTER_ENCODER(H264_NVENC,        h264_nvenc);

    REGISTER_ENCODER(H264_OMX,          h264_omx);

    REGISTER_ENCODER(H264_QSV,          h264_qsv);

    REGISTER_ENCODER(H264_VAAPI,        h264_vaapi);

    REGISTER_ENCODER(H264_VIDEOTOOLBOX, h264_videotoolbox);

#if FF_API_NVENC_OLD_NAME

    REGISTER_ENCODER(NVENC,             nvenc);

    REGISTER_ENCODER(NVENC_H264,        nvenc_h264);

    REGISTER_ENCODER(NVENC_HEVC,        nvenc_hevc);

#endif

    REGISTER_DECODER(HEVC_CUVID,        hevc_cuvid);

    REGISTER_ENCODER(HEVC_NVENC,        hevc_nvenc);

    REGISTER_ENCODER(HEVC_QSV,          hevc_qsv);

    REGISTER_ENCODER(HEVC_VAAPI,        hevc_vaapi);

    REGISTER_ENCODER(LIBKVAZAAR,        libkvazaar);

    REGISTER_DECODER(MJPEG_CUVID,       mjpeg_cuvid);

    REGISTER_ENCODER(MJPEG_VAAPI,       mjpeg_vaapi);

    REGISTER_DECODER(MPEG1_CUVID,       mpeg1_cuvid);

    REGISTER_DECODER(MPEG2_CUVID,       mpeg2_cuvid);

    REGISTER_ENCODER(MPEG2_QSV,         mpeg2_qsv);

    REGISTER_DECODER(MPEG4_CUVID,       mpeg4_cuvid);

    REGISTER_DECODER(VC1_CUVID,         vc1_cuvid);

    REGISTER_DECODER(VP8_CUVID,         vp8_cuvid);

    REGISTER_DECODER(VP9_CUVID,         vp9_cuvid);

    /* parsers */

    REGISTER_PARSER(AAC,                aac);

    REGISTER_PARSER(AAC_LATM,           aac_latm);

    REGISTER_PARSER(AC3,                ac3);

    REGISTER_PARSER(ADX,                adx);

    REGISTER_PARSER(BMP,                bmp);

    REGISTER_PARSER(CAVSVIDEO,          cavsvideo);

    REGISTER_PARSER(COOK,               cook);

    REGISTER_PARSER(DCA,                dca);

    REGISTER_PARSER(DIRAC,              dirac);

    REGISTER_PARSER(DNXHD,              dnxhd);

    REGISTER_PARSER(DPX,                dpx);

    REGISTER_PARSER(DVAUDIO,            dvaudio);

    REGISTER_PARSER(DVBSUB,             dvbsub);

    REGISTER_PARSER(DVDSUB,             dvdsub);

    REGISTER_PARSER(DVD_NAV,            dvd_nav);

    REGISTER_PARSER(FLAC,               flac);

    REGISTER_PARSER(G729,               g729);

    REGISTER_PARSER(GSM,                gsm);

    REGISTER_PARSER(H261,               h261);

    REGISTER_PARSER(H263,               h263);

    REGISTER_PARSER(H264,               h264);

    REGISTER_PARSER(HEVC,               hevc);

    REGISTER_PARSER(MJPEG,              mjpeg);

    REGISTER_PARSER(MLP,                mlp);

    REGISTER_PARSER(MPEG4VIDEO,         mpeg4video);

    REGISTER_PARSER(MPEGAUDIO,          mpegaudio);

    REGISTER_PARSER(MPEGVIDEO,          mpegvideo);

    REGISTER_PARSER(OPUS,               opus);

    REGISTER_PARSER(PNG,                png);

    REGISTER_PARSER(PNM,                pnm);

    REGISTER_PARSER(RV30,               rv30);

    REGISTER_PARSER(RV40,               rv40);

    REGISTER_PARSER(TAK,                tak);

    REGISTER_PARSER(VC1,                vc1);

    REGISTER_PARSER(VORBIS,             vorbis);

    REGISTER_PARSER(VP3,                vp3);

    REGISTER_PARSER(VP8,                vp8);

    REGISTER_PARSER(VP9,                vp9);

}


static void spapr_machine_device_unplug(HotplugHandler *hotplug_dev,

                                      DeviceState *dev, Error **errp)

{

    sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(qdev_get_machine());

    if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {

        error_setg(errp, "Memory hot unplug not supported by sPAPR");

    } else if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_CPU_CORE)) {

        if (!smc->dr_cpu_enabled) {

            error_setg(errp, "CPU hot unplug not supported on this machine");

            return;

        }

        spapr_core_unplug(hotplug_dev, dev, errp);

    }

}


static int mkv_add_cuepoint(mkv_cues *cues, int stream, int64_t ts, int64_t cluster_pos)

{

    mkv_cuepoint *entries = cues->entries;

    entries = av_realloc(entries, (cues->num_entries + 1) * sizeof(mkv_cuepoint));

    if (entries == NULL)

        return AVERROR(ENOMEM);

    if (ts < 0)

        return 0;

    entries[cues->num_entries  ].pts = ts;

    entries[cues->num_entries  ].tracknum = stream + 1;

    entries[cues->num_entries++].cluster_pos = cluster_pos - cues->segment_offset;

    cues->entries = entries;

    return 0;

}


static void gen_exception(int excp)

{

    TCGv tmp = new_tmp();

    tcg_gen_movi_i32(tmp, excp);

    gen_helper_exception(tmp);

    dead_tmp(tmp);

}


static int yop_decode_frame(AVCodecContext *avctx, void *data, int *data_size,

                            AVPacket *avpkt)

{

    YopDecContext *s = avctx->priv_data;

    int tag, firstcolor, is_odd_frame;

    int ret, i;

    uint32_t *palette;

    if (s->frame.data[0])

        avctx->release_buffer(avctx, &s->frame);

    if (avpkt->size < 4 + 3*s->num_pal_colors) {

        av_log(avctx, AV_LOG_ERROR, "packet of size %d too small\n", avpkt->size);

        return AVERROR_INVALIDDATA;

    }

    ret = avctx->get_buffer(avctx, &s->frame);

    if (ret < 0) {

        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");

        return ret;

    }

    s->frame.linesize[0] = avctx->width;

    s->dstbuf     = s->frame.data[0];

    s->dstptr     = s->frame.data[0];

    s->srcptr     = avpkt->data + 4;

    s->row_pos    = 0;

    s->low_nibble = NULL;

    is_odd_frame = avpkt->data[0];

    if(is_odd_frame>1){

        av_log(avctx, AV_LOG_ERROR, "frame is too odd %d\n", is_odd_frame);

        return AVERROR_INVALIDDATA;

    }

    firstcolor   = s->first_color[is_odd_frame];

    palette      = (uint32_t *)s->frame.data[1];

    for (i = 0; i < s->num_pal_colors; i++, s->srcptr += 3) {

        palette[i + firstcolor] = (s->srcptr[0] << 18) |

                                  (s->srcptr[1] << 10) |

                                  (s->srcptr[2] << 2);

        palette[i + firstcolor] |= 0xFF << 24 |

                                   (palette[i + firstcolor] >> 6) & 0x30303;

    }

    s->frame.palette_has_changed = 1;

    while (s->dstptr - s->dstbuf <

           avctx->width * avctx->height &&

           s->srcptr - avpkt->data < avpkt->size) {

        tag = yop_get_next_nibble(s);

        if (tag != 0xf) {

            yop_paint_block(s, tag);

        }else {

            tag = yop_get_next_nibble(s);

            ret = yop_copy_previous_block(s, tag);

            if (ret < 0) {

                avctx->release_buffer(avctx, &s->frame);

                return ret;

            }

        }

        yop_next_macroblock(s);

    }

    *data_size        = sizeof(AVFrame);

    *(AVFrame *) data = s->frame;

    return avpkt->size;

}


static int dnxhd_encode_picture(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data)
{
    DNXHDEncContext *ctx = avctx->priv_data;
    int first_field = 1;
    int offset, i, ret;
    if (buf_size < ctx->cid_table->frame_size) {
        av_log(avctx, AV_LOG_ERROR, "output buffer is too small to compress picture\n");
        return -1;
    }
    dnxhd_load_picture(ctx, data);
 encode_coding_unit:
    for (i = 0; i < 3; i++) {
        ctx->src[i] = ctx->frame.data[i];
        if (ctx->interlaced && ctx->cur_field)
            ctx->src[i] += ctx->frame.linesize[i];
    }
    dnxhd_write_header(avctx, buf);
    if (avctx->mb_decision == FF_MB_DECISION_RD)
        ret = dnxhd_encode_rdo(avctx, ctx);
    else
        ret = dnxhd_encode_fast(avctx, ctx);
    if (ret < 0) {
        av_log(avctx, AV_LOG_ERROR, "picture could not fit ratecontrol constraints\n");
        return -1;
    }
    dnxhd_setup_threads_slices(ctx, buf);
    offset = 0;
    for (i = 0; i < ctx->m.mb_height; i++) {
        AV_WB32(ctx->msip + i * 4, offset);
        offset += ctx->slice_size[i];
        assert(!(ctx->slice_size[i] & 3));
    }
    avctx->execute(avctx, dnxhd_encode_thread, (void**)&ctx->thread[0], NULL, avctx->thread_count, sizeof(void*));
    AV_WB32(buf + ctx->cid_table->coding_unit_size - 4, 0x600DC0DE); // EOF
    if (ctx->interlaced && first_field) {
        first_field     = 0;
        ctx->cur_field ^= 1;
        buf      += ctx->cid_table->coding_unit_size;
        buf_size -= ctx->cid_table->coding_unit_size;
        goto encode_coding_unit;
    }
    ctx->frame.quality = ctx->qscale*FF_QP2LAMBDA;
    return ctx->cid_table->frame_size;
}


static void mb_cpu_class_init(ObjectClass *oc, void *data)
{
    DeviceClass *dc = DEVICE_CLASS(oc);
    CPUClass *cc = CPU_CLASS(oc);
    MicroBlazeCPUClass *mcc = MICROBLAZE_CPU_CLASS(oc);
    mcc->parent_realize = dc->realize;
    dc->realize = mb_cpu_realizefn;
    mcc->parent_reset = cc->reset;
    cc->reset = mb_cpu_reset;
    cc->has_work = mb_cpu_has_work;
    cc->do_interrupt = mb_cpu_do_interrupt;
    cc->cpu_exec_interrupt = mb_cpu_exec_interrupt;
    cc->dump_state = mb_cpu_dump_state;
    cc->set_pc = mb_cpu_set_pc;
    cc->gdb_read_register = mb_cpu_gdb_read_register;
    cc->gdb_write_register = mb_cpu_gdb_write_register;
#ifdef CONFIG_USER_ONLY
    cc->handle_mmu_fault = mb_cpu_handle_mmu_fault;
#else
    cc->do_unassigned_access = mb_cpu_unassigned_access;
    cc->get_phys_page_debug = mb_cpu_get_phys_page_debug;
#endif
    dc->vmsd = &vmstate_mb_cpu;
    dc->props = mb_properties;
    cc->gdb_num_core_regs = 32 + 5;
    cc->disas_set_info = mb_disas_set_info;
}


static int vfio_connect_container(VFIOGroup *group, AddressSpace *as,

                                  Error **errp)

{

    VFIOContainer *container;

    int ret, fd;

    VFIOAddressSpace *space;

    space = vfio_get_address_space(as);

    QLIST_FOREACH(container, &space->containers, next) {

        if (!ioctl(group->fd, VFIO_GROUP_SET_CONTAINER, &container->fd)) {

            group->container = container;

            QLIST_INSERT_HEAD(&container->group_list, group, container_next);

            vfio_kvm_device_add_group(group);

            return 0;

    fd = qemu_open("/dev/vfio/vfio", O_RDWR);

    if (fd < 0) {

        error_setg_errno(errp, errno, "failed to open /dev/vfio/vfio");

        ret = -errno;

        goto put_space_exit;

    ret = ioctl(fd, VFIO_GET_API_VERSION);

    if (ret != VFIO_API_VERSION) {

        error_setg(errp, "supported vfio version: %d, "

                   "reported version: %d", VFIO_API_VERSION, ret);

        ret = -EINVAL;

        goto close_fd_exit;

    container = g_malloc0(sizeof(*container));

    container->space = space;

    container->fd = fd;

    QLIST_INIT(&container->giommu_list);

    QLIST_INIT(&container->hostwin_list);

    if (ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU) ||

        ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1v2_IOMMU)) {

        bool v2 = !!ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1v2_IOMMU);

        struct vfio_iommu_type1_info info;

        ret = ioctl(group->fd, VFIO_GROUP_SET_CONTAINER, &fd);

            error_setg_errno(errp, errno, "failed to set group container");

            ret = -errno;

            goto free_container_exit;

        container->iommu_type = v2 ? VFIO_TYPE1v2_IOMMU : VFIO_TYPE1_IOMMU;

            error_setg_errno(errp, errno, "failed to set iommu for container");

            ret = -errno;

            goto free_container_exit;

        /*

         * FIXME: This assumes that a Type1 IOMMU can map any 64-bit

         * IOVA whatsoever.  That's not actually true, but the current

         * kernel interface doesn't tell us what it can map, and the

         * existing Type1 IOMMUs generally support any IOVA we're

         * going to actually try in practice.

         */

        info.argsz = sizeof(info);

        ret = ioctl(fd, VFIO_IOMMU_GET_INFO, &info);

        /* Ignore errors */

        if (ret || !(info.flags & VFIO_IOMMU_INFO_PGSIZES)) {

            /* Assume 4k IOVA page size */

            info.iova_pgsizes = 4096;

        vfio_host_win_add(container, 0, (hwaddr)-1, info.iova_pgsizes);

    } else if (ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_SPAPR_TCE_IOMMU) ||

               ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_SPAPR_TCE_v2_IOMMU)) {

        struct vfio_iommu_spapr_tce_info info;

        bool v2 = !!ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_SPAPR_TCE_v2_IOMMU);

        ret = ioctl(group->fd, VFIO_GROUP_SET_CONTAINER, &fd);

            error_setg_errno(errp, errno, "failed to set group container");

            ret = -errno;

            goto free_container_exit;

        container->iommu_type =

            v2 ? VFIO_SPAPR_TCE_v2_IOMMU : VFIO_SPAPR_TCE_IOMMU;

            error_setg_errno(errp, errno, "failed to set iommu for container");

            ret = -errno;

            goto free_container_exit;

        /*

         * The host kernel code implementing VFIO_IOMMU_DISABLE is called

         * when container fd is closed so we do not call it explicitly

         * in this file.

         */

        if (!v2) {

            ret = ioctl(fd, VFIO_IOMMU_ENABLE);

                error_setg_errno(errp, errno, "failed to enable container");

                ret = -errno;

                goto free_container_exit;

        } else {

            container->prereg_listener = vfio_prereg_listener;

            memory_listener_register(&container->prereg_listener,

                                     &address_space_memory);

            if (container->error) {

                memory_listener_unregister(&container->prereg_listener);

                ret = container->error;

                error_setg(errp,

                    "RAM memory listener initialization failed for container");

                goto free_container_exit;

        info.argsz = sizeof(info);

        ret = ioctl(fd, VFIO_IOMMU_SPAPR_TCE_GET_INFO, &info);

            error_setg_errno(errp, errno,

                             "VFIO_IOMMU_SPAPR_TCE_GET_INFO failed");

            ret = -errno;

            if (v2) {

                memory_listener_unregister(&container->prereg_listener);

            goto free_container_exit;

        if (v2) {

            /*

             * There is a default window in just created container.

             * To make region_add/del simpler, we better remove this

             * window now and let those iommu_listener callbacks

             * create/remove them when needed.

             */

            ret = vfio_spapr_remove_window(container, info.dma32_window_start);

                error_setg_errno(errp, -ret,

                                 "failed to remove existing window");

                goto free_container_exit;

        } else {

            /* The default table uses 4K pages */

            vfio_host_win_add(container, info.dma32_window_start,

                              info.dma32_window_start +

                              info.dma32_window_size - 1,

                              0x1000);

    } else {

        error_setg(errp, "No available IOMMU models");

        ret = -EINVAL;

        goto free_container_exit;

    vfio_kvm_device_add_group(group);

    QLIST_INIT(&container->group_list);

    QLIST_INSERT_HEAD(&space->containers, container, next);

    group->container = container;

    QLIST_INSERT_HEAD(&container->group_list, group, container_next);

    container->listener = vfio_memory_listener;

    memory_listener_register(&container->listener, container->space->as);

    if (container->error) {

        ret = container->error;

        error_setg_errno(errp, -ret,

                         "memory listener initialization failed for container");

        goto listener_release_exit;

    container->initialized = true;

    return 0;

listener_release_exit:

    QLIST_REMOVE(group, container_next);

    QLIST_REMOVE(container, next);

    vfio_kvm_device_del_group(group);

    vfio_listener_release(container);

free_container_exit:

    g_free(container);

close_fd_exit:

    close(fd);

put_space_exit:

    vfio_put_address_space(space);

    return ret;


static void FUNCC(pred4x4_top_dc)(uint8_t *_src, const uint8_t *topright, int _stride){

    pixel *src = (pixel*)_src;

    int stride = _stride/sizeof(pixel);

    const int dc= (  src[-stride] + src[1-stride] + src[2-stride] + src[3-stride] + 2) >>2;

    ((pixel4*)(src+0*stride))[0]=

    ((pixel4*)(src+1*stride))[0]=

    ((pixel4*)(src+2*stride))[0]=

    ((pixel4*)(src+3*stride))[0]= PIXEL_SPLAT_X4(dc);

}


static void print_report(int is_last_report, int64_t timer_start)

{

    char buf[1024];

    OutputStream *ost;

    AVFormatContext *oc;

    int64_t total_size;

    AVCodecContext *enc;

    int frame_number, vid, i;

    double bitrate, ti1, pts;

    static int64_t last_time = -1;

    static int qp_histogram[52];

    if (!print_stats && !is_last_report)

        return;

    if (!is_last_report) {

        int64_t cur_time;

        /* display the report every 0.5 seconds */

        cur_time = av_gettime();

        if (last_time == -1) {

            last_time = cur_time;

            return;

        }

        if ((cur_time - last_time) < 500000)

            return;

        last_time = cur_time;

    }

    oc = output_files[0]->ctx;

    total_size = avio_size(oc->pb);

    if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too

        total_size = avio_tell(oc->pb);

    if (total_size < 0) {

        char errbuf[128];

        av_strerror(total_size, errbuf, sizeof(errbuf));

        av_log(NULL, AV_LOG_VERBOSE, "Bitrate not available, "

               "avio_tell() failed: %s\n", errbuf);

        total_size = 0;

    }

    buf[0] = '\0';

    ti1 = 1e10;

    vid = 0;

    for (i = 0; i < nb_output_streams; i++) {

        float q = -1;

        ost = output_streams[i];

        enc = ost->st->codec;

        if (!ost->stream_copy && enc->coded_frame)

            q = enc->coded_frame->quality / (float)FF_QP2LAMBDA;

        if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {

            snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "q=%2.1f ", q);

        }

        if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {

            float t = (av_gettime() - timer_start) / 1000000.0;

            frame_number = ost->frame_number;

            snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "frame=%5d fps=%3d q=%3.1f ",

                     frame_number, (t > 1) ? (int)(frame_number / t + 0.5) : 0, q);

            if (is_last_report)

                snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "L");

            if (qp_hist) {

                int j;

                int qp = lrintf(q);

                if (qp >= 0 && qp < FF_ARRAY_ELEMS(qp_histogram))

                    qp_histogram[qp]++;

                for (j = 0; j < 32; j++)

                    snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%X", (int)lrintf(log2(qp_histogram[j] + 1)));

            }

            if (enc->flags&CODEC_FLAG_PSNR) {

                int j;

                double error, error_sum = 0;

                double scale, scale_sum = 0;

                char type[3] = { 'Y','U','V' };

                snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "PSNR=");

                for (j = 0; j < 3; j++) {

                    if (is_last_report) {

                        error = enc->error[j];

                        scale = enc->width * enc->height * 255.0 * 255.0 * frame_number;

                    } else {

                        error = enc->coded_frame->error[j];

                        scale = enc->width * enc->height * 255.0 * 255.0;

                    }

                    if (j)

                        scale /= 4;

                    error_sum += error;

                    scale_sum += scale;

                    snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%c:%2.2f ", type[j], psnr(error / scale));

                }

                snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "*:%2.2f ", psnr(error_sum / scale_sum));

            }

            vid = 1;

        }

        /* compute min output value */

        pts = (double)ost->st->pts.val * av_q2d(ost->st->time_base);

        if ((pts < ti1) && (pts > 0))

            ti1 = pts;

    }

    if (ti1 < 0.01)

        ti1 = 0.01;

    bitrate = (double)(total_size * 8) / ti1 / 1000.0;

    snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),

            "size=%8.0fkB time=%0.2f bitrate=%6.1fkbits/s",

            (double)total_size / 1024, ti1, bitrate);

    if (nb_frames_dup || nb_frames_drop)

        snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " dup=%d drop=%d",

                nb_frames_dup, nb_frames_drop);

    av_log(NULL, AV_LOG_INFO, "%s    \r", buf);

    fflush(stderr);

    if (is_last_report) {

        int64_t raw= audio_size + video_size + extra_size;

        av_log(NULL, AV_LOG_INFO, "\n");

        av_log(NULL, AV_LOG_INFO, "video:%1.0fkB audio:%1.0fkB global headers:%1.0fkB muxing overhead %f%%\n",

               video_size / 1024.0,

               audio_size / 1024.0,

               extra_size / 1024.0,

               100.0 * (total_size - raw) / raw

        );

    }

}


static void store_slice_mmx(uint8_t *dst, const uint16_t *src,

                            int dst_stride, int src_stride,

                            int width, int height, int log2_scale,

                            const uint8_t dither[8][8])

{

    int y;

    for (y = 0; y < height; y++) {

        uint8_t *dst1 = dst;

        const int16_t *src1 = src;

        __asm__ volatile(

            "movq (%3), %%mm3           \n"

            "movq (%3), %%mm4           \n"

            "movd %4, %%mm2             \n"

            "pxor %%mm0, %%mm0          \n"

            "punpcklbw %%mm0, %%mm3     \n"

            "punpckhbw %%mm0, %%mm4     \n"

            "psraw %%mm2, %%mm3         \n"

            "psraw %%mm2, %%mm4         \n"

            "movd %5, %%mm2             \n"

            "1:                         \n"

            "movq (%0), %%mm0           \n"

            "movq 8(%0), %%mm1          \n"

            "paddw %%mm3, %%mm0         \n"

            "paddw %%mm4, %%mm1         \n"

            "psraw %%mm2, %%mm0         \n"

            "psraw %%mm2, %%mm1         \n"

            "packuswb %%mm1, %%mm0      \n"

            "movq %%mm0, (%1)           \n"

            "add $16, %0                \n"

            "add $8, %1                 \n"

            "cmp %2, %1                 \n"

            " jb 1b                     \n"

            : "+r" (src1), "+r"(dst1)

            : "r"(dst + width), "r"(dither[y]), "g"(log2_scale), "g"(MAX_LEVEL - log2_scale)

        );

        src += src_stride;

        dst += dst_stride;

    }

}


av_cold int ff_vc2enc_init_transforms(VC2TransformContext *s, int p_width, int p_height)

{

    s->vc2_subband_dwt[VC2_TRANSFORM_9_7]    = vc2_subband_dwt_97;

    s->vc2_subband_dwt[VC2_TRANSFORM_5_3]    = vc2_subband_dwt_53;

    s->vc2_subband_dwt[VC2_TRANSFORM_HAAR]   = vc2_subband_dwt_haar;

    s->vc2_subband_dwt[VC2_TRANSFORM_HAAR_S] = vc2_subband_dwt_haar_shift;

    s->buffer = av_malloc(2*p_width*p_height*sizeof(dwtcoef));

    if (!s->buffer)

        return 1;

    return 0;

}


static void fill_buffer(AVIOContext *s)

{

    int max_buffer_size = s->max_packet_size ?

                          s->max_packet_size : IO_BUFFER_SIZE;

    uint8_t *dst        = s->buf_end - s->buffer + max_buffer_size < s->buffer_size ?

                          s->buf_end : s->buffer;

    int len             = s->buffer_size - (dst - s->buffer);

    /* can't fill the buffer without read_packet, just set EOF if appropriate */

    if (!s->read_packet && s->buf_ptr >= s->buf_end)

        s->eof_reached = 1;

    /* no need to do anything if EOF already reached */

    if (s->eof_reached)

        return;

    if (s->update_checksum && dst == s->buffer) {

        if (s->buf_end > s->checksum_ptr)

            s->checksum = s->update_checksum(s->checksum, s->checksum_ptr,

                                             s->buf_end - s->checksum_ptr);

        s->checksum_ptr = s->buffer;

    }

    /* make buffer smaller in case it ended up large after probing */

    if (s->read_packet && s->orig_buffer_size && s->buffer_size > s->orig_buffer_size) {

        if (dst == s->buffer) {

            ffio_set_buf_size(s, s->orig_buffer_size);

            s->checksum_ptr = dst = s->buffer;

        }

        av_assert0(len >= s->orig_buffer_size);

        len = s->orig_buffer_size;

    }

    if (s->read_packet)

        len = s->read_packet(s->opaque, dst, len);

    else

        len = 0;

    if (len <= 0) {

        /* do not modify buffer if EOF reached so that a seek back can

           be done without rereading data */

        s->eof_reached = 1;

        if (len < 0)

            s->error = len;

    } else {

        s->pos += len;

        s->buf_ptr = dst;

        s->buf_end = dst + len;

        s->bytes_read += len;

    }

}


static int apply_param_change(AVCodecContext *avctx, AVPacket *avpkt)

{

    int size = 0, ret;

    const uint8_t *data;

    uint32_t flags;

    data = av_packet_get_side_data(avpkt, AV_PKT_DATA_PARAM_CHANGE, &size);

    if (!data)

        return 0;

    if (!(avctx->codec->capabilities & CODEC_CAP_PARAM_CHANGE)) {

        av_log(avctx, AV_LOG_ERROR, "This decoder does not support parameter "

               "changes, but PARAM_CHANGE side data was sent to it.\n");

        return AVERROR(EINVAL);

    }

    if (size < 4)

        goto fail;

    flags = bytestream_get_le32(&data);

    size -= 4;

    if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT) {

        if (size < 4)

            goto fail;

        avctx->channels = bytestream_get_le32(&data);

        size -= 4;

    }

    if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT) {

        if (size < 8)

            goto fail;

        avctx->channel_layout = bytestream_get_le64(&data);

        size -= 8;

    }

    if (flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) {

        if (size < 4)

            goto fail;

        avctx->sample_rate = bytestream_get_le32(&data);

        size -= 4;

    }

    if (flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS) {

        if (size < 8)

            goto fail;

        avctx->width  = bytestream_get_le32(&data);

        avctx->height = bytestream_get_le32(&data);

        size -= 8;

        ret = ff_set_dimensions(avctx, avctx->width, avctx->height);

        if (ret < 0)

            return ret;

    }

    return 0;

fail:

    av_log(avctx, AV_LOG_ERROR, "PARAM_CHANGE side data too small.\n");

    return AVERROR_INVALIDDATA;

}


static int get_number(void *obj, const char *name, const AVOption **o_out, double *num, int *den, int64_t *intnum)

{

    const AVOption *o = av_opt_find(obj, name, NULL, 0, 0);

    void *dst;

    if (!o || o->offset<=0)

        goto error;

    dst= ((uint8_t*)obj) + o->offset;

    if (o_out) *o_out= o;

    switch (o->type) {

    case FF_OPT_TYPE_FLAGS:     *intnum= *(unsigned int*)dst;return 0;

    case FF_OPT_TYPE_INT:       *intnum= *(int    *)dst;return 0;

    case FF_OPT_TYPE_INT64:     *intnum= *(int64_t*)dst;return 0;

    case FF_OPT_TYPE_FLOAT:     *num=    *(float  *)dst;return 0;

    case FF_OPT_TYPE_DOUBLE:    *num=    *(double *)dst;return 0;

    case FF_OPT_TYPE_RATIONAL:  *intnum= ((AVRational*)dst)->num;

                                *den   = ((AVRational*)dst)->den;

                                                        return 0;

    }

error:

    *den=*intnum=0;

    return -1;

}


static int dts_probe(AVProbeData *p)

{

    const uint8_t *buf, *bufp;

    uint32_t state = -1;

    int markers[4*16] = {0};

    int exss_markers = 0, exss_nextpos = 0;

    int sum, max, pos, i;

    int64_t diff = 0;

    uint8_t hdr[12 + AV_INPUT_BUFFER_PADDING_SIZE] = { 0 };

    for (pos = FFMIN(4096, p->buf_size); pos < p->buf_size - 2; pos += 2) {

        int marker, sample_blocks, sample_rate, sr_code, framesize;

        int lfe, wide_hdr, hdr_size;

        GetBitContext gb;

        bufp = buf = p->buf + pos;

        state = (state << 16) | bytestream_get_be16(&bufp);

        if (pos >= 4)

            diff += FFABS(((int16_t)AV_RL16(buf)) - (int16_t)AV_RL16(buf-4));

        /* extension substream (EXSS) */

        if (state == DCA_SYNCWORD_SUBSTREAM) {

            if (pos < exss_nextpos)

                continue;

            init_get_bits(&gb, buf - 2, 96);

            skip_bits_long(&gb, 42);

            wide_hdr  = get_bits1(&gb);

            hdr_size  = get_bits(&gb,  8 + 4 * wide_hdr) + 1;

            framesize = get_bits(&gb, 16 + 4 * wide_hdr) + 1;

            if (hdr_size & 3 || framesize & 3)

                continue;

            if (hdr_size < 16 || framesize < hdr_size)

                continue;

            if (pos - 2 + hdr_size > p->buf_size)

                continue;

            if (av_crc(av_crc_get_table(AV_CRC_16_CCITT), 0xffff, buf + 3, hdr_size - 5))

                continue;

            if (pos == exss_nextpos)

                exss_markers++;

            else

                exss_markers = FFMAX(1, exss_markers - 1);

            exss_nextpos = pos + framesize;

            continue;

        }

        /* regular bitstream */

        if (state == DCA_SYNCWORD_CORE_BE &&

            (bytestream_get_be16(&bufp) & 0xFC00) == 0xFC00)

            marker = 0;

        else if (state == DCA_SYNCWORD_CORE_LE &&

                 (bytestream_get_be16(&bufp) & 0x00FC) == 0x00FC)

            marker = 1;

        /* 14 bits big-endian bitstream */

        else if (state == DCA_SYNCWORD_CORE_14B_BE &&

                 (bytestream_get_be16(&bufp) & 0xFFF0) == 0x07F0)

            marker = 2;

        /* 14 bits little-endian bitstream */

        else if (state == DCA_SYNCWORD_CORE_14B_LE &&

                 (bytestream_get_be16(&bufp) & 0xF0FF) == 0xF007)

            marker = 3;

        else

            continue;

        if (avpriv_dca_convert_bitstream(buf-2, 12, hdr, 12) < 0)

            continue;

        init_get_bits(&gb, hdr, 96);

        skip_bits_long(&gb, 39);

        sample_blocks = get_bits(&gb, 7) + 1;

        if (sample_blocks < 8)

            continue;

        framesize = get_bits(&gb, 14) + 1;

        if (framesize < 95)

            continue;

        skip_bits(&gb, 6);

        sr_code = get_bits(&gb, 4);

        sample_rate = avpriv_dca_sample_rates[sr_code];

        if (sample_rate == 0)

            continue;

        get_bits(&gb, 5);

        if (get_bits(&gb, 1))

            continue;

        skip_bits_long(&gb, 9);

        lfe = get_bits(&gb, 2);

        if (lfe > 2)

            continue;

        marker += 4* sr_code;

        markers[marker] ++;

    }

    if (exss_markers > 3)

        return AVPROBE_SCORE_EXTENSION + 1;

    sum = max = 0;

    for (i=0; i<FF_ARRAY_ELEMS(markers); i++) {

        sum += markers[i];

        if (markers[max] < markers[i])

            max = i;

    }

    if (markers[max] > 3 && p->buf_size / markers[max] < 32*1024 &&

        markers[max] * 4 > sum * 3 &&

        diff / p->buf_size > 200)

        return AVPROBE_SCORE_EXTENSION + 1;

    return 0;

}


static int wc3_read_packet(AVFormatContext *s,

                           AVPacket *pkt)

{

    Wc3DemuxContext *wc3 = s->priv_data;

    ByteIOContext *pb = s->pb;

    unsigned int fourcc_tag;

    unsigned int size;

    int packet_read = 0;

    int ret = 0;

    unsigned char preamble[WC3_PREAMBLE_SIZE];

    unsigned char text[1024];

    unsigned int palette_number;

    int i;

    unsigned char r, g, b;

    int base_palette_index;

    while (!packet_read) {

        /* get the next chunk preamble */

        if ((ret = get_buffer(pb, preamble, WC3_PREAMBLE_SIZE)) !=

            WC3_PREAMBLE_SIZE)

            ret = AVERROR(EIO);

        fourcc_tag = AV_RL32(&preamble[0]);

        /* chunk sizes are 16-bit aligned */

        size = (AV_RB32(&preamble[4]) + 1) & (~1);

        switch (fourcc_tag) {

        case BRCH_TAG:

            /* no-op */

            break;

        case SHOT_TAG:

            /* load up new palette */

            if ((ret = get_buffer(pb, preamble, 4)) != 4)

                return AVERROR(EIO);

            palette_number = AV_RL32(&preamble[0]);

            if (palette_number >= wc3->palette_count)

                return AVERROR_INVALIDDATA;

            base_palette_index = palette_number * PALETTE_COUNT * 3;

            for (i = 0; i < PALETTE_COUNT; i++) {

                r = wc3->palettes[base_palette_index + i * 3 + 0];

                g = wc3->palettes[base_palette_index + i * 3 + 1];

                b = wc3->palettes[base_palette_index + i * 3 + 2];

                wc3->palette_control.palette[i] = (r << 16) | (g << 8) | (b);

            }

            wc3->palette_control.palette_changed = 1;

            break;

        case VGA__TAG:

            /* send out video chunk */

            ret= av_get_packet(pb, pkt, size);

            pkt->stream_index = wc3->video_stream_index;

            pkt->pts = wc3->pts;

            if (ret != size)

                ret = AVERROR(EIO);

            packet_read = 1;

            break;

        case TEXT_TAG:

            /* subtitle chunk */

#if 0

            url_fseek(pb, size, SEEK_CUR);

#else

            if ((unsigned)size > sizeof(text) || (ret = get_buffer(pb, text, size)) != size)

                ret = AVERROR(EIO);

            else {

                int i = 0;

                av_log (s, AV_LOG_DEBUG, "Subtitle time!\n");

                av_log (s, AV_LOG_DEBUG, "  inglish: %s\n", &text[i + 1]);

                i += text[i] + 1;

                av_log (s, AV_LOG_DEBUG, "  doytsch: %s\n", &text[i + 1]);

                i += text[i] + 1;

                av_log (s, AV_LOG_DEBUG, "  fronsay: %s\n", &text[i + 1]);

            }

#endif

            break;

        case AUDI_TAG:

            /* send out audio chunk */

            ret= av_get_packet(pb, pkt, size);

            pkt->stream_index = wc3->audio_stream_index;

            pkt->pts = wc3->pts;

            if (ret != size)

                ret = AVERROR(EIO);

            /* time to advance pts */

            wc3->pts++;

            packet_read = 1;

            break;

        default:

            av_log (s, AV_LOG_ERROR, "  unrecognized WC3 chunk: %c%c%c%c (0x%02X%02X%02X%02X)\n",

                preamble[0], preamble[1], preamble[2], preamble[3],

                preamble[0], preamble[1], preamble[2], preamble[3]);

            ret = AVERROR_INVALIDDATA;

            packet_read = 1;

            break;

        }

    }

    return ret;

}


int ff_h264_field_end(H264Context *h, H264SliceContext *sl, int in_setup)

{

    AVCodecContext *const avctx = h->avctx;

    int err = 0;

    h->mb_y = 0;

    if (!in_setup && !h->droppable)

        ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX,

                                  h->picture_structure == PICT_BOTTOM_FIELD);

    if (in_setup || !(avctx->active_thread_type & FF_THREAD_FRAME)) {

        if (!h->droppable) {

            err = ff_h264_execute_ref_pic_marking(h);

            h->poc.prev_poc_msb = h->poc.poc_msb;

            h->poc.prev_poc_lsb = h->poc.poc_lsb;

        }

        h->poc.prev_frame_num_offset = h->poc.frame_num_offset;

        h->poc.prev_frame_num        = h->poc.frame_num;

    }

    if (avctx->hwaccel) {

        if (avctx->hwaccel->end_frame(avctx) < 0)

            av_log(avctx, AV_LOG_ERROR,

                   "hardware accelerator failed to decode picture\n");

    }

#if CONFIG_ERROR_RESILIENCE

    /*

     * FIXME: Error handling code does not seem to support interlaced

     * when slices span multiple rows

     * The ff_er_add_slice calls don't work right for bottom

     * fields; they cause massive erroneous error concealing

     * Error marking covers both fields (top and bottom).

     * This causes a mismatched s->error_count

     * and a bad error table. Further, the error count goes to

     * INT_MAX when called for bottom field, because mb_y is

     * past end by one (callers fault) and resync_mb_y != 0

     * causes problems for the first MB line, too.

     */

    if (!FIELD_PICTURE(h) && h->enable_er) {

        h264_set_erpic(&sl->er.cur_pic, h->cur_pic_ptr);

        h264_set_erpic(&sl->er.last_pic,

                       sl->ref_count[0] ? sl->ref_list[0][0].parent : NULL);

        h264_set_erpic(&sl->er.next_pic,

                       sl->ref_count[1] ? sl->ref_list[1][0].parent : NULL);

        ff_er_frame_end(&sl->er);

    }

#endif /* CONFIG_ERROR_RESILIENCE */

    emms_c();

    h->current_slice = 0;

    return err;

}


static void pic_common_class_init(ObjectClass *klass, void *data)

{

    DeviceClass *dc = DEVICE_CLASS(klass);

    dc->vmsd = &vmstate_pic_common;

    dc->no_user = 1;

    dc->props = pic_properties_common;

    dc->realize = pic_common_realize;

}


static AVFrame *alloc_frame(enum AVPixelFormat pixfmt, int w, int h)

{

    AVFrame *frame = av_frame_alloc();

    if (!frame)

        return NULL;

    frame->format = pixfmt;

    frame->width  = w;

    frame->height = h;

    if (av_frame_get_buffer(frame, 32) < 0)

        return NULL;

    return frame;

}


void qdev_init_nofail(DeviceState *dev)

{

    Error *err = NULL;

    assert(!dev->realized);

    object_property_set_bool(OBJECT(dev), true, "realized", &err);

    if (err) {

        error_reportf_err(err, "Initialization of device %s failed: ",

                          object_get_typename(OBJECT(dev)));

        exit(1);

    }

}