| 1745 | } |
| 1746 | |
| 1747 | int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags) |
| 1748 | { |
| 1749 | const FFHWAccel *hwaccel = ffhwaccel(avctx->hwaccel); |
| 1750 | int override_dimensions = 1; |
| 1751 | int ret; |
| 1752 | |
| 1753 | av_assert0(ff_codec_is_decoder(avctx->codec)); |
| 1754 | |
| 1755 | if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) { |
| 1756 | if ((unsigned)avctx->width > INT_MAX - STRIDE_ALIGN || |
| 1757 | (ret = av_image_check_size2(FFALIGN(avctx->width, STRIDE_ALIGN), avctx->height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx)) < 0 || avctx->pix_fmt<0) { |
| 1758 | av_log(avctx, AV_LOG_ERROR, "video_get_buffer: image parameters invalid\n"); |
| 1759 | ret = AVERROR(EINVAL); |
| 1760 | goto fail; |
| 1761 | } |
| 1762 | |
| 1763 | if (frame->width <= 0 || frame->height <= 0) { |
| 1764 | frame->width = FFMAX(avctx->width, AV_CEIL_RSHIFT(avctx->coded_width, avctx->lowres)); |
| 1765 | frame->height = FFMAX(avctx->height, AV_CEIL_RSHIFT(avctx->coded_height, avctx->lowres)); |
| 1766 | override_dimensions = 0; |
| 1767 | } |
| 1768 | |
| 1769 | if (frame->data[0] || frame->data[1] || frame->data[2] || frame->data[3]) { |
| 1770 | av_log(avctx, AV_LOG_ERROR, "pic->data[*]!=NULL in get_buffer_internal\n"); |
| 1771 | ret = AVERROR(EINVAL); |
| 1772 | goto fail; |
| 1773 | } |
| 1774 | } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) { |
| 1775 | if (frame->nb_samples * (int64_t)avctx->ch_layout.nb_channels > avctx->max_samples) { |
| 1776 | av_log(avctx, AV_LOG_ERROR, "samples per frame %d, exceeds max_samples %"PRId64"\n", frame->nb_samples, avctx->max_samples); |
| 1777 | ret = AVERROR(EINVAL); |
| 1778 | goto fail; |
| 1779 | } |
| 1780 | } |
| 1781 | ret = ff_decode_frame_props(avctx, frame); |
| 1782 | if (ret < 0) |
| 1783 | goto fail; |
| 1784 | |
| 1785 | if (hwaccel) { |
| 1786 | if (hwaccel->alloc_frame) { |
| 1787 | ret = hwaccel->alloc_frame(avctx, frame); |
| 1788 | goto end; |
| 1789 | } |
| 1790 | } else { |
| 1791 | avctx->sw_pix_fmt = avctx->pix_fmt; |
| 1792 | ret = update_frame_props(avctx, frame); |
| 1793 | if (ret < 0) |
| 1794 | goto fail; |
| 1795 | } |
| 1796 | |
| 1797 | ret = avctx->get_buffer2(avctx, frame, flags); |
| 1798 | if (ret < 0) |
| 1799 | goto fail; |
| 1800 | |
| 1801 | validate_avframe_allocation(avctx, frame); |
| 1802 | |
| 1803 | ret = ff_attach_decode_data(frame); |
| 1804 | if (ret < 0) |
no test coverage detected