| 94 | } |
| 95 | |
| 96 | void ImageGenericDecoder::sortSamples() { |
| 97 | nvtx3::scoped_range marker{"sort samples"}; |
| 98 | assert(curr_order_.size() == code_streams_.size()); |
| 99 | int batch_size = code_streams_.size(); |
| 100 | curr_order_.clear(); |
| 101 | curr_order_.resize(batch_size); |
| 102 | std::iota(curr_order_.begin(), curr_order_.end(), 0); |
| 103 | |
| 104 | subsampling_score_.resize(batch_size); |
| 105 | area_.resize(batch_size); |
| 106 | auto subsamplingScore = [](nvimgcodecChromaSubsampling_t subsampling) { |
| 107 | switch (subsampling) { |
| 108 | case NVIMGCODEC_SAMPLING_444: |
| 109 | return 8; |
| 110 | case NVIMGCODEC_SAMPLING_422: |
| 111 | return 7; |
| 112 | case NVIMGCODEC_SAMPLING_420: |
| 113 | return 6; |
| 114 | case NVIMGCODEC_SAMPLING_440: |
| 115 | return 5; |
| 116 | case NVIMGCODEC_SAMPLING_411: |
| 117 | return 4; |
| 118 | case NVIMGCODEC_SAMPLING_410: |
| 119 | return 3; |
| 120 | case NVIMGCODEC_SAMPLING_GRAY: |
| 121 | return 2; |
| 122 | case NVIMGCODEC_SAMPLING_410V: |
| 123 | default: |
| 124 | return 1; |
| 125 | } |
| 126 | }; |
| 127 | for (int i = 0; i < batch_size; i++) { |
| 128 | nvimgcodecImageInfo_t cs_image_info{NVIMGCODEC_STRUCTURE_TYPE_IMAGE_INFO, sizeof(nvimgcodecImageInfo_t), 0}; |
| 129 | code_streams_[i]->getImageInfo(&cs_image_info); |
| 130 | subsampling_score_[i] = subsamplingScore(cs_image_info.chroma_subsampling); |
| 131 | area_[i] = cs_image_info.plane_info[0].height * cs_image_info.plane_info[0].width; |
| 132 | } |
| 133 | |
| 134 | // Sort in descending order |
| 135 | std::sort(curr_order_.begin(), curr_order_.end(), [&](int lhs, int rhs) { |
| 136 | if (subsampling_score_[lhs] != subsampling_score_[rhs]) |
| 137 | return subsampling_score_[lhs] > subsampling_score_[rhs]; // descending order |
| 138 | if (area_[lhs] != area_[rhs]) |
| 139 | return area_[lhs] > area_[rhs]; // descending order |
| 140 | else |
| 141 | return lhs < rhs; // ascending order |
| 142 | }); |
| 143 | } |
| 144 | |
| 145 | nvimgcodecProcessingStatus_t ImageGenericDecoder::canProcessImpl(Entry& sample, ProcessorEntry* processor, int tid) noexcept { |
| 146 | NVIMGCODEC_LOG_TRACE(this->logger_, tid << ": " << processor->id_ << " canDecode #" << sample.sample_idx); |