summaryrefslogtreecommitdiffstats
path: root/media/cast/logging/logging_impl.h
blob: d065655457fdfd92ab8aea1bcf182c60d8765980 (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
// 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_IMPL_H_
#define MEDIA_CAST_LOGGING_LOGGING_IMPL_H_

// Generic class that handles event logging for the cast library.
// Logging has three possible optional forms:
// 1. Raw data and stats accessible by the application.
// 2. UMA stats.
// 3. Tracing of raw events.

#include "base/memory/ref_counted.h"
#include "base/task_runner.h"
#include "media/cast/cast_config.h"
#include "media/cast/logging/logging_defines.h"
#include "media/cast/logging/logging_raw.h"
#include "media/cast/logging/logging_stats.h"

namespace media {
namespace cast {

// Should only be called from the main thread.
class LoggingImpl : public base::NonThreadSafe {
 public:
  LoggingImpl(scoped_refptr<base::TaskRunner> main_thread_proxy,
              const CastLoggingConfig& config);

  ~LoggingImpl();

  void InsertFrameEvent(const base::TimeTicks& time_of_event,
                        CastLoggingEvent event,
                        uint32 rtp_timestamp,
                        uint32 frame_id);

  void InsertFrameEventWithSize(const base::TimeTicks& time_of_event,
                                CastLoggingEvent event,
                                uint32 rtp_timestamp,
                                uint32 frame_id,
                                int frame_size);

  void InsertFrameEventWithDelay(const base::TimeTicks& time_of_event,
                                 CastLoggingEvent event,
                                 uint32 rtp_timestamp,
                                 uint32 frame_id,
                                 base::TimeDelta delay);

  void InsertPacketListEvent(const base::TimeTicks& time_of_event,
                             CastLoggingEvent event,
                             const PacketList& packets);

  void InsertPacketEvent(const base::TimeTicks& time_of_event,
                         CastLoggingEvent event,
                         uint32 rtp_timestamp,
                         uint32 frame_id,
                         uint16 packet_id,
                         uint16 max_packet_id,
                         size_t size);

  void InsertGenericEvent(const base::TimeTicks& time_of_event,
                          CastLoggingEvent event,
                          int value);

  // Get raw data.
  FrameRawMap GetFrameRawData();
  PacketRawMap GetPacketRawData();
  GenericRawMap GetGenericRawData();
  // Get stats only (computed when called). Triggers UMA stats when enabled.
  const FrameStatsMap* GetFrameStatsData(const base::TimeTicks& now);
  const PacketStatsMap* GetPacketStatsData(const base::TimeTicks& now);
  const GenericStatsMap* GetGenericStatsData();

  void Reset();

 private:
  scoped_refptr<base::TaskRunner> main_thread_proxy_;
  const CastLoggingConfig config_;
  LoggingRaw raw_;
  LoggingStats stats_;

  DISALLOW_COPY_AND_ASSIGN(LoggingImpl);
};

}  // namespace cast
}  // namespace media

#endif  // MEDIA_CAST_LOGGING_LOGGING_IMPL_H_