1/*
2 *  Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 *
4 *  Use of this source code is governed by a BSD-style license
5 *  that can be found in the LICENSE file in the root of the source
6 *  tree. An additional intellectual property rights grant can be found
7 *  in the file PATENTS.  All contributing project authors may
8 *  be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include <algorithm>
12
13#include "webrtc/modules/remote_bitrate_estimator/test/estimators/tcp.h"
14
15#include "testing/gtest/include/gtest/gtest.h"
16#include "webrtc/base/common.h"
17#include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
18#include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h"
19#include "webrtc/modules/rtp_rtcp/include/receive_statistics.h"
20
21namespace webrtc {
22namespace testing {
23namespace bwe {
24
25TcpBweReceiver::TcpBweReceiver(int flow_id)
26    : BweReceiver(flow_id),
27      last_feedback_ms_(0),
28      latest_owd_ms_(0) {
29}
30
31TcpBweReceiver::~TcpBweReceiver() {
32}
33
34void TcpBweReceiver::ReceivePacket(int64_t arrival_time_ms,
35                                   const MediaPacket& media_packet) {
36  latest_owd_ms_ = arrival_time_ms - media_packet.sender_timestamp_ms() / 1000;
37  acks_.push_back(media_packet.header().sequenceNumber);
38
39  // Log received packet information.
40  BweReceiver::ReceivePacket(arrival_time_ms, media_packet);
41}
42
43FeedbackPacket* TcpBweReceiver::GetFeedback(int64_t now_ms) {
44  int64_t corrected_send_time_ms = now_ms - latest_owd_ms_;
45  FeedbackPacket* fb =
46      new TcpFeedback(flow_id_, now_ms * 1000, corrected_send_time_ms, acks_);
47  last_feedback_ms_ = now_ms;
48  acks_.clear();
49  return fb;
50}
51
52}  // namespace bwe
53}  // namespace testing
54}  // namespace webrtc
55