Mercurial > libavcodec.hg
comparison h264.c @ 8996:e65778184ded libavcodec
Make the following H264 functions available to the parser:
ff_h264_decode_sei, ff_h264_decode_seq_parameter_set,
ff_h264_decode_picture_parameter_set, ff_h264_decode_nal,
ff_h264_decode_rbsp_trailing
Patch by Ivan Schreter, schreter gmx net
author | cehoyos |
---|---|
date | Sat, 21 Feb 2009 19:54:14 +0000 |
parents | ca768cb2bfb6 |
children | aae80543bc6e |
comparison
equal
deleted
inserted
replaced
8995:231e8535e00e | 8996:e65778184ded |
---|---|
1357 direct_table[1+1*h->b8_stride] = IS_DIRECT(h->sub_mb_type[3]) ? 1 : 0; | 1357 direct_table[1+1*h->b8_stride] = IS_DIRECT(h->sub_mb_type[3]) ? 1 : 0; |
1358 } | 1358 } |
1359 } | 1359 } |
1360 } | 1360 } |
1361 | 1361 |
1362 /** | 1362 const uint8_t *ff_h264_decode_nal(H264Context *h, const uint8_t *src, int *dst_length, int *consumed, int length){ |
1363 * Decodes a network abstraction layer unit. | |
1364 * @param consumed is the number of bytes used as input | |
1365 * @param length is the length of the array | |
1366 * @param dst_length is the number of decoded bytes FIXME here or a decode rbsp tailing? | |
1367 * @returns decoded bytes, might be src+1 if no escapes | |
1368 */ | |
1369 static const uint8_t *decode_nal(H264Context *h, const uint8_t *src, int *dst_length, int *consumed, int length){ | |
1370 int i, si, di; | 1363 int i, si, di; |
1371 uint8_t *dst; | 1364 uint8_t *dst; |
1372 int bufidx; | 1365 int bufidx; |
1373 | 1366 |
1374 // src[0]&0x80; //forbidden bit | 1367 // src[0]&0x80; //forbidden bit |
1454 *consumed= si + 1;//+1 for the header | 1447 *consumed= si + 1;//+1 for the header |
1455 //FIXME store exact number of bits in the getbitcontext (it is needed for decoding) | 1448 //FIXME store exact number of bits in the getbitcontext (it is needed for decoding) |
1456 return dst; | 1449 return dst; |
1457 } | 1450 } |
1458 | 1451 |
1459 /** | 1452 int ff_h264_decode_rbsp_trailing(H264Context *h, const uint8_t *src){ |
1460 * identifies the exact end of the bitstream | |
1461 * @return the length of the trailing, or 0 if damaged | |
1462 */ | |
1463 static int decode_rbsp_trailing(H264Context *h, const uint8_t *src){ | |
1464 int v= *src; | 1453 int v= *src; |
1465 int r; | 1454 int r; |
1466 | 1455 |
1467 tprintf(h->s.avctx, "rbsp trailing %X\n", v); | 1456 tprintf(h->s.avctx, "rbsp trailing %X\n", v); |
1468 | 1457 |
6895 | 6884 |
6896 h->sei_buffering_period_present = 1; | 6885 h->sei_buffering_period_present = 1; |
6897 return 0; | 6886 return 0; |
6898 } | 6887 } |
6899 | 6888 |
6900 static int decode_sei(H264Context *h){ | 6889 int ff_h264_decode_sei(H264Context *h){ |
6901 MpegEncContext * const s = &h->s; | 6890 MpegEncContext * const s = &h->s; |
6902 | 6891 |
6903 while(get_bits_count(&s->gb) + 16 < s->gb.size_in_bits){ | 6892 while(get_bits_count(&s->gb) + 16 < s->gb.size_in_bits){ |
6904 int size, type; | 6893 int size, type; |
6905 | 6894 |
7089 decode_scaling_list(h,scaling_matrix8[1],64,default_scaling8[1],fallback[3]); // Inter, Y | 7078 decode_scaling_list(h,scaling_matrix8[1],64,default_scaling8[1],fallback[3]); // Inter, Y |
7090 } | 7079 } |
7091 } | 7080 } |
7092 } | 7081 } |
7093 | 7082 |
7094 static inline int decode_seq_parameter_set(H264Context *h){ | 7083 int ff_h264_decode_seq_parameter_set(H264Context *h){ |
7095 MpegEncContext * const s = &h->s; | 7084 MpegEncContext * const s = &h->s; |
7096 int profile_idc, level_idc; | 7085 int profile_idc, level_idc; |
7097 unsigned int sps_id; | 7086 unsigned int sps_id; |
7098 int i; | 7087 int i; |
7099 SPS *sps; | 7088 SPS *sps; |
7236 int i; | 7225 int i; |
7237 for(i = 0; i < 52; i++) | 7226 for(i = 0; i < 52; i++) |
7238 pps->chroma_qp_table[t][i] = chroma_qp[av_clip(i + index, 0, 51)]; | 7227 pps->chroma_qp_table[t][i] = chroma_qp[av_clip(i + index, 0, 51)]; |
7239 } | 7228 } |
7240 | 7229 |
7241 static inline int decode_picture_parameter_set(H264Context *h, int bit_length){ | 7230 int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length){ |
7242 MpegEncContext * const s = &h->s; | 7231 MpegEncContext * const s = &h->s; |
7243 unsigned int pps_id= get_ue_golomb(&s->gb); | 7232 unsigned int pps_id= get_ue_golomb(&s->gb); |
7244 PPS *pps; | 7233 PPS *pps; |
7245 | 7234 |
7246 if(pps_id >= MAX_PPS_COUNT) { | 7235 if(pps_id >= MAX_PPS_COUNT) { |
7447 buf_index+=3; | 7436 buf_index+=3; |
7448 } | 7437 } |
7449 | 7438 |
7450 hx = h->thread_context[context_count]; | 7439 hx = h->thread_context[context_count]; |
7451 | 7440 |
7452 ptr= decode_nal(hx, buf + buf_index, &dst_length, &consumed, h->is_avc ? nalsize : buf_size - buf_index); | 7441 ptr= ff_h264_decode_nal(hx, buf + buf_index, &dst_length, &consumed, h->is_avc ? nalsize : buf_size - buf_index); |
7453 if (ptr==NULL || dst_length < 0){ | 7442 if (ptr==NULL || dst_length < 0){ |
7454 return -1; | 7443 return -1; |
7455 } | 7444 } |
7456 while(ptr[dst_length - 1] == 0 && dst_length > 0) | 7445 while(ptr[dst_length - 1] == 0 && dst_length > 0) |
7457 dst_length--; | 7446 dst_length--; |
7458 bit_length= !dst_length ? 0 : (8*dst_length - decode_rbsp_trailing(h, ptr + dst_length - 1)); | 7447 bit_length= !dst_length ? 0 : (8*dst_length - ff_h264_decode_rbsp_trailing(h, ptr + dst_length - 1)); |
7459 | 7448 |
7460 if(s->avctx->debug&FF_DEBUG_STARTCODE){ | 7449 if(s->avctx->debug&FF_DEBUG_STARTCODE){ |
7461 av_log(h->s.avctx, AV_LOG_DEBUG, "NAL %d at %d/%d length %d\n", hx->nal_unit_type, buf_index, buf_size, dst_length); | 7450 av_log(h->s.avctx, AV_LOG_DEBUG, "NAL %d at %d/%d length %d\n", hx->nal_unit_type, buf_index, buf_size, dst_length); |
7462 } | 7451 } |
7463 | 7452 |
7535 && avctx->skip_frame < AVDISCARD_ALL) | 7524 && avctx->skip_frame < AVDISCARD_ALL) |
7536 context_count++; | 7525 context_count++; |
7537 break; | 7526 break; |
7538 case NAL_SEI: | 7527 case NAL_SEI: |
7539 init_get_bits(&s->gb, ptr, bit_length); | 7528 init_get_bits(&s->gb, ptr, bit_length); |
7540 decode_sei(h); | 7529 ff_h264_decode_sei(h); |
7541 break; | 7530 break; |
7542 case NAL_SPS: | 7531 case NAL_SPS: |
7543 init_get_bits(&s->gb, ptr, bit_length); | 7532 init_get_bits(&s->gb, ptr, bit_length); |
7544 decode_seq_parameter_set(h); | 7533 ff_h264_decode_seq_parameter_set(h); |
7545 | 7534 |
7546 if(s->flags& CODEC_FLAG_LOW_DELAY) | 7535 if(s->flags& CODEC_FLAG_LOW_DELAY) |
7547 s->low_delay=1; | 7536 s->low_delay=1; |
7548 | 7537 |
7549 if(avctx->has_b_frames < 2) | 7538 if(avctx->has_b_frames < 2) |
7550 avctx->has_b_frames= !s->low_delay; | 7539 avctx->has_b_frames= !s->low_delay; |
7551 break; | 7540 break; |
7552 case NAL_PPS: | 7541 case NAL_PPS: |
7553 init_get_bits(&s->gb, ptr, bit_length); | 7542 init_get_bits(&s->gb, ptr, bit_length); |
7554 | 7543 |
7555 decode_picture_parameter_set(h, bit_length); | 7544 ff_h264_decode_picture_parameter_set(h, bit_length); |
7556 | 7545 |
7557 break; | 7546 break; |
7558 case NAL_AUD: | 7547 case NAL_AUD: |
7559 case NAL_END_SEQUENCE: | 7548 case NAL_END_SEQUENCE: |
7560 case NAL_END_STREAM: | 7549 case NAL_END_STREAM: |
8037 if(nal_length<0){ | 8026 if(nal_length<0){ |
8038 printf("encoding failed\n"); | 8027 printf("encoding failed\n"); |
8039 return -1; | 8028 return -1; |
8040 } | 8029 } |
8041 | 8030 |
8042 out= decode_nal(&h, nal, &out_length, &consumed, nal_length); | 8031 out= ff_h264_decode_nal(&h, nal, &out_length, &consumed, nal_length); |
8043 | 8032 |
8044 STOP_TIMER("NAL") | 8033 STOP_TIMER("NAL") |
8045 | 8034 |
8046 if(out_length != COUNT){ | 8035 if(out_length != COUNT){ |
8047 printf("incorrect length %d %d\n", out_length, COUNT); | 8036 printf("incorrect length %d %d\n", out_length, COUNT); |