2016-03-21 06:26:42 +00:00
|
|
|
/*
|
|
|
|
* H.264/HEVC common parsing code
|
|
|
|
*
|
2016-04-26 12:38:45 +00:00
|
|
|
* This file is part of FFmpeg.
|
2016-03-21 06:26:42 +00:00
|
|
|
*
|
2016-04-26 12:38:45 +00:00
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2016-03-21 06:26:42 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2016-04-26 12:38:45 +00:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2016-03-21 06:26:42 +00:00
|
|
|
* 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
|
2016-04-26 12:38:45 +00:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2016-03-21 06:26:42 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef AVCODEC_H2645_PARSE_H
|
|
|
|
#define AVCODEC_H2645_PARSE_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "avcodec.h"
|
|
|
|
#include "get_bits.h"
|
|
|
|
|
2016-08-18 18:41:31 +00:00
|
|
|
#define MAX_MBPAIR_SIZE (256*1024) // a tighter bound could be calculated if someone cares about a few bytes
|
|
|
|
|
2016-03-21 06:26:42 +00:00
|
|
|
typedef struct H2645NAL {
|
|
|
|
uint8_t *rbsp_buffer;
|
|
|
|
int rbsp_buffer_size;
|
|
|
|
|
|
|
|
int size;
|
|
|
|
const uint8_t *data;
|
|
|
|
|
2016-03-21 11:42:12 +00:00
|
|
|
/**
|
|
|
|
* Size, in bits, of just the data, excluding the stop bit and any trailing
|
|
|
|
* padding. I.e. what HEVC calls SODB.
|
|
|
|
*/
|
|
|
|
int size_bits;
|
|
|
|
|
2016-03-21 06:26:42 +00:00
|
|
|
int raw_size;
|
|
|
|
const uint8_t *raw_data;
|
|
|
|
|
|
|
|
GetBitContext gb;
|
|
|
|
|
2016-03-21 08:00:40 +00:00
|
|
|
/**
|
|
|
|
* NAL unit type
|
|
|
|
*/
|
2016-03-21 06:26:42 +00:00
|
|
|
int type;
|
2016-03-21 08:00:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* HEVC only, nuh_temporal_id_plus_1 - 1
|
|
|
|
*/
|
2016-03-21 06:26:42 +00:00
|
|
|
int temporal_id;
|
2016-04-26 12:38:45 +00:00
|
|
|
|
|
|
|
int skipped_bytes;
|
|
|
|
int skipped_bytes_pos_size;
|
|
|
|
int *skipped_bytes_pos;
|
2016-03-21 08:00:40 +00:00
|
|
|
/**
|
2016-04-27 17:45:23 +00:00
|
|
|
* H.264 only, nal_ref_idc
|
2016-03-21 08:00:40 +00:00
|
|
|
*/
|
|
|
|
int ref_idc;
|
2016-03-21 06:26:42 +00:00
|
|
|
} H2645NAL;
|
|
|
|
|
|
|
|
/* an input packet split into unescaped NAL units */
|
|
|
|
typedef struct H2645Packet {
|
|
|
|
H2645NAL *nals;
|
|
|
|
int nb_nals;
|
|
|
|
int nals_allocated;
|
|
|
|
} H2645Packet;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extract the raw (unescaped) bitstream.
|
|
|
|
*/
|
|
|
|
int ff_h2645_extract_rbsp(const uint8_t *src, int length,
|
2016-08-18 18:41:31 +00:00
|
|
|
H2645NAL *nal, int small_padding);
|
2016-03-21 06:26:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Split an input packet into NAL units.
|
|
|
|
*/
|
|
|
|
int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length,
|
2016-03-21 08:00:40 +00:00
|
|
|
void *logctx, int is_nalff, int nal_length_size,
|
2016-08-18 18:41:31 +00:00
|
|
|
enum AVCodecID codec_id, int small_padding);
|
2016-03-21 06:26:42 +00:00
|
|
|
|
2016-03-21 06:33:25 +00:00
|
|
|
/**
|
|
|
|
* Free all the allocated memory in the packet.
|
|
|
|
*/
|
|
|
|
void ff_h2645_packet_uninit(H2645Packet *pkt);
|
|
|
|
|
2016-08-19 22:36:38 +00:00
|
|
|
static inline int get_nalsize(int nal_length_size, const uint8_t *buf,
|
|
|
|
int buf_size, int *buf_index, void *logctx)
|
|
|
|
{
|
|
|
|
int i, nalsize = 0;
|
|
|
|
|
|
|
|
if (*buf_index >= buf_size - nal_length_size) {
|
|
|
|
// the end of the buffer is reached, refill it
|
|
|
|
return AVERROR(EAGAIN);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < nal_length_size; i++)
|
|
|
|
nalsize = ((unsigned)nalsize << 8) | buf[(*buf_index)++];
|
|
|
|
if (nalsize <= 0 || nalsize > buf_size - *buf_index) {
|
|
|
|
av_log(logctx, AV_LOG_ERROR,
|
2016-11-17 14:24:25 +00:00
|
|
|
"Invalid NAL unit size (%d > %d).\n", nalsize, buf_size - *buf_index);
|
2016-08-19 22:36:38 +00:00
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
return nalsize;
|
|
|
|
}
|
|
|
|
|
2016-03-21 06:26:42 +00:00
|
|
|
#endif /* AVCODEC_H2645_PARSE_H */
|