2 * Copyright (C) 2011, 2015 Ericsson AB. All rights reserved.
3 * Copyright (C) 2012 Google Inc. All rights reserved.
4 * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies).
5 * Copyright (C) 2015 Apple Inc. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer
15 * in the documentation and/or other materials provided with the
17 * 3. Neither the name of Ericsson nor the names of its contributors
18 * may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #ifndef MediaStreamPrivate_h
35 #define MediaStreamPrivate_h
37 #if ENABLE(MEDIA_STREAM)
39 #include "FloatSize.h"
40 #include "MediaStreamTrack.h"
41 #include "MediaStreamTrackPrivate.h"
42 #include <wtf/Function.h>
43 #include <wtf/HashMap.h>
44 #include <wtf/MediaTime.h>
45 #include <wtf/RefCounted.h>
46 #include <wtf/RefPtr.h>
48 #include <wtf/Vector.h>
49 #include <wtf/WeakPtr.h>
54 class OrientationNotifier;
56 class MediaStreamPrivate : public MediaStreamTrackPrivate::Observer, public RefCounted<MediaStreamPrivate>, public CanMakeWeakPtr<MediaStreamPrivate> {
60 virtual ~Observer() = default;
62 virtual void characteristicsChanged() { }
63 virtual void activeStatusChanged() { }
64 virtual void didAddTrack(MediaStreamTrackPrivate&) { }
65 virtual void didRemoveTrack(MediaStreamTrackPrivate&) { }
68 static Ref<MediaStreamPrivate> create(Ref<RealtimeMediaSource>&&);
69 static Ref<MediaStreamPrivate> create(const Vector<Ref<RealtimeMediaSource>>& audioSources, const Vector<Ref<RealtimeMediaSource>>& videoSources);
70 static Ref<MediaStreamPrivate> create(const MediaStreamTrackPrivateVector& tracks, String&& id = createCanonicalUUIDString()) { return adoptRef(*new MediaStreamPrivate(tracks, WTFMove(id))); }
72 virtual ~MediaStreamPrivate();
74 enum class NotifyClientOption { Notify, DontNotify };
76 void addObserver(Observer&);
77 void removeObserver(Observer&);
79 String id() const { return m_id; }
81 MediaStreamTrackPrivateVector tracks() const;
82 MediaStreamTrackPrivate* activeVideoTrack() { return m_activeVideoTrack; }
84 bool active() const { return m_isActive; }
85 void updateActiveState(NotifyClientOption);
87 void addTrack(RefPtr<MediaStreamTrackPrivate>&&, NotifyClientOption = NotifyClientOption::Notify);
88 void removeTrack(MediaStreamTrackPrivate&, NotifyClientOption = NotifyClientOption::Notify);
90 void startProducingData();
91 void stopProducingData();
92 bool isProducingData() const;
94 bool hasVideo() const;
95 bool hasAudio() const;
98 bool hasCaptureVideoSource() const;
99 bool hasCaptureAudioSource() const;
100 void setCaptureTracksMuted(bool);
102 FloatSize intrinsicSize() const;
104 void monitorOrientation(OrientationNotifier&);
107 MediaStreamPrivate(const MediaStreamTrackPrivateVector&, String&&);
109 // MediaStreamTrackPrivate::Observer
110 void trackStarted(MediaStreamTrackPrivate&) override;
111 void trackEnded(MediaStreamTrackPrivate&) override;
112 void trackMutedChanged(MediaStreamTrackPrivate&) override;
113 void trackSettingsChanged(MediaStreamTrackPrivate&) override;
114 void trackEnabledChanged(MediaStreamTrackPrivate&) override;
116 void characteristicsChanged();
117 void updateActiveVideoTrack();
119 void scheduleDeferredTask(Function<void ()>&&);
120 void forEachObserver(const WTF::Function<void(Observer&)>&) const;
122 HashSet<Observer*> m_observers;
124 MediaStreamTrackPrivate* m_activeVideoTrack { nullptr };
125 HashMap<String, RefPtr<MediaStreamTrackPrivate>> m_trackSet;
126 bool m_isActive { false };
129 typedef Vector<RefPtr<MediaStreamPrivate>> MediaStreamPrivateVector;
131 } // namespace WebCore
133 #endif // ENABLE(MEDIA_STREAM)
135 #endif // MediaStreamPrivate_h