| Line | Branch | Exec | Source |
|---|---|---|---|
| 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 | |||
| 19 | #include <stddef.h> | ||
| 20 | #include <stdint.h> | ||
| 21 | |||
| 22 | #include "buffer.h" | ||
| 23 | #include "frame.h" | ||
| 24 | #include "mem.h" | ||
| 25 | #include "video_enc_params.h" | ||
| 26 | |||
| 27 | 33 | AVVideoEncParams *av_video_enc_params_alloc(enum AVVideoEncParamsType type, | |
| 28 | unsigned int nb_blocks, size_t *out_size) | ||
| 29 | { | ||
| 30 | struct TestStruct { | ||
| 31 | AVVideoEncParams p; | ||
| 32 | AVVideoBlockParams b; | ||
| 33 | }; | ||
| 34 | 33 | const size_t blocks_offset = offsetof(struct TestStruct, b); | |
| 35 | 33 | size_t size = blocks_offset; | |
| 36 | AVVideoEncParams *par; | ||
| 37 | |||
| 38 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
|
33 | if (nb_blocks > (SIZE_MAX - size) / sizeof(AVVideoBlockParams)) |
| 39 | ✗ | return NULL; | |
| 40 | 33 | size += sizeof(AVVideoBlockParams) * nb_blocks; | |
| 41 | |||
| 42 | 33 | par = av_mallocz(size); | |
| 43 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
|
33 | if (!par) |
| 44 | ✗ | return NULL; | |
| 45 | |||
| 46 | 33 | par->type = type; | |
| 47 | 33 | par->nb_blocks = nb_blocks; | |
| 48 | 33 | par->block_size = sizeof(AVVideoBlockParams); | |
| 49 | 33 | par->blocks_offset = blocks_offset; | |
| 50 | |||
| 51 |
2/2✓ Branch 0 taken 31 times.
✓ Branch 1 taken 2 times.
|
33 | if (out_size) |
| 52 | 31 | *out_size = size; | |
| 53 | |||
| 54 | 33 | return par; | |
| 55 | } | ||
| 56 | |||
| 57 | AVVideoEncParams* | ||
| 58 | 26 | av_video_enc_params_create_side_data(AVFrame *frame, enum AVVideoEncParamsType type, | |
| 59 | unsigned int nb_blocks) | ||
| 60 | { | ||
| 61 | AVBufferRef *buf; | ||
| 62 | AVVideoEncParams *par; | ||
| 63 | size_t size; | ||
| 64 | |||
| 65 | 26 | par = av_video_enc_params_alloc(type, nb_blocks, &size); | |
| 66 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
|
26 | if (!par) |
| 67 | ✗ | return NULL; | |
| 68 | 26 | buf = av_buffer_create((uint8_t *)par, size, NULL, NULL, 0); | |
| 69 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
|
26 | if (!buf) { |
| 70 | ✗ | av_freep(&par); | |
| 71 | ✗ | return NULL; | |
| 72 | } | ||
| 73 | |||
| 74 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 26 times.
|
26 | if (!av_frame_new_side_data_from_buf(frame, AV_FRAME_DATA_VIDEO_ENC_PARAMS, buf)) { |
| 75 | ✗ | av_buffer_unref(&buf); | |
| 76 | ✗ | return NULL; | |
| 77 | } | ||
| 78 | |||
| 79 | 26 | return par; | |
| 80 | } | ||
| 81 |