You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
3.3KB

  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
  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 = &ff_dirac_schro_video_format_info[idx];
  52. if (avccontext->width == vf->width &&
  53. avccontext->height == vf->height) {
  54. ret_idx = idx;
  55. if (avccontext->time_base.den == vf->frame_rate_num &&
  56. avccontext->time_base.num == vf->frame_rate_denom)
  57. return idx;
  58. }
  59. }
  60. return ret_idx;
  61. }
  62. void ff_dirac_schro_queue_init(FfmpegDiracSchroQueue *queue)
  63. {
  64. queue->p_head = queue->p_tail = NULL;
  65. queue->size = 0;
  66. }
  67. void ff_dirac_schro_queue_free(FfmpegDiracSchroQueue *queue,
  68. void (*free_func)(void *))
  69. {
  70. while (queue->p_head)
  71. free_func(ff_dirac_schro_queue_pop(queue));
  72. }
  73. int ff_dirac_schro_queue_push_back(FfmpegDiracSchroQueue *queue, void *p_data)
  74. {
  75. FfmpegDiracSchroQueueElement *p_new = av_mallocz(sizeof(FfmpegDiracSchroQueueElement));
  76. if (!p_new)
  77. return -1;
  78. p_new->data = p_data;
  79. if (!queue->p_head)
  80. queue->p_head = p_new;
  81. else
  82. queue->p_tail->next = p_new;
  83. queue->p_tail = p_new;
  84. ++queue->size;
  85. return 0;
  86. }
  87. void *ff_dirac_schro_queue_pop(FfmpegDiracSchroQueue *queue)
  88. {
  89. FfmpegDiracSchroQueueElement *top = queue->p_head;
  90. if (top) {
  91. void *data = top->data;
  92. queue->p_head = queue->p_head->next;
  93. --queue->size;
  94. av_freep(&top);
  95. return data;
  96. }
  97. return NULL;
  98. }