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.

80 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 / sizeof(AVVideoBlockParams) ||
  33. nb_blocks * sizeof(AVVideoBlockParams) > SIZE_MAX - size)
  34. return NULL;
  35. size += sizeof(AVVideoBlockParams) * nb_blocks;
  36. par = av_mallocz(size);
  37. if (!par)
  38. return NULL;
  39. par->type = type;
  40. par->nb_blocks = nb_blocks;
  41. par->block_size = sizeof(AVVideoBlockParams);
  42. par->blocks_offset = sizeof(*par);
  43. if (out_size)
  44. *out_size = size;
  45. return par;
  46. }
  47. AVVideoEncParams*
  48. av_video_enc_params_create_side_data(AVFrame *frame, enum AVVideoEncParamsType type,
  49. unsigned int nb_blocks)
  50. {
  51. AVBufferRef *buf;
  52. AVVideoEncParams *par;
  53. size_t size;
  54. par = av_video_enc_params_alloc(type, nb_blocks, &size);
  55. if (!par)
  56. return NULL;
  57. buf = av_buffer_create((uint8_t *)par, size, NULL, NULL, 0);
  58. if (!buf) {
  59. av_freep(&par);
  60. return NULL;
  61. }
  62. if (!av_frame_new_side_data_from_buf(frame, AV_FRAME_DATA_VIDEO_ENC_PARAMS, buf)) {
  63. av_buffer_unref(&buf);
  64. return NULL;
  65. }
  66. return par;
  67. }