This gets rid of the duplicate, limited parser.
Reviewed-by: Hendrik Leppkes <h.leppkes@gmail.com>
Reviewed-by: Aaron Levinson <alevinsn@aracnet.com>
Signed-off-by: James Almer <jamrial@gmail.com>
... | ... |
@@ -952,7 +952,7 @@ OBJS-$(CONFIG_GSM_PARSER) += gsm_parser.o |
952 | 952 |
OBJS-$(CONFIG_H261_PARSER) += h261_parser.o |
953 | 953 |
OBJS-$(CONFIG_H263_PARSER) += h263_parser.o |
954 | 954 |
OBJS-$(CONFIG_H264_PARSER) += h264_parser.o h264_sei.o h264data.o |
955 |
-OBJS-$(CONFIG_HEVC_PARSER) += hevc_parser.o hevc_data.o |
|
955 |
+OBJS-$(CONFIG_HEVC_PARSER) += hevc_parser.o hevc_data.o hevc_sei.o |
|
956 | 956 |
OBJS-$(CONFIG_MJPEG_PARSER) += mjpeg_parser.o |
957 | 957 |
OBJS-$(CONFIG_MLP_PARSER) += mlp_parser.o mlp.o |
958 | 958 |
OBJS-$(CONFIG_MPEG4VIDEO_PARSER) += mpeg4video_parser.o h263.o \ |
... | ... |
@@ -24,114 +24,31 @@ |
24 | 24 |
|
25 | 25 |
#include "golomb.h" |
26 | 26 |
#include "hevc.h" |
27 |
-#include "hevcdec.h" |
|
27 |
+#include "hevc_ps.h" |
|
28 |
+#include "hevc_sei.h" |
|
28 | 29 |
#include "h2645_parse.h" |
30 |
+#include "internal.h" |
|
29 | 31 |
#include "parser.h" |
30 | 32 |
|
31 | 33 |
#define START_CODE 0x000001 ///< start_code_prefix_one_3bytes |
32 | 34 |
|
33 | 35 |
#define IS_IRAP_NAL(nal) (nal->type >= 16 && nal->type <= 23) |
34 |
- |
|
35 |
-#define ADVANCED_PARSER CONFIG_HEVC_DECODER |
|
36 |
+#define IS_IDR_NAL(nal) (nal->type == HEVC_NAL_IDR_W_RADL || nal->type == HEVC_NAL_IDR_N_LP) |
|
36 | 37 |
|
37 | 38 |
typedef struct HEVCParserContext { |
38 | 39 |
ParseContext pc; |
39 | 40 |
|
40 | 41 |
H2645Packet pkt; |
41 | 42 |
HEVCParamSets ps; |
43 |
+ HEVCSEIContext sei; |
|
44 |
+ SliceHeader sh; |
|
42 | 45 |
|
43 | 46 |
int parsed_extradata; |
44 | 47 |
|
45 |
-#if ADVANCED_PARSER |
|
46 |
- HEVCContext h; |
|
47 |
-#endif |
|
48 |
+ int poc; |
|
49 |
+ int pocTid0; |
|
48 | 50 |
} HEVCParserContext; |
49 | 51 |
|
50 |
-#if !ADVANCED_PARSER |
|
51 |
-static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal, |
|
52 |
- AVCodecContext *avctx) |
|
53 |
-{ |
|
54 |
- HEVCParserContext *ctx = s->priv_data; |
|
55 |
- GetBitContext *gb = &nal->gb; |
|
56 |
- |
|
57 |
- HEVCPPS *pps; |
|
58 |
- HEVCSPS *sps; |
|
59 |
- unsigned int pps_id; |
|
60 |
- |
|
61 |
- get_bits1(gb); // first slice in pic |
|
62 |
- if (IS_IRAP_NAL(nal)) |
|
63 |
- get_bits1(gb); // no output of prior pics |
|
64 |
- |
|
65 |
- pps_id = get_ue_golomb_long(gb); |
|
66 |
- if (pps_id >= HEVC_MAX_PPS_COUNT || !ctx->ps.pps_list[pps_id]) { |
|
67 |
- av_log(avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id); |
|
68 |
- return AVERROR_INVALIDDATA; |
|
69 |
- } |
|
70 |
- pps = (HEVCPPS*)ctx->ps.pps_list[pps_id]->data; |
|
71 |
- sps = (HEVCSPS*)ctx->ps.sps_list[pps->sps_id]->data; |
|
72 |
- |
|
73 |
- /* export the stream parameters */ |
|
74 |
- s->coded_width = sps->width; |
|
75 |
- s->coded_height = sps->height; |
|
76 |
- s->width = sps->output_width; |
|
77 |
- s->height = sps->output_height; |
|
78 |
- s->format = sps->pix_fmt; |
|
79 |
- avctx->profile = sps->ptl.general_ptl.profile_idc; |
|
80 |
- avctx->level = sps->ptl.general_ptl.level_idc; |
|
81 |
- |
|
82 |
- /* ignore the rest for now*/ |
|
83 |
- |
|
84 |
- return 0; |
|
85 |
-} |
|
86 |
- |
|
87 |
-static int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf, |
|
88 |
- int buf_size, AVCodecContext *avctx) |
|
89 |
-{ |
|
90 |
- HEVCParserContext *ctx = s->priv_data; |
|
91 |
- int ret, i; |
|
92 |
- |
|
93 |
- ret = ff_h2645_packet_split(&ctx->pkt, buf, buf_size, avctx, 0, 0, |
|
94 |
- AV_CODEC_ID_HEVC, 1); |
|
95 |
- if (ret < 0) |
|
96 |
- return ret; |
|
97 |
- |
|
98 |
- for (i = 0; i < ctx->pkt.nb_nals; i++) { |
|
99 |
- H2645NAL *nal = &ctx->pkt.nals[i]; |
|
100 |
- |
|
101 |
- /* ignore everything except parameter sets and VCL NALUs */ |
|
102 |
- switch (nal->type) { |
|
103 |
- case HEVC_NAL_VPS: ff_hevc_decode_nal_vps(&nal->gb, avctx, &ctx->ps); break; |
|
104 |
- case HEVC_NAL_SPS: ff_hevc_decode_nal_sps(&nal->gb, avctx, &ctx->ps, 1); break; |
|
105 |
- case HEVC_NAL_PPS: ff_hevc_decode_nal_pps(&nal->gb, avctx, &ctx->ps); break; |
|
106 |
- case HEVC_NAL_TRAIL_R: |
|
107 |
- case HEVC_NAL_TRAIL_N: |
|
108 |
- case HEVC_NAL_TSA_N: |
|
109 |
- case HEVC_NAL_TSA_R: |
|
110 |
- case HEVC_NAL_STSA_N: |
|
111 |
- case HEVC_NAL_STSA_R: |
|
112 |
- case HEVC_NAL_BLA_W_LP: |
|
113 |
- case HEVC_NAL_BLA_W_RADL: |
|
114 |
- case HEVC_NAL_BLA_N_LP: |
|
115 |
- case HEVC_NAL_IDR_W_RADL: |
|
116 |
- case HEVC_NAL_IDR_N_LP: |
|
117 |
- case HEVC_NAL_CRA_NUT: |
|
118 |
- case HEVC_NAL_RADL_N: |
|
119 |
- case HEVC_NAL_RADL_R: |
|
120 |
- case HEVC_NAL_RASL_N: |
|
121 |
- case HEVC_NAL_RASL_R: |
|
122 |
- if (buf == avctx->extradata) { |
|
123 |
- av_log(avctx, AV_LOG_ERROR, "Invalid NAL unit: %d\n", nal->type); |
|
124 |
- return AVERROR_INVALIDDATA; |
|
125 |
- } |
|
126 |
- hevc_parse_slice_header(s, nal, avctx); |
|
127 |
- break; |
|
128 |
- } |
|
129 |
- } |
|
130 |
- |
|
131 |
- return 0; |
|
132 |
-} |
|
133 |
-#endif |
|
134 |
- |
|
135 | 52 |
/** |
136 | 53 |
* Find the end of the current frame in the bitstream. |
137 | 54 |
* @return the position of the first byte of the next frame, or END_NOT_FOUND |
... | ... |
@@ -175,7 +92,6 @@ static int hevc_find_frame_end(AVCodecParserContext *s, const uint8_t *buf, |
175 | 175 |
return END_NOT_FOUND; |
176 | 176 |
} |
177 | 177 |
|
178 |
-#if ADVANCED_PARSER |
|
179 | 178 |
/** |
180 | 179 |
* Parse NAL units of found picture and decode some basic information. |
181 | 180 |
* |
... | ... |
@@ -188,28 +104,17 @@ static inline int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf, |
188 | 188 |
int buf_size, AVCodecContext *avctx) |
189 | 189 |
{ |
190 | 190 |
HEVCParserContext *ctx = s->priv_data; |
191 |
- HEVCContext *h = &ctx->h; |
|
192 |
- GetBitContext *gb; |
|
193 |
- SliceHeader *sh = &h->sh; |
|
194 |
- HEVCParamSets *ps = &h->ps; |
|
195 |
- HEVCSEIContext *sei = &h->sei; |
|
191 |
+ SliceHeader *sh = &ctx->sh; |
|
192 |
+ HEVCParamSets *ps = &ctx->ps; |
|
193 |
+ HEVCSEIContext *sei = &ctx->sei; |
|
196 | 194 |
int is_global = buf == avctx->extradata; |
197 | 195 |
int i, ret; |
198 | 196 |
|
199 |
- if (!h->HEVClc) |
|
200 |
- h->HEVClc = av_mallocz(sizeof(HEVCLocalContext)); |
|
201 |
- if (!h->HEVClc) |
|
202 |
- return AVERROR(ENOMEM); |
|
203 |
- |
|
204 |
- gb = &h->HEVClc->gb; |
|
205 |
- |
|
206 | 197 |
/* set some sane default values */ |
207 | 198 |
s->pict_type = AV_PICTURE_TYPE_I; |
208 | 199 |
s->key_frame = 0; |
209 | 200 |
s->picture_structure = AV_PICTURE_STRUCTURE_UNKNOWN; |
210 | 201 |
|
211 |
- h->avctx = avctx; |
|
212 |
- |
|
213 | 202 |
ff_hevc_reset_sei(sei); |
214 | 203 |
|
215 | 204 |
ret = ff_h2645_packet_split(&ctx->pkt, buf, buf_size, avctx, 0, 0, |
... | ... |
@@ -219,13 +124,11 @@ static inline int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf, |
219 | 219 |
|
220 | 220 |
for (i = 0; i < ctx->pkt.nb_nals; i++) { |
221 | 221 |
H2645NAL *nal = &ctx->pkt.nals[i]; |
222 |
+ GetBitContext *gb = &nal->gb; |
|
222 | 223 |
int num = 0, den = 0; |
223 | 224 |
|
224 |
- h->nal_unit_type = nal->type; |
|
225 |
- h->temporal_id = nal->temporal_id; |
|
226 |
- *gb = nal->gb; |
|
227 | 225 |
|
228 |
- switch (h->nal_unit_type) { |
|
226 |
+ switch (nal->type) { |
|
229 | 227 |
case HEVC_NAL_VPS: |
230 | 228 |
ff_hevc_decode_nal_vps(gb, avctx, ps); |
231 | 229 |
break; |
... | ... |
@@ -237,7 +140,7 @@ static inline int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf, |
237 | 237 |
break; |
238 | 238 |
case HEVC_NAL_SEI_PREFIX: |
239 | 239 |
case HEVC_NAL_SEI_SUFFIX: |
240 |
- ff_hevc_decode_nal_sei(gb, avctx, sei, ps, h->nal_unit_type); |
|
240 |
+ ff_hevc_decode_nal_sei(gb, avctx, sei, ps, nal->type); |
|
241 | 241 |
break; |
242 | 242 |
case HEVC_NAL_TRAIL_N: |
243 | 243 |
case HEVC_NAL_TRAIL_R: |
... | ... |
@@ -257,15 +160,15 @@ static inline int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf, |
257 | 257 |
case HEVC_NAL_CRA_NUT: |
258 | 258 |
|
259 | 259 |
if (is_global) { |
260 |
- av_log(avctx, AV_LOG_ERROR, "Invalid NAL unit: %d\n", h->nal_unit_type); |
|
260 |
+ av_log(avctx, AV_LOG_ERROR, "Invalid NAL unit: %d\n", nal->type); |
|
261 | 261 |
return AVERROR_INVALIDDATA; |
262 | 262 |
} |
263 | 263 |
|
264 | 264 |
sh->first_slice_in_pic_flag = get_bits1(gb); |
265 |
- s->picture_structure = h->sei.picture_timing.picture_struct; |
|
266 |
- s->field_order = h->sei.picture_timing.picture_struct; |
|
265 |
+ s->picture_structure = sei->picture_timing.picture_struct; |
|
266 |
+ s->field_order = sei->picture_timing.picture_struct; |
|
267 | 267 |
|
268 |
- if (IS_IRAP(h)) { |
|
268 |
+ if (IS_IRAP_NAL(nal)) { |
|
269 | 269 |
s->key_frame = 1; |
270 | 270 |
sh->no_output_of_prior_pics_flag = get_bits1(gb); |
271 | 271 |
} |
... | ... |
@@ -348,31 +251,30 @@ static inline int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf, |
348 | 348 |
if (ps->sps->separate_colour_plane_flag) |
349 | 349 |
sh->colour_plane_id = get_bits(gb, 2); |
350 | 350 |
|
351 |
- if (!IS_IDR(h)) { |
|
351 |
+ if (!IS_IDR_NAL(nal)) { |
|
352 | 352 |
sh->pic_order_cnt_lsb = get_bits(gb, ps->sps->log2_max_poc_lsb); |
353 |
- s->output_picture_number = h->poc = ff_hevc_compute_poc(h->ps.sps, h->pocTid0, sh->pic_order_cnt_lsb, h->nal_unit_type); |
|
353 |
+ s->output_picture_number = ctx->poc = ff_hevc_compute_poc(ps->sps, ctx->pocTid0, sh->pic_order_cnt_lsb, nal->type); |
|
354 | 354 |
} else |
355 |
- s->output_picture_number = h->poc = 0; |
|
356 |
- |
|
357 |
- if (h->temporal_id == 0 && |
|
358 |
- h->nal_unit_type != HEVC_NAL_TRAIL_N && |
|
359 |
- h->nal_unit_type != HEVC_NAL_TSA_N && |
|
360 |
- h->nal_unit_type != HEVC_NAL_STSA_N && |
|
361 |
- h->nal_unit_type != HEVC_NAL_RADL_N && |
|
362 |
- h->nal_unit_type != HEVC_NAL_RASL_N && |
|
363 |
- h->nal_unit_type != HEVC_NAL_RADL_R && |
|
364 |
- h->nal_unit_type != HEVC_NAL_RASL_R) |
|
365 |
- h->pocTid0 = h->poc; |
|
355 |
+ s->output_picture_number = ctx->poc = 0; |
|
356 |
+ |
|
357 |
+ if (nal->temporal_id == 0 && |
|
358 |
+ nal->type != HEVC_NAL_TRAIL_N && |
|
359 |
+ nal->type != HEVC_NAL_TSA_N && |
|
360 |
+ nal->type != HEVC_NAL_STSA_N && |
|
361 |
+ nal->type != HEVC_NAL_RADL_N && |
|
362 |
+ nal->type != HEVC_NAL_RASL_N && |
|
363 |
+ nal->type != HEVC_NAL_RADL_R && |
|
364 |
+ nal->type != HEVC_NAL_RASL_R) |
|
365 |
+ ctx->pocTid0 = ctx->poc; |
|
366 | 366 |
|
367 | 367 |
return 0; /* no need to evaluate the rest */ |
368 | 368 |
} |
369 | 369 |
} |
370 | 370 |
/* didn't find a picture! */ |
371 | 371 |
if (!is_global) |
372 |
- av_log(h->avctx, AV_LOG_ERROR, "missing picture in access unit\n"); |
|
372 |
+ av_log(avctx, AV_LOG_ERROR, "missing picture in access unit\n"); |
|
373 | 373 |
return -1; |
374 | 374 |
} |
375 |
-#endif |
|
376 | 375 |
|
377 | 376 |
static int hevc_parse(AVCodecParserContext *s, |
378 | 377 |
AVCodecContext *avctx, |
... | ... |
@@ -444,21 +346,6 @@ static void hevc_parser_close(AVCodecParserContext *s) |
444 | 444 |
HEVCParserContext *ctx = s->priv_data; |
445 | 445 |
int i; |
446 | 446 |
|
447 |
-#if ADVANCED_PARSER |
|
448 |
- HEVCContext *h = &ctx->h; |
|
449 |
- |
|
450 |
- for (i = 0; i < FF_ARRAY_ELEMS(h->ps.vps_list); i++) |
|
451 |
- av_buffer_unref(&h->ps.vps_list[i]); |
|
452 |
- for (i = 0; i < FF_ARRAY_ELEMS(h->ps.sps_list); i++) |
|
453 |
- av_buffer_unref(&h->ps.sps_list[i]); |
|
454 |
- for (i = 0; i < FF_ARRAY_ELEMS(h->ps.pps_list); i++) |
|
455 |
- av_buffer_unref(&h->ps.pps_list[i]); |
|
456 |
- |
|
457 |
- h->ps.sps = NULL; |
|
458 |
- |
|
459 |
- av_freep(&h->HEVClc); |
|
460 |
-#endif |
|
461 |
- |
|
462 | 447 |
for (i = 0; i < FF_ARRAY_ELEMS(ctx->ps.vps_list); i++) |
463 | 448 |
av_buffer_unref(&ctx->ps.vps_list[i]); |
464 | 449 |
for (i = 0; i < FF_ARRAY_ELEMS(ctx->ps.sps_list); i++) |