Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / media / cast / logging / raw_event_subscriber_bundle.h
blob58ab21e6e8abaebc186d397c32294f2f6c0cb205
1 // Copyright 2014 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.
5 #ifndef MEDIA_CAST_LOGGING_RAW_EVENT_SUBSCRIBER_BUNDLE_H_
6 #define MEDIA_CAST_LOGGING_RAW_EVENT_SUBSCRIBER_BUNDLE_H_
8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h"
10 #include "media/cast/logging/encoding_event_subscriber.h"
11 #include "media/cast/logging/stats_event_subscriber.h"
13 namespace media {
14 namespace cast {
16 class CastEnvironment;
17 class ReceiverTimeOffsetEstimator;
19 // Allow 9MB for serialized video / audio event logs.
20 const int kMaxSerializedBytes = 9000000;
22 // Assume serialized log data for each frame will take up to 150 bytes.
23 const int kMaxVideoEventEntries = kMaxSerializedBytes / 150;
25 // Assume serialized log data for each frame will take up to 75 bytes.
26 const int kMaxAudioEventEntries = kMaxSerializedBytes / 75;
28 // A bundle for raw event subscribers for a single stream.
29 // It contains an EncodingEventSubscriber and a StatsSubscriber.
30 class RawEventSubscriberBundleForStream {
31 public:
32 RawEventSubscriberBundleForStream(
33 const scoped_refptr<CastEnvironment>& cast_environment,
34 bool is_audio,
35 ReceiverTimeOffsetEstimator* offset_estimator);
36 ~RawEventSubscriberBundleForStream();
38 EncodingEventSubscriber* GetEncodingEventSubscriber();
39 StatsEventSubscriber* GetStatsEventSubscriber();
41 private:
42 const scoped_refptr<CastEnvironment> cast_environment_;
43 EncodingEventSubscriber event_subscriber_;
44 StatsEventSubscriber stats_subscriber_;
46 DISALLOW_COPY_AND_ASSIGN(RawEventSubscriberBundleForStream);
49 // A bundle of subscribers for all streams. An instance of this object
50 // is associated with a CastEnvironment.
51 // This class can be used for managing event subscribers
52 // in a session where they could be multiple streams (i.e. CastSessionDelegate).
53 // It also contains a ReceiverTimeOffsetEstimator that is shared by subscribers
54 // of different streams.
55 class RawEventSubscriberBundle {
56 public:
57 explicit RawEventSubscriberBundle(
58 const scoped_refptr<CastEnvironment>& cast_environment);
59 ~RawEventSubscriberBundle();
61 void AddEventSubscribers(bool is_audio);
62 void RemoveEventSubscribers(bool is_audio);
63 EncodingEventSubscriber* GetEncodingEventSubscriber(
64 bool is_audio);
65 StatsEventSubscriber* GetStatsEventSubscriber(bool is_audio);
67 private:
68 // Map from (is_audio) -> RawEventSubscriberBundleForStream.
69 // TODO(imcheng): This works because we only have 1 audio and 1 video stream.
70 // This needs to scale better.
71 typedef std::map<bool, linked_ptr<RawEventSubscriberBundleForStream> >
72 SubscribersMapByStream;
73 const scoped_refptr<CastEnvironment> cast_environment_;
74 SubscribersMapByStream subscribers_;
75 scoped_ptr<ReceiverTimeOffsetEstimator> receiver_offset_estimator_;
77 DISALLOW_COPY_AND_ASSIGN(RawEventSubscriberBundle);
80 } // namespace cast
81 } // namespace media
83 #endif // MEDIA_CAST_LOGGING_RAW_EVENT_SUBSCRIBER_BUNDLE_H_