@@ -110,10 +110,10 @@ class UserTimestampTransformer : public webrtc::FrameTransformerInterface {
110110 // / Get the last received user timestamp (receiver side only)
111111 std::optional<int64_t > last_user_timestamp () const ;
112112
113- // / Pop the next received user timestamp from the receive queue .
114- // / Returns the user timestamp if available , nullopt otherwise.
115- // / Each decoded frame should call this once to get its matching timestamp .
116- std::optional<int64_t > pop_user_timestamp ( );
113+ // / Lookup the user timestamp associated with a given RTP timestamp .
114+ // / Returns the user timestamp if found , nullopt otherwise.
115+ // / The entry is removed from the map after lookup .
116+ std::optional<int64_t > lookup_user_timestamp ( uint32_t rtp_timestamp );
117117
118118 private:
119119 void TransformSend (
@@ -148,11 +148,14 @@ class UserTimestampTransformer : public webrtc::FrameTransformerInterface {
148148 mutable webrtc::Mutex send_cache_mutex_;
149149 mutable int64_t last_sent_user_timestamp_{0 };
150150
151- // Receive-side FIFO queue: one entry per received encoded frame, popped
152- // one-to-one as decoded frames are delivered to the video sink.
153- mutable webrtc::Mutex recv_queue_mutex_;
154- mutable std::deque<int64_t > recv_queue_;
155- static constexpr size_t kMaxRecvQueueEntries = 300 ;
151+ // Receive-side map: RTP timestamp -> user timestamp.
152+ // Keyed by RTP timestamp so decoded frames can look up their user
153+ // timestamp regardless of frame drops or reordering.
154+ mutable webrtc::Mutex recv_map_mutex_;
155+ mutable std::unordered_map<uint32_t , int64_t > recv_map_;
156+ // Track insertion order for pruning old entries.
157+ mutable std::deque<uint32_t > recv_map_order_;
158+ static constexpr size_t kMaxRecvMapEntries = 300 ;
156159};
157160
158161// / Wrapper class for Rust FFI that manages user timestamp transformers.
@@ -178,9 +181,9 @@ class UserTimestampHandler {
178181 // / Returns -1 if no timestamp has been received yet
179182 int64_t last_user_timestamp () const ;
180183
181- // / Pop the next received user timestamp from the receive queue .
182- // / Returns -1 if the queue is empty .
183- int64_t pop_user_timestamp ( ) const ;
184+ // / Lookup the user timestamp for a given RTP timestamp (receiver side) .
185+ // / Returns -1 if not found .
186+ int64_t lookup_user_timestamp ( uint32_t rtp_timestamp ) const ;
184187
185188 // / Check if a user timestamp has been received
186189 bool has_user_timestamp () const ;
0 commit comments