libdirac_libschro.c 3.39 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * Copyright (c) 2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com >
 *
 * This file is part of FFmpeg.
 *
 * FFmpeg is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * FFmpeg is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with FFmpeg; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

/**
22
* @file libavcodec/libdirac_libschro.c
23 24 25
* functions common to libdirac and libschroedinger
*/

26
#include "libdirac_libschro.h"
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61

static const FfmpegDiracSchroVideoFormatInfo ff_dirac_schro_video_format_info[] = {
    { 640,  480,  24000, 1001},
    { 176,  120,  15000, 1001},
    { 176,  144,  25,    2   },
    { 352,  240,  15000, 1001},
    { 352,  288,  25,    2   },
    { 704,  480,  15000, 1001},
    { 704,  576,  25,    2   },
    { 720,  480,  30000, 1001},
    { 720,  576,  25,    1   },
    { 1280, 720,  60000, 1001},
    { 1280, 720,  50,    1   },
    { 1920, 1080, 30000, 1001},
    { 1920, 1080, 25,    1   },
    { 1920, 1080, 60000, 1001},
    { 1920, 1080, 50,    1   },
    { 2048, 1080, 24,    1   },
    { 4096, 2160, 24,    1   },
};

unsigned int ff_dirac_schro_get_video_format_idx (AVCodecContext *avccontext)
{
    unsigned int ret_idx = 0;
    unsigned int idx;
    unsigned int num_formats = sizeof(ff_dirac_schro_video_format_info) /
                               sizeof(ff_dirac_schro_video_format_info[0]);

    for (idx = 1 ; idx < num_formats; ++idx ) {
        const FfmpegDiracSchroVideoFormatInfo *vf =
                                        &ff_dirac_schro_video_format_info[idx];
        if (avccontext->width  == vf->width &&
            avccontext->height == vf->height){
            ret_idx = idx;
            if (avccontext->time_base.den == vf->frame_rate_num &&
62
                avccontext->time_base.num == vf->frame_rate_denom)
63 64 65 66 67 68 69 70 71
                return idx;
        }
    }
    return ret_idx;
}

void ff_dirac_schro_queue_init (FfmpegDiracSchroQueue *queue)
{
    queue->p_head = queue->p_tail = NULL;
72
    queue->size = 0;
73 74 75 76 77
}

void ff_dirac_schro_queue_free (FfmpegDiracSchroQueue *queue,
                                void (*free_func)(void *))
{
78
    while (queue->p_head)
79 80 81 82 83 84 85 86
        free_func( ff_dirac_schro_queue_pop(queue) );
}

int ff_dirac_schro_queue_push_back (FfmpegDiracSchroQueue *queue, void *p_data)
{
    FfmpegDiracSchroQueueElement *p_new =
                             av_mallocz(sizeof(FfmpegDiracSchroQueueElement));

87
    if (!p_new)
88 89 90 91
        return -1;

    p_new->data = p_data;

92
    if (!queue->p_head)
93 94 95 96 97
        queue->p_head = p_new;
    else
        queue->p_tail->next = p_new;
    queue->p_tail = p_new;

98
    ++queue->size;
99 100 101 102 103 104 105
    return 0;
}

void *ff_dirac_schro_queue_pop (FfmpegDiracSchroQueue *queue)
{
    FfmpegDiracSchroQueueElement *top = queue->p_head;

106
    if (top) {
107 108
        void *data = top->data;
        queue->p_head = queue->p_head->next;
109
        --queue->size;
110 111 112 113 114 115
        av_freep (&top);
        return data;
    }

    return NULL;
}