| // Copyright 2024 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 "quiche/quic/moqt/moqt_stream_map.h" |
| |
| #include <cstdint> |
| #include <limits> |
| #include <optional> |
| #include <vector> |
| |
| #include "quiche/quic/core/quic_interval.h" |
| #include "quiche/quic/moqt/moqt_messages.h" |
| #include "quiche/quic/platform/api/quic_bug_tracker.h" |
| #include "quiche/common/platform/api/quiche_logging.h" |
| #include "quiche/web_transport/web_transport.h" |
| |
| namespace moqt { |
| |
| std::optional<webtransport::StreamId> SendStreamMap::GetStreamFor( |
| DataStreamIndex index) const { |
| auto it = send_streams_.find(index); |
| if (it == send_streams_.end()) { |
| return std::nullopt; |
| } |
| return it->second; |
| } |
| |
| void SendStreamMap::AddStream(DataStreamIndex index, |
| webtransport::StreamId stream_id) { |
| auto [it, success] = send_streams_.emplace(index, stream_id); |
| QUICHE_BUG_IF(quic_bug_moqt_draft_03_02, !success) << "Stream already added"; |
| } |
| |
| void SendStreamMap::RemoveStream(DataStreamIndex index) { |
| send_streams_.erase(index); |
| } |
| |
| std::vector<webtransport::StreamId> SendStreamMap::GetAllStreams() const { |
| std::vector<webtransport::StreamId> ids; |
| for (const auto& [index, stream_id] : send_streams_) { |
| ids.push_back(stream_id); |
| } |
| return ids; |
| } |
| |
| std::vector<webtransport::StreamId> SendStreamMap::GetStreamsForGroup( |
| uint64_t group_id) const { |
| const auto start_it = send_streams_.lower_bound(DataStreamIndex(group_id, 0)); |
| const auto end_it = send_streams_.upper_bound( |
| DataStreamIndex(group_id, std::numeric_limits<uint64_t>::max())); |
| std::vector<webtransport::StreamId> ids; |
| for (auto it = start_it; it != end_it; ++it) { |
| ids.push_back(it->second); |
| } |
| return ids; |
| } |
| |
| } // namespace moqt |