libavcodec/libdirac_libschro.c
6ef4ba3f
 /*
  * 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
  */
 
 /**
ba87f080
 * @file
6ef4ba3f
 * functions common to libdirac and libschroedinger
 */
 
9fa58f19
 #include "libdirac_libschro.h"
6ef4ba3f
 
 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   },
 };
 
0ebe3b8e
 unsigned int ff_dirac_schro_get_video_format_idx(AVCodecContext *avccontext)
6ef4ba3f
 {
     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]);
 
0ebe3b8e
     for (idx = 1; idx < num_formats; ++idx) {
         const FfmpegDiracSchroVideoFormatInfo *vf = &ff_dirac_schro_video_format_info[idx];
6ef4ba3f
         if (avccontext->width  == vf->width &&
0ebe3b8e
             avccontext->height == vf->height) {
6ef4ba3f
             ret_idx = idx;
             if (avccontext->time_base.den == vf->frame_rate_num &&
735a3804
                 avccontext->time_base.num == vf->frame_rate_denom)
6ef4ba3f
                 return idx;
         }
     }
     return ret_idx;
 }
 
0ebe3b8e
 void ff_dirac_schro_queue_init(FfmpegDiracSchroQueue *queue)
6ef4ba3f
 {
     queue->p_head = queue->p_tail = NULL;
0cf0e25d
     queue->size = 0;
6ef4ba3f
 }
 
0ebe3b8e
 void ff_dirac_schro_queue_free(FfmpegDiracSchroQueue *queue,
                                void (*free_func)(void *))
6ef4ba3f
 {
735a3804
     while (queue->p_head)
0ebe3b8e
         free_func(ff_dirac_schro_queue_pop(queue));
6ef4ba3f
 }
 
0ebe3b8e
 int ff_dirac_schro_queue_push_back(FfmpegDiracSchroQueue *queue, void *p_data)
6ef4ba3f
 {
0ebe3b8e
     FfmpegDiracSchroQueueElement *p_new = av_mallocz(sizeof(FfmpegDiracSchroQueueElement));
6ef4ba3f
 
7c809dc3
     if (!p_new)
6ef4ba3f
         return -1;
 
     p_new->data = p_data;
 
7c809dc3
     if (!queue->p_head)
6ef4ba3f
         queue->p_head = p_new;
     else
         queue->p_tail->next = p_new;
     queue->p_tail = p_new;
 
0cf0e25d
     ++queue->size;
6ef4ba3f
     return 0;
 }
 
0ebe3b8e
 void *ff_dirac_schro_queue_pop(FfmpegDiracSchroQueue *queue)
6ef4ba3f
 {
     FfmpegDiracSchroQueueElement *top = queue->p_head;
 
7c809dc3
     if (top) {
6ef4ba3f
         void *data = top->data;
         queue->p_head = queue->p_head->next;
0cf0e25d
         --queue->size;
0ebe3b8e
         av_freep(&top);
6ef4ba3f
         return data;
     }
 
     return NULL;
 }