summaryrefslogtreecommitdiff
path: root/chromium/media/base/subsample_entry.cc
blob: 85975ce2005c38d42444992aede1a44f8b3240c4 (plain)
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
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "media/base/subsample_entry.h"

#include "base/logging.h"
#include "base/numerics/safe_math.h"

namespace media {

bool VerifySubsamplesMatchSize(const std::vector<SubsampleEntry>& subsamples,
                               size_t input_size) {
  base::CheckedNumeric<size_t> total_size = 0;
  for (const auto& subsample : subsamples) {
    // Add each entry separately to avoid the compiler doing the wrong thing.
    total_size += subsample.clear_bytes;
    total_size += subsample.cypher_bytes;
  }

  if (!total_size.IsValid() || total_size.ValueOrDie() != input_size) {
    DVLOG(1) << "Subsample sizes do not equal input size";
    return false;
  }

  return true;
}

}  // namespace media