Reduces differences with libav.
James Almer authored on 2017/05/06 07:26:56... | ... |
@@ -49,49 +49,6 @@ typedef struct HEVCParserContext { |
49 | 49 |
int pocTid0; |
50 | 50 |
} HEVCParserContext; |
51 | 51 |
|
52 |
-/** |
|
53 |
- * Find the end of the current frame in the bitstream. |
|
54 |
- * @return the position of the first byte of the next frame, or END_NOT_FOUND |
|
55 |
- */ |
|
56 |
-static int hevc_find_frame_end(AVCodecParserContext *s, const uint8_t *buf, |
|
57 |
- int buf_size) |
|
58 |
-{ |
|
59 |
- int i; |
|
60 |
- ParseContext *pc = s->priv_data; |
|
61 |
- |
|
62 |
- for (i = 0; i < buf_size; i++) { |
|
63 |
- int nut; |
|
64 |
- |
|
65 |
- pc->state64 = (pc->state64 << 8) | buf[i]; |
|
66 |
- |
|
67 |
- if (((pc->state64 >> 3 * 8) & 0xFFFFFF) != START_CODE) |
|
68 |
- continue; |
|
69 |
- |
|
70 |
- nut = (pc->state64 >> 2 * 8 + 1) & 0x3F; |
|
71 |
- // Beginning of access unit |
|
72 |
- if ((nut >= HEVC_NAL_VPS && nut <= HEVC_NAL_AUD) || nut == HEVC_NAL_SEI_PREFIX || |
|
73 |
- (nut >= 41 && nut <= 44) || (nut >= 48 && nut <= 55)) { |
|
74 |
- if (pc->frame_start_found) { |
|
75 |
- pc->frame_start_found = 0; |
|
76 |
- return i - 5; |
|
77 |
- } |
|
78 |
- } else if (nut <= HEVC_NAL_RASL_R || |
|
79 |
- (nut >= HEVC_NAL_BLA_W_LP && nut <= HEVC_NAL_CRA_NUT)) { |
|
80 |
- int first_slice_segment_in_pic_flag = buf[i] >> 7; |
|
81 |
- if (first_slice_segment_in_pic_flag) { |
|
82 |
- if (!pc->frame_start_found) { |
|
83 |
- pc->frame_start_found = 1; |
|
84 |
- } else { // First slice of next frame found |
|
85 |
- pc->frame_start_found = 0; |
|
86 |
- return i - 5; |
|
87 |
- } |
|
88 |
- } |
|
89 |
- } |
|
90 |
- } |
|
91 |
- |
|
92 |
- return END_NOT_FOUND; |
|
93 |
-} |
|
94 |
- |
|
95 | 52 |
static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal, |
96 | 53 |
AVCodecContext *avctx) |
97 | 54 |
{ |
... | ... |
@@ -289,6 +246,50 @@ static inline int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf, |
289 | 289 |
return -1; |
290 | 290 |
} |
291 | 291 |
|
292 |
+/** |
|
293 |
+ * Find the end of the current frame in the bitstream. |
|
294 |
+ * @return the position of the first byte of the next frame, or END_NOT_FOUND |
|
295 |
+ */ |
|
296 |
+static int hevc_find_frame_end(AVCodecParserContext *s, const uint8_t *buf, |
|
297 |
+ int buf_size) |
|
298 |
+{ |
|
299 |
+ HEVCParserContext *ctx = s->priv_data; |
|
300 |
+ ParseContext *pc = &ctx->pc; |
|
301 |
+ int i; |
|
302 |
+ |
|
303 |
+ for (i = 0; i < buf_size; i++) { |
|
304 |
+ int nut; |
|
305 |
+ |
|
306 |
+ pc->state64 = (pc->state64 << 8) | buf[i]; |
|
307 |
+ |
|
308 |
+ if (((pc->state64 >> 3 * 8) & 0xFFFFFF) != START_CODE) |
|
309 |
+ continue; |
|
310 |
+ |
|
311 |
+ nut = (pc->state64 >> 2 * 8 + 1) & 0x3F; |
|
312 |
+ // Beginning of access unit |
|
313 |
+ if ((nut >= HEVC_NAL_VPS && nut <= HEVC_NAL_AUD) || nut == HEVC_NAL_SEI_PREFIX || |
|
314 |
+ (nut >= 41 && nut <= 44) || (nut >= 48 && nut <= 55)) { |
|
315 |
+ if (pc->frame_start_found) { |
|
316 |
+ pc->frame_start_found = 0; |
|
317 |
+ return i - 5; |
|
318 |
+ } |
|
319 |
+ } else if (nut <= HEVC_NAL_RASL_R || |
|
320 |
+ (nut >= HEVC_NAL_BLA_W_LP && nut <= HEVC_NAL_CRA_NUT)) { |
|
321 |
+ int first_slice_segment_in_pic_flag = buf[i] >> 7; |
|
322 |
+ if (first_slice_segment_in_pic_flag) { |
|
323 |
+ if (!pc->frame_start_found) { |
|
324 |
+ pc->frame_start_found = 1; |
|
325 |
+ } else { // First slice of next frame found |
|
326 |
+ pc->frame_start_found = 0; |
|
327 |
+ return i - 5; |
|
328 |
+ } |
|
329 |
+ } |
|
330 |
+ } |
|
331 |
+ } |
|
332 |
+ |
|
333 |
+ return END_NOT_FOUND; |
|
334 |
+} |
|
335 |
+ |
|
292 | 336 |
static int hevc_parse(AVCodecParserContext *s, |
293 | 337 |
AVCodecContext *avctx, |
294 | 338 |
const uint8_t **poutbuf, int *poutbuf_size, |