1// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "media/cast/logging/logging_internal.h"
6
7namespace media {
8namespace cast {
9
10FrameLogData::FrameLogData(base::TickClock* clock)
11    : clock_(clock),
12      frame_map_() {}
13
14FrameLogData::~FrameLogData() {}
15
16void FrameLogData::Insert(uint32 rtp_timestamp, uint32 frame_id) {
17  FrameEvent info;
18  InsertBase(rtp_timestamp, frame_id, info);
19}
20
21void FrameLogData::InsertWithSize(
22      uint32 rtp_timestamp, uint32 frame_id, int size) {
23  FrameEvent info;
24  info.size = size;
25  InsertBase(rtp_timestamp, frame_id, info);
26}
27
28void FrameLogData::InsertWithDelay(
29    uint32 rtp_timestamp, uint32 frame_id, base::TimeDelta delay) {
30  FrameEvent info;
31  info.delay_delta = delay;
32  InsertBase(rtp_timestamp, frame_id, info);
33}
34
35void FrameLogData::InsertBase(
36    uint32 rtp_timestamp, uint32 frame_id, FrameEvent info) {
37  info.timestamp = clock_->NowTicks();
38  info.frame_id = frame_id;
39  frame_map_.insert(std::make_pair(rtp_timestamp, info));
40}
41
42PacketLogData::PacketLogData(base::TickClock* clock)
43    : clock_(clock),
44      packet_map_() {}
45
46PacketLogData::~PacketLogData() {}
47
48void PacketLogData::Insert(uint32 rtp_timestamp,
49    uint32 frame_id, uint16 packet_id, uint16 max_packet_id, int size) {
50  PacketEvent info;
51  info.size = size;
52  info.max_packet_id = max_packet_id;
53  info.frame_id = frame_id;
54  info.timestamp = clock_->NowTicks();
55  // Is this a new frame?
56  PacketMap::iterator it = packet_map_.find(rtp_timestamp);
57  if (it == packet_map_.end()) {
58    // New rtp_timestamp id - create base packet map.
59    BasePacketMap base_map;
60    base_map.insert(std::make_pair(packet_id, info));
61    packet_map_.insert(std::make_pair(rtp_timestamp, base_map));
62  } else {
63    // Existing rtp_timestamp.
64    it->second.insert(std::make_pair(packet_id, info));
65  }
66}
67
68GenericLogData::GenericLogData(base::TickClock* clock)
69    : clock_(clock) {}
70
71GenericLogData::~GenericLogData() {}
72
73void GenericLogData::Insert(int data) {
74  data_.push_back(data);
75  timestamp_.push_back(clock_->NowTicks());
76}
77
78}  // namespace cast
79}  // namespace media
80