-
Notifications
You must be signed in to change notification settings - Fork 4
/
nal.c
171 lines (158 loc) · 4.03 KB
/
nal.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#include <stdio.h>
#include "nal.h"
#include "sei.h"
#include "common.h"
#include "mp4tree.h"
void
mp4tree_box_mdat_hevc_nal_print(
const uint8_t * p,
size_t len,
int depth)
{
/*
* nal_unit_header( ) { Descriptor
* forbidden_zero_bit f(1)
* nal_unit_type u(6)
* nuh_layer_id u(6)
* nuh_temporal_id_plus1 u(3)
* }
*/
uint8_t type = (p[0] & 0x7e) >> 1;
uint8_t layer_id = ((p[0] & 1) << 5) | (p[1] >> 3);
uint8_t temporal_id_plus1 = p[1] & 0x3;
char * typestr = NULL;
mp4tree_parse_func print_func = NULL;
switch (type)
{
case 0:
case 1:
typestr = "SLICE non-TSA non-STSA";
break;
case 2:
case 3:
typestr = "SLICE TSA";
break;
case 8:
typestr = "SLICE RASL_N";
break;
case 9:
typestr = "SLICE RASL_R";
break;
case 19:
case 20:
typestr = "IDR";
break;
case 21:
typestr = "CRA";
break;
case 32:
typestr = "VPS";
print_func = mp4tree_hexdump;
break;
case 33:
typestr = "SPS";
print_func = mp4tree_hexdump;
break;
case 34:
typestr = "PPS";
print_func = mp4tree_hexdump;
break;
case 35:
typestr = "AUD";
print_func = mp4tree_hexdump;
break;
case 39:
typestr = "PREFIX SEI";
print_func = mp4tree_print_hevc_prefix_sei;
break;
case 40:
typestr = "SUFFIX SEI";
print_func = mp4tree_print_hevc_suffix_sei;
break;
default:
typestr = "UND";
break;
}
printf("%s nal_unit_type: %u (%s)\n", indent(depth, 0), type, typestr);
printf("%s nuh_layer_id: %u\n", indent(depth, 0), layer_id);
printf("%s nuh_temporal_id_plus1 %u\n", indent(depth, 0), temporal_id_plus1);
if (print_func)
{
print_func(p, len, depth);
}
}
void
mp4tree_sei_h264_nal_print(
const uint8_t * p,
size_t len,
int depth)
{
/*
* nal_unit( NumBytesInNALunit ) {
* forbidden_zero_bit f(1)
* nal_ref_idc u(2)
* nal_unit_type u(5)
* }
*/
const uint8_t nal_ref_idc = (p[0] >> 5) & 0x03;
const uint8_t nal_unit_type = p[0] & 0x1f;
char * typestr = NULL;
mp4tree_parse_func print_func = NULL;
switch (nal_unit_type)
{
case 1:
typestr = "Non-IDR";
break;
case 2:
typestr = "DPA";
break;
case 3:
typestr = "DPB";
break;
case 4:
typestr = "DPC";
break;
case 5:
typestr = "IDR";
break;
case 6:
typestr = "SEI";
print_func = mp4tree_print_h264_sei;
break;
case 7:
typestr = "SPS";
print_func = mp4tree_hexdump;
break;
case 8:
typestr = "PPS";
print_func = mp4tree_hexdump;
break;
case 9:
typestr = "AUD";
break;
case 10:
typestr = "End Of Sequence";
break;
case 11:
typestr = "End Of Stream";
break;
case 12:
typestr = "Filler";
break;
case 13:
typestr = "SPS Ext";
break;
case 19:
typestr = "Aux Slice";
break;
default:
typestr = "Unknown";
break;
}
printf("%s nal_ref_idc: %u\n", indent(depth, 0), nal_ref_idc);
printf("%s nal_unit_type: %u (%s)\n", indent(depth, 0), nal_unit_type, typestr);
if (print_func)
{
print_func(p, len, depth);
}
}