/* * Copyright (c) 2016, Alliance for Open Media. All rights reserved. * * This source code is subject to the terms of the BSD 2 Clause License and * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License * was not distributed with this source code in the LICENSE file, you can * obtain it at www.aomedia.org/license/software. If the Alliance for Open * Media Patent License 1.0 was not distributed with this source code in the * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
// TODO(jkoleszar): Maybe replace this with struct aom_image int aom_free_frame_buffer(YV12_BUFFER_CONFIG *ybf) { if (ybf) { if (ybf->buffer_alloc_sz > 0) {
aom_free(ybf->buffer_alloc);
} #if CONFIG_AV1_ENCODER && !CONFIG_REALTIME_ONLY if (ybf->y_pyramid) {
aom_free_pyramid(ybf->y_pyramid);
} if (ybf->corners) {
av1_free_corner_list(ybf->corners);
} #endif// CONFIG_AV1_ENCODER && !CONFIG_REALTIME_ONLY
aom_remove_metadata_from_frame_buffer(ybf); /* buffer_alloc isn't accessed by most functions. Rather y_buffer, u_buffer and v_buffer point to buffer_alloc and are used. Clear out
all of this so that a freed pointer isn't inadvertently used */
memset(ybf, 0, sizeof(YV12_BUFFER_CONFIG)); return 0;
}
return AOM_CODEC_MEM_ERROR;
}
staticint realloc_frame_buffer_aligned(
YV12_BUFFER_CONFIG *ybf, int width, int height, int ss_x, int ss_y, int use_highbitdepth, int border, int byte_alignment,
aom_codec_frame_buffer_t *fb, aom_get_frame_buffer_cb_fn_t cb, void *cb_priv, constint y_stride, const uint64_t yplane_size, const uint64_t uvplane_size, constint aligned_width, constint aligned_height, constint uv_width, constint uv_height, constint uv_stride, constint uv_border_w, constint uv_border_h, bool alloc_pyramid, int alloc_y_plane_only) { if (ybf) { constint aom_byte_align = (byte_alignment == 0) ? 1 : byte_alignment; const uint64_t frame_size =
(1 + use_highbitdepth) * (yplane_size + 2 * uvplane_size);
uint8_t *buf = NULL;
#if CONFIG_REALTIME_ONLY || !CONFIG_AV1_ENCODER // We should only need an 8-bit version of the source frame if we are // encoding in non-realtime mode
(void)alloc_pyramid;
assert(!alloc_pyramid); #endif// CONFIG_REALTIME_ONLY || !CONFIG_AV1_ENCODER
#ifdefined AOM_MAX_ALLOCABLE_MEMORY // The size of ybf->buffer_alloc.
uint64_t alloc_size = frame_size; #if CONFIG_AV1_ENCODER && !CONFIG_REALTIME_ONLY // The size of ybf->y_pyramid if (alloc_pyramid) {
alloc_size += aom_get_pyramid_alloc_size(width, height, use_highbitdepth);
alloc_size += av1_get_corner_list_size();
} #endif// CONFIG_AV1_ENCODER && !CONFIG_REALTIME_ONLY // The decoder may allocate REF_FRAMES frame buffers in the frame buffer // pool. Bound the total amount of allocated memory as if these REF_FRAMES // frame buffers were allocated in a single allocation. if (alloc_size > AOM_MAX_ALLOCABLE_MEMORY / REF_FRAMES) return AOM_CODEC_MEM_ERROR; #endif
#ifdefined(__has_feature) #if __has_feature(memory_sanitizer) // This memset is needed for fixing the issue of using uninitialized // value in msan test. It will cause a perf loss, so only do this for // msan test.
memset(ybf->buffer_alloc, 0, (size_t)frame_size); #endif #endif
} elseif (frame_size > ybf->buffer_alloc_sz) { // Allocation to hold larger frame, or first allocation.
aom_free(ybf->buffer_alloc);
ybf->buffer_alloc = NULL;
ybf->buffer_alloc_sz = 0;
if (frame_size != (size_t)frame_size) return AOM_CODEC_MEM_ERROR;
ybf->buffer_alloc = (uint8_t *)aom_memalign(32, (size_t)frame_size); if (!ybf->buffer_alloc) return AOM_CODEC_MEM_ERROR;
ybf->buffer_alloc_sz = (size_t)frame_size;
// This memset is needed for fixing valgrind error from C loop filter // due to access uninitialized memory in frame border. It could be // removed if border is totally removed.
memset(ybf->buffer_alloc, 0, ybf->buffer_alloc_sz);
}
#if CONFIG_AV1_ENCODER && !CONFIG_REALTIME_ONLY if (ybf->y_pyramid) {
aom_free_pyramid(ybf->y_pyramid);
ybf->y_pyramid = NULL;
} if (ybf->corners) {
av1_free_corner_list(ybf->corners);
ybf->corners = NULL;
} if (alloc_pyramid) {
ybf->y_pyramid = aom_alloc_pyramid(width, height, use_highbitdepth); if (!ybf->y_pyramid) return AOM_CODEC_MEM_ERROR;
ybf->corners = av1_alloc_corner_list(); if (!ybf->corners) return AOM_CODEC_MEM_ERROR;
} #endif// CONFIG_AV1_ENCODER && !CONFIG_REALTIME_ONLY
ybf->corrupted = 0; /* assume not corrupted by errors */ return 0;
} return AOM_CODEC_MEM_ERROR;
}
staticint calc_stride_and_planesize( constint ss_x, constint ss_y, constint aligned_width, constint aligned_height, constint border, constint byte_alignment, int alloc_y_plane_only, int *y_stride, int *uv_stride,
uint64_t *yplane_size, uint64_t *uvplane_size, constint uv_height) { /* Only support allocating buffers that have a border that's a multiple * of 32. The border restriction is required to get 16-byte alignment of * the start of the chroma rows without introducing an arbitrary gap * between planes, which would break the semantics of things like
* aom_img_set_rect(). */ if (border & 0x1f) return AOM_CODEC_MEM_ERROR;
*y_stride = aom_calc_y_stride(aligned_width, border);
*yplane_size =
(aligned_height + 2 * border) * (uint64_t)(*y_stride) + byte_alignment;
int aom_alloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, int width, int height, int ss_x, int ss_y, int use_highbitdepth, int border, int byte_alignment, bool alloc_pyramid, int alloc_y_plane_only) { if (ybf) {
aom_free_frame_buffer(ybf); return aom_realloc_frame_buffer(
ybf, width, height, ss_x, ss_y, use_highbitdepth, border,
byte_alignment, NULL, NULL, NULL, alloc_pyramid, alloc_y_plane_only);
} return AOM_CODEC_MEM_ERROR;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.