| 144 | } |
| 145 | |
| 146 | static int get_audio_buffer(AVFrame *frame, int align) |
| 147 | { |
| 148 | int planar = av_sample_fmt_is_planar(frame->format); |
| 149 | int channels, planes; |
| 150 | size_t size; |
| 151 | int ret; |
| 152 | |
| 153 | channels = frame->ch_layout.nb_channels; |
| 154 | planes = planar ? channels : 1; |
| 155 | if (!frame->linesize[0]) { |
| 156 | ret = av_samples_get_buffer_size(&frame->linesize[0], channels, |
| 157 | frame->nb_samples, frame->format, |
| 158 | align); |
| 159 | if (ret < 0) |
| 160 | return ret; |
| 161 | } |
| 162 | |
| 163 | if (align <= 0) |
| 164 | align = ALIGN; |
| 165 | |
| 166 | if (planes > AV_NUM_DATA_POINTERS) { |
| 167 | frame->extended_data = av_calloc(planes, |
| 168 | sizeof(*frame->extended_data)); |
| 169 | frame->extended_buf = av_calloc(planes - AV_NUM_DATA_POINTERS, |
| 170 | sizeof(*frame->extended_buf)); |
| 171 | if (!frame->extended_data || !frame->extended_buf) { |
| 172 | av_freep(&frame->extended_data); |
| 173 | av_freep(&frame->extended_buf); |
| 174 | return AVERROR(ENOMEM); |
| 175 | } |
| 176 | frame->nb_extended_buf = planes - AV_NUM_DATA_POINTERS; |
| 177 | } else |
| 178 | frame->extended_data = frame->data; |
| 179 | |
| 180 | if (frame->linesize[0] > SIZE_MAX - align) |
| 181 | return AVERROR(EINVAL); |
| 182 | size = frame->linesize[0] + (size_t)align; |
| 183 | |
| 184 | for (int i = 0; i < FFMIN(planes, AV_NUM_DATA_POINTERS); i++) { |
| 185 | frame->buf[i] = av_buffer_alloc(size); |
| 186 | if (!frame->buf[i]) { |
| 187 | av_frame_unref(frame); |
| 188 | return AVERROR(ENOMEM); |
| 189 | } |
| 190 | frame->extended_data[i] = frame->data[i] = |
| 191 | (uint8_t *)FFALIGN((uintptr_t)frame->buf[i]->data, align); |
| 192 | } |
| 193 | for (int i = 0; i < planes - AV_NUM_DATA_POINTERS; i++) { |
| 194 | frame->extended_buf[i] = av_buffer_alloc(size); |
| 195 | if (!frame->extended_buf[i]) { |
| 196 | av_frame_unref(frame); |
| 197 | return AVERROR(ENOMEM); |
| 198 | } |
| 199 | frame->extended_data[i + AV_NUM_DATA_POINTERS] = |
| 200 | (uint8_t *)FFALIGN((uintptr_t)frame->extended_buf[i]->data, align); |
| 201 | } |
| 202 | return 0; |
| 203 |
no test coverage detected