2 * This file is part of FFmpeg.
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.
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.
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
21 #include "vaapi_encode_h26x.h"
23 int ff_vaapi_encode_h26x_nal_unit_to_byte_stream(uint8_t *dst, size_t *dst_bit_len,
24 uint8_t *src, size_t src_bit_len)
28 size_t dst_len = *dst_bit_len / 8;
29 size_t src_len = (src_bit_len + 7) / 8;
30 int trailing_zeroes = src_len * 8 - src_bit_len;
32 if (dst_len < src_len + 4) {
33 // Definitely doesn't fit.
38 dst[0] = dst[1] = dst[2] = 0;
42 for (sp = 0; sp < src_len; sp++) {
51 if ((src[sp] & ~3) == 0) {
52 // emulation_prevention_three_byte
57 zero_run = src[sp] == 0;
62 *dst_bit_len = 8 * dp - trailing_zeroes;
67 return AVERROR(ENOSPC);