#include "h2645_parse.h"
int ff_h2645_extract_rbsp(const uint8_t *src, int length,
- H2645NAL *nal)
+ H2645NAL *nal, int small_padding)
{
int i, si, di;
uint8_t *dst;
+ int64_t padding = small_padding ? 0 : MAX_MBPAIR_SIZE;
nal->skipped_bytes = 0;
#define STARTCODE_TEST \
}
#endif /* HAVE_FAST_UNALIGNED */
- if (i >= length - 1) { // no escaped 0
+ if (i >= length - 1 && small_padding) { // no escaped 0
nal->data =
nal->raw_data = src;
nal->size =
nal->raw_size = length;
return length;
- }
+ } else if (i > length)
+ i = length;
- av_fast_malloc(&nal->rbsp_buffer, &nal->rbsp_buffer_size,
- length + AV_INPUT_BUFFER_PADDING_SIZE);
+ av_fast_padded_malloc(&nal->rbsp_buffer, &nal->rbsp_buffer_size,
+ length + padding);
if (!nal->rbsp_buffer)
return AVERROR(ENOMEM);
int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length,
void *logctx, int is_nalff, int nal_length_size,
- enum AVCodecID codec_id)
+ enum AVCodecID codec_id, int small_padding)
{
int consumed, ret = 0;
const uint8_t *next_avc = is_nalff ? buf : buf + length;
int extract_length = 0;
int skip_trailing_zeros = 1;
- if (buf >= next_avc) {
- int i;
- for (i = 0; i < nal_length_size; i++)
- extract_length = (extract_length << 8) | buf[i];
+ if (buf == next_avc) {
+ int i = 0;
+ extract_length = get_nalsize(nal_length_size,
+ buf, length, &i, logctx);
+ if (extract_length < 0)
+ return extract_length;
+
buf += nal_length_size;
length -= nal_length_size;
- if (extract_length > length) {
- av_log(logctx, AV_LOG_ERROR, "Invalid NAL unit size.\n");
- return AVERROR_INVALIDDATA;
- }
next_avc = buf + extract_length;
} else {
+ if (buf > next_avc)
+ av_log(logctx, AV_LOG_WARNING, "Exceeded next NALFF position, re-syncing.\n");
+
/* search start code */
while (buf[0] != 0 || buf[1] != 0 || buf[2] != 1) {
++buf;
buf += 3;
length -= 3;
- extract_length = length;
+ extract_length = FFMIN(length, next_avc - buf);
if (buf >= next_avc) {
/* skip to the start of the next NAL */
}
nal = &pkt->nals[pkt->nb_nals];
- consumed = ff_h2645_extract_rbsp(buf, extract_length, nal);
+ consumed = ff_h2645_extract_rbsp(buf, extract_length, nal, small_padding);
if (consumed < 0)
return consumed;