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

Side by Side Diff: media/filters/vp9_uncompressed_header_parser.cc

Issue 2229353002: V4L2SVDA: Add a VP9Accelerator implementation utilizing the V4L2 VP9 frame API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: compilation fixes Created 4 years, 3 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
« no previous file with comments | « media/filters/vp9_parser_unittest.cc ('k') | media/gpu/accelerated_video_decoder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/filters/vp9_uncompressed_header_parser.h" 5 #include "media/filters/vp9_uncompressed_header_parser.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 namespace media { 9 namespace media {
10 10
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 fhdr->render_height = fhdr->frame_height; 704 fhdr->render_height = fhdr->frame_height;
705 } 705 }
706 } 706 }
707 707
708 // 6.2.5 Frame size with refs syntax 708 // 6.2.5 Frame size with refs syntax
709 bool Vp9UncompressedHeaderParser::ReadFrameSizeFromRefs(Vp9FrameHeader* fhdr) { 709 bool Vp9UncompressedHeaderParser::ReadFrameSizeFromRefs(Vp9FrameHeader* fhdr) {
710 bool found_ref = false; 710 bool found_ref = false;
711 for (const auto& idx : fhdr->ref_frame_idx) { 711 for (const auto& idx : fhdr->ref_frame_idx) {
712 found_ref = reader_.ReadBool(); 712 found_ref = reader_.ReadBool();
713 if (found_ref) { 713 if (found_ref) {
714 const Vp9Parser::ReferenceSlot& ref = context_->ref_slots[idx]; 714 const Vp9Parser::ReferenceSlot& ref = context_->GetRefSlot(idx);
715 DCHECK(ref.initialized); 715 DCHECK(ref.initialized);
716 fhdr->frame_width = ref.frame_width; 716 fhdr->frame_width = ref.frame_width;
717 fhdr->frame_height = ref.frame_height; 717 fhdr->frame_height = ref.frame_height;
718 718
719 const unsigned kMaxDimension = 1u << 16; 719 const unsigned kMaxDimension = 1u << 16;
720 DCHECK_LE(fhdr->frame_width, kMaxDimension); 720 DCHECK_LE(fhdr->frame_width, kMaxDimension);
721 DCHECK_LE(fhdr->frame_height, kMaxDimension); 721 DCHECK_LE(fhdr->frame_height, kMaxDimension);
722 break; 722 break;
723 } 723 }
724 } 724 }
725 725
726 if (!found_ref) 726 if (!found_ref)
727 ReadFrameSize(fhdr); 727 ReadFrameSize(fhdr);
728 728
729 // 7.2.5 Frame size with refs semantics 729 // 7.2.5 Frame size with refs semantics
730 bool has_valid_ref_frame = false; 730 bool has_valid_ref_frame = false;
731 for (const auto& idx : fhdr->ref_frame_idx) { 731 for (const auto& idx : fhdr->ref_frame_idx) {
732 const Vp9Parser::ReferenceSlot& ref = context_->ref_slots[idx]; 732 const Vp9Parser::ReferenceSlot& ref = context_->GetRefSlot(idx);
733 if (2 * fhdr->frame_width >= ref.frame_width && 733 if (2 * fhdr->frame_width >= ref.frame_width &&
734 2 * fhdr->frame_height >= ref.frame_height && 734 2 * fhdr->frame_height >= ref.frame_height &&
735 fhdr->frame_width <= 16 * ref.frame_width && 735 fhdr->frame_width <= 16 * ref.frame_width &&
736 fhdr->frame_height <= 16 * ref.frame_height) { 736 fhdr->frame_height <= 16 * ref.frame_height) {
737 has_valid_ref_frame = true; 737 has_valid_ref_frame = true;
738 break; 738 break;
739 } 739 }
740 } 740 }
741 if (!has_valid_ref_frame) { 741 if (!has_valid_ref_frame) {
742 DVLOG(1) << "There should be at least one reference frame meeting " 742 DVLOG(1) << "There should be at least one reference frame meeting "
(...skipping 12 matching lines...) Expand all
755 755
756 // The mapping table for next two bits. 756 // The mapping table for next two bits.
757 const Vp9InterpolationFilter table[] = { 757 const Vp9InterpolationFilter table[] = {
758 Vp9InterpolationFilter::EIGHTTAP_SMOOTH, Vp9InterpolationFilter::EIGHTTAP, 758 Vp9InterpolationFilter::EIGHTTAP_SMOOTH, Vp9InterpolationFilter::EIGHTTAP,
759 Vp9InterpolationFilter::EIGHTTAP_SHARP, Vp9InterpolationFilter::BILINEAR, 759 Vp9InterpolationFilter::EIGHTTAP_SHARP, Vp9InterpolationFilter::BILINEAR,
760 }; 760 };
761 return table[reader_.ReadLiteral(2)]; 761 return table[reader_.ReadLiteral(2)];
762 } 762 }
763 763
764 void Vp9UncompressedHeaderParser::SetupPastIndependence(Vp9FrameHeader* fhdr) { 764 void Vp9UncompressedHeaderParser::SetupPastIndependence(Vp9FrameHeader* fhdr) {
765 memset(&context_->segmentation, 0, sizeof(context_->segmentation)); 765 memset(&context_->segmentation_, 0, sizeof(context_->segmentation_));
766 ResetLoopfilter(); 766 ResetLoopfilter();
767 fhdr->frame_context = kVp9DefaultFrameContext; 767 fhdr->frame_context = kVp9DefaultFrameContext;
768 DCHECK(Vp9FrameContextManager::IsValidFrameContext(fhdr->frame_context)); 768 DCHECK(fhdr->frame_context.IsValid());
769 } 769 }
770 770
771 // 6.2.8 Loop filter params syntax 771 // 6.2.8 Loop filter params syntax
772 void Vp9UncompressedHeaderParser::ReadLoopFilterParams() { 772 void Vp9UncompressedHeaderParser::ReadLoopFilterParams() {
773 Vp9LoopFilterParams& loop_filter = context_->loop_filter; 773 Vp9LoopFilterParams& loop_filter = context_->loop_filter_;
774 774
775 loop_filter.level = reader_.ReadLiteral(6); 775 loop_filter.level = reader_.ReadLiteral(6);
776 loop_filter.sharpness = reader_.ReadLiteral(3); 776 loop_filter.sharpness = reader_.ReadLiteral(3);
777 loop_filter.delta_update = false; 777 loop_filter.delta_update = false;
778 778
779 loop_filter.delta_enabled = reader_.ReadBool(); 779 loop_filter.delta_enabled = reader_.ReadBool();
780 if (loop_filter.delta_enabled) { 780 if (loop_filter.delta_enabled) {
781 loop_filter.delta_update = reader_.ReadBool(); 781 loop_filter.delta_update = reader_.ReadBool();
782 if (loop_filter.delta_update) { 782 if (loop_filter.delta_update) {
783 for (size_t i = 0; i < Vp9RefType::VP9_FRAME_MAX; i++) { 783 for (size_t i = 0; i < Vp9RefType::VP9_FRAME_MAX; i++) {
(...skipping 23 matching lines...) Expand all
807 807
808 // 6.2.10 Delta quantizer syntax 808 // 6.2.10 Delta quantizer syntax
809 int8_t Vp9UncompressedHeaderParser::ReadDeltaQ() { 809 int8_t Vp9UncompressedHeaderParser::ReadDeltaQ() {
810 if (reader_.ReadBool()) 810 if (reader_.ReadBool())
811 return reader_.ReadSignedLiteral(4); 811 return reader_.ReadSignedLiteral(4);
812 return 0; 812 return 0;
813 } 813 }
814 814
815 // 6.2.11 Segmentation params syntax 815 // 6.2.11 Segmentation params syntax
816 bool Vp9UncompressedHeaderParser::ReadSegmentationParams() { 816 bool Vp9UncompressedHeaderParser::ReadSegmentationParams() {
817 Vp9SegmentationParams& segmentation = context_->segmentation; 817 Vp9SegmentationParams& segmentation = context_->segmentation_;
818 segmentation.update_map = false; 818 segmentation.update_map = false;
819 segmentation.update_data = false; 819 segmentation.update_data = false;
820 820
821 segmentation.enabled = reader_.ReadBool(); 821 segmentation.enabled = reader_.ReadBool();
822 if (!segmentation.enabled) 822 if (!segmentation.enabled)
823 return true; 823 return true;
824 824
825 segmentation.update_map = reader_.ReadBool(); 825 segmentation.update_map = reader_.ReadBool();
826 if (segmentation.update_map) { 826 if (segmentation.update_map) {
827 for (auto& tree_prob : segmentation.tree_probs) { 827 for (auto& tree_prob : segmentation.tree_probs) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 // 7.2.11 Tile info semantics 889 // 7.2.11 Tile info semantics
890 if (fhdr->tile_cols_log2 > 6) { 890 if (fhdr->tile_cols_log2 > 6) {
891 DVLOG(1) << "tile_cols_log2 should be <= 6"; 891 DVLOG(1) << "tile_cols_log2 should be <= 6";
892 return false; 892 return false;
893 } 893 }
894 894
895 return true; 895 return true;
896 } 896 }
897 897
898 void Vp9UncompressedHeaderParser::ResetLoopfilter() { 898 void Vp9UncompressedHeaderParser::ResetLoopfilter() {
899 Vp9LoopFilterParams& loop_filter = context_->loop_filter; 899 Vp9LoopFilterParams& loop_filter = context_->loop_filter_;
900 900
901 loop_filter.delta_enabled = true; 901 loop_filter.delta_enabled = true;
902 loop_filter.delta_update = true; 902 loop_filter.delta_update = true;
903 903
904 loop_filter.ref_deltas[VP9_FRAME_INTRA] = 1; 904 loop_filter.ref_deltas[VP9_FRAME_INTRA] = 1;
905 loop_filter.ref_deltas[VP9_FRAME_LAST] = 0; 905 loop_filter.ref_deltas[VP9_FRAME_LAST] = 0;
906 loop_filter.ref_deltas[VP9_FRAME_GOLDEN] = -1; 906 loop_filter.ref_deltas[VP9_FRAME_GOLDEN] = -1;
907 loop_filter.ref_deltas[VP9_FRAME_ALTREF] = -1; 907 loop_filter.ref_deltas[VP9_FRAME_ALTREF] = -1;
908 908
909 memset(loop_filter.mode_deltas, 0, sizeof(loop_filter.mode_deltas)); 909 memset(loop_filter.mode_deltas, 0, sizeof(loop_filter.mode_deltas));
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 Vp9RefType::VP9_FRAME_LAST + kVp9NumRefsPerFrame, 994 Vp9RefType::VP9_FRAME_LAST + kVp9NumRefsPerFrame,
995 "ref_frame_sign_bias is not big enough"); 995 "ref_frame_sign_bias is not big enough");
996 for (size_t i = 0; i < kVp9NumRefsPerFrame; i++) { 996 for (size_t i = 0; i < kVp9NumRefsPerFrame; i++) {
997 fhdr->ref_frame_idx[i] = reader_.ReadLiteral(kVp9NumRefFramesLog2); 997 fhdr->ref_frame_idx[i] = reader_.ReadLiteral(kVp9NumRefFramesLog2);
998 fhdr->ref_frame_sign_bias[Vp9RefType::VP9_FRAME_LAST + i] = 998 fhdr->ref_frame_sign_bias[Vp9RefType::VP9_FRAME_LAST + i] =
999 reader_.ReadBool(); 999 reader_.ReadBool();
1000 1000
1001 // 8.2 Frame order constraints 1001 // 8.2 Frame order constraints
1002 // ref_frame_idx[i] refers to an earlier decoded frame. 1002 // ref_frame_idx[i] refers to an earlier decoded frame.
1003 const Vp9Parser::ReferenceSlot& ref = 1003 const Vp9Parser::ReferenceSlot& ref =
1004 context_->ref_slots[fhdr->ref_frame_idx[i]]; 1004 context_->GetRefSlot(fhdr->ref_frame_idx[i]);
1005 if (!ref.initialized) { 1005 if (!ref.initialized) {
1006 DVLOG(1) << "ref_frame_idx[" << i 1006 DVLOG(1) << "ref_frame_idx[" << i
1007 << "]=" << static_cast<int>(fhdr->ref_frame_idx[i]) 1007 << "]=" << static_cast<int>(fhdr->ref_frame_idx[i])
1008 << " refers to unused frame"; 1008 << " refers to unused frame";
1009 return false; 1009 return false;
1010 } 1010 }
1011 1011
1012 // 7.2 Uncompressed header semantics 1012 // 7.2 Uncompressed header semantics
1013 // the selected reference frames match the current frame in bit depth, 1013 // the selected reference frames match the current frame in bit depth,
1014 // profile, chroma subsampling, and color space. 1014 // profile, chroma subsampling, and color space.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 } 1049 }
1050 1050
1051 if (fhdr->error_resilient_mode) { 1051 if (fhdr->error_resilient_mode) {
1052 fhdr->refresh_frame_context = false; 1052 fhdr->refresh_frame_context = false;
1053 fhdr->frame_parallel_decoding_mode = true; 1053 fhdr->frame_parallel_decoding_mode = true;
1054 } else { 1054 } else {
1055 fhdr->refresh_frame_context = reader_.ReadBool(); 1055 fhdr->refresh_frame_context = reader_.ReadBool();
1056 fhdr->frame_parallel_decoding_mode = reader_.ReadBool(); 1056 fhdr->frame_parallel_decoding_mode = reader_.ReadBool();
1057 } 1057 }
1058 1058
1059 static_assert(
1060 arraysize(context_->frame_context_managers) == (1 << 2),
1061 "bits of frame_context_idx doesn't match size of frame_context_managers");
1062 fhdr->frame_context_idx_to_save_probs = fhdr->frame_context_idx = 1059 fhdr->frame_context_idx_to_save_probs = fhdr->frame_context_idx =
1063 reader_.ReadLiteral(2); 1060 reader_.ReadLiteral(kVp9NumFrameContextsLog2);
1064 1061
1065 if (fhdr->IsIntra()) { 1062 if (fhdr->IsIntra()) {
1066 SetupPastIndependence(fhdr); 1063 SetupPastIndependence(fhdr);
1067 if (fhdr->IsKeyframe() || fhdr->error_resilient_mode || 1064 if (fhdr->IsKeyframe() || fhdr->error_resilient_mode ||
1068 fhdr->reset_frame_context == 3) { 1065 fhdr->reset_frame_context == 3) {
1069 for (auto& frame_context_manage : context_->frame_context_managers) 1066 for (size_t i = 0; i < kVp9NumFrameContexts; ++i)
1070 frame_context_manage.Update(fhdr->frame_context); 1067 context_->UpdateFrameContext(i, fhdr->frame_context);
1071 } else if (fhdr->reset_frame_context == 2) { 1068 } else if (fhdr->reset_frame_context == 2) {
1072 context_->frame_context_managers[fhdr->frame_context_idx].Update( 1069 context_->UpdateFrameContext(fhdr->frame_context_idx,
1073 fhdr->frame_context); 1070 fhdr->frame_context);
1074 } 1071 }
1075 fhdr->frame_context_idx = 0; 1072 fhdr->frame_context_idx = 0;
1076 } 1073 }
1077 1074
1078 ReadLoopFilterParams(); 1075 ReadLoopFilterParams();
1079 ReadQuantizationParams(&fhdr->quant_params); 1076 ReadQuantizationParams(&fhdr->quant_params);
1080 if (!ReadSegmentationParams()) 1077 if (!ReadSegmentationParams())
1081 return false; 1078 return false;
1082 1079
1083 if (!ReadTileInfo(fhdr)) 1080 if (!ReadTileInfo(fhdr))
(...skipping 12 matching lines...) Expand all
1096 if (!reader_.IsValid()) { 1093 if (!reader_.IsValid()) {
1097 DVLOG(1) << "parser reads beyond the end of buffer"; 1094 DVLOG(1) << "parser reads beyond the end of buffer";
1098 return false; 1095 return false;
1099 } 1096 }
1100 fhdr->uncompressed_header_size = reader_.GetBytesRead(); 1097 fhdr->uncompressed_header_size = reader_.GetBytesRead();
1101 1098
1102 return true; 1099 return true;
1103 } 1100 }
1104 1101
1105 } // namespace media 1102 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/vp9_parser_unittest.cc ('k') | media/gpu/accelerated_video_decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698