/* * The default get_buffer2() implementation * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
typedefstruct FramePool { /** * Pools for each data plane. For audio all the planes have the same size, * so only pools[0] is used.
*/
AVBufferPool *pools[4];
/* * Pool parameters
*/ int format; int width, height; int stride_align[AV_NUM_DATA_POINTERS]; int linesize[4]; int planes; int channels; int samples;
} FramePool;
pool = av_refstruct_alloc_ext(sizeof(*pool), 0, NULL, frame_pool_free); if (!pool) return AVERROR(ENOMEM);
switch (avctx->codec_type) { case AVMEDIA_TYPE_VIDEO: { int linesize[4]; int w = frame->width; int h = frame->height; int unaligned;
ptrdiff_t linesize1[4];
size_t size[4];
do { // NOTE: do not align linesizes individually, this breaks e.g. assumptions // that linesize[0] == 2*linesize[1] in the MPEG-encoder for 4:2:2
ret = av_image_fill_linesizes(linesize, avctx->pix_fmt, w); if (ret < 0) goto fail; // increase alignment of w for next try (rhs gives the lowest bit set in w)
w += w & ~(w - 1);
unaligned = 0; for (i = 0; i < 4; i++)
unaligned |= linesize[i] % pool->stride_align[i];
} while (unaligned);
for (i = 0; i < 4; i++)
linesize1[i] = linesize[i];
ret = av_image_fill_plane_sizes(size, avctx->pix_fmt, h, linesize1); if (ret < 0) goto fail;
for (i = 0; i < 4; i++) {
pool->linesize[i] = linesize[i]; if (size[i]) { if (size[i] > INT_MAX - (16 + STRIDE_ALIGN - 1)) {
ret = AVERROR(EINVAL); goto fail;
}
pool->pools[i] = av_buffer_pool_init(size[i] + 16 + STRIDE_ALIGN - 1,
CONFIG_MEMORY_POISONING ?
NULL :
av_buffer_allocz); if (!pool->pools[i]) {
ret = AVERROR(ENOMEM); goto fail;
}
}
}
pool->format = frame->format;
pool->width = frame->width;
pool->height = frame->height;
break;
} case AVMEDIA_TYPE_AUDIO: {
ret = av_samples_get_buffer_size(&pool->linesize[0],
frame->ch_layout.nb_channels,
frame->nb_samples, frame->format, 0); if (ret < 0) goto fail;
pool->pools[0] = av_buffer_pool_init(pool->linesize[0],
CONFIG_MEMORY_POISONING ?
NULL :
av_buffer_allocz); if (!pool->pools[0]) {
ret = AVERROR(ENOMEM); goto fail;
}
int avcodec_default_get_buffer2(AVCodecContext *avctx, AVFrame *frame, int flags)
{ int ret;
if (avctx->hw_frames_ctx) {
ret = av_hwframe_get_buffer(avctx->hw_frames_ctx, frame, 0); if (ret == AVERROR(ENOMEM)) {
AVHWFramesContext *frames_ctx =
(AVHWFramesContext*)avctx->hw_frames_ctx->data; if (frames_ctx->initial_pool_size > 0 &&
!avctx->internal->warned_on_failed_allocation_from_fixed_pool) {
av_log(avctx, AV_LOG_WARNING, "Failed to allocate a %s/%s " "frame from a fixed pool of hardware frames.\n",
av_get_pix_fmt_name(frames_ctx->format),
av_get_pix_fmt_name(frames_ctx->sw_format));
av_log(avctx, AV_LOG_WARNING, "Consider setting " "extra_hw_frames to a larger value " "(currently set to %d, giving a pool size of %d).\n",
avctx->extra_hw_frames, frames_ctx->initial_pool_size);
avctx->internal->warned_on_failed_allocation_from_fixed_pool = 1;
}
}
frame->width = avctx->coded_width;
frame->height = avctx->coded_height; return ret;
}
if ((ret = update_frame_pool(avctx, frame)) < 0) return ret;
switch (avctx->codec_type) { case AVMEDIA_TYPE_VIDEO: return video_get_buffer(avctx, frame); case AVMEDIA_TYPE_AUDIO: return audio_get_buffer(avctx, frame); default: return -1;
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet)
¤
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.