1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152
  153
  154

media / gpu / v4l2 / test / h264_dpb.cc [blame]

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "media/gpu/v4l2/test/h264_dpb.h"

namespace media {
namespace v4l2_test {

H264SliceMetadata::H264SliceMetadata() = default;

H264SliceMetadata::H264SliceMetadata(const H264SliceMetadata&) = default;

int H264DPB::CountRefPics() {
  int ret = 0;
  for (auto& i : *this) {
    if (i.second.ref) {
      ret++;
    }
  }
  return ret;
}

void H264DPB::Delete(const H264SliceMetadata& pic) {
  erase(pic.ref_ts_nsec);
}

void H264DPB::DeleteUnused() {
  std::vector<uint64_t> keys;
  for (auto& i : *this) {
    if (i.second.outputted && !i.second.ref) {
      keys.push_back(i.first);
    }
  }
  for (auto i : keys) {
    erase(i);
  }
}

void H264DPB::UnmarkLowestFrameNumWrapShortRefPic() {
  int key = -1;
  for (auto& i : *this) {
    H264SliceMetadata pic = i.second;
    if (pic.ref && !pic.long_term_reference_flag &&
        (key < 0 || pic.frame_num_wrap < this->at(key).frame_num_wrap)) {
      key = i.first;
    }
  }

  if (key >= 0) {
    this->at(key).ref = false;
  }
}

std::vector<H264SliceMetadata*> H264DPB::GetNotOutputtedPicsAppending() {
  std::vector<H264SliceMetadata*> notOutputtedSlices;
  for (auto& i : *this) {
    if (!i.second.outputted) {
      notOutputtedSlices.push_back(&(i.second));
    }
  }

  return notOutputtedSlices;
}

void H264DPB::MarkAllUnusedRef() {
  for (auto& i : *this) {
    i.second.ref = false;
  }
}

void H264DPB::UpdatePicNums(const int curr_frame_num, const int max_frame_num) {
  for (auto& i : *this) {
    if (!i.second.ref) {
      continue;
    }

    // Update picture numbers as defined in section 8.2.4.1.
    if (i.second.long_term_reference_flag) {
      i.second.long_term_pic_num = i.second.long_term_frame_idx;
    } else {
      if (i.second.frame_num > curr_frame_num) {
        i.second.frame_num_wrap = i.second.frame_num - max_frame_num;
      } else {
        i.second.frame_num_wrap = i.second.frame_num;
      }

      i.second.pic_num = i.second.frame_num_wrap;
    }
  }
}

void H264DPB::UnmarkPicByPicNum(const int pic_num) {
  for (auto& i : *this) {
    if (i.second.pic_num == pic_num && i.second.ref &&
        !i.second.long_term_reference_flag) {
      i.second.ref = false;
      break;
    }
  }
}

void H264DPB::UnmarkLongTerm(const int pic_num) {
  for (auto& i : *this) {
    if (i.second.long_term_pic_num == pic_num && i.second.ref &&
        i.second.long_term_reference_flag) {
      i.second.ref = false;
      break;
    }
  }
}

H264SliceMetadata* H264DPB::GetShortRefPicByPicNum(const int pic_num) {
  for (auto& i : *this) {
    if (i.second.ref && !i.second.long_term_reference_flag &&
        i.second.pic_num == pic_num) {
      return &i.second;
    }
  }
  return nullptr;
}

H264SliceMetadata* H264DPB::GetLongRefPicByFrameIdx(const int frame_index) {
  for (auto& i : *this) {
    if (i.second.ref && i.second.long_term_reference_flag &&
        i.second.long_term_frame_idx == frame_index) {
      return &i.second;
    }
  }
  return nullptr;
}

void H264DPB::UnmarkLongTermPicsGreaterThanFrameIndex(const int index) {
  for (auto& i : *this) {
    if (i.second.long_term_reference_flag &&
        i.second.long_term_frame_idx > index) {
      i.second.ref = false;
    }
  }
}

std::set<int> H264DPB::GetHeldCaptureIds() const {
  std::set<int> dpb_ids;
  for (auto& i : *this) {
    if (i.second.ref || !i.second.outputted) {
      dpb_ids.insert(i.second.capture_queue_buffer_id);
    }
  }

  return dpb_ids;
}

}  // namespace v4l2_test
}  // namespace media