libdirac_libschro.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (c) 2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com >
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /**
  21. * @file libavcodec/libdirac_libschro.c
  22. * functions common to libdirac and libschroedinger
  23. */
  24. #include "libdirac_libschro.h"
  25. static const FfmpegDiracSchroVideoFormatInfo ff_dirac_schro_video_format_info[] = {
  26. { 640, 480, 24000, 1001},
  27. { 176, 120, 15000, 1001},
  28. { 176, 144, 25, 2 },
  29. { 352, 240, 15000, 1001},
  30. { 352, 288, 25, 2 },
  31. { 704, 480, 15000, 1001},
  32. { 704, 576, 25, 2 },
  33. { 720, 480, 30000, 1001},
  34. { 720, 576, 25, 1 },
  35. { 1280, 720, 60000, 1001},
  36. { 1280, 720, 50, 1 },
  37. { 1920, 1080, 30000, 1001},
  38. { 1920, 1080, 25, 1 },
  39. { 1920, 1080, 60000, 1001},
  40. { 1920, 1080, 50, 1 },
  41. { 2048, 1080, 24, 1 },
  42. { 4096, 2160, 24, 1 },
  43. };
  44. unsigned int ff_dirac_schro_get_video_format_idx (AVCodecContext *avccontext)
  45. {
  46. unsigned int ret_idx = 0;
  47. unsigned int idx;
  48. unsigned int num_formats = sizeof(ff_dirac_schro_video_format_info) /
  49. sizeof(ff_dirac_schro_video_format_info[0]);
  50. for (idx = 1 ; idx < num_formats; ++idx ) {
  51. const FfmpegDiracSchroVideoFormatInfo *vf =
  52. &ff_dirac_schro_video_format_info[idx];
  53. if (avccontext->width == vf->width &&
  54. avccontext->height == vf->height){
  55. ret_idx = idx;
  56. if (avccontext->time_base.den == vf->frame_rate_num &&
  57. avccontext->time_base.num == vf->frame_rate_denom) {
  58. return idx;
  59. }
  60. }
  61. }
  62. return ret_idx;
  63. }
  64. void ff_dirac_schro_queue_init (FfmpegDiracSchroQueue *queue)
  65. {
  66. queue->p_head = queue->p_tail = NULL;
  67. queue->size = 0;
  68. }
  69. void ff_dirac_schro_queue_free (FfmpegDiracSchroQueue *queue,
  70. void (*free_func)(void *))
  71. {
  72. while (queue->p_head) {
  73. free_func( ff_dirac_schro_queue_pop(queue) );
  74. }
  75. }
  76. int ff_dirac_schro_queue_push_back (FfmpegDiracSchroQueue *queue, void *p_data)
  77. {
  78. FfmpegDiracSchroQueueElement *p_new =
  79. av_mallocz(sizeof(FfmpegDiracSchroQueueElement));
  80. if (p_new == NULL)
  81. return -1;
  82. p_new->data = p_data;
  83. if (queue->p_head == NULL)
  84. queue->p_head = p_new;
  85. else
  86. queue->p_tail->next = p_new;
  87. queue->p_tail = p_new;
  88. ++queue->size;
  89. return 0;
  90. }
  91. void *ff_dirac_schro_queue_pop (FfmpegDiracSchroQueue *queue)
  92. {
  93. FfmpegDiracSchroQueueElement *top = queue->p_head;
  94. if (top != NULL) {
  95. void *data = top->data;
  96. queue->p_head = queue->p_head->next;
  97. --queue->size;
  98. av_freep (&top);
  99. return data;
  100. }
  101. return NULL;
  102. }