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.

83 lines
2.2KB

  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include <limits.h>
  19. #include <stddef.h>
  20. #include <stdint.h>
  21. #include "buffer.h"
  22. #include "common.h"
  23. #include "frame.h"
  24. #include "mem.h"
  25. #include "video_enc_params.h"
  26. AVVideoEncParams *av_video_enc_params_alloc(enum AVVideoEncParamsType type,
  27. unsigned int nb_blocks, size_t *out_size)
  28. {
  29. AVVideoEncParams *par;
  30. size_t size;
  31. size = sizeof(*par);
  32. if (nb_blocks > (SIZE_MAX - size) / sizeof(AVVideoBlockParams))
  33. return NULL;
  34. size += sizeof(AVVideoBlockParams) * nb_blocks;
  35. par = av_mallocz(size);
  36. if (!par)
  37. return NULL;
  38. par->type = type;
  39. par->nb_blocks = nb_blocks;
  40. par->block_size = sizeof(AVVideoBlockParams);
  41. par->blocks_offset = sizeof(*par);
  42. if (out_size)
  43. *out_size = size;
  44. return par;
  45. }
  46. AVVideoEncParams*
  47. av_video_enc_params_create_side_data(AVFrame *frame, enum AVVideoEncParamsType type,
  48. unsigned int nb_blocks)
  49. {
  50. AVBufferRef *buf;
  51. AVVideoEncParams *par;
  52. size_t size;
  53. par = av_video_enc_params_alloc(type, nb_blocks, &size);
  54. if (!par)
  55. return NULL;
  56. if (size > INT_MAX) {
  57. av_free(par);
  58. return NULL;
  59. }
  60. buf = av_buffer_create((uint8_t *)par, size, NULL, NULL, 0);
  61. if (!buf) {
  62. av_freep(&par);
  63. return NULL;
  64. }
  65. if (!av_frame_new_side_data_from_buf(frame, AV_FRAME_DATA_VIDEO_ENC_PARAMS, buf)) {
  66. av_buffer_unref(&buf);
  67. return NULL;
  68. }
  69. return par;
  70. }