Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: source/libvpx/vp9/encoder/vp9_encoder.c

Issue 668403002: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_encoder.h ('k') | source/libvpx/vp9/encoder/vp9_extend.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 cm->fc = cm->frame_contexts[cm->frame_context_idx]; 137 cm->fc = cm->frame_contexts[cm->frame_context_idx];
138 vp9_zero(cpi->interp_filter_selected[0]); 138 vp9_zero(cpi->interp_filter_selected[0]);
139 } 139 }
140 } 140 }
141 141
142 void vp9_initialize_enc() { 142 void vp9_initialize_enc() {
143 static int init_done = 0; 143 static int init_done = 0;
144 144
145 if (!init_done) { 145 if (!init_done) {
146 vp9_rtcd(); 146 vp9_rtcd();
147 vp9_init_neighbors();
148 vp9_init_intra_predictors(); 147 vp9_init_intra_predictors();
149 vp9_coef_tree_initialize(); 148 vp9_coef_tree_initialize();
150 vp9_tokenize_initialize(); 149 vp9_tokenize_initialize();
151 vp9_init_me_luts(); 150 vp9_init_me_luts();
152 vp9_rc_init_minq_luts(); 151 vp9_rc_init_minq_luts();
153 vp9_entropy_mv_init(); 152 vp9_entropy_mv_init();
154 vp9_entropy_mode_init(); 153 vp9_entropy_mode_init();
155 vp9_temporal_filter_init(); 154 vp9_temporal_filter_init();
156 init_done = 1; 155 init_done = 1;
157 } 156 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 if (cpi->source_diff_var != NULL) { 218 if (cpi->source_diff_var != NULL) {
220 vpx_free(cpi->source_diff_var); 219 vpx_free(cpi->source_diff_var);
221 cpi->source_diff_var = NULL; 220 cpi->source_diff_var = NULL;
222 } 221 }
223 222
224 for (i = 0; i < MAX_LAG_BUFFERS; ++i) { 223 for (i = 0; i < MAX_LAG_BUFFERS; ++i) {
225 vp9_free_frame_buffer(&cpi->svc.scaled_frames[i]); 224 vp9_free_frame_buffer(&cpi->svc.scaled_frames[i]);
226 } 225 }
227 vpx_memset(&cpi->svc.scaled_frames[0], 0, 226 vpx_memset(&cpi->svc.scaled_frames[0], 0,
228 MAX_LAG_BUFFERS * sizeof(cpi->svc.scaled_frames[0])); 227 MAX_LAG_BUFFERS * sizeof(cpi->svc.scaled_frames[0]));
228
229 vp9_free_frame_buffer(&cpi->svc.empty_frame.img);
230 vpx_memset(&cpi->svc.empty_frame, 0, sizeof(cpi->svc.empty_frame));
229 } 231 }
230 232
231 static void save_coding_context(VP9_COMP *cpi) { 233 static void save_coding_context(VP9_COMP *cpi) {
232 CODING_CONTEXT *const cc = &cpi->coding_context; 234 CODING_CONTEXT *const cc = &cpi->coding_context;
233 VP9_COMMON *cm = &cpi->common; 235 VP9_COMMON *cm = &cpi->common;
234 236
235 // Stores a snapshot of key state variables which can subsequently be 237 // Stores a snapshot of key state variables which can subsequently be
236 // restored with a call to vp9_restore_coding_context. These functions are 238 // restored with a call to vp9_restore_coding_context. These functions are
237 // intended for use in a re-code loop in vp9_compress_frame where the 239 // intended for use in a re-code loop in vp9_compress_frame where the
238 // quantizer value is adjusted between loop iterations. 240 // quantizer value is adjusted between loop iterations.
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 vp9_init_layer_context(cpi); 581 vp9_init_layer_context(cpi);
580 } 582 }
581 583
582 // change includes all joint functionality 584 // change includes all joint functionality
583 vp9_change_config(cpi, oxcf); 585 vp9_change_config(cpi, oxcf);
584 586
585 cpi->static_mb_pct = 0; 587 cpi->static_mb_pct = 0;
586 cpi->ref_frame_flags = 0; 588 cpi->ref_frame_flags = 0;
587 589
588 init_buffer_indices(cpi); 590 init_buffer_indices(cpi);
589
590 set_tile_limits(cpi);
591 } 591 }
592 592
593 static void set_rc_buffer_sizes(RATE_CONTROL *rc, 593 static void set_rc_buffer_sizes(RATE_CONTROL *rc,
594 const VP9EncoderConfig *oxcf) { 594 const VP9EncoderConfig *oxcf) {
595 const int64_t bandwidth = oxcf->target_bandwidth; 595 const int64_t bandwidth = oxcf->target_bandwidth;
596 const int64_t starting = oxcf->starting_buffer_level_ms; 596 const int64_t starting = oxcf->starting_buffer_level_ms;
597 const int64_t optimal = oxcf->optimal_buffer_level_ms; 597 const int64_t optimal = oxcf->optimal_buffer_level_ms;
598 const int64_t maximum = oxcf->maximum_buffer_size_ms; 598 const int64_t maximum = oxcf->maximum_buffer_size_ms;
599 599
600 rc->starting_buffer_level = starting * bandwidth / 1000; 600 rc->starting_buffer_level = starting * bandwidth / 1000;
601 rc->optimal_buffer_level = (optimal == 0) ? bandwidth / 8 601 rc->optimal_buffer_level = (optimal == 0) ? bandwidth / 8
602 : optimal * bandwidth / 1000; 602 : optimal * bandwidth / 1000;
603 rc->maximum_buffer_size = (maximum == 0) ? bandwidth / 8 603 rc->maximum_buffer_size = (maximum == 0) ? bandwidth / 8
604 : maximum * bandwidth / 1000; 604 : maximum * bandwidth / 1000;
605 } 605 }
606 606
607 #if CONFIG_VP9_HIGHBITDEPTH
608 #define HIGHBD_BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF) \
609 cpi->fn_ptr[BT].sdf = SDF; \
610 cpi->fn_ptr[BT].sdaf = SDAF; \
611 cpi->fn_ptr[BT].vf = VF; \
612 cpi->fn_ptr[BT].svf = SVF; \
613 cpi->fn_ptr[BT].svaf = SVAF; \
614 cpi->fn_ptr[BT].sdx3f = SDX3F; \
615 cpi->fn_ptr[BT].sdx8f = SDX8F; \
616 cpi->fn_ptr[BT].sdx4df = SDX4DF;
617
618 #define MAKE_BFP_SAD_WRAPPER(fnname) \
619 static unsigned int fnname##_bits8(const uint8_t *src_ptr, \
620 int source_stride, \
621 const uint8_t *ref_ptr, \
622 int ref_stride) { \
623 return fnname(src_ptr, source_stride, ref_ptr, ref_stride); \
624 } \
625 static unsigned int fnname##_bits10(const uint8_t *src_ptr, \
626 int source_stride, \
627 const uint8_t *ref_ptr, \
628 int ref_stride) { \
629 return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 2; \
630 } \
631 static unsigned int fnname##_bits12(const uint8_t *src_ptr, \
632 int source_stride, \
633 const uint8_t *ref_ptr, \
634 int ref_stride) { \
635 return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 4; \
636 }
637
638 #define MAKE_BFP_SADAVG_WRAPPER(fnname) static unsigned int \
639 fnname##_bits8(const uint8_t *src_ptr, \
640 int source_stride, \
641 const uint8_t *ref_ptr, \
642 int ref_stride, \
643 const uint8_t *second_pred) { \
644 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred); \
645 } \
646 static unsigned int fnname##_bits10(const uint8_t *src_ptr, \
647 int source_stride, \
648 const uint8_t *ref_ptr, \
649 int ref_stride, \
650 const uint8_t *second_pred) { \
651 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \
652 second_pred) >> 2; \
653 } \
654 static unsigned int fnname##_bits12(const uint8_t *src_ptr, \
655 int source_stride, \
656 const uint8_t *ref_ptr, \
657 int ref_stride, \
658 const uint8_t *second_pred) { \
659 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \
660 second_pred) >> 4; \
661 }
662
663 #define MAKE_BFP_SAD3_WRAPPER(fnname) \
664 static void fnname##_bits8(const uint8_t *src_ptr, \
665 int source_stride, \
666 const uint8_t *ref_ptr, \
667 int ref_stride, \
668 unsigned int *sad_array) { \
669 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
670 } \
671 static void fnname##_bits10(const uint8_t *src_ptr, \
672 int source_stride, \
673 const uint8_t *ref_ptr, \
674 int ref_stride, \
675 unsigned int *sad_array) { \
676 int i; \
677 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
678 for (i = 0; i < 3; i++) \
679 sad_array[i] >>= 2; \
680 } \
681 static void fnname##_bits12(const uint8_t *src_ptr, \
682 int source_stride, \
683 const uint8_t *ref_ptr, \
684 int ref_stride, \
685 unsigned int *sad_array) { \
686 int i; \
687 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
688 for (i = 0; i < 3; i++) \
689 sad_array[i] >>= 4; \
690 }
691
692 #define MAKE_BFP_SAD8_WRAPPER(fnname) \
693 static void fnname##_bits8(const uint8_t *src_ptr, \
694 int source_stride, \
695 const uint8_t *ref_ptr, \
696 int ref_stride, \
697 unsigned int *sad_array) { \
698 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
699 } \
700 static void fnname##_bits10(const uint8_t *src_ptr, \
701 int source_stride, \
702 const uint8_t *ref_ptr, \
703 int ref_stride, \
704 unsigned int *sad_array) { \
705 int i; \
706 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
707 for (i = 0; i < 8; i++) \
708 sad_array[i] >>= 2; \
709 } \
710 static void fnname##_bits12(const uint8_t *src_ptr, \
711 int source_stride, \
712 const uint8_t *ref_ptr, \
713 int ref_stride, \
714 unsigned int *sad_array) { \
715 int i; \
716 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
717 for (i = 0; i < 8; i++) \
718 sad_array[i] >>= 4; \
719 }
720 #define MAKE_BFP_SAD4D_WRAPPER(fnname) \
721 static void fnname##_bits8(const uint8_t *src_ptr, \
722 int source_stride, \
723 const uint8_t* const ref_ptr[], \
724 int ref_stride, \
725 unsigned int *sad_array) { \
726 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
727 } \
728 static void fnname##_bits10(const uint8_t *src_ptr, \
729 int source_stride, \
730 const uint8_t* const ref_ptr[], \
731 int ref_stride, \
732 unsigned int *sad_array) { \
733 int i; \
734 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
735 for (i = 0; i < 4; i++) \
736 sad_array[i] >>= 2; \
737 } \
738 static void fnname##_bits12(const uint8_t *src_ptr, \
739 int source_stride, \
740 const uint8_t* const ref_ptr[], \
741 int ref_stride, \
742 unsigned int *sad_array) { \
743 int i; \
744 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
745 for (i = 0; i < 4; i++) \
746 sad_array[i] >>= 4; \
747 }
748
749 MAKE_BFP_SAD_WRAPPER(vp9_highbd_sad32x16)
750 MAKE_BFP_SADAVG_WRAPPER(vp9_highbd_sad32x16_avg)
751 MAKE_BFP_SAD4D_WRAPPER(vp9_highbd_sad32x16x4d)
752 MAKE_BFP_SAD_WRAPPER(vp9_highbd_sad16x32)
753 MAKE_BFP_SADAVG_WRAPPER(vp9_highbd_sad16x32_avg)
754 MAKE_BFP_SAD4D_WRAPPER(vp9_highbd_sad16x32x4d)
755 MAKE_BFP_SAD_WRAPPER(vp9_highbd_sad64x32)
756 MAKE_BFP_SADAVG_WRAPPER(vp9_highbd_sad64x32_avg)
757 MAKE_BFP_SAD4D_WRAPPER(vp9_highbd_sad64x32x4d)
758 MAKE_BFP_SAD_WRAPPER(vp9_highbd_sad32x64)
759 MAKE_BFP_SADAVG_WRAPPER(vp9_highbd_sad32x64_avg)
760 MAKE_BFP_SAD4D_WRAPPER(vp9_highbd_sad32x64x4d)
761 MAKE_BFP_SAD_WRAPPER(vp9_highbd_sad32x32)
762 MAKE_BFP_SADAVG_WRAPPER(vp9_highbd_sad32x32_avg)
763 MAKE_BFP_SAD3_WRAPPER(vp9_highbd_sad32x32x3)
764 MAKE_BFP_SAD8_WRAPPER(vp9_highbd_sad32x32x8)
765 MAKE_BFP_SAD4D_WRAPPER(vp9_highbd_sad32x32x4d)
766 MAKE_BFP_SAD_WRAPPER(vp9_highbd_sad64x64)
767 MAKE_BFP_SADAVG_WRAPPER(vp9_highbd_sad64x64_avg)
768 MAKE_BFP_SAD3_WRAPPER(vp9_highbd_sad64x64x3)
769 MAKE_BFP_SAD8_WRAPPER(vp9_highbd_sad64x64x8)
770 MAKE_BFP_SAD4D_WRAPPER(vp9_highbd_sad64x64x4d)
771 MAKE_BFP_SAD_WRAPPER(vp9_highbd_sad16x16)
772 MAKE_BFP_SADAVG_WRAPPER(vp9_highbd_sad16x16_avg)
773 MAKE_BFP_SAD3_WRAPPER(vp9_highbd_sad16x16x3)
774 MAKE_BFP_SAD8_WRAPPER(vp9_highbd_sad16x16x8)
775 MAKE_BFP_SAD4D_WRAPPER(vp9_highbd_sad16x16x4d)
776 MAKE_BFP_SAD_WRAPPER(vp9_highbd_sad16x8)
777 MAKE_BFP_SADAVG_WRAPPER(vp9_highbd_sad16x8_avg)
778 MAKE_BFP_SAD3_WRAPPER(vp9_highbd_sad16x8x3)
779 MAKE_BFP_SAD8_WRAPPER(vp9_highbd_sad16x8x8)
780 MAKE_BFP_SAD4D_WRAPPER(vp9_highbd_sad16x8x4d)
781 MAKE_BFP_SAD_WRAPPER(vp9_highbd_sad8x16)
782 MAKE_BFP_SADAVG_WRAPPER(vp9_highbd_sad8x16_avg)
783 MAKE_BFP_SAD3_WRAPPER(vp9_highbd_sad8x16x3)
784 MAKE_BFP_SAD8_WRAPPER(vp9_highbd_sad8x16x8)
785 MAKE_BFP_SAD4D_WRAPPER(vp9_highbd_sad8x16x4d)
786 MAKE_BFP_SAD_WRAPPER(vp9_highbd_sad8x8)
787 MAKE_BFP_SADAVG_WRAPPER(vp9_highbd_sad8x8_avg)
788 MAKE_BFP_SAD3_WRAPPER(vp9_highbd_sad8x8x3)
789 MAKE_BFP_SAD8_WRAPPER(vp9_highbd_sad8x8x8)
790 MAKE_BFP_SAD4D_WRAPPER(vp9_highbd_sad8x8x4d)
791 MAKE_BFP_SAD_WRAPPER(vp9_highbd_sad8x4)
792 MAKE_BFP_SADAVG_WRAPPER(vp9_highbd_sad8x4_avg)
793 MAKE_BFP_SAD8_WRAPPER(vp9_highbd_sad8x4x8)
794 MAKE_BFP_SAD4D_WRAPPER(vp9_highbd_sad8x4x4d)
795 MAKE_BFP_SAD_WRAPPER(vp9_highbd_sad4x8)
796 MAKE_BFP_SADAVG_WRAPPER(vp9_highbd_sad4x8_avg)
797 MAKE_BFP_SAD8_WRAPPER(vp9_highbd_sad4x8x8)
798 MAKE_BFP_SAD4D_WRAPPER(vp9_highbd_sad4x8x4d)
799 MAKE_BFP_SAD_WRAPPER(vp9_highbd_sad4x4)
800 MAKE_BFP_SADAVG_WRAPPER(vp9_highbd_sad4x4_avg)
801 MAKE_BFP_SAD3_WRAPPER(vp9_highbd_sad4x4x3)
802 MAKE_BFP_SAD8_WRAPPER(vp9_highbd_sad4x4x8)
803 MAKE_BFP_SAD4D_WRAPPER(vp9_highbd_sad4x4x4d)
804
805 static void highbd_set_var_fns(VP9_COMP *const cpi) {
806 VP9_COMMON *const cm = &cpi->common;
807 if (cm->use_highbitdepth) {
808 switch (cm->bit_depth) {
809 case VPX_BITS_8:
810 HIGHBD_BFP(BLOCK_32X16,
811 vp9_highbd_sad32x16_bits8,
812 vp9_highbd_sad32x16_avg_bits8,
813 vp9_highbd_variance32x16,
814 vp9_highbd_sub_pixel_variance32x16,
815 vp9_highbd_sub_pixel_avg_variance32x16,
816 NULL,
817 NULL,
818 vp9_highbd_sad32x16x4d_bits8)
819
820 HIGHBD_BFP(BLOCK_16X32,
821 vp9_highbd_sad16x32_bits8,
822 vp9_highbd_sad16x32_avg_bits8,
823 vp9_highbd_variance16x32,
824 vp9_highbd_sub_pixel_variance16x32,
825 vp9_highbd_sub_pixel_avg_variance16x32,
826 NULL,
827 NULL,
828 vp9_highbd_sad16x32x4d_bits8)
829
830 HIGHBD_BFP(BLOCK_64X32,
831 vp9_highbd_sad64x32_bits8,
832 vp9_highbd_sad64x32_avg_bits8,
833 vp9_highbd_variance64x32,
834 vp9_highbd_sub_pixel_variance64x32,
835 vp9_highbd_sub_pixel_avg_variance64x32,
836 NULL,
837 NULL,
838 vp9_highbd_sad64x32x4d_bits8)
839
840 HIGHBD_BFP(BLOCK_32X64,
841 vp9_highbd_sad32x64_bits8,
842 vp9_highbd_sad32x64_avg_bits8,
843 vp9_highbd_variance32x64,
844 vp9_highbd_sub_pixel_variance32x64,
845 vp9_highbd_sub_pixel_avg_variance32x64,
846 NULL,
847 NULL,
848 vp9_highbd_sad32x64x4d_bits8)
849
850 HIGHBD_BFP(BLOCK_32X32,
851 vp9_highbd_sad32x32_bits8,
852 vp9_highbd_sad32x32_avg_bits8,
853 vp9_highbd_variance32x32,
854 vp9_highbd_sub_pixel_variance32x32,
855 vp9_highbd_sub_pixel_avg_variance32x32,
856 vp9_highbd_sad32x32x3_bits8,
857 vp9_highbd_sad32x32x8_bits8,
858 vp9_highbd_sad32x32x4d_bits8)
859
860 HIGHBD_BFP(BLOCK_64X64,
861 vp9_highbd_sad64x64_bits8,
862 vp9_highbd_sad64x64_avg_bits8,
863 vp9_highbd_variance64x64,
864 vp9_highbd_sub_pixel_variance64x64,
865 vp9_highbd_sub_pixel_avg_variance64x64,
866 vp9_highbd_sad64x64x3_bits8,
867 vp9_highbd_sad64x64x8_bits8,
868 vp9_highbd_sad64x64x4d_bits8)
869
870 HIGHBD_BFP(BLOCK_16X16,
871 vp9_highbd_sad16x16_bits8,
872 vp9_highbd_sad16x16_avg_bits8,
873 vp9_highbd_variance16x16,
874 vp9_highbd_sub_pixel_variance16x16,
875 vp9_highbd_sub_pixel_avg_variance16x16,
876 vp9_highbd_sad16x16x3_bits8,
877 vp9_highbd_sad16x16x8_bits8,
878 vp9_highbd_sad16x16x4d_bits8)
879
880 HIGHBD_BFP(BLOCK_16X8,
881 vp9_highbd_sad16x8_bits8,
882 vp9_highbd_sad16x8_avg_bits8,
883 vp9_highbd_variance16x8,
884 vp9_highbd_sub_pixel_variance16x8,
885 vp9_highbd_sub_pixel_avg_variance16x8,
886 vp9_highbd_sad16x8x3_bits8,
887 vp9_highbd_sad16x8x8_bits8,
888 vp9_highbd_sad16x8x4d_bits8)
889
890 HIGHBD_BFP(BLOCK_8X16,
891 vp9_highbd_sad8x16_bits8,
892 vp9_highbd_sad8x16_avg_bits8,
893 vp9_highbd_variance8x16,
894 vp9_highbd_sub_pixel_variance8x16,
895 vp9_highbd_sub_pixel_avg_variance8x16,
896 vp9_highbd_sad8x16x3_bits8,
897 vp9_highbd_sad8x16x8_bits8,
898 vp9_highbd_sad8x16x4d_bits8)
899
900 HIGHBD_BFP(BLOCK_8X8,
901 vp9_highbd_sad8x8_bits8,
902 vp9_highbd_sad8x8_avg_bits8,
903 vp9_highbd_variance8x8,
904 vp9_highbd_sub_pixel_variance8x8,
905 vp9_highbd_sub_pixel_avg_variance8x8,
906 vp9_highbd_sad8x8x3_bits8,
907 vp9_highbd_sad8x8x8_bits8,
908 vp9_highbd_sad8x8x4d_bits8)
909
910 HIGHBD_BFP(BLOCK_8X4,
911 vp9_highbd_sad8x4_bits8,
912 vp9_highbd_sad8x4_avg_bits8,
913 vp9_highbd_variance8x4,
914 vp9_highbd_sub_pixel_variance8x4,
915 vp9_highbd_sub_pixel_avg_variance8x4,
916 NULL,
917 vp9_highbd_sad8x4x8_bits8,
918 vp9_highbd_sad8x4x4d_bits8)
919
920 HIGHBD_BFP(BLOCK_4X8,
921 vp9_highbd_sad4x8_bits8,
922 vp9_highbd_sad4x8_avg_bits8,
923 vp9_highbd_variance4x8,
924 vp9_highbd_sub_pixel_variance4x8,
925 vp9_highbd_sub_pixel_avg_variance4x8,
926 NULL,
927 vp9_highbd_sad4x8x8_bits8,
928 vp9_highbd_sad4x8x4d_bits8)
929
930 HIGHBD_BFP(BLOCK_4X4,
931 vp9_highbd_sad4x4_bits8,
932 vp9_highbd_sad4x4_avg_bits8,
933 vp9_highbd_variance4x4,
934 vp9_highbd_sub_pixel_variance4x4,
935 vp9_highbd_sub_pixel_avg_variance4x4,
936 vp9_highbd_sad4x4x3_bits8,
937 vp9_highbd_sad4x4x8_bits8,
938 vp9_highbd_sad4x4x4d_bits8)
939 break;
940
941 case VPX_BITS_10:
942 HIGHBD_BFP(BLOCK_32X16,
943 vp9_highbd_sad32x16_bits10,
944 vp9_highbd_sad32x16_avg_bits10,
945 vp9_highbd_10_variance32x16,
946 vp9_highbd_10_sub_pixel_variance32x16,
947 vp9_highbd_10_sub_pixel_avg_variance32x16,
948 NULL,
949 NULL,
950 vp9_highbd_sad32x16x4d_bits10)
951
952 HIGHBD_BFP(BLOCK_16X32,
953 vp9_highbd_sad16x32_bits10,
954 vp9_highbd_sad16x32_avg_bits10,
955 vp9_highbd_10_variance16x32,
956 vp9_highbd_10_sub_pixel_variance16x32,
957 vp9_highbd_10_sub_pixel_avg_variance16x32,
958 NULL,
959 NULL,
960 vp9_highbd_sad16x32x4d_bits10)
961
962 HIGHBD_BFP(BLOCK_64X32,
963 vp9_highbd_sad64x32_bits10,
964 vp9_highbd_sad64x32_avg_bits10,
965 vp9_highbd_10_variance64x32,
966 vp9_highbd_10_sub_pixel_variance64x32,
967 vp9_highbd_10_sub_pixel_avg_variance64x32,
968 NULL,
969 NULL,
970 vp9_highbd_sad64x32x4d_bits10)
971
972 HIGHBD_BFP(BLOCK_32X64,
973 vp9_highbd_sad32x64_bits10,
974 vp9_highbd_sad32x64_avg_bits10,
975 vp9_highbd_10_variance32x64,
976 vp9_highbd_10_sub_pixel_variance32x64,
977 vp9_highbd_10_sub_pixel_avg_variance32x64,
978 NULL,
979 NULL,
980 vp9_highbd_sad32x64x4d_bits10)
981
982 HIGHBD_BFP(BLOCK_32X32,
983 vp9_highbd_sad32x32_bits10,
984 vp9_highbd_sad32x32_avg_bits10,
985 vp9_highbd_10_variance32x32,
986 vp9_highbd_10_sub_pixel_variance32x32,
987 vp9_highbd_10_sub_pixel_avg_variance32x32,
988 vp9_highbd_sad32x32x3_bits10,
989 vp9_highbd_sad32x32x8_bits10,
990 vp9_highbd_sad32x32x4d_bits10)
991
992 HIGHBD_BFP(BLOCK_64X64,
993 vp9_highbd_sad64x64_bits10,
994 vp9_highbd_sad64x64_avg_bits10,
995 vp9_highbd_10_variance64x64,
996 vp9_highbd_10_sub_pixel_variance64x64,
997 vp9_highbd_10_sub_pixel_avg_variance64x64,
998 vp9_highbd_sad64x64x3_bits10,
999 vp9_highbd_sad64x64x8_bits10,
1000 vp9_highbd_sad64x64x4d_bits10)
1001
1002 HIGHBD_BFP(BLOCK_16X16,
1003 vp9_highbd_sad16x16_bits10,
1004 vp9_highbd_sad16x16_avg_bits10,
1005 vp9_highbd_10_variance16x16,
1006 vp9_highbd_10_sub_pixel_variance16x16,
1007 vp9_highbd_10_sub_pixel_avg_variance16x16,
1008 vp9_highbd_sad16x16x3_bits10,
1009 vp9_highbd_sad16x16x8_bits10,
1010 vp9_highbd_sad16x16x4d_bits10)
1011
1012 HIGHBD_BFP(BLOCK_16X8,
1013 vp9_highbd_sad16x8_bits10,
1014 vp9_highbd_sad16x8_avg_bits10,
1015 vp9_highbd_10_variance16x8,
1016 vp9_highbd_10_sub_pixel_variance16x8,
1017 vp9_highbd_10_sub_pixel_avg_variance16x8,
1018 vp9_highbd_sad16x8x3_bits10,
1019 vp9_highbd_sad16x8x8_bits10,
1020 vp9_highbd_sad16x8x4d_bits10)
1021
1022 HIGHBD_BFP(BLOCK_8X16,
1023 vp9_highbd_sad8x16_bits10,
1024 vp9_highbd_sad8x16_avg_bits10,
1025 vp9_highbd_10_variance8x16,
1026 vp9_highbd_10_sub_pixel_variance8x16,
1027 vp9_highbd_10_sub_pixel_avg_variance8x16,
1028 vp9_highbd_sad8x16x3_bits10,
1029 vp9_highbd_sad8x16x8_bits10,
1030 vp9_highbd_sad8x16x4d_bits10)
1031
1032 HIGHBD_BFP(BLOCK_8X8,
1033 vp9_highbd_sad8x8_bits10,
1034 vp9_highbd_sad8x8_avg_bits10,
1035 vp9_highbd_10_variance8x8,
1036 vp9_highbd_10_sub_pixel_variance8x8,
1037 vp9_highbd_10_sub_pixel_avg_variance8x8,
1038 vp9_highbd_sad8x8x3_bits10,
1039 vp9_highbd_sad8x8x8_bits10,
1040 vp9_highbd_sad8x8x4d_bits10)
1041
1042 HIGHBD_BFP(BLOCK_8X4,
1043 vp9_highbd_sad8x4_bits10,
1044 vp9_highbd_sad8x4_avg_bits10,
1045 vp9_highbd_10_variance8x4,
1046 vp9_highbd_10_sub_pixel_variance8x4,
1047 vp9_highbd_10_sub_pixel_avg_variance8x4,
1048 NULL,
1049 vp9_highbd_sad8x4x8_bits10,
1050 vp9_highbd_sad8x4x4d_bits10)
1051
1052 HIGHBD_BFP(BLOCK_4X8,
1053 vp9_highbd_sad4x8_bits10,
1054 vp9_highbd_sad4x8_avg_bits10,
1055 vp9_highbd_10_variance4x8,
1056 vp9_highbd_10_sub_pixel_variance4x8,
1057 vp9_highbd_10_sub_pixel_avg_variance4x8,
1058 NULL,
1059 vp9_highbd_sad4x8x8_bits10,
1060 vp9_highbd_sad4x8x4d_bits10)
1061
1062 HIGHBD_BFP(BLOCK_4X4,
1063 vp9_highbd_sad4x4_bits10,
1064 vp9_highbd_sad4x4_avg_bits10,
1065 vp9_highbd_10_variance4x4,
1066 vp9_highbd_10_sub_pixel_variance4x4,
1067 vp9_highbd_10_sub_pixel_avg_variance4x4,
1068 vp9_highbd_sad4x4x3_bits10,
1069 vp9_highbd_sad4x4x8_bits10,
1070 vp9_highbd_sad4x4x4d_bits10)
1071 break;
1072
1073 case VPX_BITS_12:
1074 HIGHBD_BFP(BLOCK_32X16,
1075 vp9_highbd_sad32x16_bits12,
1076 vp9_highbd_sad32x16_avg_bits12,
1077 vp9_highbd_12_variance32x16,
1078 vp9_highbd_12_sub_pixel_variance32x16,
1079 vp9_highbd_12_sub_pixel_avg_variance32x16,
1080 NULL,
1081 NULL,
1082 vp9_highbd_sad32x16x4d_bits12)
1083
1084 HIGHBD_BFP(BLOCK_16X32,
1085 vp9_highbd_sad16x32_bits12,
1086 vp9_highbd_sad16x32_avg_bits12,
1087 vp9_highbd_12_variance16x32,
1088 vp9_highbd_12_sub_pixel_variance16x32,
1089 vp9_highbd_12_sub_pixel_avg_variance16x32,
1090 NULL,
1091 NULL,
1092 vp9_highbd_sad16x32x4d_bits12)
1093
1094 HIGHBD_BFP(BLOCK_64X32,
1095 vp9_highbd_sad64x32_bits12,
1096 vp9_highbd_sad64x32_avg_bits12,
1097 vp9_highbd_12_variance64x32,
1098 vp9_highbd_12_sub_pixel_variance64x32,
1099 vp9_highbd_12_sub_pixel_avg_variance64x32,
1100 NULL,
1101 NULL,
1102 vp9_highbd_sad64x32x4d_bits12)
1103
1104 HIGHBD_BFP(BLOCK_32X64,
1105 vp9_highbd_sad32x64_bits12,
1106 vp9_highbd_sad32x64_avg_bits12,
1107 vp9_highbd_12_variance32x64,
1108 vp9_highbd_12_sub_pixel_variance32x64,
1109 vp9_highbd_12_sub_pixel_avg_variance32x64,
1110 NULL,
1111 NULL,
1112 vp9_highbd_sad32x64x4d_bits12)
1113
1114 HIGHBD_BFP(BLOCK_32X32,
1115 vp9_highbd_sad32x32_bits12,
1116 vp9_highbd_sad32x32_avg_bits12,
1117 vp9_highbd_12_variance32x32,
1118 vp9_highbd_12_sub_pixel_variance32x32,
1119 vp9_highbd_12_sub_pixel_avg_variance32x32,
1120 vp9_highbd_sad32x32x3_bits12,
1121 vp9_highbd_sad32x32x8_bits12,
1122 vp9_highbd_sad32x32x4d_bits12)
1123
1124 HIGHBD_BFP(BLOCK_64X64,
1125 vp9_highbd_sad64x64_bits12,
1126 vp9_highbd_sad64x64_avg_bits12,
1127 vp9_highbd_12_variance64x64,
1128 vp9_highbd_12_sub_pixel_variance64x64,
1129 vp9_highbd_12_sub_pixel_avg_variance64x64,
1130 vp9_highbd_sad64x64x3_bits12,
1131 vp9_highbd_sad64x64x8_bits12,
1132 vp9_highbd_sad64x64x4d_bits12)
1133
1134 HIGHBD_BFP(BLOCK_16X16,
1135 vp9_highbd_sad16x16_bits12,
1136 vp9_highbd_sad16x16_avg_bits12,
1137 vp9_highbd_12_variance16x16,
1138 vp9_highbd_12_sub_pixel_variance16x16,
1139 vp9_highbd_12_sub_pixel_avg_variance16x16,
1140 vp9_highbd_sad16x16x3_bits12,
1141 vp9_highbd_sad16x16x8_bits12,
1142 vp9_highbd_sad16x16x4d_bits12)
1143
1144 HIGHBD_BFP(BLOCK_16X8,
1145 vp9_highbd_sad16x8_bits12,
1146 vp9_highbd_sad16x8_avg_bits12,
1147 vp9_highbd_12_variance16x8,
1148 vp9_highbd_12_sub_pixel_variance16x8,
1149 vp9_highbd_12_sub_pixel_avg_variance16x8,
1150 vp9_highbd_sad16x8x3_bits12,
1151 vp9_highbd_sad16x8x8_bits12,
1152 vp9_highbd_sad16x8x4d_bits12)
1153
1154 HIGHBD_BFP(BLOCK_8X16,
1155 vp9_highbd_sad8x16_bits12,
1156 vp9_highbd_sad8x16_avg_bits12,
1157 vp9_highbd_12_variance8x16,
1158 vp9_highbd_12_sub_pixel_variance8x16,
1159 vp9_highbd_12_sub_pixel_avg_variance8x16,
1160 vp9_highbd_sad8x16x3_bits12,
1161 vp9_highbd_sad8x16x8_bits12,
1162 vp9_highbd_sad8x16x4d_bits12)
1163
1164 HIGHBD_BFP(BLOCK_8X8,
1165 vp9_highbd_sad8x8_bits12,
1166 vp9_highbd_sad8x8_avg_bits12,
1167 vp9_highbd_12_variance8x8,
1168 vp9_highbd_12_sub_pixel_variance8x8,
1169 vp9_highbd_12_sub_pixel_avg_variance8x8,
1170 vp9_highbd_sad8x8x3_bits12,
1171 vp9_highbd_sad8x8x8_bits12,
1172 vp9_highbd_sad8x8x4d_bits12)
1173
1174 HIGHBD_BFP(BLOCK_8X4,
1175 vp9_highbd_sad8x4_bits12,
1176 vp9_highbd_sad8x4_avg_bits12,
1177 vp9_highbd_12_variance8x4,
1178 vp9_highbd_12_sub_pixel_variance8x4,
1179 vp9_highbd_12_sub_pixel_avg_variance8x4,
1180 NULL,
1181 vp9_highbd_sad8x4x8_bits12,
1182 vp9_highbd_sad8x4x4d_bits12)
1183
1184 HIGHBD_BFP(BLOCK_4X8,
1185 vp9_highbd_sad4x8_bits12,
1186 vp9_highbd_sad4x8_avg_bits12,
1187 vp9_highbd_12_variance4x8,
1188 vp9_highbd_12_sub_pixel_variance4x8,
1189 vp9_highbd_12_sub_pixel_avg_variance4x8,
1190 NULL,
1191 vp9_highbd_sad4x8x8_bits12,
1192 vp9_highbd_sad4x8x4d_bits12)
1193
1194 HIGHBD_BFP(BLOCK_4X4,
1195 vp9_highbd_sad4x4_bits12,
1196 vp9_highbd_sad4x4_avg_bits12,
1197 vp9_highbd_12_variance4x4,
1198 vp9_highbd_12_sub_pixel_variance4x4,
1199 vp9_highbd_12_sub_pixel_avg_variance4x4,
1200 vp9_highbd_sad4x4x3_bits12,
1201 vp9_highbd_sad4x4x8_bits12,
1202 vp9_highbd_sad4x4x4d_bits12)
1203 break;
1204
1205 default:
1206 assert(0 && "cm->bit_depth should be VPX_BITS_8, "
1207 "VPX_BITS_10 or VPX_BITS_12");
1208 }
1209 }
1210 }
1211 #endif // CONFIG_VP9_HIGHBITDEPTH
1212
607 void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) { 1213 void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) {
608 VP9_COMMON *const cm = &cpi->common; 1214 VP9_COMMON *const cm = &cpi->common;
609 RATE_CONTROL *const rc = &cpi->rc; 1215 RATE_CONTROL *const rc = &cpi->rc;
610 1216
611 if (cm->profile != oxcf->profile) 1217 if (cm->profile != oxcf->profile)
612 cm->profile = oxcf->profile; 1218 cm->profile = oxcf->profile;
613 cm->bit_depth = oxcf->bit_depth; 1219 cm->bit_depth = oxcf->bit_depth;
614 1220
615 if (cm->profile <= PROFILE_1) 1221 if (cm->profile <= PROFILE_1)
616 assert(cm->bit_depth == VPX_BITS_8); 1222 assert(cm->bit_depth == VPX_BITS_8);
617 else 1223 else
618 assert(cm->bit_depth > VPX_BITS_8); 1224 assert(cm->bit_depth > VPX_BITS_8);
619 1225
620 cpi->oxcf = *oxcf; 1226 cpi->oxcf = *oxcf;
621 #if CONFIG_VP9_HIGHBITDEPTH 1227 #if CONFIG_VP9_HIGHBITDEPTH
622 if (cpi->oxcf.use_highbitdepth) { 1228 cpi->mb.e_mbd.bd = (int)cm->bit_depth;
623 cpi->mb.e_mbd.bd = (int)cm->bit_depth; 1229 #endif // CONFIG_VP9_HIGHBITDEPTH
624 }
625 #endif
626 1230
627 rc->baseline_gf_interval = DEFAULT_GF_INTERVAL; 1231 rc->baseline_gf_interval = DEFAULT_GF_INTERVAL;
628 1232
629 cpi->refresh_golden_frame = 0; 1233 cpi->refresh_golden_frame = 0;
630 cpi->refresh_last_frame = 1; 1234 cpi->refresh_last_frame = 1;
631 cm->refresh_frame_context = 1; 1235 cm->refresh_frame_context = 1;
632 cm->reset_frame_context = 0; 1236 cm->reset_frame_context = 0;
633 1237
634 vp9_reset_segment_features(&cm->seg); 1238 vp9_reset_segment_features(&cm->seg);
635 vp9_set_high_precision_mv(cpi, 0); 1239 vp9_set_high_precision_mv(cpi, 0);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 // Experimental RD Code 1290 // Experimental RD Code
687 cpi->frame_distortion = 0; 1291 cpi->frame_distortion = 0;
688 cpi->last_frame_distortion = 0; 1292 cpi->last_frame_distortion = 0;
689 #endif 1293 #endif
690 1294
691 set_tile_limits(cpi); 1295 set_tile_limits(cpi);
692 1296
693 cpi->ext_refresh_frame_flags_pending = 0; 1297 cpi->ext_refresh_frame_flags_pending = 0;
694 cpi->ext_refresh_frame_context_pending = 0; 1298 cpi->ext_refresh_frame_context_pending = 0;
695 1299
1300 #if CONFIG_VP9_HIGHBITDEPTH
1301 highbd_set_var_fns(cpi);
1302 #endif
1303
696 #if CONFIG_VP9_TEMPORAL_DENOISING 1304 #if CONFIG_VP9_TEMPORAL_DENOISING
697 if (cpi->oxcf.noise_sensitivity > 0) { 1305 if (cpi->oxcf.noise_sensitivity > 0) {
698 vp9_denoiser_alloc(&(cpi->denoiser), cm->width, cm->height, 1306 vp9_denoiser_alloc(&(cpi->denoiser), cm->width, cm->height,
699 cm->subsampling_x, cm->subsampling_y, 1307 cm->subsampling_x, cm->subsampling_y,
700 #if CONFIG_VP9_HIGHBITDEPTH 1308 #if CONFIG_VP9_HIGHBITDEPTH
701 cm->use_highbitdepth, 1309 cm->use_highbitdepth,
702 #endif 1310 #endif
703 VP9_ENC_BORDER_IN_PIXELS); 1311 VP9_ENC_BORDER_IN_PIXELS);
704 } 1312 }
705 #endif 1313 #endif
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 } 1373 }
766 1374
767 cm->error.setjmp = 1; 1375 cm->error.setjmp = 1;
768 1376
769 cpi->use_svc = 0; 1377 cpi->use_svc = 0;
770 1378
771 init_config(cpi, oxcf); 1379 init_config(cpi, oxcf);
772 vp9_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc); 1380 vp9_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc);
773 1381
774 cm->current_video_frame = 0; 1382 cm->current_video_frame = 0;
775 cpi->skippable_frame = 0; 1383 cpi->partition_search_skippable_frame = 0;
776 1384
777 // Create the encoder segmentation map and set all entries to 0 1385 // Create the encoder segmentation map and set all entries to 0
778 CHECK_MEM_ERROR(cm, cpi->segmentation_map, 1386 CHECK_MEM_ERROR(cm, cpi->segmentation_map,
779 vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); 1387 vpx_calloc(cm->mi_rows * cm->mi_cols, 1));
780 1388
781 // Create a complexity map used for rd adjustment 1389 // Create a complexity map used for rd adjustment
782 CHECK_MEM_ERROR(cm, cpi->complexity_map, 1390 CHECK_MEM_ERROR(cm, cpi->complexity_map,
783 vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); 1391 vpx_calloc(cm->mi_rows * cm->mi_cols, 1));
784 1392
785 // Create a map used for cyclic background refresh. 1393 // Create a map used for cyclic background refresh.
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
1059 1667
1060 BFP(BLOCK_4X8, vp9_sad4x8, vp9_sad4x8_avg, 1668 BFP(BLOCK_4X8, vp9_sad4x8, vp9_sad4x8_avg,
1061 vp9_variance4x8, vp9_sub_pixel_variance4x8, 1669 vp9_variance4x8, vp9_sub_pixel_variance4x8,
1062 vp9_sub_pixel_avg_variance4x8, NULL, vp9_sad4x8x8, vp9_sad4x8x4d) 1670 vp9_sub_pixel_avg_variance4x8, NULL, vp9_sad4x8x8, vp9_sad4x8x4d)
1063 1671
1064 BFP(BLOCK_4X4, vp9_sad4x4, vp9_sad4x4_avg, 1672 BFP(BLOCK_4X4, vp9_sad4x4, vp9_sad4x4_avg,
1065 vp9_variance4x4, vp9_sub_pixel_variance4x4, 1673 vp9_variance4x4, vp9_sub_pixel_variance4x4,
1066 vp9_sub_pixel_avg_variance4x4, 1674 vp9_sub_pixel_avg_variance4x4,
1067 vp9_sad4x4x3, vp9_sad4x4x8, vp9_sad4x4x4d) 1675 vp9_sad4x4x3, vp9_sad4x4x8, vp9_sad4x4x4d)
1068 1676
1677 #if CONFIG_VP9_HIGHBITDEPTH
1678 highbd_set_var_fns(cpi);
1679 #endif
1680
1069 /* vp9_init_quantizer() is first called here. Add check in 1681 /* vp9_init_quantizer() is first called here. Add check in
1070 * vp9_frame_init_quantizer() so that vp9_init_quantizer is only 1682 * vp9_frame_init_quantizer() so that vp9_init_quantizer is only
1071 * called later when needed. This will avoid unnecessary calls of 1683 * called later when needed. This will avoid unnecessary calls of
1072 * vp9_init_quantizer() for every frame. 1684 * vp9_init_quantizer() for every frame.
1073 */ 1685 */
1074 vp9_init_quantizer(cpi); 1686 vp9_init_quantizer(cpi);
1075 1687
1076 vp9_loop_filter_init(cm); 1688 vp9_loop_filter_init(cm);
1077 1689
1078 cm->error.setjmp = 0; 1690 cm->error.setjmp = 0;
(...skipping 12 matching lines...) Expand all
1091 1703
1092 vp9_clear_system_state(); 1704 vp9_clear_system_state();
1093 1705
1094 // printf("\n8x8-4x4:%d-%d\n", cpi->t8x8_count, cpi->t4x4_count); 1706 // printf("\n8x8-4x4:%d-%d\n", cpi->t8x8_count, cpi->t4x4_count);
1095 if (cpi->oxcf.pass != 1) { 1707 if (cpi->oxcf.pass != 1) {
1096 FILE *f = fopen("opsnr.stt", "a"); 1708 FILE *f = fopen("opsnr.stt", "a");
1097 double time_encoded = (cpi->last_end_time_stamp_seen 1709 double time_encoded = (cpi->last_end_time_stamp_seen
1098 - cpi->first_time_stamp_ever) / 10000000.000; 1710 - cpi->first_time_stamp_ever) / 10000000.000;
1099 double total_encode_time = (cpi->time_receive_data + 1711 double total_encode_time = (cpi->time_receive_data +
1100 cpi->time_compress_data) / 1000.000; 1712 cpi->time_compress_data) / 1000.000;
1101 double dr = (double)cpi->bytes * (double) 8 / (double)1000 1713 const double dr =
1102 / time_encoded; 1714 (double)cpi->bytes * (double) 8 / (double)1000 / time_encoded;
1715 const double peak = (double)((1 << cpi->oxcf.input_bit_depth) - 1);
1103 1716
1104 if (cpi->b_calculate_psnr) { 1717 if (cpi->b_calculate_psnr) {
1105 const double total_psnr = 1718 const double total_psnr =
1106 vpx_sse_to_psnr((double)cpi->total_samples, 255.0, 1719 vpx_sse_to_psnr((double)cpi->total_samples, peak,
1107 (double)cpi->total_sq_error); 1720 (double)cpi->total_sq_error);
1108 const double totalp_psnr = 1721 const double totalp_psnr =
1109 vpx_sse_to_psnr((double)cpi->totalp_samples, 255.0, 1722 vpx_sse_to_psnr((double)cpi->totalp_samples, peak,
1110 (double)cpi->totalp_sq_error); 1723 (double)cpi->totalp_sq_error);
1111 const double total_ssim = 100 * pow(cpi->summed_quality / 1724 const double total_ssim = 100 * pow(cpi->summed_quality /
1112 cpi->summed_weights, 8.0); 1725 cpi->summed_weights, 8.0);
1113 const double totalp_ssim = 100 * pow(cpi->summedp_quality / 1726 const double totalp_ssim = 100 * pow(cpi->summedp_quality /
1114 cpi->summedp_weights, 8.0); 1727 cpi->summedp_weights, 8.0);
1115 1728
1116 fprintf(f, "Bitrate\tAVGPsnr\tGLBPsnr\tAVPsnrP\tGLPsnrP\t" 1729 fprintf(f, "Bitrate\tAVGPsnr\tGLBPsnr\tAVPsnrP\tGLPsnrP\t"
1117 "VPXSSIM\tVPSSIMP\t Time(ms)\n"); 1730 "VPXSSIM\tVPSSIMP\t Time(ms)\n");
1118 fprintf(f, "%7.2f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t%8.0f\n", 1731 fprintf(f, "%7.2f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t%8.0f\n",
1119 dr, cpi->total / cpi->count, total_psnr, 1732 dr, cpi->total / cpi->count, total_psnr,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 fclose(keyfile); 1799 fclose(keyfile);
1187 1800
1188 if (framepsnr) 1801 if (framepsnr)
1189 fclose(framepsnr); 1802 fclose(framepsnr);
1190 1803
1191 if (kf_list) 1804 if (kf_list)
1192 fclose(kf_list); 1805 fclose(kf_list);
1193 1806
1194 #endif 1807 #endif
1195 } 1808 }
1809
1196 static int64_t get_sse(const uint8_t *a, int a_stride, 1810 static int64_t get_sse(const uint8_t *a, int a_stride,
1197 const uint8_t *b, int b_stride, 1811 const uint8_t *b, int b_stride,
1198 int width, int height) { 1812 int width, int height) {
1199 const int dw = width % 16; 1813 const int dw = width % 16;
1200 const int dh = height % 16; 1814 const int dh = height % 16;
1201 int64_t total_sse = 0; 1815 int64_t total_sse = 0;
1202 unsigned int sse = 0; 1816 unsigned int sse = 0;
1203 int sum = 0; 1817 int sum = 0;
1204 int x, y; 1818 int x, y;
1205 1819
(...skipping 21 matching lines...) Expand all
1227 pb += 16; 1841 pb += 16;
1228 } 1842 }
1229 1843
1230 a += 16 * a_stride; 1844 a += 16 * a_stride;
1231 b += 16 * b_stride; 1845 b += 16 * b_stride;
1232 } 1846 }
1233 1847
1234 return total_sse; 1848 return total_sse;
1235 } 1849 }
1236 1850
1851 #if CONFIG_VP9_HIGHBITDEPTH
1852 static int64_t highbd_get_sse_shift(const uint8_t *a8, int a_stride,
1853 const uint8_t *b8, int b_stride,
1854 int width, int height,
1855 unsigned int input_shift) {
1856 const uint16_t *a = CONVERT_TO_SHORTPTR(a8);
1857 const uint16_t *b = CONVERT_TO_SHORTPTR(b8);
1858 int64_t total_sse = 0;
1859 int x, y;
1860 for (y = 0; y < height; ++y) {
1861 for (x = 0; x < width; ++x) {
1862 int64_t diff;
1863 diff = (a[x] >> input_shift) - (b[x] >> input_shift);
1864 total_sse += diff * diff;
1865 }
1866 a += a_stride;
1867 b += b_stride;
1868 }
1869 return total_sse;
1870 }
1871
1872 static int64_t highbd_get_sse(const uint8_t *a, int a_stride,
1873 const uint8_t *b, int b_stride,
1874 int width, int height) {
1875 int64_t total_sse = 0;
1876 int x, y;
1877 const int dw = width % 16;
1878 const int dh = height % 16;
1879 unsigned int sse = 0;
1880 int sum = 0;
1881 if (dw > 0) {
1882 highbd_variance(&a[width - dw], a_stride, &b[width - dw], b_stride,
1883 dw, height, &sse, &sum);
1884 total_sse += sse;
1885 }
1886 if (dh > 0) {
1887 highbd_variance(&a[(height - dh) * a_stride], a_stride,
1888 &b[(height - dh) * b_stride], b_stride,
1889 width - dw, dh, &sse, &sum);
1890 total_sse += sse;
1891 }
1892 for (y = 0; y < height / 16; ++y) {
1893 const uint8_t *pa = a;
1894 const uint8_t *pb = b;
1895 for (x = 0; x < width / 16; ++x) {
1896 vp9_highbd_mse16x16(pa, a_stride, pb, b_stride, &sse);
1897 total_sse += sse;
1898 pa += 16;
1899 pb += 16;
1900 }
1901 a += 16 * a_stride;
1902 b += 16 * b_stride;
1903 }
1904 return total_sse;
1905 }
1906 #endif // CONFIG_VP9_HIGHBITDEPTH
1907
1237 typedef struct { 1908 typedef struct {
1238 double psnr[4]; // total/y/u/v 1909 double psnr[4]; // total/y/u/v
1239 uint64_t sse[4]; // total/y/u/v 1910 uint64_t sse[4]; // total/y/u/v
1240 uint32_t samples[4]; // total/y/u/v 1911 uint32_t samples[4]; // total/y/u/v
1241 } PSNR_STATS; 1912 } PSNR_STATS;
1242 1913
1243 static void calc_psnr(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b, 1914 static void calc_psnr(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b,
1244 PSNR_STATS *psnr) { 1915 PSNR_STATS *psnr) {
1916 static const double peak = 255.0;
1245 const int widths[3] = {a->y_width, a->uv_width, a->uv_width }; 1917 const int widths[3] = {a->y_width, a->uv_width, a->uv_width };
1246 const int heights[3] = {a->y_height, a->uv_height, a->uv_height}; 1918 const int heights[3] = {a->y_height, a->uv_height, a->uv_height};
1247 const uint8_t *a_planes[3] = {a->y_buffer, a->u_buffer, a->v_buffer }; 1919 const uint8_t *a_planes[3] = {a->y_buffer, a->u_buffer, a->v_buffer };
1248 const int a_strides[3] = {a->y_stride, a->uv_stride, a->uv_stride}; 1920 const int a_strides[3] = {a->y_stride, a->uv_stride, a->uv_stride};
1249 const uint8_t *b_planes[3] = {b->y_buffer, b->u_buffer, b->v_buffer }; 1921 const uint8_t *b_planes[3] = {b->y_buffer, b->u_buffer, b->v_buffer };
1250 const int b_strides[3] = {b->y_stride, b->uv_stride, b->uv_stride}; 1922 const int b_strides[3] = {b->y_stride, b->uv_stride, b->uv_stride};
1251 int i; 1923 int i;
1252 uint64_t total_sse = 0; 1924 uint64_t total_sse = 0;
1253 uint32_t total_samples = 0; 1925 uint32_t total_samples = 0;
1254 1926
1255 for (i = 0; i < 3; ++i) { 1927 for (i = 0; i < 3; ++i) {
1256 const int w = widths[i]; 1928 const int w = widths[i];
1257 const int h = heights[i]; 1929 const int h = heights[i];
1258 const uint32_t samples = w * h; 1930 const uint32_t samples = w * h;
1259 const uint64_t sse = get_sse(a_planes[i], a_strides[i], 1931 const uint64_t sse = get_sse(a_planes[i], a_strides[i],
1260 b_planes[i], b_strides[i], 1932 b_planes[i], b_strides[i],
1261 w, h); 1933 w, h);
1262 psnr->sse[1 + i] = sse; 1934 psnr->sse[1 + i] = sse;
1263 psnr->samples[1 + i] = samples; 1935 psnr->samples[1 + i] = samples;
1264 psnr->psnr[1 + i] = vpx_sse_to_psnr(samples, 255.0, (double)sse); 1936 psnr->psnr[1 + i] = vpx_sse_to_psnr(samples, peak, (double)sse);
1265 1937
1266 total_sse += sse; 1938 total_sse += sse;
1267 total_samples += samples; 1939 total_samples += samples;
1268 } 1940 }
1269 1941
1270 psnr->sse[0] = total_sse; 1942 psnr->sse[0] = total_sse;
1271 psnr->samples[0] = total_samples; 1943 psnr->samples[0] = total_samples;
1272 psnr->psnr[0] = vpx_sse_to_psnr((double)total_samples, 255.0, 1944 psnr->psnr[0] = vpx_sse_to_psnr((double)total_samples, peak,
1273 (double)total_sse); 1945 (double)total_sse);
1274 } 1946 }
1275 1947
1948 #if CONFIG_VP9_HIGHBITDEPTH
1949 static void calc_highbd_psnr(const YV12_BUFFER_CONFIG *a,
1950 const YV12_BUFFER_CONFIG *b,
1951 PSNR_STATS *psnr,
1952 unsigned int bit_depth,
1953 unsigned int in_bit_depth) {
1954 const int widths[3] = {a->y_width, a->uv_width, a->uv_width };
1955 const int heights[3] = {a->y_height, a->uv_height, a->uv_height};
1956 const uint8_t *a_planes[3] = {a->y_buffer, a->u_buffer, a->v_buffer };
1957 const int a_strides[3] = {a->y_stride, a->uv_stride, a->uv_stride};
1958 const uint8_t *b_planes[3] = {b->y_buffer, b->u_buffer, b->v_buffer };
1959 const int b_strides[3] = {b->y_stride, b->uv_stride, b->uv_stride};
1960 int i;
1961 uint64_t total_sse = 0;
1962 uint32_t total_samples = 0;
1963 const double peak = (double)((1 << in_bit_depth) - 1);
1964 const unsigned int input_shift = bit_depth - in_bit_depth;
1965
1966 for (i = 0; i < 3; ++i) {
1967 const int w = widths[i];
1968 const int h = heights[i];
1969 const uint32_t samples = w * h;
1970 uint64_t sse;
1971 if (a->flags & YV12_FLAG_HIGHBITDEPTH) {
1972 if (input_shift) {
1973 sse = highbd_get_sse_shift(a_planes[i], a_strides[i],
1974 b_planes[i], b_strides[i], w, h,
1975 input_shift);
1976 } else {
1977 sse = highbd_get_sse(a_planes[i], a_strides[i],
1978 b_planes[i], b_strides[i], w, h);
1979 }
1980 } else {
1981 sse = get_sse(a_planes[i], a_strides[i],
1982 b_planes[i], b_strides[i],
1983 w, h);
1984 }
1985 psnr->sse[1 + i] = sse;
1986 psnr->samples[1 + i] = samples;
1987 psnr->psnr[1 + i] = vpx_sse_to_psnr(samples, peak, (double)sse);
1988
1989 total_sse += sse;
1990 total_samples += samples;
1991 }
1992
1993 psnr->sse[0] = total_sse;
1994 psnr->samples[0] = total_samples;
1995 psnr->psnr[0] = vpx_sse_to_psnr((double)total_samples, peak,
1996 (double)total_sse);
1997 }
1998 #endif // CONFIG_VP9_HIGHBITDEPTH
1999
1276 static void generate_psnr_packet(VP9_COMP *cpi) { 2000 static void generate_psnr_packet(VP9_COMP *cpi) {
1277 struct vpx_codec_cx_pkt pkt; 2001 struct vpx_codec_cx_pkt pkt;
1278 int i; 2002 int i;
1279 PSNR_STATS psnr; 2003 PSNR_STATS psnr;
2004 #if CONFIG_VP9_HIGHBITDEPTH
2005 calc_highbd_psnr(cpi->Source, cpi->common.frame_to_show, &psnr,
2006 cpi->mb.e_mbd.bd, cpi->oxcf.input_bit_depth);
2007 #else
1280 calc_psnr(cpi->Source, cpi->common.frame_to_show, &psnr); 2008 calc_psnr(cpi->Source, cpi->common.frame_to_show, &psnr);
2009 #endif
2010
1281 for (i = 0; i < 4; ++i) { 2011 for (i = 0; i < 4; ++i) {
1282 pkt.data.psnr.samples[i] = psnr.samples[i]; 2012 pkt.data.psnr.samples[i] = psnr.samples[i];
1283 pkt.data.psnr.sse[i] = psnr.sse[i]; 2013 pkt.data.psnr.sse[i] = psnr.sse[i];
1284 pkt.data.psnr.psnr[i] = psnr.psnr[i]; 2014 pkt.data.psnr.psnr[i] = psnr.psnr[i];
1285 } 2015 }
1286 pkt.kind = VPX_CODEC_PSNR_PKT; 2016 pkt.kind = VPX_CODEC_PSNR_PKT;
1287 if (is_two_pass_svc(cpi)) 2017 if (is_two_pass_svc(cpi))
1288 cpi->svc.layer_context[cpi->svc.spatial_layer_id].psnr_pkt = pkt.data.psnr; 2018 cpi->svc.layer_context[cpi->svc.spatial_layer_id].psnr_pkt = pkt.data.psnr;
1289 else 2019 else
1290 vpx_codec_pkt_list_add(cpi->output_pkt_list, &pkt); 2020 vpx_codec_pkt_list_add(cpi->output_pkt_list, &pkt);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1379 } 2109 }
1380 #endif 2110 #endif
1381 #endif 2111 #endif
1382 2112
1383 #ifdef OUTPUT_YUV_REC 2113 #ifdef OUTPUT_YUV_REC
1384 void vp9_write_yuv_rec_frame(VP9_COMMON *cm) { 2114 void vp9_write_yuv_rec_frame(VP9_COMMON *cm) {
1385 YV12_BUFFER_CONFIG *s = cm->frame_to_show; 2115 YV12_BUFFER_CONFIG *s = cm->frame_to_show;
1386 uint8_t *src = s->y_buffer; 2116 uint8_t *src = s->y_buffer;
1387 int h = cm->height; 2117 int h = cm->height;
1388 2118
2119 #if CONFIG_VP9_HIGHBITDEPTH
2120 if (s->flags & YV12_FLAG_HIGHBITDEPTH) {
2121 uint16_t *src16 = CONVERT_TO_SHORTPTR(s->y_buffer);
2122
2123 do {
2124 fwrite(src16, s->y_width, 2, yuv_rec_file);
2125 src16 += s->y_stride;
2126 } while (--h);
2127
2128 src16 = CONVERT_TO_SHORTPTR(s->u_buffer);
2129 h = s->uv_height;
2130
2131 do {
2132 fwrite(src16, s->uv_width, 2, yuv_rec_file);
2133 src16 += s->uv_stride;
2134 } while (--h);
2135
2136 src16 = CONVERT_TO_SHORTPTR(s->v_buffer);
2137 h = s->uv_height;
2138
2139 do {
2140 fwrite(src16, s->uv_width, 2, yuv_rec_file);
2141 src16 += s->uv_stride;
2142 } while (--h);
2143
2144 fflush(yuv_rec_file);
2145 return;
2146 }
2147 #endif // CONFIG_VP9_HIGHBITDEPTH
2148
1389 do { 2149 do {
1390 fwrite(src, s->y_width, 1, yuv_rec_file); 2150 fwrite(src, s->y_width, 1, yuv_rec_file);
1391 src += s->y_stride; 2151 src += s->y_stride;
1392 } while (--h); 2152 } while (--h);
1393 2153
1394 src = s->u_buffer; 2154 src = s->u_buffer;
1395 h = s->uv_height; 2155 h = s->uv_height;
1396 2156
1397 do { 2157 do {
1398 fwrite(src, s->uv_width, 1, yuv_rec_file); 2158 fwrite(src, s->uv_width, 1, yuv_rec_file);
1399 src += s->uv_stride; 2159 src += s->uv_stride;
1400 } while (--h); 2160 } while (--h);
1401 2161
1402 src = s->v_buffer; 2162 src = s->v_buffer;
1403 h = s->uv_height; 2163 h = s->uv_height;
1404 2164
1405 do { 2165 do {
1406 fwrite(src, s->uv_width, 1, yuv_rec_file); 2166 fwrite(src, s->uv_width, 1, yuv_rec_file);
1407 src += s->uv_stride; 2167 src += s->uv_stride;
1408 } while (--h); 2168 } while (--h);
1409 2169
1410 fflush(yuv_rec_file); 2170 fflush(yuv_rec_file);
1411 } 2171 }
1412 #endif 2172 #endif
1413 2173
2174 #if CONFIG_VP9_HIGHBITDEPTH
2175 static void scale_and_extend_frame_nonnormative(const YV12_BUFFER_CONFIG *src,
2176 YV12_BUFFER_CONFIG *dst,
2177 int bd) {
2178 #else
1414 static void scale_and_extend_frame_nonnormative(const YV12_BUFFER_CONFIG *src, 2179 static void scale_and_extend_frame_nonnormative(const YV12_BUFFER_CONFIG *src,
1415 YV12_BUFFER_CONFIG *dst) { 2180 YV12_BUFFER_CONFIG *dst) {
2181 #endif // CONFIG_VP9_HIGHBITDEPTH
1416 // TODO(dkovalev): replace YV12_BUFFER_CONFIG with vpx_image_t 2182 // TODO(dkovalev): replace YV12_BUFFER_CONFIG with vpx_image_t
1417 int i; 2183 int i;
1418 const uint8_t *const srcs[3] = {src->y_buffer, src->u_buffer, src->v_buffer}; 2184 const uint8_t *const srcs[3] = {src->y_buffer, src->u_buffer, src->v_buffer};
1419 const int src_strides[3] = {src->y_stride, src->uv_stride, src->uv_stride}; 2185 const int src_strides[3] = {src->y_stride, src->uv_stride, src->uv_stride};
1420 const int src_widths[3] = {src->y_crop_width, src->uv_crop_width, 2186 const int src_widths[3] = {src->y_crop_width, src->uv_crop_width,
1421 src->uv_crop_width }; 2187 src->uv_crop_width };
1422 const int src_heights[3] = {src->y_crop_height, src->uv_crop_height, 2188 const int src_heights[3] = {src->y_crop_height, src->uv_crop_height,
1423 src->uv_crop_height}; 2189 src->uv_crop_height};
1424 uint8_t *const dsts[3] = {dst->y_buffer, dst->u_buffer, dst->v_buffer}; 2190 uint8_t *const dsts[3] = {dst->y_buffer, dst->u_buffer, dst->v_buffer};
1425 const int dst_strides[3] = {dst->y_stride, dst->uv_stride, dst->uv_stride}; 2191 const int dst_strides[3] = {dst->y_stride, dst->uv_stride, dst->uv_stride};
1426 const int dst_widths[3] = {dst->y_crop_width, dst->uv_crop_width, 2192 const int dst_widths[3] = {dst->y_crop_width, dst->uv_crop_width,
1427 dst->uv_crop_width}; 2193 dst->uv_crop_width};
1428 const int dst_heights[3] = {dst->y_crop_height, dst->uv_crop_height, 2194 const int dst_heights[3] = {dst->y_crop_height, dst->uv_crop_height,
1429 dst->uv_crop_height}; 2195 dst->uv_crop_height};
1430 2196
1431 for (i = 0; i < MAX_MB_PLANE; ++i) 2197 for (i = 0; i < MAX_MB_PLANE; ++i) {
2198 #if CONFIG_VP9_HIGHBITDEPTH
2199 if (src->flags & YV12_FLAG_HIGHBITDEPTH) {
2200 vp9_highbd_resize_plane(srcs[i], src_heights[i], src_widths[i],
2201 src_strides[i], dsts[i], dst_heights[i],
2202 dst_widths[i], dst_strides[i], bd);
2203 } else {
2204 vp9_resize_plane(srcs[i], src_heights[i], src_widths[i], src_strides[i],
2205 dsts[i], dst_heights[i], dst_widths[i], dst_strides[i]);
2206 }
2207 #else
1432 vp9_resize_plane(srcs[i], src_heights[i], src_widths[i], src_strides[i], 2208 vp9_resize_plane(srcs[i], src_heights[i], src_widths[i], src_strides[i],
1433 dsts[i], dst_heights[i], dst_widths[i], dst_strides[i]); 2209 dsts[i], dst_heights[i], dst_widths[i], dst_strides[i]);
1434 2210 #endif // CONFIG_VP9_HIGHBITDEPTH
2211 }
1435 vp9_extend_frame_borders(dst); 2212 vp9_extend_frame_borders(dst);
1436 } 2213 }
1437 2214
2215 #if CONFIG_VP9_HIGHBITDEPTH
2216 static void scale_and_extend_frame(const YV12_BUFFER_CONFIG *src,
2217 YV12_BUFFER_CONFIG *dst, int bd) {
2218 #else
1438 static void scale_and_extend_frame(const YV12_BUFFER_CONFIG *src, 2219 static void scale_and_extend_frame(const YV12_BUFFER_CONFIG *src,
1439 YV12_BUFFER_CONFIG *dst) { 2220 YV12_BUFFER_CONFIG *dst) {
2221 #endif // CONFIG_VP9_HIGHBITDEPTH
1440 const int src_w = src->y_crop_width; 2222 const int src_w = src->y_crop_width;
1441 const int src_h = src->y_crop_height; 2223 const int src_h = src->y_crop_height;
1442 const int dst_w = dst->y_crop_width; 2224 const int dst_w = dst->y_crop_width;
1443 const int dst_h = dst->y_crop_height; 2225 const int dst_h = dst->y_crop_height;
1444 const uint8_t *const srcs[3] = {src->y_buffer, src->u_buffer, src->v_buffer}; 2226 const uint8_t *const srcs[3] = {src->y_buffer, src->u_buffer, src->v_buffer};
1445 const int src_strides[3] = {src->y_stride, src->uv_stride, src->uv_stride}; 2227 const int src_strides[3] = {src->y_stride, src->uv_stride, src->uv_stride};
1446 uint8_t *const dsts[3] = {dst->y_buffer, dst->u_buffer, dst->v_buffer}; 2228 uint8_t *const dsts[3] = {dst->y_buffer, dst->u_buffer, dst->v_buffer};
1447 const int dst_strides[3] = {dst->y_stride, dst->uv_stride, dst->uv_stride}; 2229 const int dst_strides[3] = {dst->y_stride, dst->uv_stride, dst->uv_stride};
1448 const InterpKernel *const kernel = vp9_get_interp_kernel(EIGHTTAP); 2230 const InterpKernel *const kernel = vp9_get_interp_kernel(EIGHTTAP);
1449 int x, y, i; 2231 int x, y, i;
1450 2232
1451 for (y = 0; y < dst_h; y += 16) { 2233 for (y = 0; y < dst_h; y += 16) {
1452 for (x = 0; x < dst_w; x += 16) { 2234 for (x = 0; x < dst_w; x += 16) {
1453 for (i = 0; i < MAX_MB_PLANE; ++i) { 2235 for (i = 0; i < MAX_MB_PLANE; ++i) {
1454 const int factor = (i == 0 || i == 3 ? 1 : 2); 2236 const int factor = (i == 0 || i == 3 ? 1 : 2);
1455 const int x_q4 = x * (16 / factor) * src_w / dst_w; 2237 const int x_q4 = x * (16 / factor) * src_w / dst_w;
1456 const int y_q4 = y * (16 / factor) * src_h / dst_h; 2238 const int y_q4 = y * (16 / factor) * src_h / dst_h;
1457 const int src_stride = src_strides[i]; 2239 const int src_stride = src_strides[i];
1458 const int dst_stride = dst_strides[i]; 2240 const int dst_stride = dst_strides[i];
1459 const uint8_t *src_ptr = srcs[i] + (y / factor) * src_h / dst_h * 2241 const uint8_t *src_ptr = srcs[i] + (y / factor) * src_h / dst_h *
1460 src_stride + (x / factor) * src_w / dst_w; 2242 src_stride + (x / factor) * src_w / dst_w;
1461 uint8_t *dst_ptr = dsts[i] + (y / factor) * dst_stride + (x / factor); 2243 uint8_t *dst_ptr = dsts[i] + (y / factor) * dst_stride + (x / factor);
1462 2244
2245 #if CONFIG_VP9_HIGHBITDEPTH
2246 if (src->flags & YV12_FLAG_HIGHBITDEPTH) {
2247 vp9_highbd_convolve8(src_ptr, src_stride, dst_ptr, dst_stride,
2248 kernel[x_q4 & 0xf], 16 * src_w / dst_w,
2249 kernel[y_q4 & 0xf], 16 * src_h / dst_h,
2250 16 / factor, 16 / factor, bd);
2251 } else {
2252 vp9_convolve8(src_ptr, src_stride, dst_ptr, dst_stride,
2253 kernel[x_q4 & 0xf], 16 * src_w / dst_w,
2254 kernel[y_q4 & 0xf], 16 * src_h / dst_h,
2255 16 / factor, 16 / factor);
2256 }
2257 #else
1463 vp9_convolve8(src_ptr, src_stride, dst_ptr, dst_stride, 2258 vp9_convolve8(src_ptr, src_stride, dst_ptr, dst_stride,
1464 kernel[x_q4 & 0xf], 16 * src_w / dst_w, 2259 kernel[x_q4 & 0xf], 16 * src_w / dst_w,
1465 kernel[y_q4 & 0xf], 16 * src_h / dst_h, 2260 kernel[y_q4 & 0xf], 16 * src_h / dst_h,
1466 16 / factor, 16 / factor); 2261 16 / factor, 16 / factor);
2262 #endif // CONFIG_VP9_HIGHBITDEPTH
1467 } 2263 }
1468 } 2264 }
1469 } 2265 }
1470 2266
1471 vp9_extend_frame_borders(dst); 2267 vp9_extend_frame_borders(dst);
1472 } 2268 }
1473 2269
1474 // Function to test for conditions that indicate we should loop 2270 // Function to test for conditions that indicate we should loop
1475 // back and recode a frame. 2271 // back and recode a frame.
1476 static int recode_loop_test(const VP9_COMP *cpi, 2272 static int recode_loop_test(const VP9_COMP *cpi,
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1625 2421
1626 // Need to convert from VP9_REFFRAME to index into ref_mask (subtract 1). 2422 // Need to convert from VP9_REFFRAME to index into ref_mask (subtract 1).
1627 if ((cpi->ref_frame_flags & ref_mask[ref_frame - 1]) && 2423 if ((cpi->ref_frame_flags & ref_mask[ref_frame - 1]) &&
1628 (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height)) { 2424 (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height)) {
1629 const int new_fb = get_free_fb(cm); 2425 const int new_fb = get_free_fb(cm);
1630 vp9_realloc_frame_buffer(&cm->frame_bufs[new_fb].buf, 2426 vp9_realloc_frame_buffer(&cm->frame_bufs[new_fb].buf,
1631 cm->width, cm->height, 2427 cm->width, cm->height,
1632 cm->subsampling_x, cm->subsampling_y, 2428 cm->subsampling_x, cm->subsampling_y,
1633 #if CONFIG_VP9_HIGHBITDEPTH 2429 #if CONFIG_VP9_HIGHBITDEPTH
1634 cm->use_highbitdepth, 2430 cm->use_highbitdepth,
1635 #endif 2431 #endif // CONFIG_VP9_HIGHBITDEPTH
1636 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL); 2432 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL);
2433 #if CONFIG_VP9_HIGHBITDEPTH
2434 scale_and_extend_frame(ref, &cm->frame_bufs[new_fb].buf,
2435 (int)cm->bit_depth);
2436 #else
1637 scale_and_extend_frame(ref, &cm->frame_bufs[new_fb].buf); 2437 scale_and_extend_frame(ref, &cm->frame_bufs[new_fb].buf);
2438 #endif // CONFIG_VP9_HIGHBITDEPTH
1638 cpi->scaled_ref_idx[ref_frame - 1] = new_fb; 2439 cpi->scaled_ref_idx[ref_frame - 1] = new_fb;
1639 } else { 2440 } else {
1640 cpi->scaled_ref_idx[ref_frame - 1] = idx; 2441 cpi->scaled_ref_idx[ref_frame - 1] = idx;
1641 cm->frame_bufs[idx].ref_count++; 2442 cm->frame_bufs[idx].ref_count++;
1642 } 2443 }
1643 } 2444 }
1644 } 2445 }
1645 2446
1646 static void release_scaled_references(VP9_COMP *cpi) { 2447 static void release_scaled_references(VP9_COMP *cpi) {
1647 VP9_COMMON *cm = &cpi->common; 2448 VP9_COMMON *cm = &cpi->common;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1691 "%10"PRId64" %10.3lf" 2492 "%10"PRId64" %10.3lf"
1692 "%10lf %8u %10d %10d %10d\n", 2493 "%10lf %8u %10d %10d %10d\n",
1693 cpi->common.current_video_frame, cpi->rc.this_frame_target, 2494 cpi->common.current_video_frame, cpi->rc.this_frame_target,
1694 cpi->rc.projected_frame_size, 2495 cpi->rc.projected_frame_size,
1695 cpi->rc.projected_frame_size / cpi->common.MBs, 2496 cpi->rc.projected_frame_size / cpi->common.MBs,
1696 (cpi->rc.projected_frame_size - cpi->rc.this_frame_target), 2497 (cpi->rc.projected_frame_size - cpi->rc.this_frame_target),
1697 cpi->rc.vbr_bits_off_target, 2498 cpi->rc.vbr_bits_off_target,
1698 cpi->rc.total_target_vs_actual, 2499 cpi->rc.total_target_vs_actual,
1699 (cpi->rc.starting_buffer_level - cpi->rc.bits_off_target), 2500 (cpi->rc.starting_buffer_level - cpi->rc.bits_off_target),
1700 cpi->rc.total_actual_bits, cm->base_qindex, 2501 cpi->rc.total_actual_bits, cm->base_qindex,
1701 vp9_convert_qindex_to_q(cm->base_qindex), 2502 vp9_convert_qindex_to_q(cm->base_qindex, cm->bit_depth),
1702 (double)vp9_dc_quant(cm->base_qindex, 0) / 4.0, 2503 (double)vp9_dc_quant(cm->base_qindex, 0, cm->bit_depth) / 4.0,
1703 vp9_convert_qindex_to_q(cpi->twopass.active_worst_quality), 2504 vp9_convert_qindex_to_q(cpi->twopass.active_worst_quality,
2505 cm->bit_depth),
1704 cpi->rc.avg_q, 2506 cpi->rc.avg_q,
1705 vp9_convert_qindex_to_q(cpi->oxcf.cq_level), 2507 vp9_convert_qindex_to_q(cpi->oxcf.cq_level, cm->bit_depth),
1706 cpi->refresh_last_frame, cpi->refresh_golden_frame, 2508 cpi->refresh_last_frame, cpi->refresh_golden_frame,
1707 cpi->refresh_alt_ref_frame, cm->frame_type, cpi->rc.gfu_boost, 2509 cpi->refresh_alt_ref_frame, cm->frame_type, cpi->rc.gfu_boost,
1708 cpi->twopass.bits_left, 2510 cpi->twopass.bits_left,
1709 cpi->twopass.total_left_stats.coded_error, 2511 cpi->twopass.total_left_stats.coded_error,
1710 cpi->twopass.bits_left / 2512 cpi->twopass.bits_left /
1711 (1 + cpi->twopass.total_left_stats.coded_error), 2513 (1 + cpi->twopass.total_left_stats.coded_error),
1712 cpi->tot_recode_hits, recon_err, cpi->rc.kf_boost, 2514 cpi->tot_recode_hits, recon_err, cpi->rc.kf_boost,
1713 cpi->twopass.kf_zeromotion_pct); 2515 cpi->twopass.kf_zeromotion_pct);
1714 2516
1715 fclose(f); 2517 fclose(f);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1817 frame_over_shoot_limit = 1; 2619 frame_over_shoot_limit = 1;
1818 } 2620 }
1819 2621
1820 if (cpi->oxcf.rc_mode == VPX_Q) { 2622 if (cpi->oxcf.rc_mode == VPX_Q) {
1821 loop = 0; 2623 loop = 0;
1822 } else { 2624 } else {
1823 if ((cm->frame_type == KEY_FRAME) && 2625 if ((cm->frame_type == KEY_FRAME) &&
1824 rc->this_key_frame_forced && 2626 rc->this_key_frame_forced &&
1825 (rc->projected_frame_size < rc->max_frame_bandwidth)) { 2627 (rc->projected_frame_size < rc->max_frame_bandwidth)) {
1826 int last_q = q; 2628 int last_q = q;
1827 int kf_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm)); 2629 int kf_err;
1828 2630
1829 int high_err_target = cpi->ambient_err; 2631 int high_err_target = cpi->ambient_err;
1830 int low_err_target = cpi->ambient_err >> 1; 2632 int low_err_target = cpi->ambient_err >> 1;
1831 2633
2634 #if CONFIG_VP9_HIGHBITDEPTH
2635 if (cm->use_highbitdepth) {
2636 kf_err = vp9_highbd_get_y_sse(cpi->Source, get_frame_new_buffer(cm),
2637 cm->bit_depth);
2638 } else {
2639 kf_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm));
2640 }
2641 #else
2642 kf_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm));
2643 #endif // CONFIG_VP9_HIGHBITDEPTH
2644
1832 // Prevent possible divide by zero error below for perfect KF 2645 // Prevent possible divide by zero error below for perfect KF
1833 kf_err += !kf_err; 2646 kf_err += !kf_err;
1834 2647
1835 // The key frame is not good enough or we can afford 2648 // The key frame is not good enough or we can afford
1836 // to make it better without undue risk of popping. 2649 // to make it better without undue risk of popping.
1837 if ((kf_err > high_err_target && 2650 if ((kf_err > high_err_target &&
1838 rc->projected_frame_size <= frame_over_shoot_limit) || 2651 rc->projected_frame_size <= frame_over_shoot_limit) ||
1839 (kf_err > low_err_target && 2652 (kf_err > low_err_target &&
1840 rc->projected_frame_size <= frame_under_shoot_limit)) { 2653 rc->projected_frame_size <= frame_under_shoot_limit)) {
1841 // Lower q_high 2654 // Lower q_high
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1992 cpi->refresh_alt_ref_frame = cpi->ext_refresh_alt_ref_frame; 2805 cpi->refresh_alt_ref_frame = cpi->ext_refresh_alt_ref_frame;
1993 cpi->ext_refresh_frame_flags_pending = 0; 2806 cpi->ext_refresh_frame_flags_pending = 0;
1994 } 2807 }
1995 } 2808 }
1996 2809
1997 YV12_BUFFER_CONFIG *vp9_scale_if_required(VP9_COMMON *cm, 2810 YV12_BUFFER_CONFIG *vp9_scale_if_required(VP9_COMMON *cm,
1998 YV12_BUFFER_CONFIG *unscaled, 2811 YV12_BUFFER_CONFIG *unscaled,
1999 YV12_BUFFER_CONFIG *scaled) { 2812 YV12_BUFFER_CONFIG *scaled) {
2000 if (cm->mi_cols * MI_SIZE != unscaled->y_width || 2813 if (cm->mi_cols * MI_SIZE != unscaled->y_width ||
2001 cm->mi_rows * MI_SIZE != unscaled->y_height) { 2814 cm->mi_rows * MI_SIZE != unscaled->y_height) {
2815 #if CONFIG_VP9_HIGHBITDEPTH
2816 scale_and_extend_frame_nonnormative(unscaled, scaled, (int)cm->bit_depth);
2817 #else
2002 scale_and_extend_frame_nonnormative(unscaled, scaled); 2818 scale_and_extend_frame_nonnormative(unscaled, scaled);
2819 #endif // CONFIG_VP9_HIGHBITDEPTH
2003 return scaled; 2820 return scaled;
2004 } else { 2821 } else {
2005 return unscaled; 2822 return unscaled;
2006 } 2823 }
2007 } 2824 }
2008 2825
2009 static int is_skippable_frame(const VP9_COMP *cpi) { 2826 static int is_skippable_frame(const VP9_COMP *cpi) {
2010 // If the current frame does not have non-zero motion vector detected in the 2827 // If the current frame does not have non-zero motion vector detected in the
2011 // first pass, and so do its previous and forward frames, then this frame 2828 // first pass, and so do its previous and forward frames, then this frame
2012 // can be skipped for partition check, and the partition size is assigned 2829 // can be skipped for partition check, and the partition size is assigned
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
2158 cm->frame_parallel_decoding_mode = 1; 2975 cm->frame_parallel_decoding_mode = 1;
2159 cm->reset_frame_context = 0; 2976 cm->reset_frame_context = 0;
2160 cm->refresh_frame_context = 0; 2977 cm->refresh_frame_context = 0;
2161 } else if (cm->intra_only) { 2978 } else if (cm->intra_only) {
2162 cm->frame_parallel_decoding_mode = oxcf->frame_parallel_decoding_mode; 2979 cm->frame_parallel_decoding_mode = oxcf->frame_parallel_decoding_mode;
2163 // Only reset the current context. 2980 // Only reset the current context.
2164 cm->reset_frame_context = 2; 2981 cm->reset_frame_context = 2;
2165 } 2982 }
2166 } 2983 }
2167 if (is_two_pass_svc(cpi) && cm->error_resilient_mode == 0) { 2984 if (is_two_pass_svc(cpi) && cm->error_resilient_mode == 0) {
2985 // Use the last frame context for the empty frame.
2168 cm->frame_context_idx = 2986 cm->frame_context_idx =
2987 (cpi->svc.encode_empty_frame_state == ENCODING) ? FRAME_CONTEXTS - 1 :
2169 cpi->svc.spatial_layer_id * cpi->svc.number_temporal_layers + 2988 cpi->svc.spatial_layer_id * cpi->svc.number_temporal_layers +
2170 cpi->svc.temporal_layer_id; 2989 cpi->svc.temporal_layer_id;
2171 2990
2172 // The probs will be updated based on the frame type of its previous 2991 // The probs will be updated based on the frame type of its previous
2173 // frame if frame_parallel_decoding_mode is 0. The type may vary for 2992 // frame if frame_parallel_decoding_mode is 0. The type may vary for
2174 // the frame after a key frame in base layer since we may drop enhancement 2993 // the frame after a key frame in base layer since we may drop enhancement
2175 // layers. So set frame_parallel_decoding_mode to 1 in this case. 2994 // layers. So set frame_parallel_decoding_mode to 1 in this case.
2176 if (cpi->svc.number_temporal_layers == 1) { 2995 if (cpi->svc.number_temporal_layers == 1) {
2177 if (cpi->svc.spatial_layer_id == 0 && 2996 if (cpi->svc.spatial_layer_id == 0 &&
2178 cpi->svc.layer_context[0].last_frame_type == KEY_FRAME) 2997 cpi->svc.layer_context[0].last_frame_type == KEY_FRAME)
(...skipping 17 matching lines...) Expand all
2196 3015
2197 // Configure experimental use of segmentation for enhanced coding of 3016 // Configure experimental use of segmentation for enhanced coding of
2198 // static regions if indicated. 3017 // static regions if indicated.
2199 // Only allowed in second pass of two pass (as requires lagged coding) 3018 // Only allowed in second pass of two pass (as requires lagged coding)
2200 // and if the relevant speed feature flag is set. 3019 // and if the relevant speed feature flag is set.
2201 if (oxcf->pass == 2 && cpi->sf.static_segmentation) 3020 if (oxcf->pass == 2 && cpi->sf.static_segmentation)
2202 configure_static_seg_features(cpi); 3021 configure_static_seg_features(cpi);
2203 3022
2204 // Check if the current frame is skippable for the partition search in the 3023 // Check if the current frame is skippable for the partition search in the
2205 // second pass according to the first pass stats 3024 // second pass according to the first pass stats
2206 if (oxcf->pass == 2 && 3025 if (cpi->sf.allow_partition_search_skip && oxcf->pass == 2 &&
2207 (!cpi->use_svc || is_two_pass_svc(cpi))) { 3026 (!cpi->use_svc || is_two_pass_svc(cpi))) {
2208 cpi->skippable_frame = is_skippable_frame(cpi); 3027 cpi->partition_search_skippable_frame = is_skippable_frame(cpi);
2209 } 3028 }
2210 3029
2211 // For 1 pass CBR, check if we are dropping this frame. 3030 // For 1 pass CBR, check if we are dropping this frame.
2212 // Never drop on key frame. 3031 // Never drop on key frame.
2213 if (oxcf->pass == 0 && 3032 if (oxcf->pass == 0 &&
2214 oxcf->rc_mode == VPX_CBR && 3033 oxcf->rc_mode == VPX_CBR &&
2215 cm->frame_type != KEY_FRAME) { 3034 cm->frame_type != KEY_FRAME) {
2216 if (vp9_rc_drop_frame(cpi)) { 3035 if (vp9_rc_drop_frame(cpi)) {
2217 vp9_rc_postencode_update_drop_frame(cpi); 3036 vp9_rc_postencode_update_drop_frame(cpi);
2218 ++cm->current_video_frame; 3037 ++cm->current_video_frame;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2282 yuv_denoised_file); 3101 yuv_denoised_file);
2283 } 3102 }
2284 #endif 3103 #endif
2285 #endif 3104 #endif
2286 3105
2287 3106
2288 // Special case code to reduce pulsing when key frames are forced at a 3107 // Special case code to reduce pulsing when key frames are forced at a
2289 // fixed interval. Note the reconstruction error if it is the frame before 3108 // fixed interval. Note the reconstruction error if it is the frame before
2290 // the force key frame 3109 // the force key frame
2291 if (cpi->rc.next_key_frame_forced && cpi->rc.frames_to_key == 1) { 3110 if (cpi->rc.next_key_frame_forced && cpi->rc.frames_to_key == 1) {
3111 #if CONFIG_VP9_HIGHBITDEPTH
3112 if (cm->use_highbitdepth) {
3113 cpi->ambient_err = vp9_highbd_get_y_sse(cpi->Source,
3114 get_frame_new_buffer(cm),
3115 cm->bit_depth);
3116 } else {
3117 cpi->ambient_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm));
3118 }
3119 #else
2292 cpi->ambient_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm)); 3120 cpi->ambient_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm));
3121 #endif // CONFIG_VP9_HIGHBITDEPTH
2293 } 3122 }
2294 3123
2295 // If the encoder forced a KEY_FRAME decision 3124 // If the encoder forced a KEY_FRAME decision
2296 if (cm->frame_type == KEY_FRAME) 3125 if (cm->frame_type == KEY_FRAME)
2297 cpi->refresh_last_frame = 1; 3126 cpi->refresh_last_frame = 1;
2298 3127
2299 cm->frame_to_show = get_frame_new_buffer(cm); 3128 cm->frame_to_show = get_frame_new_buffer(cm);
2300 3129
2301 // Pick the loop filter level for the frame. 3130 // Pick the loop filter level for the frame.
2302 loopfilter_frame(cpi, cm); 3131 loopfilter_frame(cpi, cm);
(...skipping 26 matching lines...) Expand all
2329 cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN; 3158 cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN;
2330 3159
2331 if (cpi->refresh_alt_ref_frame == 1) 3160 if (cpi->refresh_alt_ref_frame == 1)
2332 cpi->frame_flags |= FRAMEFLAGS_ALTREF; 3161 cpi->frame_flags |= FRAMEFLAGS_ALTREF;
2333 else 3162 else
2334 cpi->frame_flags &= ~FRAMEFLAGS_ALTREF; 3163 cpi->frame_flags &= ~FRAMEFLAGS_ALTREF;
2335 3164
2336 cpi->ref_frame_flags = get_ref_frame_flags(cpi); 3165 cpi->ref_frame_flags = get_ref_frame_flags(cpi);
2337 3166
2338 cm->last_frame_type = cm->frame_type; 3167 cm->last_frame_type = cm->frame_type;
2339 vp9_rc_postencode_update(cpi, *size); 3168
3169 if (!(is_two_pass_svc(cpi) && cpi->svc.encode_empty_frame_state == ENCODING))
3170 vp9_rc_postencode_update(cpi, *size);
2340 3171
2341 #if 0 3172 #if 0
2342 output_frame_level_debug_stats(cpi); 3173 output_frame_level_debug_stats(cpi);
2343 #endif 3174 #endif
2344 3175
2345 if (cm->frame_type == KEY_FRAME) { 3176 if (cm->frame_type == KEY_FRAME) {
2346 // Tell the caller that the frame was coded as a key frame 3177 // Tell the caller that the frame was coded as a key frame
2347 *frame_flags = cpi->frame_flags | FRAMEFLAGS_KEY; 3178 *frame_flags = cpi->frame_flags | FRAMEFLAGS_KEY;
2348 } else { 3179 } else {
2349 *frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY; 3180 *frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY;
2350 } 3181 }
2351 3182
2352 // Clear the one shot update flags for segmentation map and mode/ref loop 3183 // Clear the one shot update flags for segmentation map and mode/ref loop
2353 // filter deltas. 3184 // filter deltas.
2354 cm->seg.update_map = 0; 3185 cm->seg.update_map = 0;
2355 cm->seg.update_data = 0; 3186 cm->seg.update_data = 0;
2356 cm->lf.mode_ref_delta_update = 0; 3187 cm->lf.mode_ref_delta_update = 0;
2357 3188
2358 // keep track of the last coded dimensions 3189 // keep track of the last coded dimensions
2359 cm->last_width = cm->width; 3190 cm->last_width = cm->width;
2360 cm->last_height = cm->height; 3191 cm->last_height = cm->height;
2361 3192
2362 // reset to normal state now that we are done. 3193 // reset to normal state now that we are done.
2363 if (!cm->show_existing_frame) { 3194 if (!cm->show_existing_frame)
2364 if (is_two_pass_svc(cpi) && cm->error_resilient_mode == 0) 3195 cm->last_show_frame = cm->show_frame;
2365 cm->last_show_frame = 0;
2366 else
2367 cm->last_show_frame = cm->show_frame;
2368 }
2369 3196
2370 if (cm->show_frame) { 3197 if (cm->show_frame) {
2371 vp9_swap_mi_and_prev_mi(cm); 3198 vp9_swap_mi_and_prev_mi(cm);
2372 3199
2373 // Don't increment frame counters if this was an altref buffer 3200 // Don't increment frame counters if this was an altref buffer
2374 // update not a real frame 3201 // update not a real frame
2375 ++cm->current_video_frame; 3202 ++cm->current_video_frame;
2376 if (cpi->use_svc) 3203 if (cpi->use_svc)
2377 vp9_inc_frame_in_layer(cpi); 3204 vp9_inc_frame_in_layer(cpi);
2378 } 3205 }
(...skipping 16 matching lines...) Expand all
2395 } else { 3222 } else {
2396 vp9_rc_get_one_pass_vbr_params(cpi); 3223 vp9_rc_get_one_pass_vbr_params(cpi);
2397 } 3224 }
2398 encode_frame_to_data_rate(cpi, size, dest, frame_flags); 3225 encode_frame_to_data_rate(cpi, size, dest, frame_flags);
2399 } 3226 }
2400 3227
2401 static void Pass2Encode(VP9_COMP *cpi, size_t *size, 3228 static void Pass2Encode(VP9_COMP *cpi, size_t *size,
2402 uint8_t *dest, unsigned int *frame_flags) { 3229 uint8_t *dest, unsigned int *frame_flags) {
2403 cpi->allow_encode_breakout = ENCODE_BREAKOUT_ENABLED; 3230 cpi->allow_encode_breakout = ENCODE_BREAKOUT_ENABLED;
2404 encode_frame_to_data_rate(cpi, size, dest, frame_flags); 3231 encode_frame_to_data_rate(cpi, size, dest, frame_flags);
2405 vp9_twopass_postencode_update(cpi); 3232
3233 if (!(is_two_pass_svc(cpi) && cpi->svc.encode_empty_frame_state == ENCODING))
3234 vp9_twopass_postencode_update(cpi);
2406 } 3235 }
2407 3236
2408 static void init_motion_estimation(VP9_COMP *cpi) { 3237 static void init_motion_estimation(VP9_COMP *cpi) {
2409 int y_stride = cpi->scaled_source.y_stride; 3238 int y_stride = cpi->scaled_source.y_stride;
2410 3239
2411 if (cpi->sf.mv.search_method == NSTEP) { 3240 if (cpi->sf.mv.search_method == NSTEP) {
2412 vp9_init3smotion_compensation(&cpi->ss_cfg, y_stride); 3241 vp9_init3smotion_compensation(&cpi->ss_cfg, y_stride);
2413 } else if (cpi->sf.mv.search_method == DIAMOND) { 3242 } else if (cpi->sf.mv.search_method == DIAMOND) {
2414 vp9_init_dsmotion_compensation(&cpi->ss_cfg, y_stride); 3243 vp9_init_dsmotion_compensation(&cpi->ss_cfg, y_stride);
2415 } 3244 }
2416 } 3245 }
2417 3246
2418 static void check_initial_width(VP9_COMP *cpi, int subsampling_x, 3247 static void check_initial_width(VP9_COMP *cpi,
2419 int subsampling_y) { 3248 #if CONFIG_VP9_HIGHBITDEPTH
3249 int use_highbitdepth,
3250 #endif
3251 int subsampling_x, int subsampling_y) {
2420 VP9_COMMON *const cm = &cpi->common; 3252 VP9_COMMON *const cm = &cpi->common;
2421 3253
2422 if (!cpi->initial_width) { 3254 if (!cpi->initial_width) {
2423 cm->subsampling_x = subsampling_x; 3255 cm->subsampling_x = subsampling_x;
2424 cm->subsampling_y = subsampling_y; 3256 cm->subsampling_y = subsampling_y;
3257 #if CONFIG_VP9_HIGHBITDEPTH
3258 cm->use_highbitdepth = use_highbitdepth;
3259 #endif
2425 3260
2426 alloc_raw_frame_buffers(cpi); 3261 alloc_raw_frame_buffers(cpi);
2427 alloc_ref_frame_buffers(cpi); 3262 alloc_ref_frame_buffers(cpi);
2428 alloc_util_frame_buffers(cpi); 3263 alloc_util_frame_buffers(cpi);
2429 3264
2430 init_motion_estimation(cpi); 3265 init_motion_estimation(cpi);
2431 3266
2432 cpi->initial_width = cm->width; 3267 cpi->initial_width = cm->width;
2433 cpi->initial_height = cm->height; 3268 cpi->initial_height = cm->height;
2434 } 3269 }
2435 } 3270 }
2436 3271
2437 3272
2438 int vp9_receive_raw_frame(VP9_COMP *cpi, unsigned int frame_flags, 3273 int vp9_receive_raw_frame(VP9_COMP *cpi, unsigned int frame_flags,
2439 YV12_BUFFER_CONFIG *sd, int64_t time_stamp, 3274 YV12_BUFFER_CONFIG *sd, int64_t time_stamp,
2440 int64_t end_time) { 3275 int64_t end_time) {
2441 VP9_COMMON *cm = &cpi->common; 3276 VP9_COMMON *cm = &cpi->common;
2442 struct vpx_usec_timer timer; 3277 struct vpx_usec_timer timer;
2443 int res = 0; 3278 int res = 0;
2444 const int subsampling_x = sd->uv_width < sd->y_width; 3279 const int subsampling_x = sd->subsampling_x;
2445 const int subsampling_y = sd->uv_height < sd->y_height; 3280 const int subsampling_y = sd->subsampling_y;
2446 3281 #if CONFIG_VP9_HIGHBITDEPTH
3282 const int use_highbitdepth = sd->flags & YV12_FLAG_HIGHBITDEPTH;
3283 check_initial_width(cpi, use_highbitdepth, subsampling_x, subsampling_y);
3284 #else
2447 check_initial_width(cpi, subsampling_x, subsampling_y); 3285 check_initial_width(cpi, subsampling_x, subsampling_y);
3286 #endif // CONFIG_VP9_HIGHBITDEPTH
2448 3287
2449 vpx_usec_timer_start(&timer); 3288 vpx_usec_timer_start(&timer);
2450 3289
2451 if (vp9_lookahead_push(cpi->lookahead, sd, time_stamp, end_time, frame_flags)) 3290 if (vp9_lookahead_push(cpi->lookahead, sd, time_stamp, end_time, frame_flags))
2452 res = -1; 3291 res = -1;
2453 vpx_usec_timer_mark(&timer); 3292 vpx_usec_timer_mark(&timer);
2454 cpi->time_receive_data += vpx_usec_timer_elapsed(&timer); 3293 cpi->time_receive_data += vpx_usec_timer_elapsed(&timer);
2455 3294
2456 if ((cm->profile == PROFILE_0 || cm->profile == PROFILE_2) && 3295 if ((cm->profile == PROFILE_0 || cm->profile == PROFILE_2) &&
2457 (subsampling_x != 1 || subsampling_y != 1)) { 3296 (subsampling_x != 1 || subsampling_y != 1)) {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
2573 struct vpx_usec_timer cmptimer; 3412 struct vpx_usec_timer cmptimer;
2574 YV12_BUFFER_CONFIG *force_src_buffer = NULL; 3413 YV12_BUFFER_CONFIG *force_src_buffer = NULL;
2575 struct lookahead_entry *last_source = NULL; 3414 struct lookahead_entry *last_source = NULL;
2576 struct lookahead_entry *source = NULL; 3415 struct lookahead_entry *source = NULL;
2577 MV_REFERENCE_FRAME ref_frame; 3416 MV_REFERENCE_FRAME ref_frame;
2578 int arf_src_index; 3417 int arf_src_index;
2579 3418
2580 if (is_two_pass_svc(cpi)) { 3419 if (is_two_pass_svc(cpi)) {
2581 #if CONFIG_SPATIAL_SVC 3420 #if CONFIG_SPATIAL_SVC
2582 vp9_svc_start_frame(cpi); 3421 vp9_svc_start_frame(cpi);
3422 // Use a small empty frame instead of a real frame
3423 if (cpi->svc.encode_empty_frame_state == ENCODING)
3424 source = &cpi->svc.empty_frame;
2583 #endif 3425 #endif
2584 if (oxcf->pass == 2) 3426 if (oxcf->pass == 2)
2585 vp9_restore_layer_context(cpi); 3427 vp9_restore_layer_context(cpi);
2586 } 3428 }
2587 3429
2588 vpx_usec_timer_start(&cmptimer); 3430 vpx_usec_timer_start(&cmptimer);
2589 3431
2590 vp9_set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV); 3432 vp9_set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV);
2591 3433
2592 // Normal defaults 3434 // Normal defaults
2593 cm->reset_frame_context = 0; 3435 cm->reset_frame_context = 0;
2594 cm->refresh_frame_context = 1; 3436 cm->refresh_frame_context = 1;
2595 cpi->refresh_last_frame = 1; 3437 cpi->refresh_last_frame = 1;
2596 cpi->refresh_golden_frame = 0; 3438 cpi->refresh_golden_frame = 0;
2597 cpi->refresh_alt_ref_frame = 0; 3439 cpi->refresh_alt_ref_frame = 0;
2598 3440
2599 // Should we encode an arf frame. 3441 // Should we encode an arf frame.
2600 arf_src_index = get_arf_src_index(cpi); 3442 arf_src_index = get_arf_src_index(cpi);
3443
3444 // Skip alt frame if we encode the empty frame
3445 if (is_two_pass_svc(cpi) && source != NULL)
3446 arf_src_index = 0;
3447
2601 if (arf_src_index) { 3448 if (arf_src_index) {
2602 assert(arf_src_index <= rc->frames_to_key); 3449 assert(arf_src_index <= rc->frames_to_key);
2603 3450
2604 if ((source = vp9_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) { 3451 if ((source = vp9_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) {
2605 cpi->alt_ref_source = source; 3452 cpi->alt_ref_source = source;
2606 3453
2607 #if CONFIG_SPATIAL_SVC 3454 #if CONFIG_SPATIAL_SVC
2608 if (is_two_pass_svc(cpi) && cpi->svc.spatial_layer_id > 0) { 3455 if (is_two_pass_svc(cpi) && cpi->svc.spatial_layer_id > 0) {
2609 int i; 3456 int i;
2610 // Reference a hidden frame from a lower layer 3457 // Reference a hidden frame from a lower layer
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
2701 *size = 0; 3548 *size = 0;
2702 3549
2703 /* find a free buffer for the new frame, releasing the reference previously 3550 /* find a free buffer for the new frame, releasing the reference previously
2704 * held. 3551 * held.
2705 */ 3552 */
2706 cm->frame_bufs[cm->new_fb_idx].ref_count--; 3553 cm->frame_bufs[cm->new_fb_idx].ref_count--;
2707 cm->new_fb_idx = get_free_fb(cm); 3554 cm->new_fb_idx = get_free_fb(cm);
2708 3555
2709 // For two pass encodes analyse the first pass stats and determine 3556 // For two pass encodes analyse the first pass stats and determine
2710 // the bit allocation and other parameters for this frame / group of frames. 3557 // the bit allocation and other parameters for this frame / group of frames.
2711 if ((oxcf->pass == 2) && (!cpi->use_svc || is_two_pass_svc(cpi))) { 3558 if ((oxcf->pass == 2) &&
3559 (!cpi->use_svc ||
3560 (is_two_pass_svc(cpi) &&
3561 cpi->svc.encode_empty_frame_state != ENCODING))) {
2712 vp9_rc_get_second_pass_params(cpi); 3562 vp9_rc_get_second_pass_params(cpi);
2713 } 3563 }
2714 3564
2715 if (!cpi->use_svc && cpi->multi_arf_allowed) { 3565 if (!cpi->use_svc && cpi->multi_arf_allowed) {
2716 if (cm->frame_type == KEY_FRAME) { 3566 if (cm->frame_type == KEY_FRAME) {
2717 init_buffer_indices(cpi); 3567 init_buffer_indices(cpi);
2718 } else if (oxcf->pass == 2) { 3568 } else if (oxcf->pass == 2) {
2719 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; 3569 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
2720 cpi->alt_fb_idx = gf_group->arf_ref_idx[gf_group->index]; 3570 cpi->alt_fb_idx = gf_group->arf_ref_idx[gf_group->index];
2721 } 3571 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2753 #if CONFIG_VP9_HIGHBITDEPTH 3603 #if CONFIG_VP9_HIGHBITDEPTH
2754 vp9_setup_scale_factors_for_frame(&ref_buf->sf, 3604 vp9_setup_scale_factors_for_frame(&ref_buf->sf,
2755 buf->y_crop_width, buf->y_crop_height, 3605 buf->y_crop_width, buf->y_crop_height,
2756 cm->width, cm->height, 3606 cm->width, cm->height,
2757 (buf->flags & YV12_FLAG_HIGHBITDEPTH) ? 3607 (buf->flags & YV12_FLAG_HIGHBITDEPTH) ?
2758 1 : 0); 3608 1 : 0);
2759 #else 3609 #else
2760 vp9_setup_scale_factors_for_frame(&ref_buf->sf, 3610 vp9_setup_scale_factors_for_frame(&ref_buf->sf,
2761 buf->y_crop_width, buf->y_crop_height, 3611 buf->y_crop_width, buf->y_crop_height,
2762 cm->width, cm->height); 3612 cm->width, cm->height);
2763 #endif 3613 #endif // CONFIG_VP9_HIGHBITDEPTH
2764 if (vp9_is_scaled(&ref_buf->sf)) 3614 if (vp9_is_scaled(&ref_buf->sf))
2765 vp9_extend_frame_borders(buf); 3615 vp9_extend_frame_borders(buf);
2766 } 3616 }
2767 3617
2768 set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); 3618 set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME);
2769 3619
2770 if (oxcf->aq_mode == VARIANCE_AQ) { 3620 if (oxcf->aq_mode == VARIANCE_AQ) {
2771 vp9_vaq_init(); 3621 vp9_vaq_init();
2772 } 3622 }
2773 3623
2774 if (oxcf->pass == 1 && 3624 if (oxcf->pass == 1 &&
2775 (!cpi->use_svc || is_two_pass_svc(cpi))) { 3625 (!cpi->use_svc || is_two_pass_svc(cpi))) {
2776 const int lossless = is_lossless_requested(oxcf); 3626 const int lossless = is_lossless_requested(oxcf);
2777 #if CONFIG_VP9_HIGHBITDEPTH 3627 #if CONFIG_VP9_HIGHBITDEPTH
2778 if (cpi->oxcf.use_highbitdepth) 3628 if (cpi->oxcf.use_highbitdepth)
2779 cpi->mb.fwd_txm4x4 = lossless ? vp9_high_fwht4x4 : vp9_high_fdct4x4; 3629 cpi->mb.fwd_txm4x4 = lossless ? vp9_highbd_fwht4x4 : vp9_highbd_fdct4x4;
2780 else 3630 else
2781 cpi->mb.fwd_txm4x4 = lossless ? vp9_fwht4x4 : vp9_fdct4x4; 3631 cpi->mb.fwd_txm4x4 = lossless ? vp9_fwht4x4 : vp9_fdct4x4;
2782 cpi->mb.high_itxm_add = lossless ? vp9_high_iwht4x4_add : 3632 cpi->mb.highbd_itxm_add = lossless ? vp9_highbd_iwht4x4_add :
2783 vp9_high_idct4x4_add; 3633 vp9_highbd_idct4x4_add;
2784 #else 3634 #else
2785 cpi->mb.fwd_txm4x4 = lossless ? vp9_fwht4x4 : vp9_fdct4x4; 3635 cpi->mb.fwd_txm4x4 = lossless ? vp9_fwht4x4 : vp9_fdct4x4;
2786 #endif 3636 #endif // CONFIG_VP9_HIGHBITDEPTH
2787 cpi->mb.itxm_add = lossless ? vp9_iwht4x4_add : vp9_idct4x4_add; 3637 cpi->mb.itxm_add = lossless ? vp9_iwht4x4_add : vp9_idct4x4_add;
2788 vp9_first_pass(cpi, source); 3638 vp9_first_pass(cpi, source);
2789 } else if (oxcf->pass == 2 && 3639 } else if (oxcf->pass == 2 &&
2790 (!cpi->use_svc || is_two_pass_svc(cpi))) { 3640 (!cpi->use_svc || is_two_pass_svc(cpi))) {
2791 Pass2Encode(cpi, size, dest, frame_flags); 3641 Pass2Encode(cpi, size, dest, frame_flags);
2792 } else if (cpi->use_svc) { 3642 } else if (cpi->use_svc) {
2793 SvcEncode(cpi, size, dest, frame_flags); 3643 SvcEncode(cpi, size, dest, frame_flags);
2794 } else { 3644 } else {
2795 // One pass encode 3645 // One pass encode
2796 Pass0Encode(cpi, size, dest, frame_flags); 3646 Pass0Encode(cpi, size, dest, frame_flags);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2829 cpi->bytes += (int)(*size); 3679 cpi->bytes += (int)(*size);
2830 3680
2831 if (cm->show_frame) { 3681 if (cm->show_frame) {
2832 cpi->count++; 3682 cpi->count++;
2833 3683
2834 if (cpi->b_calculate_psnr) { 3684 if (cpi->b_calculate_psnr) {
2835 YV12_BUFFER_CONFIG *orig = cpi->Source; 3685 YV12_BUFFER_CONFIG *orig = cpi->Source;
2836 YV12_BUFFER_CONFIG *recon = cpi->common.frame_to_show; 3686 YV12_BUFFER_CONFIG *recon = cpi->common.frame_to_show;
2837 YV12_BUFFER_CONFIG *pp = &cm->post_proc_buffer; 3687 YV12_BUFFER_CONFIG *pp = &cm->post_proc_buffer;
2838 PSNR_STATS psnr; 3688 PSNR_STATS psnr;
3689 #if CONFIG_VP9_HIGHBITDEPTH
3690 calc_highbd_psnr(orig, recon, &psnr, cpi->mb.e_mbd.bd,
3691 cpi->oxcf.input_bit_depth);
3692 #else
2839 calc_psnr(orig, recon, &psnr); 3693 calc_psnr(orig, recon, &psnr);
3694 #endif // CONFIG_VP9_HIGHBITDEPTH
2840 3695
2841 cpi->total += psnr.psnr[0]; 3696 cpi->total += psnr.psnr[0];
2842 cpi->total_y += psnr.psnr[1]; 3697 cpi->total_y += psnr.psnr[1];
2843 cpi->total_u += psnr.psnr[2]; 3698 cpi->total_u += psnr.psnr[2];
2844 cpi->total_v += psnr.psnr[3]; 3699 cpi->total_v += psnr.psnr[3];
2845 cpi->total_sq_error += psnr.sse[0]; 3700 cpi->total_sq_error += psnr.sse[0];
2846 cpi->total_samples += psnr.samples[0]; 3701 cpi->total_samples += psnr.samples[0];
2847 3702
2848 { 3703 {
2849 PSNR_STATS psnr2; 3704 PSNR_STATS psnr2;
2850 double frame_ssim2 = 0, weight = 0; 3705 double frame_ssim2 = 0, weight = 0;
2851 #if CONFIG_VP9_POSTPROC 3706 #if CONFIG_VP9_POSTPROC
2852 // TODO(agrange) Add resizing of post-proc buffer in here when the 3707 // TODO(agrange) Add resizing of post-proc buffer in here when the
2853 // encoder is changed to use on-demand buffer allocation. 3708 // encoder is changed to use on-demand buffer allocation.
2854 vp9_deblock(cm->frame_to_show, &cm->post_proc_buffer, 3709 vp9_deblock(cm->frame_to_show, &cm->post_proc_buffer,
2855 cm->lf.filter_level * 10 / 6); 3710 cm->lf.filter_level * 10 / 6);
2856 #endif 3711 #endif
2857 vp9_clear_system_state(); 3712 vp9_clear_system_state();
2858 3713
3714 #if CONFIG_VP9_HIGHBITDEPTH
3715 calc_highbd_psnr(orig, pp, &psnr, cpi->mb.e_mbd.bd,
3716 cpi->oxcf.input_bit_depth);
3717 #else
2859 calc_psnr(orig, pp, &psnr2); 3718 calc_psnr(orig, pp, &psnr2);
3719 #endif // CONFIG_VP9_HIGHBITDEPTH
2860 3720
2861 cpi->totalp += psnr2.psnr[0]; 3721 cpi->totalp += psnr2.psnr[0];
2862 cpi->totalp_y += psnr2.psnr[1]; 3722 cpi->totalp_y += psnr2.psnr[1];
2863 cpi->totalp_u += psnr2.psnr[2]; 3723 cpi->totalp_u += psnr2.psnr[2];
2864 cpi->totalp_v += psnr2.psnr[3]; 3724 cpi->totalp_v += psnr2.psnr[3];
2865 cpi->totalp_sq_error += psnr2.sse[0]; 3725 cpi->totalp_sq_error += psnr2.sse[0];
2866 cpi->totalp_samples += psnr2.samples[0]; 3726 cpi->totalp_samples += psnr2.samples[0];
2867 3727
3728 #if CONFIG_VP9_HIGHBITDEPTH
3729 if (cm->use_highbitdepth) {
3730 frame_ssim2 = vp9_highbd_calc_ssim(orig, recon, &weight, xd->bd);
3731 } else {
3732 frame_ssim2 = vp9_calc_ssim(orig, recon, &weight);
3733 }
3734 #else
2868 frame_ssim2 = vp9_calc_ssim(orig, recon, &weight); 3735 frame_ssim2 = vp9_calc_ssim(orig, recon, &weight);
3736 #endif // CONFIG_VP9_HIGHBITDEPTH
2869 3737
2870 cpi->summed_quality += frame_ssim2 * weight; 3738 cpi->summed_quality += frame_ssim2 * weight;
2871 cpi->summed_weights += weight; 3739 cpi->summed_weights += weight;
2872 3740
3741 #if CONFIG_VP9_HIGHBITDEPTH
3742 if (cm->use_highbitdepth) {
3743 frame_ssim2 = vp9_highbd_calc_ssim(
3744 orig, &cm->post_proc_buffer, &weight, xd->bd);
3745 } else {
3746 frame_ssim2 = vp9_calc_ssim(orig, &cm->post_proc_buffer, &weight);
3747 }
3748 #else
2873 frame_ssim2 = vp9_calc_ssim(orig, &cm->post_proc_buffer, &weight); 3749 frame_ssim2 = vp9_calc_ssim(orig, &cm->post_proc_buffer, &weight);
3750 #endif // CONFIG_VP9_HIGHBITDEPTH
2874 3751
2875 cpi->summedp_quality += frame_ssim2 * weight; 3752 cpi->summedp_quality += frame_ssim2 * weight;
2876 cpi->summedp_weights += weight; 3753 cpi->summedp_weights += weight;
2877 #if 0 3754 #if 0
2878 { 3755 {
2879 FILE *f = fopen("q_used.stt", "a"); 3756 FILE *f = fopen("q_used.stt", "a");
2880 fprintf(f, "%5d : Y%f7.3:U%f7.3:V%f7.3:F%f7.3:S%7.3f\n", 3757 fprintf(f, "%5d : Y%f7.3:U%f7.3:V%f7.3:F%f7.3:S%7.3f\n",
2881 cpi->common.current_video_frame, y2, u2, v2, 3758 cpi->common.current_video_frame, y2, u2, v2,
2882 frame_psnr2, frame_ssim2); 3759 frame_psnr2, frame_ssim2);
2883 fclose(f); 3760 fclose(f);
2884 } 3761 }
2885 #endif 3762 #endif
2886 } 3763 }
2887 } 3764 }
2888 3765
2889 3766
2890 if (cpi->b_calculate_ssimg) { 3767 if (cpi->b_calculate_ssimg) {
2891 double y, u, v, frame_all; 3768 double y, u, v, frame_all;
3769 #if CONFIG_VP9_HIGHBITDEPTH
3770 if (cm->use_highbitdepth) {
3771 frame_all = vp9_highbd_calc_ssimg(cpi->Source, cm->frame_to_show, &y,
3772 &u, &v, xd->bd);
3773 } else {
3774 frame_all = vp9_calc_ssimg(cpi->Source, cm->frame_to_show, &y, &u,
3775 &v);
3776 }
3777 #else
2892 frame_all = vp9_calc_ssimg(cpi->Source, cm->frame_to_show, &y, &u, &v); 3778 frame_all = vp9_calc_ssimg(cpi->Source, cm->frame_to_show, &y, &u, &v);
3779 #endif // CONFIG_VP9_HIGHBITDEPTH
2893 cpi->total_ssimg_y += y; 3780 cpi->total_ssimg_y += y;
2894 cpi->total_ssimg_u += u; 3781 cpi->total_ssimg_u += u;
2895 cpi->total_ssimg_v += v; 3782 cpi->total_ssimg_v += v;
2896 cpi->total_ssimg_all += frame_all; 3783 cpi->total_ssimg_all += frame_all;
2897 } 3784 }
2898 } 3785 }
2899 } 3786 }
2900 3787
2901 #endif 3788 #endif
2902 3789
2903 if (is_two_pass_svc(cpi) && cm->show_frame) { 3790 if (is_two_pass_svc(cpi)) {
2904 ++cpi->svc.spatial_layer_to_encode; 3791 if (cpi->svc.encode_empty_frame_state == ENCODING)
2905 if (cpi->svc.spatial_layer_to_encode >= cpi->svc.number_spatial_layers) 3792 cpi->svc.encode_empty_frame_state = ENCODED;
2906 cpi->svc.spatial_layer_to_encode = 0; 3793
3794 if (cm->show_frame) {
3795 ++cpi->svc.spatial_layer_to_encode;
3796 if (cpi->svc.spatial_layer_to_encode >= cpi->svc.number_spatial_layers)
3797 cpi->svc.spatial_layer_to_encode = 0;
3798
3799 // May need the empty frame after an visible frame.
3800 cpi->svc.encode_empty_frame_state = NEED_TO_ENCODE;
3801 }
2907 } 3802 }
2908 return 0; 3803 return 0;
2909 } 3804 }
2910 3805
2911 int vp9_get_preview_raw_frame(VP9_COMP *cpi, YV12_BUFFER_CONFIG *dest, 3806 int vp9_get_preview_raw_frame(VP9_COMP *cpi, YV12_BUFFER_CONFIG *dest,
2912 vp9_ppflags_t *flags) { 3807 vp9_ppflags_t *flags) {
2913 VP9_COMMON *cm = &cpi->common; 3808 VP9_COMMON *cm = &cpi->common;
2914 #if !CONFIG_VP9_POSTPROC 3809 #if !CONFIG_VP9_POSTPROC
2915 (void)flags; 3810 (void)flags;
2916 #endif 3811 #endif
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
2979 assert(cm->height <= cpi->initial_height); 3874 assert(cm->height <= cpi->initial_height);
2980 3875
2981 update_frame_size(cpi); 3876 update_frame_size(cpi);
2982 3877
2983 return 0; 3878 return 0;
2984 } 3879 }
2985 3880
2986 int vp9_set_size_literal(VP9_COMP *cpi, unsigned int width, 3881 int vp9_set_size_literal(VP9_COMP *cpi, unsigned int width,
2987 unsigned int height) { 3882 unsigned int height) {
2988 VP9_COMMON *cm = &cpi->common; 3883 VP9_COMMON *cm = &cpi->common;
2989 3884 #if CONFIG_VP9_HIGHBITDEPTH
3885 check_initial_width(cpi, 1, 1, cm->use_highbitdepth);
3886 #else
2990 check_initial_width(cpi, 1, 1); 3887 check_initial_width(cpi, 1, 1);
3888 #endif // CONFIG_VP9_HIGHBITDEPTH
2991 3889
2992 if (width) { 3890 if (width) {
2993 cm->width = width; 3891 cm->width = width;
2994 if (cm->width * 5 < cpi->initial_width) {
2995 cm->width = cpi->initial_width / 5 + 1;
2996 printf("Warning: Desired width too small, changed to %d\n", cm->width);
2997 }
2998 if (cm->width > cpi->initial_width) { 3892 if (cm->width > cpi->initial_width) {
2999 cm->width = cpi->initial_width; 3893 cm->width = cpi->initial_width;
3000 printf("Warning: Desired width too large, changed to %d\n", cm->width); 3894 printf("Warning: Desired width too large, changed to %d\n", cm->width);
3001 } 3895 }
3002 } 3896 }
3003 3897
3004 if (height) { 3898 if (height) {
3005 cm->height = height; 3899 cm->height = height;
3006 if (cm->height * 5 < cpi->initial_height) {
3007 cm->height = cpi->initial_height / 5 + 1;
3008 printf("Warning: Desired height too small, changed to %d\n", cm->height);
3009 }
3010 if (cm->height > cpi->initial_height) { 3900 if (cm->height > cpi->initial_height) {
3011 cm->height = cpi->initial_height; 3901 cm->height = cpi->initial_height;
3012 printf("Warning: Desired height too large, changed to %d\n", cm->height); 3902 printf("Warning: Desired height too large, changed to %d\n", cm->height);
3013 } 3903 }
3014 } 3904 }
3015 assert(cm->width <= cpi->initial_width); 3905 assert(cm->width <= cpi->initial_width);
3016 assert(cm->height <= cpi->initial_height); 3906 assert(cm->height <= cpi->initial_height);
3017 3907
3018 update_frame_size(cpi); 3908 update_frame_size(cpi);
3019 3909
3020 return 0; 3910 return 0;
3021 } 3911 }
3022 3912
3023 void vp9_set_svc(VP9_COMP *cpi, int use_svc) { 3913 void vp9_set_svc(VP9_COMP *cpi, int use_svc) {
3024 cpi->use_svc = use_svc; 3914 cpi->use_svc = use_svc;
3025 return; 3915 return;
3026 } 3916 }
3027 3917
3028 int vp9_get_y_sse(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b) { 3918 int vp9_get_y_sse(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b) {
3029 assert(a->y_crop_width == b->y_crop_width); 3919 assert(a->y_crop_width == b->y_crop_width);
3030 assert(a->y_crop_height == b->y_crop_height); 3920 assert(a->y_crop_height == b->y_crop_height);
3031 3921
3032 return (int)get_sse(a->y_buffer, a->y_stride, b->y_buffer, b->y_stride, 3922 return (int)get_sse(a->y_buffer, a->y_stride, b->y_buffer, b->y_stride,
3033 a->y_crop_width, a->y_crop_height); 3923 a->y_crop_width, a->y_crop_height);
3034 } 3924 }
3035 3925
3926 #if CONFIG_VP9_HIGHBITDEPTH
3927 int vp9_highbd_get_y_sse(const YV12_BUFFER_CONFIG *a,
3928 const YV12_BUFFER_CONFIG *b,
3929 vpx_bit_depth_t bit_depth) {
3930 unsigned int sse;
3931 int sum;
3932 assert(a->y_crop_width == b->y_crop_width);
3933 assert(a->y_crop_height == b->y_crop_height);
3934 assert((a->flags & YV12_FLAG_HIGHBITDEPTH) != 0);
3935 assert((b->flags & YV12_FLAG_HIGHBITDEPTH) != 0);
3936 switch (bit_depth) {
3937 case VPX_BITS_8:
3938 highbd_variance(a->y_buffer, a->y_stride, b->y_buffer, b->y_stride,
3939 a->y_crop_width, a->y_crop_height, &sse, &sum);
3940 return (int) sse;
3941 case VPX_BITS_10:
3942 highbd_10_variance(a->y_buffer, a->y_stride, b->y_buffer, b->y_stride,
3943 a->y_crop_width, a->y_crop_height, &sse, &sum);
3944 return (int) sse;
3945 case VPX_BITS_12:
3946 highbd_12_variance(a->y_buffer, a->y_stride, b->y_buffer, b->y_stride,
3947 a->y_crop_width, a->y_crop_height, &sse, &sum);
3948 return (int) sse;
3949 default:
3950 assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
3951 return -1;
3952 }
3953 }
3954 #endif // CONFIG_VP9_HIGHBITDEPTH
3036 3955
3037 int vp9_get_quantizer(VP9_COMP *cpi) { 3956 int vp9_get_quantizer(VP9_COMP *cpi) {
3038 return cpi->common.base_qindex; 3957 return cpi->common.base_qindex;
3039 } 3958 }
3040 3959
3041 void vp9_apply_encoding_flags(VP9_COMP *cpi, vpx_enc_frame_flags_t flags) { 3960 void vp9_apply_encoding_flags(VP9_COMP *cpi, vpx_enc_frame_flags_t flags) {
3042 if (flags & (VP8_EFLAG_NO_REF_LAST | VP8_EFLAG_NO_REF_GF | 3961 if (flags & (VP8_EFLAG_NO_REF_LAST | VP8_EFLAG_NO_REF_GF |
3043 VP8_EFLAG_NO_REF_ARF)) { 3962 VP8_EFLAG_NO_REF_ARF)) {
3044 int ref = 7; 3963 int ref = 7;
3045 3964
(...skipping 23 matching lines...) Expand all
3069 if (flags & VP8_EFLAG_NO_UPD_ARF) 3988 if (flags & VP8_EFLAG_NO_UPD_ARF)
3070 upd ^= VP9_ALT_FLAG; 3989 upd ^= VP9_ALT_FLAG;
3071 3990
3072 vp9_update_reference(cpi, upd); 3991 vp9_update_reference(cpi, upd);
3073 } 3992 }
3074 3993
3075 if (flags & VP8_EFLAG_NO_UPD_ENTROPY) { 3994 if (flags & VP8_EFLAG_NO_UPD_ENTROPY) {
3076 vp9_update_entropy(cpi, 0); 3995 vp9_update_entropy(cpi, 0);
3077 } 3996 }
3078 } 3997 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_encoder.h ('k') | source/libvpx/vp9/encoder/vp9_extend.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698