2
0

alloccommon.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include "vpx_config.h"
  11. #include "alloccommon.h"
  12. #include "blockd.h"
  13. #include "vpx_mem/vpx_mem.h"
  14. #include "onyxc_int.h"
  15. #include "findnearmv.h"
  16. #include "entropymode.h"
  17. #include "systemdependent.h"
  18. void vp8_de_alloc_frame_buffers(VP8_COMMON *oci) {
  19. int i;
  20. for (i = 0; i < NUM_YV12_BUFFERS; ++i) {
  21. vp8_yv12_de_alloc_frame_buffer(&oci->yv12_fb[i]);
  22. }
  23. vp8_yv12_de_alloc_frame_buffer(&oci->temp_scale_frame);
  24. #if CONFIG_POSTPROC
  25. vp8_yv12_de_alloc_frame_buffer(&oci->post_proc_buffer);
  26. if (oci->post_proc_buffer_int_used) {
  27. vp8_yv12_de_alloc_frame_buffer(&oci->post_proc_buffer_int);
  28. }
  29. vpx_free(oci->pp_limits_buffer);
  30. oci->pp_limits_buffer = NULL;
  31. vpx_free(oci->postproc_state.generated_noise);
  32. oci->postproc_state.generated_noise = NULL;
  33. #endif
  34. vpx_free(oci->above_context);
  35. vpx_free(oci->mip);
  36. #if CONFIG_ERROR_CONCEALMENT
  37. vpx_free(oci->prev_mip);
  38. oci->prev_mip = NULL;
  39. #endif
  40. oci->above_context = NULL;
  41. oci->mip = NULL;
  42. }
  43. int vp8_alloc_frame_buffers(VP8_COMMON *oci, int width, int height) {
  44. int i;
  45. vp8_de_alloc_frame_buffers(oci);
  46. /* our internal buffers are always multiples of 16 */
  47. if ((width & 0xf) != 0) width += 16 - (width & 0xf);
  48. if ((height & 0xf) != 0) height += 16 - (height & 0xf);
  49. for (i = 0; i < NUM_YV12_BUFFERS; ++i) {
  50. oci->fb_idx_ref_cnt[i] = 0;
  51. oci->yv12_fb[i].flags = 0;
  52. if (vp8_yv12_alloc_frame_buffer(&oci->yv12_fb[i], width, height,
  53. VP8BORDERINPIXELS) < 0) {
  54. goto allocation_fail;
  55. }
  56. }
  57. oci->new_fb_idx = 0;
  58. oci->lst_fb_idx = 1;
  59. oci->gld_fb_idx = 2;
  60. oci->alt_fb_idx = 3;
  61. oci->fb_idx_ref_cnt[0] = 1;
  62. oci->fb_idx_ref_cnt[1] = 1;
  63. oci->fb_idx_ref_cnt[2] = 1;
  64. oci->fb_idx_ref_cnt[3] = 1;
  65. if (vp8_yv12_alloc_frame_buffer(&oci->temp_scale_frame, width, 16,
  66. VP8BORDERINPIXELS) < 0) {
  67. goto allocation_fail;
  68. }
  69. oci->mb_rows = height >> 4;
  70. oci->mb_cols = width >> 4;
  71. oci->MBs = oci->mb_rows * oci->mb_cols;
  72. oci->mode_info_stride = oci->mb_cols + 1;
  73. oci->mip =
  74. vpx_calloc((oci->mb_cols + 1) * (oci->mb_rows + 1), sizeof(MODE_INFO));
  75. if (!oci->mip) goto allocation_fail;
  76. oci->mi = oci->mip + oci->mode_info_stride + 1;
  77. /* Allocation of previous mode info will be done in vp8_decode_frame()
  78. * as it is a decoder only data */
  79. oci->above_context =
  80. vpx_calloc(sizeof(ENTROPY_CONTEXT_PLANES) * oci->mb_cols, 1);
  81. if (!oci->above_context) goto allocation_fail;
  82. #if CONFIG_POSTPROC
  83. if (vp8_yv12_alloc_frame_buffer(&oci->post_proc_buffer, width, height,
  84. VP8BORDERINPIXELS) < 0) {
  85. goto allocation_fail;
  86. }
  87. oci->post_proc_buffer_int_used = 0;
  88. memset(&oci->postproc_state, 0, sizeof(oci->postproc_state));
  89. memset(oci->post_proc_buffer.buffer_alloc, 128,
  90. oci->post_proc_buffer.frame_size);
  91. /* Allocate buffer to store post-processing filter coefficients.
  92. *
  93. * Note: Round up mb_cols to support SIMD reads
  94. */
  95. oci->pp_limits_buffer = vpx_memalign(16, 24 * ((oci->mb_cols + 1) & ~1));
  96. if (!oci->pp_limits_buffer) goto allocation_fail;
  97. #endif
  98. return 0;
  99. allocation_fail:
  100. vp8_de_alloc_frame_buffers(oci);
  101. return 1;
  102. }
  103. void vp8_setup_version(VP8_COMMON *cm) {
  104. switch (cm->version) {
  105. case 0:
  106. cm->no_lpf = 0;
  107. cm->filter_type = NORMAL_LOOPFILTER;
  108. cm->use_bilinear_mc_filter = 0;
  109. cm->full_pixel = 0;
  110. break;
  111. case 1:
  112. cm->no_lpf = 0;
  113. cm->filter_type = SIMPLE_LOOPFILTER;
  114. cm->use_bilinear_mc_filter = 1;
  115. cm->full_pixel = 0;
  116. break;
  117. case 2:
  118. cm->no_lpf = 1;
  119. cm->filter_type = NORMAL_LOOPFILTER;
  120. cm->use_bilinear_mc_filter = 1;
  121. cm->full_pixel = 0;
  122. break;
  123. case 3:
  124. cm->no_lpf = 1;
  125. cm->filter_type = SIMPLE_LOOPFILTER;
  126. cm->use_bilinear_mc_filter = 1;
  127. cm->full_pixel = 1;
  128. break;
  129. default:
  130. /*4,5,6,7 are reserved for future use*/
  131. cm->no_lpf = 0;
  132. cm->filter_type = NORMAL_LOOPFILTER;
  133. cm->use_bilinear_mc_filter = 0;
  134. cm->full_pixel = 0;
  135. break;
  136. }
  137. }
  138. void vp8_create_common(VP8_COMMON *oci) {
  139. vp8_machine_specific_config(oci);
  140. vp8_init_mbmode_probs(oci);
  141. vp8_default_bmode_probs(oci->fc.bmode_prob);
  142. oci->mb_no_coeff_skip = 1;
  143. oci->no_lpf = 0;
  144. oci->filter_type = NORMAL_LOOPFILTER;
  145. oci->use_bilinear_mc_filter = 0;
  146. oci->full_pixel = 0;
  147. oci->multi_token_partition = ONE_PARTITION;
  148. oci->clamp_type = RECON_CLAMP_REQUIRED;
  149. /* Initialize reference frame sign bias structure to defaults */
  150. memset(oci->ref_frame_sign_bias, 0, sizeof(oci->ref_frame_sign_bias));
  151. /* Default disable buffer to buffer copying */
  152. oci->copy_buffer_to_gf = 0;
  153. oci->copy_buffer_to_arf = 0;
  154. }
  155. void vp8_remove_common(VP8_COMMON *oci) { vp8_de_alloc_frame_buffers(oci); }