65#define MOD_NAME "[rtpdec_h264] "
109 uint8_t nal = data[0];
128 unsigned nal_count = 0;
132 while (data_len > 2) {
134 memcpy(&nal_size, data,
sizeof(uint16_t));
135 nal_size = ntohs(nal_size);
141 "STAP-A subpacket NAL type %d (nri: %d)\n",
145 if (nal_size <= data_len) {
150 assert(nal_count <
sizeof nal_sizes /
sizeof nal_sizes[0] - 1);
151 nal_sizes[nal_count++] = nal_size;
154 error_msg(
"NAL size exceeds length: %u %d\n", nal_size, data_len);
158 data_len -= nal_size;
161 error_msg(
"Consumed more bytes than we got! (%d)\n", data_len);
167 for (
int i = nal_count - 1; i >= 0; i--) {
168 int nal_size = nal_sizes[i];
189 uint8_t fu_header = *data;
190 uint8_t start_bit = fu_header >> 7;
191 uint8_t end_bit = (fu_header & 0x40) >> 6;
193 uint8_t reconstructed_nal;
198 reconstructed_nal = nal & 0xe0;
207 fu_length = data_len;
209 fu_length += data_len;
212 *total_length +=
sizeof(
start_sequence) +
sizeof(reconstructed_nal) + data_len;
215 *total_length += data_len;
219 *dst -=
sizeof(
start_sequence) +
sizeof(reconstructed_nal) + data_len;
221 memcpy(*dst +
sizeof(
start_sequence), &reconstructed_nal,
sizeof(reconstructed_nal));
222 memcpy(*dst +
sizeof(
start_sequence) +
sizeof(reconstructed_nal), data, data_len);
225 memcpy(*dst, data, data_len);
229 error_msg(
"Too short data for FU-A H264 RTP packet\n");
270 int total_length = 0;
276 for (
int pass = 0; pass < 2; pass++) {
277 unsigned char *dst = NULL;
291 while (cdata != NULL) {
294 if (!
decode_nal_unit(
frame, &total_length, pass, &dst, (uint8_t *) pckt->data, pckt->data_len)) {
310 uint32_t width, height;
312 uint8_t* rbsp_buf = (uint8_t*)malloc(data_len);
313 if (
nal_to_rbsp(data, &data_len, rbsp_buf, &data_len) < 0){
349 uint32_t width, height;
351 uint8_t* rbsp_buf = (uint8_t*)malloc(data_len);
352 if (
nal_to_rbsp(data, &data_len, rbsp_buf, &data_len) < 0){
373 debug_msg(
"\n\n[width_height_from_SDP] width: %d height: %d\n\n",width,height);
struct video_frame * frame
void vf_free(struct video_frame *buf)
Frees video_frame structure.
void vf_data_deleter(struct video_frame *buf)
struct video_frame * vf_alloc_desc_data(struct video_desc desc)
static void bs_free(bs_t *b)
static bs_t * bs_new(uint8_t *buf, size_t size)
void log_msg(int level, const char *format,...)
#define debug_msg(...)
#define debug_msg(...) log_msg(LOG_LEVEL_DEBUG, "[pid/%d +%d %s] ", getpid(), LINE,...
int nal_to_rbsp(const uint8_t *nal_buf, int *nal_size, uint8_t *rbsp_buf, int *rbsp_size)
int read_seq_parameter_set_rbsp(sps_t *sps, bs_t *b)
int width_height_from_SDP(int *widthOut, int *heightOut, unsigned char *data, int data_len)
#define H264_NAL
type was 1-23 representing H.264 NAL type
static const uint8_t start_sequence[]
static _Bool decode_nal_unit(struct video_frame *frame, int *total_length, int pass, unsigned char **dst, uint8_t *data, int data_len)
int decode_frame_h264(struct coded_data *cdata, void *decode_data)
static uint8_t process_nal(uint8_t nal, struct video_frame *frame, uint8_t *data, int data_len)
int fill_coded_frame_from_sps(struct video_frame *rx_data, unsigned char *data, int data_len)
static void write_sps_pps(struct video_frame *frame, struct decode_data_rtsp *decode_data)
struct video_frame * get_sps_pps_frame(const struct video_desc *desc, struct decode_data_rtsp *decode_data)
#define H264_NALU_HDR_GET_TYPE(nal)
#define H264_NALU_HDR_GET_NRI(nal)
const char * get_nalu_name(int type)
struct decode_data_rtsp::@46::@48 h264
struct video_frame * frame
unsigned char offset_buffer[2048]
SPS/PPS headers extracted from RTSP.
int frame_crop_right_offset
int frame_crop_left_offset
int pic_height_in_map_units_minus1
int frame_crop_top_offset
int frame_crop_bottom_offset
int pic_width_in_mbs_minus1
char * data
Raw tile data. Pointer must be at least 4B aligned.
unsigned int data_len
length of the data
void(* data_deleter)(struct video_frame *)
void(* dispose)(struct video_frame *)
Struct video_frame represents a video frame and contains video description.
struct tile tiles[FLEXIBLE_ARRAY_MEMBER]
struct video_frame_callbacks callbacks
struct tile * vf_get_tile(struct video_frame *buf, int pos)
Returns pointer to n-th tile from video frame Equivalent to &video_frame::tiles[pos].