Revert "Omit calls to set composing region when pasting image."
[chromium-blink-merge.git] / media / cast / logging / raw_event_subscriber_bundle.cc
blob5dc5f793f5a7b311e00f8edb8daced4aa09881a2
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 #include "media/cast/logging/raw_event_subscriber_bundle.h"
7 #include "media/cast/cast_environment.h"
8 #include "media/cast/logging/receiver_time_offset_estimator_impl.h"
10 namespace media {
11 namespace cast {
13 RawEventSubscriberBundleForStream::RawEventSubscriberBundleForStream(
14 const scoped_refptr<CastEnvironment>& cast_environment,
15 bool is_audio,
16 ReceiverTimeOffsetEstimator* offset_estimator)
17 : cast_environment_(cast_environment),
18 event_subscriber_(
19 is_audio ? AUDIO_EVENT : VIDEO_EVENT,
20 is_audio ? kMaxAudioEventEntries : kMaxVideoEventEntries),
21 stats_subscriber_(
22 is_audio ? AUDIO_EVENT : VIDEO_EVENT,
23 cast_environment->Clock(), offset_estimator) {
24 cast_environment_->Logging()->AddRawEventSubscriber(&event_subscriber_);
25 cast_environment_->Logging()->AddRawEventSubscriber(&stats_subscriber_);
28 RawEventSubscriberBundleForStream::~RawEventSubscriberBundleForStream() {
29 cast_environment_->Logging()->RemoveRawEventSubscriber(&event_subscriber_);
30 cast_environment_->Logging()->RemoveRawEventSubscriber(&stats_subscriber_);
33 EncodingEventSubscriber*
34 RawEventSubscriberBundleForStream::GetEncodingEventSubscriber() {
35 return &event_subscriber_;
38 StatsEventSubscriber*
39 RawEventSubscriberBundleForStream::GetStatsEventSubscriber() {
40 return &stats_subscriber_;
43 RawEventSubscriberBundle::RawEventSubscriberBundle(
44 const scoped_refptr<CastEnvironment>& cast_environment)
45 : cast_environment_(cast_environment) {}
47 RawEventSubscriberBundle::~RawEventSubscriberBundle() {
48 if (receiver_offset_estimator_.get()) {
49 cast_environment_->Logging()->RemoveRawEventSubscriber(
50 receiver_offset_estimator_.get());
54 void RawEventSubscriberBundle::AddEventSubscribers(bool is_audio) {
55 if (!receiver_offset_estimator_.get()) {
56 receiver_offset_estimator_.reset(new ReceiverTimeOffsetEstimatorImpl);
57 cast_environment_->Logging()->AddRawEventSubscriber(
58 receiver_offset_estimator_.get());
60 SubscribersMapByStream::iterator it = subscribers_.find(is_audio);
61 if (it != subscribers_.end())
62 return;
64 subscribers_.insert(std::make_pair(
65 is_audio,
66 make_linked_ptr(new RawEventSubscriberBundleForStream(
67 cast_environment_, is_audio, receiver_offset_estimator_.get()))));
70 void RawEventSubscriberBundle::RemoveEventSubscribers(bool is_audio) {
71 SubscribersMapByStream::iterator it = subscribers_.find(is_audio);
72 if (it == subscribers_.end())
73 return;
75 subscribers_.erase(it);
76 if (subscribers_.empty()) {
77 cast_environment_->Logging()->RemoveRawEventSubscriber(
78 receiver_offset_estimator_.get());
79 receiver_offset_estimator_.reset();
83 EncodingEventSubscriber*
84 RawEventSubscriberBundle::GetEncodingEventSubscriber(bool is_audio) {
85 SubscribersMapByStream::iterator it = subscribers_.find(is_audio);
86 return it == subscribers_.end() ?
87 NULL : it->second->GetEncodingEventSubscriber();
90 StatsEventSubscriber*
91 RawEventSubscriberBundle::GetStatsEventSubscriber(bool is_audio) {
92 SubscribersMapByStream::iterator it = subscribers_.find(is_audio);
93 return it == subscribers_.end() ?
94 NULL : it->second->GetStatsEventSubscriber();
97 } // namespace cast
98 } // namespace media