[FFmpeg-devel] [RFC] lockmgr callback inclusion into libs sources

Andrey Utkin andrey.krieger.utkin at gmail.com
Mon May 7 16:20:34 CEST 2012

I'd like to offer inclusion of suitable lockmgr callback functions
into libraries code.
(To make it clear for non-familiar people: i mean the function we
register with lavc av_lockmgr_register() when we work multithreadingly
with {de,en}coders.
Currently every app maker who needs it must copy&paste it from web,
while there seem not to be much deviations in implementation of this
routine for different case.
E.g. for pthreads-enabled compilations, it should be what is at bottom
of the letter.
We can include such standard implementations for major platforms
(posix, winapi), and embrace it with ifdefs. So app makers can just
av_lockmgr_register() it with functions which are already there in
Comments, and help on patch forming are appreciated.

int lockmgr(void **mutex, enum AVLockOp op)
    int r;
    switch (op) {
        case AV_LOCK_CREATE:
                pthread_mutex_t *mtx_ptr;
                mtx_ptr = calloc(1, sizeof(*mtx_ptr));
                if (!mtx_ptr) {
                    av_log(NULL, AV_LOG_ERROR, "mutex alloc fail\n");
                    return 1;
                r = pthread_mutex_init(mtx_ptr, NULL);
                if (r) {
                    av_log(NULL, AV_LOG_ERROR, "mutex create fail\n");
                    return 1;
                *mutex = mtx_ptr;
                return 0;

        case AV_LOCK_DESTROY:
            return 0;

        case AV_LOCK_OBTAIN:
            return pthread_mutex_lock(*mutex);

        case AV_LOCK_RELEASE:
            return pthread_mutex_unlock(*mutex);
    return 1;
Andrey Utkin

More information about the ffmpeg-devel mailing list