summaryrefslogtreecommitdiff
path: root/media/cast/logging/logging_internal.h
blob: 6f028b925feb9777a2690e4f859c56ceaab10032 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2013 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.

#ifndef MEDIA_CAST_LOGGING_LOGGING_INTERNAL_H_
#define MEDIA_CAST_LOGGING_LOGGING_INTERNAL_H_

#include <map>
#include <string>
#include <vector>

#include "base/basictypes.h"
#include "base/time/tick_clock.h"
#include "base/time/time.h"

namespace media {
namespace cast {

// TODO(mikhal): Consider storing only the delta time and not absolute time.
struct FrameEvent {
  uint32 frame_id;
  int size;
  base::TimeTicks timestamp;
  base::TimeDelta delay_delta;  // render/playout delay.
};

struct PacketEvent {
  uint32 frame_id;
  int max_packet_id;
  size_t size;
  base::TimeTicks timestamp;
};

// Frame and packet maps are sorted based on the rtp_timestamp.
typedef std::map<uint32, FrameEvent> FrameMap;
typedef std::map<uint16, PacketEvent> BasePacketMap;
typedef std::map<uint32, BasePacketMap> PacketMap;

class FrameLogData {
 public:
  explicit FrameLogData(base::TickClock* clock);
  ~FrameLogData();
  void Insert(uint32 rtp_timestamp, uint32 frame_id);
  // Include size for encoded images (compute bitrate),
  void InsertWithSize(uint32 rtp_timestamp, uint32 frame_id, int size);
  // Include playout/render delay info.
  void InsertWithDelay(
      uint32 rtp_timestamp, uint32 frame_id, base::TimeDelta delay);
  void Reset();

 private:
  void InsertBase(uint32 rtp_timestamp, uint32 frame_id, FrameEvent info);

  base::TickClock* const clock_;  // Not owned by this class.
  FrameMap frame_map_;

  DISALLOW_COPY_AND_ASSIGN(FrameLogData);
};

// TODO(mikhal): Should be able to handle packet bursts.
class PacketLogData {
 public:
  explicit PacketLogData(base::TickClock* clock);
  ~PacketLogData();
  void Insert(uint32 rtp_timestamp, uint32 frame_id, uint16 packet_id,
      uint16 max_packet_id, int size);
  void Reset();

 private:
  base::TickClock* const clock_;  // Not owned by this class.
  PacketMap packet_map_;

  DISALLOW_COPY_AND_ASSIGN(PacketLogData);
};

class GenericLogData {
 public:
  explicit GenericLogData(base::TickClock* clock);
  ~GenericLogData();
  void Insert(int value);
  void Reset();

 private:
  base::TickClock* const clock_;  // Not owned by this class.
  std::vector<int> data_;
  std::vector<base::TimeTicks> timestamp_;

  DISALLOW_COPY_AND_ASSIGN(GenericLogData);
};


}  // namespace cast
}  // namespace media

#endif  // MEDIA_CAST_LOGGING_LOGGING_INTERNAL_H_