callback(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time)

{

    AVFormatContext *s = priv_data;

    struct dshow_ctx *ctx = s->priv_data;

    AVPacketList **ppktl, *pktl_next;



//    dump_videohdr(s, vdhdr);



    WaitForSingleObject(ctx->mutex, INFINITE);



    if(shall_we_drop(s))

        goto fail;



    pktl_next = av_mallocz(sizeof(AVPacketList));

    if(!pktl_next)

        goto fail;



    if(av_new_packet(&pktl_next->pkt, buf_size) < 0) {

        av_free(pktl_next);

        goto fail;

    }



    pktl_next->pkt.stream_index = index;

    pktl_next->pkt.pts = time;

    memcpy(pktl_next->pkt.data, buf, buf_size);



    for(ppktl = &ctx->pktl ; *ppktl ; ppktl = &(*ppktl)->next);

    *ppktl = pktl_next;



    ctx->curbufsize += buf_size;



    SetEvent(ctx->event);

    ReleaseMutex(ctx->mutex);



    return;

fail:

    ReleaseMutex(ctx->mutex);

    return;

}
