Migrate VP9 callbacks.
The callback is called only once in:
* https://cs.chromium.org/chromium/src/media/gpu/vp9_decoder.cc?rcl=af8dbb2317dd34f61874625286391d4e093bef45&l=275
and further evidenced by the BindOnce call in:
* https://cs.chromium.org/chromium/src/media/gpu/vp9_decoder.cc?rcl=af8dbb2317dd34f61874625286391d4e093bef45&l=286
This is part of the base::Callback migration.
Context: https://cs.chromium.org/chromium/src/docs/callback.md?rcl=9fcc3764aea8f97e9f6de4a9ee61d554e67edcda&l=40
Bug: 714018
Change-Id: I440e2505defc3703e92d9c222bf89c2e11721435
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2058816
Commit-Queue: Jose Lopes <jabolopes@google.com>
Reviewed-by: Dale Curtis <dalecurtis@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#743522}
diff --git a/media/filters/vp9_parser.cc b/media/filters/vp9_parser.cc
index 66d3233..3c759f4 100644
--- a/media/filters/vp9_parser.cc
+++ b/media/filters/vp9_parser.cc
@@ -14,6 +14,7 @@
#include <algorithm>
#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/containers/circular_deque.h"
#include "base/logging.h"
#include "base/numerics/ranges.h"
@@ -215,8 +216,9 @@
// It's possible that the previous frame didn't use all the clear bytes
// in this subsample, in which case we have to start from midway through
// the clear section.
- if (*extra_clear_subsample_bytes)
+ if (*extra_clear_subsample_bytes) {
subsample_clear = *extra_clear_subsample_bytes;
+ }
if (subsample_clear > frame_size) {
// Support scenario where clear section is larger than our frame:
@@ -245,8 +247,9 @@
}
// Don't go to the next subsample if there are more clear bytes.
- if (!*extra_clear_subsample_bytes)
+ if (!*extra_clear_subsample_bytes) {
(*current_subsample_index)++;
+ }
// It is possible for there to be more than one subsample associated
// with a single frame, so we need to try again if there are more bytes
@@ -261,13 +264,16 @@
const std::vector<SubsampleEntry>& subsamples) {
off_t original_byte = byte;
for (const SubsampleEntry& subsample : subsamples) {
- if (byte < 0)
+ if (byte < 0) {
return false;
- if (static_cast<uint32_t>(byte) < subsample.clear_bytes)
+ }
+ if (static_cast<uint32_t>(byte) < subsample.clear_bytes) {
return false;
+ }
byte -= subsample.clear_bytes;
- if (static_cast<uint32_t>(byte) < subsample.cypher_bytes)
+ if (static_cast<uint32_t>(byte) < subsample.cypher_bytes) {
return true;
+ }
byte -= subsample.cypher_bytes;
}
DVLOG(3) << "Subsamples do not extend to cover offset " << original_byte;
@@ -354,12 +360,15 @@
// probs should be in [1, 255] range.
static_assert(sizeof(Vp9Prob) == 1,
"following checks assuming Vp9Prob is single byte");
- if (memchr(tx_probs_8x8, 0, sizeof(tx_probs_8x8)))
+ if (memchr(tx_probs_8x8, 0, sizeof(tx_probs_8x8))) {
return false;
- if (memchr(tx_probs_16x16, 0, sizeof(tx_probs_16x16)))
+ }
+ if (memchr(tx_probs_16x16, 0, sizeof(tx_probs_16x16))) {
return false;
- if (memchr(tx_probs_32x32, 0, sizeof(tx_probs_32x32)))
+ }
+ if (memchr(tx_probs_32x32, 0, sizeof(tx_probs_32x32))) {
return false;
+ }
for (auto& a : coef_probs) {
for (auto& ai : a) {
@@ -368,52 +377,72 @@
int max_l = (ak == aj[0]) ? 3 : 6;
for (int l = 0; l < max_l; l++) {
for (auto& x : ak[l]) {
- if (x == 0)
+ if (x == 0) {
return false;
+ }
}
}
}
}
}
}
- if (memchr(skip_prob, 0, sizeof(skip_prob)))
+ if (memchr(skip_prob, 0, sizeof(skip_prob))) {
return false;
- if (memchr(inter_mode_probs, 0, sizeof(inter_mode_probs)))
+ }
+ if (memchr(inter_mode_probs, 0, sizeof(inter_mode_probs))) {
return false;
- if (memchr(interp_filter_probs, 0, sizeof(interp_filter_probs)))
+ }
+ if (memchr(interp_filter_probs, 0, sizeof(interp_filter_probs))) {
return false;
- if (memchr(is_inter_prob, 0, sizeof(is_inter_prob)))
+ }
+ if (memchr(is_inter_prob, 0, sizeof(is_inter_prob))) {
return false;
- if (memchr(comp_mode_prob, 0, sizeof(comp_mode_prob)))
+ }
+ if (memchr(comp_mode_prob, 0, sizeof(comp_mode_prob))) {
return false;
- if (memchr(single_ref_prob, 0, sizeof(single_ref_prob)))
+ }
+ if (memchr(single_ref_prob, 0, sizeof(single_ref_prob))) {
return false;
- if (memchr(comp_ref_prob, 0, sizeof(comp_ref_prob)))
+ }
+ if (memchr(comp_ref_prob, 0, sizeof(comp_ref_prob))) {
return false;
- if (memchr(y_mode_probs, 0, sizeof(y_mode_probs)))
+ }
+ if (memchr(y_mode_probs, 0, sizeof(y_mode_probs))) {
return false;
- if (memchr(uv_mode_probs, 0, sizeof(uv_mode_probs)))
+ }
+ if (memchr(uv_mode_probs, 0, sizeof(uv_mode_probs))) {
return false;
- if (memchr(partition_probs, 0, sizeof(partition_probs)))
+ }
+ if (memchr(partition_probs, 0, sizeof(partition_probs))) {
return false;
- if (memchr(mv_joint_probs, 0, sizeof(mv_joint_probs)))
+ }
+ if (memchr(mv_joint_probs, 0, sizeof(mv_joint_probs))) {
return false;
- if (memchr(mv_sign_prob, 0, sizeof(mv_sign_prob)))
+ }
+ if (memchr(mv_sign_prob, 0, sizeof(mv_sign_prob))) {
return false;
- if (memchr(mv_class_probs, 0, sizeof(mv_class_probs)))
+ }
+ if (memchr(mv_class_probs, 0, sizeof(mv_class_probs))) {
return false;
- if (memchr(mv_class0_bit_prob, 0, sizeof(mv_class0_bit_prob)))
+ }
+ if (memchr(mv_class0_bit_prob, 0, sizeof(mv_class0_bit_prob))) {
return false;
- if (memchr(mv_bits_prob, 0, sizeof(mv_bits_prob)))
+ }
+ if (memchr(mv_bits_prob, 0, sizeof(mv_bits_prob))) {
return false;
- if (memchr(mv_class0_fr_probs, 0, sizeof(mv_class0_fr_probs)))
+ }
+ if (memchr(mv_class0_fr_probs, 0, sizeof(mv_class0_fr_probs))) {
return false;
- if (memchr(mv_fr_probs, 0, sizeof(mv_fr_probs)))
+ }
+ if (memchr(mv_fr_probs, 0, sizeof(mv_fr_probs))) {
return false;
- if (memchr(mv_class0_hp_prob, 0, sizeof(mv_class0_hp_prob)))
+ }
+ if (memchr(mv_class0_hp_prob, 0, sizeof(mv_class0_hp_prob))) {
return false;
- if (memchr(mv_hp_prob, 0, sizeof(mv_hp_prob)))
+ }
+ if (memchr(mv_hp_prob, 0, sizeof(mv_hp_prob))) {
return false;
+ }
return true;
}
@@ -443,11 +472,12 @@
Vp9Parser::ContextRefreshCallback
Vp9Parser::Context::Vp9FrameContextManager::GetUpdateCb() {
- if (needs_client_update_)
- return base::Bind(&Vp9FrameContextManager::UpdateFromClient,
- weak_ptr_factory_.GetWeakPtr());
- else
- return Vp9Parser::ContextRefreshCallback();
+ if (needs_client_update_) {
+ return base::BindOnce(&Vp9FrameContextManager::UpdateFromClient,
+ weak_ptr_factory_.GetWeakPtr());
+ }
+
+ return {};
}
void Vp9Parser::Context::Vp9FrameContextManager::Update(
@@ -655,8 +685,9 @@
} else {
if (frames_.empty()) {
// No frames to be decoded, if there is no more stream, request more.
- if (!stream_)
+ if (!stream_) {
return kEOStream;
+ }
// New stream to be parsed, parse it and fill frames_.
if (!spatial_layer_frame_size_.empty()) {
@@ -676,14 +707,16 @@
frame_info = frames_.front();
frames_.pop_front();
if (frame_decrypt_config) {
- if (frame_info.decrypt_config)
+ if (frame_info.decrypt_config) {
*frame_decrypt_config = frame_info.decrypt_config->Clone();
- else
+ } else {
*frame_decrypt_config = nullptr;
+ }
}
- if (ParseUncompressedHeader(frame_info, fhdr, &result, &context_))
+ if (ParseUncompressedHeader(frame_info, fhdr, &result, &context_)) {
return result;
+ }
}
if (parsing_compressed_header_) {
@@ -693,15 +726,17 @@
}
}
- if (!SetupSegmentationDequant())
+ if (!SetupSegmentationDequant()) {
return kInvalidStream;
+ }
SetupLoopFilter();
UpdateSlots(&context_);
*fhdr = curr_frame_header_;
// show_frame must be true for the last frame, otherwise false in SVC frame.
- if (!spatial_layer_frame_size_.empty())
+ if (!spatial_layer_frame_size_.empty()) {
fhdr->show_frame = frames_.empty();
+ }
if (frame_info.allocate_size.IsEmpty()) {
allocate_size->SetSize(fhdr->frame_width, fhdr->frame_height);
@@ -724,13 +759,15 @@
std::unique_ptr<DecryptConfig> Vp9Parser::NextFrameDecryptContextForTesting() {
if (frames_.empty()) {
// No frames to be decoded, if there is no more stream, request more.
- if (!stream_)
+ if (!stream_) {
return nullptr;
+ }
// New stream to be parsed, parse it and fill frames_.
frames_ = ParseSuperframe();
- if (frames_.empty())
+ if (frames_.empty()) {
return nullptr;
+ }
}
FrameInfo frame_info = std::move(frames_.front());
frames_.pop_front();
@@ -753,8 +790,9 @@
base::circular_deque<FrameInfo> frames;
- if (bytes_left < 1)
+ if (bytes_left < 1) {
return frames;
+ }
// The marker byte might be encrypted, in which case we should treat
// the stream as a single frame.
@@ -772,8 +810,9 @@
uint8_t marker = *(stream + marker_offset);
if ((marker & 0xe0) != 0xc0) {
frames.push_back(FrameInfo(stream, bytes_left));
- if (stream_decrypt_config_)
+ if (stream_decrypt_config_) {
frames[0].decrypt_config = stream_decrypt_config_->Clone();
+ }
return frames;
}
@@ -786,12 +825,14 @@
size_t mag = ((marker >> 3) & 0x3) + 1;
off_t index_size = 2 + mag * num_frames;
- if (bytes_left < index_size)
+ if (bytes_left < index_size) {
return base::circular_deque<FrameInfo>();
+ }
const uint8_t* index_ptr = stream + bytes_left - index_size;
- if (marker != *index_ptr)
+ if (marker != *index_ptr) {
return base::circular_deque<FrameInfo>();
+ }
++index_ptr;
bytes_left -= index_size;
@@ -971,8 +1012,9 @@
// 8.8.1 Loop filter frame init process
void Vp9Parser::SetupLoopFilter() {
Vp9LoopFilterParams& loop_filter = context_.loop_filter_;
- if (!loop_filter.level)
+ if (!loop_filter.level) {
return;
+ }
int scale = loop_filter.level < 32 ? 1 : 2;
diff --git a/media/filters/vp9_parser.h b/media/filters/vp9_parser.h
index 359bafd8..4f36038 100644
--- a/media/filters/vp9_parser.h
+++ b/media/filters/vp9_parser.h
@@ -272,7 +272,8 @@
public:
// If context update is needed after decoding a frame, the client must
// execute this callback, passing the updated context state.
- using ContextRefreshCallback = base::Callback<void(const Vp9FrameContext&)>;
+ using ContextRefreshCallback =
+ base::OnceCallback<void(const Vp9FrameContext&)>;
// ParseNextFrame() return values. See documentation for ParseNextFrame().
enum Result {
diff --git a/media/filters/vp9_parser_unittest.cc b/media/filters/vp9_parser_unittest.cc
index 84e6da24..6f4da1b2 100644
--- a/media/filters/vp9_parser_unittest.cc
+++ b/media/filters/vp9_parser_unittest.cc
@@ -648,7 +648,7 @@
} else {
EXPECT_TRUE(should_update);
ReadContext(&frame_context);
- context_refresh_cb.Run(frame_context);
+ std::move(context_refresh_cb).Run(frame_context);
}
++num_parsed_frames;
@@ -680,7 +680,7 @@
// After update, parse should be ok.
auto context_refresh_cb = GetContextRefreshCb(fhdr);
EXPECT_FALSE(!context_refresh_cb);
- context_refresh_cb.Run(frame_context);
+ std::move(context_refresh_cb).Run(frame_context);
EXPECT_EQ(Vp9Parser::kOk, ParseNextFrame(&fhdr));
// Make sure it parsed the 2nd frame.
diff --git a/media/gpu/vp9_decoder.cc b/media/gpu/vp9_decoder.cc
index ed4306a..b66feb0 100644
--- a/media/gpu/vp9_decoder.cc
+++ b/media/gpu/vp9_decoder.cc
@@ -22,8 +22,9 @@
#if defined(ARCH_CPU_X86_FAMILY) && defined(OS_CHROMEOS)
const uint32_t* cue_data =
reinterpret_cast<const uint32_t*>(decoder_buffer.side_data());
- if (!cue_data)
+ if (!cue_data) {
return {};
+ }
if (!base::FeatureList::IsEnabled(media::kVp9kSVCHWDecoding)) {
DLOG(ERROR) << "Vp9Parser doesn't support parsing SVC stream";
return {};
@@ -104,8 +105,9 @@
parser_.Reset();
- if (state_ == kDecoding)
+ if (state_ == kDecoding) {
state_ = kAfterReset;
+ }
}
VP9Decoder::DecodeResult VP9Decoder::Decode() {
@@ -236,8 +238,9 @@
}
scoped_refptr<VP9Picture> pic = accelerator_->CreateVP9Picture();
- if (!pic)
+ if (!pic) {
return kRanOutOfSurfaces;
+ }
DVLOG(2) << "Render resolution: " << new_render_rect.ToString();
pic->set_visible_rect(new_render_rect);
@@ -262,7 +265,7 @@
void VP9Decoder::UpdateFrameContext(
scoped_refptr<VP9Picture> pic,
- const base::Callback<void(const Vp9FrameContext&)>& context_refresh_cb) {
+ Vp9Parser::ContextRefreshCallback context_refresh_cb) {
DCHECK(context_refresh_cb);
Vp9FrameContext frame_ctx;
memset(&frame_ctx, 0, sizeof(frame_ctx));
@@ -272,7 +275,7 @@
return;
}
- context_refresh_cb.Run(frame_ctx);
+ std::move(context_refresh_cb).Run(frame_ctx);
}
bool VP9Decoder::DecodeAndOutputPicture(scoped_refptr<VP9Picture> pic) {
@@ -280,11 +283,13 @@
DCHECK(pic->frame_hdr);
base::OnceClosure done_cb;
- const auto& context_refresh_cb =
+ Vp9Parser::ContextRefreshCallback context_refresh_cb =
parser_.GetContextRefreshCb(pic->frame_hdr->frame_context_idx);
- if (context_refresh_cb)
- done_cb = base::BindOnce(&VP9Decoder::UpdateFrameContext,
- base::Unretained(this), pic, context_refresh_cb);
+ if (context_refresh_cb) {
+ done_cb =
+ base::BindOnce(&VP9Decoder::UpdateFrameContext, base::Unretained(this),
+ pic, std::move(context_refresh_cb));
+ }
const Vp9Parser::Context& context = parser_.context();
if (!accelerator_->SubmitDecode(pic, context.segmentation(),
@@ -294,8 +299,9 @@
}
if (pic->frame_hdr->show_frame) {
- if (!accelerator_->OutputPicture(pic))
+ if (!accelerator_->OutputPicture(pic)) {
return false;
+ }
}
ref_frames_.Refresh(std::move(pic));
diff --git a/media/gpu/vp9_decoder.h b/media/gpu/vp9_decoder.h
index b183a29..63f3ef2 100644
--- a/media/gpu/vp9_decoder.h
+++ b/media/gpu/vp9_decoder.h
@@ -117,9 +117,8 @@
// Get frame context state after decoding |pic| from the accelerator, and call
// |context_refresh_cb| with the acquired state.
- void UpdateFrameContext(
- scoped_refptr<VP9Picture> pic,
- const base::Callback<void(const Vp9FrameContext&)>& context_refresh_cb);
+ void UpdateFrameContext(scoped_refptr<VP9Picture> pic,
+ Vp9Parser::ContextRefreshCallback context_refresh_cb);
// Called on error, when decoding cannot continue. Sets state_ to kError and
// releases current state.