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"
13 RawEventSubscriberBundleForStream::RawEventSubscriberBundleForStream(
14 const scoped_refptr
<CastEnvironment
>& cast_environment
,
16 ReceiverTimeOffsetEstimator
* offset_estimator
)
17 : cast_environment_(cast_environment
),
19 is_audio
? AUDIO_EVENT
: VIDEO_EVENT
,
20 is_audio
? kMaxAudioEventEntries
: kMaxVideoEventEntries
),
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_
;
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(
57 new ReceiverTimeOffsetEstimatorImpl
);
58 cast_environment_
->Logging()->AddRawEventSubscriber(
59 receiver_offset_estimator_
.get());
61 SubscribersMapByStream::iterator it
= subscribers_
.find(is_audio
);
62 if (it
!= subscribers_
.end())
65 subscribers_
.insert(std::make_pair(
67 make_linked_ptr(new RawEventSubscriberBundleForStream(
68 cast_environment_
, is_audio
, receiver_offset_estimator_
.get()))));
71 void RawEventSubscriberBundle::RemoveEventSubscribers(bool is_audio
) {
72 SubscribersMapByStream::iterator it
= subscribers_
.find(is_audio
);
73 if (it
== subscribers_
.end())
76 subscribers_
.erase(it
);
77 if (subscribers_
.empty()) {
78 cast_environment_
->Logging()->RemoveRawEventSubscriber(
79 receiver_offset_estimator_
.get());
80 receiver_offset_estimator_
.reset();
84 EncodingEventSubscriber
*
85 RawEventSubscriberBundle::GetEncodingEventSubscriber(bool is_audio
) {
86 SubscribersMapByStream::iterator it
= subscribers_
.find(is_audio
);
87 return it
== subscribers_
.end() ?
88 NULL
: it
->second
->GetEncodingEventSubscriber();
92 RawEventSubscriberBundle::GetStatsEventSubscriber(bool is_audio
) {
93 SubscribersMapByStream::iterator it
= subscribers_
.find(is_audio
);
94 return it
== subscribers_
.end() ?
95 NULL
: it
->second
->GetStatsEventSubscriber();