mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
avcodec: move leb reading functions to its own header
Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
parent
db6e360afb
commit
fa469545ba
@ -30,6 +30,7 @@
|
||||
|
||||
#include "av1.h"
|
||||
#include "get_bits.h"
|
||||
#include "leb.h"
|
||||
|
||||
// OBU header fields + max leb128 length
|
||||
#define MAX_OBU_HEADER_SIZE (2 + 8)
|
||||
@ -88,19 +89,6 @@ int ff_av1_packet_split(AV1Packet *pkt, const uint8_t *buf, int length,
|
||||
*/
|
||||
void ff_av1_packet_uninit(AV1Packet *pkt);
|
||||
|
||||
static inline int64_t leb128(GetBitContext *gb) {
|
||||
int64_t ret = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
int byte = get_bits(gb, 8);
|
||||
ret |= (int64_t)(byte & 0x7f) << (i * 7);
|
||||
if (!(byte & 0x80))
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline int parse_obu_header(const uint8_t *buf, int buf_size,
|
||||
int64_t *obu_size, int *start_pos, int *type,
|
||||
int *temporal_id, int *spatial_id)
|
||||
@ -129,7 +117,7 @@ static inline int parse_obu_header(const uint8_t *buf, int buf_size,
|
||||
*temporal_id = *spatial_id = 0;
|
||||
}
|
||||
|
||||
*obu_size = has_size_flag ? leb128(&gb)
|
||||
*obu_size = has_size_flag ? get_leb128(&gb)
|
||||
: buf_size - 1 - extension_flag;
|
||||
|
||||
if (get_bits_left(&gb) < 0)
|
||||
|
@ -103,7 +103,6 @@
|
||||
# define bits_apply_sign bits_apply_sign_le
|
||||
# define bits_read_vlc bits_read_vlc_le
|
||||
# define bits_read_vlc_multi bits_read_vlc_multi_le
|
||||
# define bits_read_leb bits_read_leb_le
|
||||
|
||||
#elif defined(BITS_DEFAULT_BE)
|
||||
|
||||
@ -133,7 +132,6 @@
|
||||
# define bits_apply_sign bits_apply_sign_be
|
||||
# define bits_read_vlc bits_read_vlc_be
|
||||
# define bits_read_vlc_multi bits_read_vlc_multi_be
|
||||
# define bits_read_leb bits_read_leb_be
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -562,29 +562,6 @@ static inline int BS_FUNC(read_vlc_multi)(BSCTX *bc, uint8_t dst[8],
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a unsigned integer coded as a variable number of up to eight
|
||||
* little-endian bytes, where the MSB in a byte signals another byte
|
||||
* must be read.
|
||||
* Values > UINT_MAX are truncated, but all coded bits are read.
|
||||
*/
|
||||
static inline unsigned BS_FUNC(read_leb)(BSCTX *bc) {
|
||||
int more, i = 0;
|
||||
unsigned leb = 0;
|
||||
|
||||
do {
|
||||
int byte = BS_FUNC(read)(bc, 8);
|
||||
unsigned bits = byte & 0x7f;
|
||||
more = byte & 0x80;
|
||||
if (i <= 4)
|
||||
leb |= bits << (i * 7);
|
||||
if (++i == 8)
|
||||
break;
|
||||
} while (more);
|
||||
|
||||
return leb;
|
||||
}
|
||||
|
||||
#undef BSCTX
|
||||
#undef BS_FUNC
|
||||
#undef BS_JOIN3
|
||||
|
@ -68,7 +68,7 @@ static int metadata_is_global(const AV1OBU *obu)
|
||||
if (init_get_bits(&gb, obu->data, obu->size_bits) < 0)
|
||||
return 0;
|
||||
|
||||
metadata_type = leb128(&gb);
|
||||
metadata_type = get_leb(&gb);
|
||||
|
||||
return val_in_array(metadata_obu_types, FF_ARRAY_ELEMS(metadata_obu_types),
|
||||
metadata_type);
|
||||
|
@ -94,7 +94,6 @@ typedef BitstreamContext GetBitContext;
|
||||
#define align_get_bits bits_align
|
||||
#define get_vlc2 bits_read_vlc
|
||||
#define get_vlc_multi bits_read_vlc_multi
|
||||
#define get_leb bits_read_leb
|
||||
|
||||
#define init_get_bits8_le(s, buffer, byte_size) bits_init8_le((BitstreamContextLE*)s, buffer, byte_size)
|
||||
#define get_bits_le(s, n) bits_read_le((BitstreamContextLE*)s, n)
|
||||
@ -711,29 +710,6 @@ static inline int skip_1stop_8data_bits(GetBitContext *gb)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a unsigned integer coded as a variable number of up to eight
|
||||
* little-endian bytes, where the MSB in a byte signals another byte
|
||||
* must be read.
|
||||
* All coded bits are read, but values > UINT_MAX are truncated.
|
||||
*/
|
||||
static inline unsigned get_leb(GetBitContext *s) {
|
||||
int more, i = 0;
|
||||
unsigned leb = 0;
|
||||
|
||||
do {
|
||||
int byte = get_bits(s, 8);
|
||||
unsigned bits = byte & 0x7f;
|
||||
more = byte & 0x80;
|
||||
if (i <= 4)
|
||||
leb |= bits << (i * 7);
|
||||
if (++i == 8)
|
||||
break;
|
||||
} while (more);
|
||||
|
||||
return leb;
|
||||
}
|
||||
|
||||
#endif // CACHED_BITSTREAM_READER
|
||||
|
||||
#endif /* AVCODEC_GET_BITS_H */
|
||||
|
70
libavcodec/leb.h
Normal file
70
libavcodec/leb.h
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* leb128 handling implementations
|
||||
*/
|
||||
|
||||
#ifndef AVCODEC_LEB_H
|
||||
#define AVCODEC_LEB_H
|
||||
|
||||
#include "get_bits.h"
|
||||
|
||||
/**
|
||||
* Read a unsigned integer coded as a variable number of up to eight
|
||||
* little-endian bytes, where the MSB in a byte signals another byte
|
||||
* must be read.
|
||||
* All coded bits are read, but values > UINT_MAX are truncated.
|
||||
*/
|
||||
static inline unsigned get_leb(GetBitContext *s) {
|
||||
int more, i = 0;
|
||||
unsigned leb = 0;
|
||||
|
||||
do {
|
||||
int byte = get_bits(s, 8);
|
||||
unsigned bits = byte & 0x7f;
|
||||
more = byte & 0x80;
|
||||
if (i <= 4)
|
||||
leb |= bits << (i * 7);
|
||||
if (++i == 8)
|
||||
break;
|
||||
} while (more);
|
||||
|
||||
return leb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a unsigned integer coded as a variable number of up to eight
|
||||
* little-endian bytes, where the MSB in a byte signals another byte
|
||||
* must be read.
|
||||
*/
|
||||
static inline int64_t get_leb128(GetBitContext *gb) {
|
||||
int64_t ret = 0;
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
int byte = get_bits(gb, 8);
|
||||
ret |= (int64_t)(byte & 0x7f) << (i * 7);
|
||||
if (!(byte & 0x80))
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* AVCODEC_LEB_H */
|
@ -325,7 +325,7 @@ static int read_obu_with_size(const uint8_t *buf, int buf_size, int64_t *obu_siz
|
||||
skip_bits(&gb, 3); // extension_header_reserved_3bits
|
||||
}
|
||||
|
||||
*obu_size = leb128(&gb);
|
||||
*obu_size = get_leb128(&gb);
|
||||
if (*obu_size > INT_MAX)
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "libavutil/log.h"
|
||||
#include "libavcodec/get_bits.h"
|
||||
#include "libavcodec/flac.h"
|
||||
#include "libavcodec/leb.h"
|
||||
#include "libavcodec/mpeg4audio.h"
|
||||
#include "libavcodec/put_bits.h"
|
||||
#include "avio_internal.h"
|
||||
|
Loading…
Reference in New Issue
Block a user