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.

133 lines
4.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. * function definitions common to libschroedingerdec.c and libschroedingerenc.c
  23. */
  24. #include "libdirac_libschro.h"
  25. #include "libschroedinger.h"
  26. /**
  27. * Schroedinger video preset table. Ensure that this tables matches up correctly
  28. * with the ff_dirac_schro_video_format_info table in libdirac_libschro.c.
  29. */
  30. static const SchroVideoFormatEnum ff_schro_video_formats[]={
  31. SCHRO_VIDEO_FORMAT_CUSTOM ,
  32. SCHRO_VIDEO_FORMAT_QSIF ,
  33. SCHRO_VIDEO_FORMAT_QCIF ,
  34. SCHRO_VIDEO_FORMAT_SIF ,
  35. SCHRO_VIDEO_FORMAT_CIF ,
  36. SCHRO_VIDEO_FORMAT_4SIF ,
  37. SCHRO_VIDEO_FORMAT_4CIF ,
  38. SCHRO_VIDEO_FORMAT_SD480I_60 ,
  39. SCHRO_VIDEO_FORMAT_SD576I_50 ,
  40. SCHRO_VIDEO_FORMAT_HD720P_60 ,
  41. SCHRO_VIDEO_FORMAT_HD720P_50 ,
  42. SCHRO_VIDEO_FORMAT_HD1080I_60 ,
  43. SCHRO_VIDEO_FORMAT_HD1080I_50 ,
  44. SCHRO_VIDEO_FORMAT_HD1080P_60 ,
  45. SCHRO_VIDEO_FORMAT_HD1080P_50 ,
  46. SCHRO_VIDEO_FORMAT_DC2K_24 ,
  47. SCHRO_VIDEO_FORMAT_DC4K_24 ,
  48. };
  49. SchroVideoFormatEnum ff_get_schro_video_format_preset(AVCodecContext *avccontext)
  50. {
  51. unsigned int num_formats = sizeof(ff_schro_video_formats) /
  52. sizeof(ff_schro_video_formats[0]);
  53. unsigned int idx = ff_dirac_schro_get_video_format_idx (avccontext);
  54. return (idx < num_formats) ? ff_schro_video_formats[idx] :
  55. SCHRO_VIDEO_FORMAT_CUSTOM;
  56. }
  57. int ff_get_schro_frame_format (SchroChromaFormat schro_pix_fmt,
  58. SchroFrameFormat *schro_frame_fmt)
  59. {
  60. unsigned int num_formats = sizeof(ffmpeg_schro_pixel_format_map) /
  61. sizeof(ffmpeg_schro_pixel_format_map[0]);
  62. int idx;
  63. for (idx = 0; idx < num_formats; ++idx) {
  64. if (ffmpeg_schro_pixel_format_map[idx].schro_pix_fmt == schro_pix_fmt) {
  65. *schro_frame_fmt = ffmpeg_schro_pixel_format_map[idx].schro_frame_fmt;
  66. return 0;
  67. }
  68. }
  69. return -1;
  70. }
  71. static void FreeSchroFrame(SchroFrame *frame, void *priv)
  72. {
  73. AVPicture *p_pic = priv;
  74. if (!p_pic)
  75. return;
  76. avpicture_free(p_pic);
  77. av_freep(&p_pic);
  78. }
  79. SchroFrame *ff_create_schro_frame(AVCodecContext *avccontext,
  80. SchroFrameFormat schro_frame_fmt)
  81. {
  82. AVPicture *p_pic;
  83. SchroFrame *p_frame;
  84. int y_width, uv_width;
  85. int y_height, uv_height;
  86. int i;
  87. y_width = avccontext->width;
  88. y_height = avccontext->height;
  89. uv_width = y_width >> (SCHRO_FRAME_FORMAT_H_SHIFT(schro_frame_fmt));
  90. uv_height = y_height >> (SCHRO_FRAME_FORMAT_V_SHIFT(schro_frame_fmt));
  91. p_pic = av_mallocz(sizeof(AVPicture));
  92. avpicture_alloc(p_pic, avccontext->pix_fmt, y_width, y_height);
  93. p_frame = schro_frame_new();
  94. p_frame->format = schro_frame_fmt;
  95. p_frame->width = y_width;
  96. p_frame->height = y_height;
  97. schro_frame_set_free_callback(p_frame, FreeSchroFrame, (void *)p_pic);
  98. for (i = 0; i < 3; ++i) {
  99. p_frame->components[i].width = i ? uv_width : y_width;
  100. p_frame->components[i].stride = p_pic->linesize[i];
  101. p_frame->components[i].height = i ? uv_height : y_height;
  102. p_frame->components[i].length =
  103. p_frame->components[i].stride * p_frame->components[i].height;
  104. p_frame->components[i].data = p_pic->data[i];
  105. if (i) {
  106. p_frame->components[i].v_shift =
  107. SCHRO_FRAME_FORMAT_V_SHIFT(p_frame->format);
  108. p_frame->components[i].h_shift =
  109. SCHRO_FRAME_FORMAT_H_SHIFT(p_frame->format);
  110. }
  111. }
  112. return p_frame;
  113. }