| // 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/muxers/output_position_tracker.h" |
| |
| #include "base/functional/callback.h" |
| #include "base/numerics/checked_math.h" |
| #include "base/strings/string_piece.h" |
| |
| namespace media { |
| |
| OutputPositionTracker::OutputPositionTracker( |
| Muxer::WriteDataCB write_data_callback) |
| : write_data_callback_(std::move(write_data_callback)) { |
| CHECK(write_data_callback_); |
| } |
| |
| OutputPositionTracker::~OutputPositionTracker() = default; |
| |
| void OutputPositionTracker::WriteString(base::StringPiece data) { |
| DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| |
| write_data_callback_.Run(data); |
| CHECK(base::CheckAdd(current_pos_, data.size()).AssignIfValid(¤t_pos_)); |
| } |
| |
| uint32_t OutputPositionTracker::GetCurrentPos() const { |
| DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| |
| return current_pos_; |
| } |
| |
| } // namespace media |