49 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3,
53 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,
70 static const int8_t top [12]= {-1, 0,
LEFT_DC_PRED,-1,-1,-1,-1,-1, 0};
87 static const int mask[4]={0x8000,0x2000,0x80,0x20};
151 #if HAVE_FAST_UNALIGNED
154 for(i=0; i+1<length; i+=9){
155 if(!((~
AV_RN64A(src+i) & (
AV_RN64A(src+i) - 0x0100010001000101ULL)) & 0x8000800080008080ULL))
158 for(i=0; i+1<length; i+=5){
162 if(i>0 && !src[i]) i--;
166 for(i=0; i+1<length; i+=2){
168 if(i>0 && src[i-1]==0) i--;
170 if(i+2<length && src[i+1]==0 && src[i+2]<=3){
200 dst[di++]= src[si++];
201 dst[di++]= src[si++];
202 }
else if(src[si]==0 && src[si+1]==0){
212 dst[di++]= src[si++];
215 dst[di++]= src[si++];
244 int y_offset,
int list){
246 int filter_height= (raw_my&3) ? 2 : 0;
247 int full_my= (raw_my>>2) + y_offset;
248 int top = full_my - filter_height, bottom = full_my + height + filter_height;
250 return FFMAX(abs(top), bottom);
254 int y_offset,
int list0,
int list1,
int *nrefs){
270 if (refs[0][ref_n] < 0) nrefs[0] += 1;
271 refs[0][ref_n] =
FFMAX(refs[0][ref_n], my);
282 if (refs[1][ref_n] < 0) nrefs[1] += 1;
283 refs[1][ref_n] =
FFMAX(refs[1][ref_n], my);
295 const int mb_xy= h->
mb_xy;
301 memset(refs, -1,
sizeof(refs));
324 int y_offset= (i&2)<<2;
328 IS_DIR(sub_mb_type, 0, 0),
IS_DIR(sub_mb_type, 0, 1), nrefs);
331 IS_DIR(sub_mb_type, 0, 0),
IS_DIR(sub_mb_type, 0, 1), nrefs);
333 IS_DIR(sub_mb_type, 0, 0),
IS_DIR(sub_mb_type, 0, 1), nrefs);
336 IS_DIR(sub_mb_type, 0, 0),
IS_DIR(sub_mb_type, 0, 1), nrefs);
338 IS_DIR(sub_mb_type, 0, 0),
IS_DIR(sub_mb_type, 0, 1), nrefs);
343 int sub_y_offset= y_offset + 2*(j&2);
345 IS_DIR(sub_mb_type, 0, 0),
IS_DIR(sub_mb_type, 0, 1), nrefs);
352 for(ref=0; ref<48 && nrefs[list]; ref++){
353 int row = refs[list][ref];
358 int pic_height = 16*s->
mb_height >> ref_field_picture;
387 static const int x_offset[4]={0, 1*
stride, 4*
stride, 5*stride};
388 static const int y_offset[4]={0, 2*
stride, 8*
stride, 10*stride};
391 const int offset= y_offset[i];
392 const int z0= block[offset+
stride*0] + block[offset+
stride*4];
393 const int z1= block[offset+
stride*0] - block[offset+
stride*4];
394 const int z2= block[offset+
stride*1] - block[offset+
stride*5];
395 const int z3= block[offset+
stride*1] + block[offset+
stride*5];
404 const int offset= x_offset[i];
405 const int z0= temp[4*0+i] + temp[4*2+i];
406 const int z1= temp[4*0+i] - temp[4*2+i];
407 const int z2= temp[4*1+i] - temp[4*3+i];
408 const int z3= temp[4*1+i] + temp[4*3+i];
410 block[
stride*0 +offset]= (z0 + z3)>>1;
411 block[
stride*2 +offset]= (z1 + z2)>>1;
412 block[
stride*8 +offset]= (z1 - z2)>>1;
413 block[
stride*10+offset]= (z0 - z3)>>1;
422 static void chroma_dc_dct_c(
DCTELEM *block){
424 const int xStride= 16;
427 a= block[stride*0 + xStride*0];
428 b= block[stride*0 + xStride*1];
429 c= block[stride*1 + xStride*0];
430 d= block[stride*1 + xStride*1];
437 block[stride*0 + xStride*0]= (a+c);
438 block[stride*0 + xStride*1]= (e+
b);
439 block[stride*1 + xStride*0]= (a-c);
440 block[stride*1 + xStride*1]= (e-
b);
447 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
448 int src_x_offset,
int src_y_offset,
450 int pixel_shift,
int chroma_idc)
453 const int mx= h->
mv_cache[list][
scan8[n] ][0] + src_x_offset*8;
455 const int luma_xy= (mx&3) + ((my&3)<<2);
456 int offset = ((mx>>2) << pixel_shift) + (my>>2)*h->
mb_linesize;
457 uint8_t * src_y = pic->
f.
data[0] + offset;
458 uint8_t * src_cb, * src_cr;
462 const int full_mx= mx>>2;
463 const int full_my= my>>2;
464 const int pic_width = 16*s->
mb_width;
468 if(mx&7) extra_width -= 3;
469 if(my&7) extra_height -= 3;
471 if( full_mx < 0-extra_width
472 || full_my < 0-extra_height
473 || full_mx + 16 > pic_width + extra_width
474 || full_my + 16 > pic_height + extra_height){
476 16+5, 16+5, full_mx-2, full_my-2, pic_width, pic_height);
488 if(chroma_idc == 3 ){
489 src_cb = pic->
f.
data[1] + offset;
492 16+5, 16+5, full_mx-2, full_my-2, pic_width, pic_height);
500 src_cr = pic->
f.
data[2] + offset;
503 16+5, 16+5, full_mx-2, full_my-2, pic_width, pic_height);
513 ysh = 3 - (chroma_idc == 2 );
517 emu |= (my>>3) < 0 || (my>>3) + 8 >= (pic_height>>1);
520 src_cb = pic->
f.
data[1] + ((mx >> 3) << pixel_shift) + (my >> ysh) * h->
mb_uvlinesize;
521 src_cr = pic->
f.
data[2] + ((mx >> 3) << pixel_shift) + (my >> ysh) * h->
mb_uvlinesize;
525 9, 8 * chroma_idc + 1, (mx >> 3), (my >> ysh),
526 pic_width >> 1, pic_height >> (chroma_idc == 1 ));
529 chroma_op(dest_cb, src_cb, h->
mb_uvlinesize, height >> (chroma_idc == 1 ),
530 mx&7, (my << (chroma_idc == 2 )) &7);
534 9, 8 * chroma_idc + 1, (mx >> 3), (my >> ysh),
535 pic_width >> 1, pic_height >> (chroma_idc == 1 ));
538 chroma_op(dest_cr, src_cr, h->
mb_uvlinesize, height >> (chroma_idc == 1 ),
539 mx&7, (my << (chroma_idc == 2 )) &7);
544 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
545 int x_offset,
int y_offset,
548 int list0,
int list1,
int pixel_shift,
int chroma_idc)
554 dest_y += (2*x_offset << pixel_shift) + 2*y_offset*h->
mb_linesize;
555 if (chroma_idc == 3 ) {
556 dest_cb += (2*x_offset << pixel_shift) + 2*y_offset*h->
mb_linesize;
557 dest_cr += (2*x_offset << pixel_shift) + 2*y_offset*h->
mb_linesize;
558 }
else if (chroma_idc == 2 ) {
559 dest_cb += ( x_offset << pixel_shift) + 2*y_offset*h->
mb_uvlinesize;
560 dest_cr += ( x_offset << pixel_shift) + 2*y_offset*h->
mb_uvlinesize;
562 dest_cb += ( x_offset << pixel_shift) + y_offset*h->
mb_uvlinesize;
563 dest_cr += ( x_offset << pixel_shift) + y_offset*h->
mb_uvlinesize;
565 x_offset += 8*s->
mb_x;
571 dest_y, dest_cb, dest_cr, x_offset, y_offset,
572 qpix_op, chroma_op, pixel_shift, chroma_idc);
575 chroma_op= chroma_avg;
581 dest_y, dest_cb, dest_cr, x_offset, y_offset,
582 qpix_op, chroma_op, pixel_shift, chroma_idc);
588 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
589 int x_offset,
int y_offset,
593 int list0,
int list1,
int pixel_shift,
int chroma_idc){
597 dest_y += (2*x_offset << pixel_shift) + 2*y_offset*h->
mb_linesize;
598 if (chroma_idc == 3 ) {
600 chroma_weight_avg = luma_weight_avg;
601 chroma_weight_op = luma_weight_op;
602 dest_cb += (2*x_offset << pixel_shift) + 2*y_offset*h->
mb_linesize;
603 dest_cr += (2*x_offset << pixel_shift) + 2*y_offset*h->
mb_linesize;
604 }
else if (chroma_idc == 2 ) {
606 dest_cb += ( x_offset << pixel_shift) + 2*y_offset*h->
mb_uvlinesize;
607 dest_cr += ( x_offset << pixel_shift) + 2*y_offset*h->
mb_uvlinesize;
609 chroma_height = height >> 1;
610 dest_cb += ( x_offset << pixel_shift) + y_offset*h->
mb_uvlinesize;
611 dest_cr += ( x_offset << pixel_shift) + y_offset*h->
mb_uvlinesize;
613 x_offset += 8*s->
mb_x;
626 dest_y, dest_cb, dest_cr,
627 x_offset, y_offset, qpix_put, chroma_put,
628 pixel_shift, chroma_idc);
630 tmp_y, tmp_cb, tmp_cr,
631 x_offset, y_offset, qpix_put, chroma_put,
632 pixel_shift, chroma_idc);
636 int weight1 = 64 - weight0;
637 luma_weight_avg( dest_y, tmp_y, h-> mb_linesize,
638 height, 5, weight0, weight1, 0);
640 chroma_height, 5, weight0, weight1, 0);
642 chroma_height, 5, weight0, weight1, 0);
655 int list = list1 ? 1 : 0;
658 mc_dir_part(h, ref, n, square, height, delta, list,
659 dest_y, dest_cb, dest_cr, x_offset, y_offset,
660 qpix_put, chroma_put, pixel_shift, chroma_idc);
675 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
676 int x_offset,
int y_offset,
680 int list0,
int list1,
int pixel_shift,
int chroma_idc)
686 x_offset, y_offset, qpix_put, chroma_put,
687 weight_op[0], weight_op[1], weight_avg[0],
688 weight_avg[1], list0, list1, pixel_shift, chroma_idc);
690 mc_part_std(h, n, square, height, delta, dest_y, dest_cb, dest_cr,
691 x_offset, y_offset, qpix_put, chroma_put, qpix_avg,
692 chroma_avg, list0, list1, pixel_shift, chroma_idc);
706 int off= (mx << pixel_shift) + (my + (s->
mb_x&3)*4)*h->
mb_linesize + (64 << pixel_shift);
708 if (chroma_idc == 3 ) {
712 off= ((mx>>1) << pixel_shift) + ((my>>1) + (s->
mb_x&7))*s->
uvlinesize + (64 << pixel_shift);
722 int pixel_shift,
int chroma_idc)
725 const int mb_xy= h->
mb_xy;
735 mc_part(h, 0, 1, 16, 0, dest_y, dest_cb, dest_cr, 0, 0,
736 qpix_put[0], chroma_put[0], qpix_avg[0], chroma_avg[0],
737 weight_op, weight_avg,
739 pixel_shift, chroma_idc);
741 mc_part(h, 0, 0, 8, 8 << pixel_shift, dest_y, dest_cb, dest_cr, 0, 0,
742 qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0],
743 weight_op, weight_avg,
745 pixel_shift, chroma_idc);
746 mc_part(h, 8, 0, 8, 8 << pixel_shift, dest_y, dest_cb, dest_cr, 0, 4,
747 qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0],
748 weight_op, weight_avg,
750 pixel_shift, chroma_idc);
752 mc_part(h, 0, 0, 16, 8*h->
mb_linesize, dest_y, dest_cb, dest_cr, 0, 0,
753 qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],
754 &weight_op[1], &weight_avg[1],
756 pixel_shift, chroma_idc);
757 mc_part(h, 4, 0, 16, 8*h->
mb_linesize, dest_y, dest_cb, dest_cr, 4, 0,
758 qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],
759 &weight_op[1], &weight_avg[1],
761 pixel_shift, chroma_idc);
770 int x_offset= (i&1)<<2;
771 int y_offset= (i&2)<<1;
774 mc_part(h, n, 1, 8, 0, dest_y, dest_cb, dest_cr, x_offset, y_offset,
775 qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],
776 &weight_op[1], &weight_avg[1],
778 pixel_shift, chroma_idc);
780 mc_part(h, n , 0, 4, 4 << pixel_shift, dest_y, dest_cb, dest_cr, x_offset, y_offset,
781 qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],
782 &weight_op[1], &weight_avg[1],
784 pixel_shift, chroma_idc);
785 mc_part(h, n+2, 0, 4, 4 << pixel_shift, dest_y, dest_cb, dest_cr, x_offset, y_offset+2,
786 qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],
787 &weight_op[1], &weight_avg[1],
789 pixel_shift, chroma_idc);
791 mc_part(h, n , 0, 8, 4*h->
mb_linesize, dest_y, dest_cb, dest_cr, x_offset, y_offset,
792 qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],
793 &weight_op[2], &weight_avg[2],
795 pixel_shift, chroma_idc);
796 mc_part(h, n+1, 0, 8, 4*h->
mb_linesize, dest_y, dest_cb, dest_cr, x_offset+2, y_offset,
797 qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],
798 &weight_op[2], &weight_avg[2],
800 pixel_shift, chroma_idc);
805 int sub_x_offset= x_offset + 2*(j&1);
806 int sub_y_offset= y_offset + (j&2);
807 mc_part(h, n+j, 1, 4, 0, dest_y, dest_cb, dest_cr, sub_x_offset, sub_y_offset,
808 qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],
809 &weight_op[2], &weight_avg[2],
811 pixel_shift, chroma_idc);
827 hl_motion(h, dest_y, dest_cb, dest_cr, qpix_put, chroma_put,
828 qpix_avg, chroma_avg, weight_op, weight_avg, pixel_shift, 1);
838 hl_motion(h, dest_y, dest_cb, dest_cr, qpix_put, chroma_put,
839 qpix_avg, chroma_avg, weight_op, weight_avg, pixel_shift, 2);
891 for(q=0; q<max_qp+1; q++){
916 for(q=0; q<max_qp+1; q++){
917 int shift =
div6[q] + 2;
970 const int b_xy = 4*x + 4*y*h->
b_stride;
1051 int i, cnt, nalsize;
1064 cnt = *(p+5) & 0x1f;
1066 for (i = 0; i < cnt; i++) {
1078 for (i = 0; i < cnt; i++) {
1150 #define IN_RANGE(a, b, size) (((a) >= (b)) && ((a) < ((b)+(size))))
1155 for (i=0; i<count; i++){
1156 assert((
IN_RANGE(from[i], old_base,
sizeof(*old_base)) ||
1167 for (i=0; i<count; i++){
1168 if (to[i] && !from[i])
av_freep(&to[i]);
1169 else if (from[i] && !to[i]) to[i] =
av_malloc(size);
1171 if (from[i]) memcpy(to[i], from[i], size);
1186 #define copy_fields(to, from, start_field, end_field) memcpy(&to->start_field, &from->start_field, (char*)&to->end_field - (char*)&to->start_field)
1193 if(dst == src || !
s1->context_initialized)
return 0;
1241 copy_fields(h, h1, dequant4_buffer, dequant4_coeff);
1300 for(i=0; i<16; i++){
1304 for(i=0; i<16; i++){
1351 int i, pics, out_of_order, out_idx;
1352 int invalid = 0, cnt = 0;
1471 invalid += out->
poc == INT_MIN;
1473 if (!h->
mmco_reset && !cur->
f.
key_frame && cnt + invalid == MAX_DELAYED_PIC_COUNT && cnt > 0) {
1482 invalid = MAX_DELAYED_PIC_COUNT;
1486 for (i = 1; i < MAX_DELAYED_PIC_COUNT && h->
delayed_pic[i] &&
1502 if (invalid + cnt < MAX_DELAYED_PIC_COUNT) {
1548 uint8_t *src_cb, uint8_t *src_cr,
1549 int linesize,
int uvlinesize,
int simple)
1552 uint8_t *top_border;
1559 src_cb -= uvlinesize;
1560 src_cr -= uvlinesize;
1568 AV_COPY128(top_border+16, src_y+15*linesize+16);
1572 AV_COPY128(top_border+32, src_cb + 15*uvlinesize);
1573 AV_COPY128(top_border+48, src_cb + 15*uvlinesize+16);
1574 AV_COPY128(top_border+64, src_cr + 15*uvlinesize);
1575 AV_COPY128(top_border+80, src_cr + 15*uvlinesize+16);
1577 AV_COPY128(top_border+16, src_cb + 15*uvlinesize);
1578 AV_COPY128(top_border+32, src_cr + 15*uvlinesize);
1580 }
else if(chroma422) {
1582 AV_COPY128(top_border+32, src_cb + 15*uvlinesize);
1583 AV_COPY128(top_border+48, src_cr + 15*uvlinesize);
1585 AV_COPY64(top_border+16, src_cb + 15*uvlinesize);
1586 AV_COPY64(top_border+24, src_cr + 15*uvlinesize);
1590 AV_COPY128(top_border+32, src_cb+7*uvlinesize);
1591 AV_COPY128(top_border+48, src_cr+7*uvlinesize);
1593 AV_COPY64(top_border+16, src_cb+7*uvlinesize);
1594 AV_COPY64(top_border+24, src_cr+7*uvlinesize);
1610 AV_COPY128(top_border+16, src_y+16*linesize+16);
1615 AV_COPY128(top_border+32, src_cb + 16*linesize);
1616 AV_COPY128(top_border+48, src_cb + 16*linesize+16);
1617 AV_COPY128(top_border+64, src_cr + 16*linesize);
1618 AV_COPY128(top_border+80, src_cr + 16*linesize+16);
1620 AV_COPY128(top_border+16, src_cb + 16*linesize);
1621 AV_COPY128(top_border+32, src_cr + 16*linesize);
1623 }
else if(chroma422) {
1625 AV_COPY128(top_border+32, src_cb+16*uvlinesize);
1626 AV_COPY128(top_border+48, src_cr+16*uvlinesize);
1628 AV_COPY64(top_border+16, src_cb+16*uvlinesize);
1629 AV_COPY64(top_border+24, src_cr+16*uvlinesize);
1633 AV_COPY128(top_border+32, src_cb+8*uvlinesize);
1634 AV_COPY128(top_border+48, src_cr+8*uvlinesize);
1636 AV_COPY64(top_border+16, src_cb+8*uvlinesize);
1637 AV_COPY64(top_border+24, src_cr+8*uvlinesize);
1644 uint8_t *src_cb, uint8_t *src_cr,
1645 int linesize,
int uvlinesize,
1646 int xchg,
int chroma444,
1647 int simple,
int pixel_shift){
1649 int deblock_topleft;
1652 uint8_t *top_border_m1;
1653 uint8_t *top_border;
1668 deblock_topleft = (s->
mb_x > 0);
1672 src_y -= linesize + 1 + pixel_shift;
1673 src_cb -= uvlinesize + 1 + pixel_shift;
1674 src_cr -= uvlinesize + 1 + pixel_shift;
1679 #define XCHG(a,b,xchg)\
1682 AV_SWAP64(b+0,a+0);\
1683 AV_SWAP64(b+8,a+8);\
1688 if (xchg) AV_SWAP64(b,a);\
1689 else AV_COPY64(b,a);
1692 if(deblock_topleft){
1693 XCHG(top_border_m1 + (8 << pixel_shift), src_y - (7 << pixel_shift), 1);
1695 XCHG(top_border + (0 << pixel_shift), src_y + (1 << pixel_shift), xchg);
1696 XCHG(top_border + (8 << pixel_shift), src_y + (9 << pixel_shift), 1);
1703 if(deblock_topleft){
1704 XCHG(top_border_m1 + (24 << pixel_shift), src_cb - (7 << pixel_shift), 1);
1705 XCHG(top_border_m1 + (40 << pixel_shift), src_cr - (7 << pixel_shift), 1);
1707 XCHG(top_border + (16 << pixel_shift), src_cb + (1 << pixel_shift), xchg);
1708 XCHG(top_border + (24 << pixel_shift), src_cb + (9 << pixel_shift), 1);
1709 XCHG(top_border + (32 << pixel_shift), src_cr + (1 << pixel_shift), xchg);
1710 XCHG(top_border + (40 << pixel_shift), src_cr + (9 << pixel_shift), 1);
1712 XCHG(h->
top_borders[top_idx][s->
mb_x+1] + (16 << pixel_shift), src_cb + (17 << pixel_shift), 1);
1713 XCHG(h->
top_borders[top_idx][s->
mb_x+1] + (32 << pixel_shift), src_cr + (17 << pixel_shift), 1);
1717 if(deblock_topleft){
1718 XCHG(top_border_m1 + (16 << pixel_shift), src_cb - (7 << pixel_shift), 1);
1719 XCHG(top_border_m1 + (24 << pixel_shift), src_cr - (7 << pixel_shift), 1);
1721 XCHG(top_border + (16 << pixel_shift), src_cb+1+pixel_shift, 1);
1722 XCHG(top_border + (24 << pixel_shift), src_cr+1+pixel_shift, 1);
1729 if (high_bit_depth) {
1730 return AV_RN32A(((int32_t*)mb) + index);
1736 if (high_bit_depth) {
1737 AV_WN32A(((int32_t*)mb) + index, value);
1743 int pixel_shift,
int *block_offset,
int linesize, uint8_t *dest_y,
int p)
1750 block_offset += 16*p;
1754 if(transform_bypass){
1761 for(i=0; i<16; i+=4){
1762 uint8_t *
const ptr= dest_y + block_offset[i];
1772 idct_dc_add(ptr, h->
mb + (i*16+p*256 << pixel_shift), linesize);
1774 idct_add (ptr, h->
mb + (i*16+p*256 << pixel_shift), linesize);
1779 if(transform_bypass){
1786 for(i=0; i<16; i++){
1787 uint8_t *
const ptr= dest_y + block_offset[i];
1791 h->
hpc.
pred4x4_add[dir](ptr, h->
mb + (i*16+p*256 << pixel_shift), linesize);
1798 assert(s->
mb_y || linesize <= block_offset[i]);
1799 if(!topright_avail){
1801 tr_high= ((uint16_t*)ptr)[3 - linesize/2]*0x0001000100010001ULL;
1802 topright= (uint8_t*) &tr_high;
1804 tr= ptr[3 - linesize]*0x01010101u;
1805 topright= (uint8_t*) &tr;
1808 topright= ptr + (4 << pixel_shift) - linesize;
1812 h->
hpc.
pred4x4[ dir ](ptr, topright, linesize);
1817 idct_dc_add(ptr, h->
mb + (i*16+p*256 << pixel_shift), linesize);
1819 idct_add (ptr, h->
mb + (i*16+p*256 << pixel_shift), linesize);
1831 if(!transform_bypass)
1834 static const uint8_t dc_mapping[16] = { 0*16, 1*16, 4*16, 5*16, 2*16, 3*16, 6*16, 7*16,
1835 8*16, 9*16,12*16,13*16,10*16,11*16,14*16,15*16};
1836 for(i = 0; i < 16; i++)
1846 int pixel_shift,
int *block_offset,
int linesize, uint8_t *dest_y,
int p)
1851 block_offset += 16*p;
1855 if(transform_bypass){
1859 for(i=0; i<16; i++){
1861 s->
dsp.
add_pixels4(dest_y + block_offset[i], h->
mb + (i*16+p*256 << pixel_shift), linesize);
1867 }
else if(h->
cbp&15){
1868 if(transform_bypass){
1869 const int di =
IS_8x8DCT(mb_type) ? 4 : 1;
1871 for(i=0; i<16; i+=di){
1873 idct_add(dest_y + block_offset[i], h->
mb + (i*16+p*256 << pixel_shift), linesize);
1885 for(i=0; i<16; i++){
1887 uint8_t *
const ptr= dest_y + block_offset[i];
1898 const int mb_x= s->
mb_x;
1899 const int mb_y= s->
mb_y;
1900 const int mb_xy= h->
mb_xy;
1902 uint8_t *dest_y, *dest_cb, *dest_cr;
1903 int linesize, uvlinesize ;
1940 for(i=0; i<16; i+=4){
1961 for (i = 0; i < 16; i++) {
1962 uint16_t *tmp_y = (uint16_t*)(dest_y + i*linesize);
1963 for (j = 0; j < 16; j++)
1964 tmp_y[j] =
get_bits(&gb, bit_depth);
1968 for (i = 0; i < block_h; i++) {
1969 uint16_t *tmp_cb = (uint16_t*)(dest_cb + i*uvlinesize);
1970 for (j = 0; j < 8; j++) {
1971 tmp_cb[j] = 1 << (bit_depth - 1);
1974 for (i = 0; i < block_h; i++) {
1975 uint16_t *tmp_cr = (uint16_t*)(dest_cr + i*uvlinesize);
1976 for (j = 0; j < 8; j++) {
1977 tmp_cr[j] = 1 << (bit_depth - 1);
1981 for (i = 0; i < block_h; i++) {
1982 uint16_t *tmp_cb = (uint16_t*)(dest_cb + i*uvlinesize);
1983 for (j = 0; j < 8; j++)
1984 tmp_cb[j] =
get_bits(&gb, bit_depth);
1986 for (i = 0; i < block_h; i++) {
1987 uint16_t *tmp_cr = (uint16_t*)(dest_cr + i*uvlinesize);
1988 for (j = 0; j < 8; j++)
1989 tmp_cr[j] =
get_bits(&gb, bit_depth);
1994 for (i=0; i<16; i++) {
1995 memcpy(dest_y + i* linesize, h->
mb + i*8, 16);
1999 for (i = 0; i < block_h; i++) {
2000 memset(dest_cb + i*uvlinesize, 128, 8);
2001 memset(dest_cr + i*uvlinesize, 128, 8);
2004 for (i = 0; i < block_h; i++) {
2005 memcpy(dest_cb + i*uvlinesize, h->
mb + 128 + i*4, 8);
2006 memcpy(dest_cr + i*uvlinesize, h->
mb + 160 + i*4, 8);
2014 xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 1, 0, simple, pixel_shift);
2021 hl_decode_mb_predict_luma(h, mb_type, is_h264, simple, transform_bypass, pixel_shift, block_offset, linesize, dest_y, 0);
2024 xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 0, 0, simple, pixel_shift);
2043 hl_decode_mb_idct_luma(h, mb_type, is_h264, simple, transform_bypass, pixel_shift, block_offset, linesize, dest_y, 0);
2046 uint8_t *dest[2] = {dest_cb, dest_cr};
2047 if(transform_bypass){
2054 for(i=j*16; i<j*16+4; i++){
2056 idct_add (dest[j-1] + block_offset[i], h->
mb + (i*16 << pixel_shift), uvlinesize);
2059 for(i=j*16+4; i<j*16+8; i++){
2061 idct_add (dest[j-1] + block_offset[i+4], h->
mb + (i*16 << pixel_shift), uvlinesize);
2087 for(i=j*16; i<j*16+4; i++){
2089 uint8_t *
const ptr= dest[j-1] + block_offset[i];
2107 const int mb_x= s->
mb_x;
2108 const int mb_y= s->
mb_y;
2109 const int mb_xy= h->
mb_xy;
2118 for (p = 0; p < plane_count; p++)
2130 for (p = 0; p < 3; p++)
2141 for(i=0; i<16; i+=4){
2159 for (p = 0; p < plane_count; p++) {
2160 for (i = 0; i < 16; i++) {
2161 uint16_t *tmp = (uint16_t*)(dest[p] + i*linesize);
2162 for (j = 0; j < 16; j++)
2167 for (p = 0; p < plane_count; p++) {
2168 for (i = 0; i < 16; i++) {
2169 memcpy(dest[p] + i*linesize, h->
mb + p*128 + i*8, 16);
2176 xchg_mb_border(h, dest[0], dest[1], dest[2], linesize, linesize, 1, 1, simple, pixel_shift);
2178 for (p = 0; p < plane_count; p++)
2182 xchg_mb_border(h, dest[0], dest[1], dest[2], linesize, linesize, 0, 1, simple, pixel_shift);
2191 for (p = 0; p < plane_count; p++)
2192 hl_decode_mb_idct_luma(h, mb_type, 1, simple, transform_bypass, pixel_shift, block_offset, linesize, dest[p], p);
2204 #define hl_decode_mb_simple(sh, bits) \
2205 static void hl_decode_mb_simple_ ## bits(H264Context *h){ \
2206 hl_decode_mb_internal(h, 1, sh); \
2228 const int mb_xy= h->
mb_xy;
2237 }
else if (is_complex) {
2238 hl_decode_mb_complex(h);
2240 hl_decode_mb_simple_16(h);
2242 hl_decode_mb_simple_8(h);
2248 int luma_def, chroma_def;
2258 for(list=0; list<2; list++){
2262 int luma_weight_flag, chroma_weight_flag;
2265 if(luma_weight_flag){
2280 if(chroma_weight_flag){
2313 int ref0, ref1, i, cur_poc, ref_start, ref_count0, ref_count1;
2315 for (i = 0; i < 2; i++) {
2347 for(ref0=ref_start; ref0 < ref_count0; ref0++){
2349 for(ref1=ref_start; ref1 < ref_count1; ref1++){
2353 int td = av_clip(poc1 - poc0, -128, 127);
2355 int tb = av_clip(cur_poc - poc0, -128, 127);
2356 int tx = (16384 + (
FFABS(td) >> 1)) / td;
2357 int dist_scale_factor = (tb*tx + 32) >> 8;
2358 if(dist_scale_factor >= -64 && dist_scale_factor <= 128)
2359 w = 64 - dist_scale_factor;
2429 int abs_frame_num, expected_delta_per_poc_cycle, expectedpoc;
2440 expected_delta_per_poc_cycle = 0;
2444 if(abs_frame_num > 0){
2448 expectedpoc = poc_cycle_cnt * expected_delta_per_poc_cycle;
2449 for(i = 0; i <= frame_num_in_poc_cycle; i++)
2457 field_poc[0] = expectedpoc + h->
delta_poc[0];
2487 for(i=0; i<16; i++){
2488 #define T(x) (x>>2) | ((x<<2) & 0xF)
2493 for(i=0; i<64; i++){
2494 #define T(x) (x>>3) | ((x&7)<<3)
2635 "Reenabling low delay requires a codec flush.\n");
2649 "VDPAU decoding does not support video colorspace.\n");
2684 unsigned int first_mb_in_slice;
2685 unsigned int pps_id;
2686 int num_ref_idx_active_override_flag;
2687 unsigned int slice_type, tmp, i, j;
2688 int default_ref_list_done = 0;
2689 int last_pic_structure, last_pic_dropable, ret;
2702 if(first_mb_in_slice == 0){
2732 default_ref_list_done = 1;
2948 last_pic_dropable != s->
dropable) {
2950 "Changing field mode (%d -> %d) between slices is not allowed\n",
2957 "unset current_picture_ptr on %d. slice\n",
2968 if (unwrap_prev_frame_num > h->
frame_num) unwrap_prev_frame_num -= max_frame_num;
2972 if (unwrap_prev_frame_num < 0)
2973 unwrap_prev_frame_num += max_frame_num;
2999 if (!last_pic_dropable && last_pic_structure !=
PICT_FRAME) {
3009 if (!last_pic_dropable && last_pic_structure !=
PICT_FRAME) {
3020 "Invalid field mode combination %d/%d\n",
3025 }
else if (last_pic_dropable != s->
dropable) {
3027 "Cannot combine reference and non-reference fields in the same frame\n");
3131 first_mb_in_slice >= s->
mb_num){
3184 num_ref_idx_active_override_flag=
get_bits1(&s->
gb);
3186 if(num_ref_idx_active_override_flag){
3210 if(!default_ref_list_done){
3235 for (i = 0; i < 2; i++) {
3305 "deblocking filter parameters %d %d out of range\n",
3326 av_log(s->
avctx,
AV_LOG_INFO,
"Cannot parallelize deblocking type 1, decoding such frames in sequential order\n");
3351 for(i=0; i<16; i++){
3372 ref2frm[i+2]= 4*id_list[i]
3376 for(i=16; i<48; i++)
3377 ref2frm[i+4]= 4*id_list[(i-16)>>1]
3386 av_log(h->
s.
avctx,
AV_LOG_DEBUG,
"slice:%d %s mb:%d %c%s%s pps:%u frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\n",
3419 int left_xy[
LEFT_MBS],
int top_type,
int left_type[LEFT_MBS],
int mb_xy,
int list)
3426 const int b_xy= h->
mb2b_xy[top_xy] + 3*b_stride;
3427 const int b8_xy= 4*top_xy + 2;
3442 const int b8_xy= 4*left_xy[
LTOP] + 1;
3477 uint32_t ref01 = (
pack16to32(ref2frm[list][ref[0]],ref2frm[list][ref[1]])&0x00FF00FF)*0x0101;
3478 uint32_t ref23 = (
pack16to32(ref2frm[list][ref[2]],ref2frm[list][ref[3]])&0x00FF00FF)*0x0101;
3487 AV_COPY128(mv_dst + 8*0, mv_src + 0*b_stride);
3488 AV_COPY128(mv_dst + 8*1, mv_src + 1*b_stride);
3489 AV_COPY128(mv_dst + 8*2, mv_src + 2*b_stride);
3490 AV_COPY128(mv_dst + 8*3, mv_src + 3*b_stride);
3500 const int mb_xy= h->
mb_xy;
3511 left_xy[
LBOT] = left_xy[
LTOP] = mb_xy-1;
3516 if (left_mb_field_flag != curr_mb_field_flag) {
3520 if(curr_mb_field_flag){
3523 if (left_mb_field_flag != curr_mb_field_flag) {
3555 if(h->
slice_table[top_xy ] == 0xFFFF) top_type= 0;
3579 AV_COPY32(&nnz_cache[4+8*0], &nnz[3*4]);
3582 if(left_type[
LTOP]){
3584 nnz_cache[3+8*1]= nnz[3+0*4];
3585 nnz_cache[3+8*2]= nnz[3+1*4];
3586 nnz_cache[3+8*3]= nnz[3+2*4];
3587 nnz_cache[3+8*4]= nnz[3+3*4];
3594 nnz_cache[5+8*0]= (h->
cbp_table[top_xy] & 0x4000) >> 12;
3596 nnz_cache[7+8*0]= (h->
cbp_table[top_xy] & 0x8000) >> 12;
3600 nnz_cache[3+8*2]= (h->
cbp_table[left_xy[
LTOP]]&0x2000) >> 12;
3604 nnz_cache[3+8*4]= (h->
cbp_table[left_xy[
LBOT]]&0x8000) >> 12;
3608 nnz_cache[
scan8[0 ]]= nnz_cache[scan8[1 ]]=
3609 nnz_cache[scan8[2 ]]= nnz_cache[scan8[3 ]]= (h->
cbp & 0x1000) >> 12;
3611 nnz_cache[scan8[0+ 4]]= nnz_cache[scan8[1+ 4]]=
3612 nnz_cache[scan8[2+ 4]]= nnz_cache[scan8[3+ 4]]= (h->
cbp & 0x2000) >> 12;
3614 nnz_cache[scan8[0+ 8]]= nnz_cache[scan8[1+ 8]]=
3615 nnz_cache[scan8[2+ 8]]= nnz_cache[scan8[3+ 8]]= (h->
cbp & 0x4000) >> 12;
3617 nnz_cache[scan8[0+12]]= nnz_cache[scan8[1+12]]=
3618 nnz_cache[scan8[2+12]]= nnz_cache[scan8[3+12]]= (h->
cbp & 0x8000) >> 12;
3627 uint8_t *dest_y, *dest_cb, *dest_cr;
3628 int linesize, uvlinesize, mb_x, mb_y;
3635 for(mb_x= start_x; mb_x<end_x; mb_x++){
3636 for(mb_y=end_mb_y -
FRAME_MBAFF; mb_y<= end_mb_y; mb_y++){
3672 ff_h264_filter_mb (h, mb_x, mb_y, dest_y, dest_cb, dest_cr, linesize, uvlinesize);
3708 if((top + height) >= pic_height)
3709 height += deblock_border;
3711 top -= deblock_border;
3717 height =
FFMIN(height, pic_height - top);
3718 if (top < h->emu_edge_height) {
3735 int lf_x_start = s->
mb_x;
3785 s->
mb_x = lf_x_start = 0;
3825 s->
mb_x = lf_x_start = 0;
3880 "Input contains more MB rows than the frame height.\n");
3886 if(context_count == 1) {
3889 for(i = 1; i < context_count; i++) {
3904 for(i = 1; i < context_count; i++)
3931 for(;pass <= 1;pass++){
3934 next_avc = h->
is_avc ? 0 : buf_size;
3944 if(buf_index >= next_avc) {
3948 nalsize = (nalsize << 8) | buf[buf_index++];
3949 if(nalsize <= 0 || nalsize > buf_size - buf_index){
3953 next_avc= buf_index + nalsize;
3956 for(; buf_index + 3 < next_avc; buf_index++){
3958 if(buf[buf_index] == 0 && buf[buf_index+1] == 0 && buf[buf_index+2] == 1)
3963 if (buf_index + 3 >= buf_size) {
3964 buf_index = buf_size;
3969 if(buf_index >= next_avc)
continue;
3974 ptr=
ff_h264_decode_nal(hx, buf + buf_index, &dst_length, &consumed, next_avc - buf_index);
3975 if (ptr ==
NULL || dst_length < 0) {
3979 i= buf_index + consumed;
3981 buf[i]==0x00 && buf[i+1]==0x00 && buf[i+2]==0x01 && buf[i+3]==0xE0)
3985 while(dst_length > 0 && ptr[dst_length - 1] == 0)
3994 if (h->
is_avc && (nalsize != consumed) && nalsize){
3998 buf_index += consumed;
4008 nals_needed = nal_index;
4014 nals_needed = nal_index;
4067 static const uint8_t start_code[] = {0x00, 0x00, 0x01};
4077 "Decoding in chunks is not supported for "
4078 "partitioned slices.\n");
4121 h->
is_avc && (nalsize != consumed) && nalsize) {
4123 "try parsing the coomplete NAL\n");
4159 }
else if (err == 1) {
4190 if(pos+10>buf_size) pos=buf_size;
4196 void *
data,
int *data_size,
4199 const uint8_t *buf = avpkt->
data;
4200 int buf_size = avpkt->
size;
4214 if (buf_size == 0) {
4272 assert(pict->
data[0] || !*data_size);
4302 #define SIZE (COUNT*40)
4315 printf(
"testing unsigned exp golomb\n");
4316 for(i=0; i<COUNT; i++){
4324 for(i=0; i<COUNT; i++){
4330 printf(
"mismatch! at %d (%d should be %d) bits:%6X\n", i, j, i, s);
4338 printf(
"testing signed exp golomb\n");
4339 for(i=0; i<COUNT; i++){
4347 for(i=0; i<COUNT; i++){
4352 if(j != i - COUNT/2){
4353 printf(
"mismatch! at %d (%d should be %d) bits:%6X\n", i, j, i, s);
4359 printf(
"Testing RBSP\n");
4428 #if CONFIG_H264_VDPAU_DECODER
4429 AVCodec ff_h264_vdpau_decoder = {
4430 .
name =
"h264_vdpau",
4439 .long_name =
NULL_IF_CONFIG_SMALL(
"H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (VDPAU acceleration)"),