| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Ericsson AB. All rights reserved. | 2 * Copyright (C) 2011 Ericsson AB. All rights reserved. |
| 3 * Copyright (C) 2012 Google Inc. All rights reserved. | 3 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 #include "wtf/Allocator.h" | 38 #include "wtf/Allocator.h" |
| 39 #include "wtf/OwnPtr.h" | 39 #include "wtf/OwnPtr.h" |
| 40 #include "wtf/PassOwnPtr.h" | 40 #include "wtf/PassOwnPtr.h" |
| 41 #include "wtf/ThreadingPrimitives.h" | 41 #include "wtf/ThreadingPrimitives.h" |
| 42 #include "wtf/Vector.h" | 42 #include "wtf/Vector.h" |
| 43 #include "wtf/text/WTFString.h" | 43 #include "wtf/text/WTFString.h" |
| 44 | 44 |
| 45 namespace blink { | 45 namespace blink { |
| 46 | 46 |
| 47 class PLATFORM_EXPORT MediaStreamSource final : public GarbageCollectedFinalized
<MediaStreamSource> { | 47 class PLATFORM_EXPORT MediaStreamSource final : public GarbageCollectedFinalized
<MediaStreamSource> { |
| 48 USING_PRE_FINALIZER(MediaStreamSource, dispose); | |
| 49 public: | 48 public: |
| 50 class PLATFORM_EXPORT Observer : public GarbageCollectedMixin { | 49 class PLATFORM_EXPORT Observer : public GarbageCollectedMixin { |
| 51 public: | 50 public: |
| 52 virtual ~Observer() { } | 51 virtual ~Observer() { } |
| 53 virtual void sourceChangedState() = 0; | 52 virtual void sourceChangedState() = 0; |
| 54 }; | 53 }; |
| 55 | 54 |
| 56 class ExtraData { | 55 class ExtraData { |
| 56 USING_FAST_MALLOC(ExtraData); |
| 57 public: | 57 public: |
| 58 virtual ~ExtraData() { } | 58 virtual ~ExtraData() { } |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 enum StreamType { | 61 enum StreamType { |
| 62 TypeAudio, | 62 TypeAudio, |
| 63 TypeVideo | 63 TypeVideo |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 enum ReadyState { | 66 enum ReadyState { |
| 67 ReadyStateLive = 0, | 67 ReadyStateLive = 0, |
| 68 ReadyStateMuted = 1, | 68 ReadyStateMuted = 1, |
| 69 ReadyStateEnded = 2 | 69 ReadyStateEnded = 2 |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 static MediaStreamSource* create(const String& id, StreamType, const String&
name, bool remote, ReadyState = ReadyStateLive, bool requiresConsumer = false); | 72 static MediaStreamSource* create(const String& id, StreamType, const String&
name, bool remote, ReadyState = ReadyStateLive, bool requiresConsumer = false); |
| 73 void dispose(); | |
| 74 | 73 |
| 75 const String& id() const { return m_id; } | 74 const String& id() const { return m_id; } |
| 76 StreamType type() const { return m_type; } | 75 StreamType type() const { return m_type; } |
| 77 const String& name() const { return m_name; } | 76 const String& name() const { return m_name; } |
| 78 bool remote() const { return m_remote; } | 77 bool remote() const { return m_remote; } |
| 79 | 78 |
| 80 void setReadyState(ReadyState); | 79 void setReadyState(ReadyState); |
| 81 ReadyState getReadyState() const { return m_readyState; } | 80 ReadyState getReadyState() const { return m_readyState; } |
| 82 | 81 |
| 83 void addObserver(Observer*); | 82 void addObserver(Observer*); |
| 84 | 83 |
| 85 ExtraData* getExtraData() const { return m_extraData.get(); } | 84 ExtraData* getExtraData() const { return m_extraData.get(); } |
| 86 void setExtraData(PassOwnPtr<ExtraData> extraData) { m_extraData = std::move
(extraData); } | 85 void setExtraData(PassOwnPtr<ExtraData> extraData) { m_extraData = std::move
(extraData); } |
| 87 | 86 |
| 88 void setConstraints(WebMediaConstraints constraints) { m_constraints = const
raints; } | 87 void setConstraints(WebMediaConstraints constraints) { m_constraints = const
raints; } |
| 89 WebMediaConstraints constraints() { return m_constraints; } | 88 WebMediaConstraints constraints() { return m_constraints; } |
| 90 | 89 |
| 91 void setAudioFormat(size_t numberOfChannels, float sampleRate); | 90 void setAudioFormat(size_t numberOfChannels, float sampleRate); |
| 92 void consumeAudio(AudioBus*, size_t numberOfFrames); | 91 void consumeAudio(AudioBus*, size_t numberOfFrames); |
| 93 | 92 |
| 94 bool requiresAudioConsumer() const { return m_requiresConsumer; } | 93 bool requiresAudioConsumer() const { return m_requiresConsumer; } |
| 95 void addAudioConsumer(AudioDestinationConsumer*); | 94 void addAudioConsumer(AudioDestinationConsumer*); |
| 96 bool removeAudioConsumer(AudioDestinationConsumer*); | 95 bool removeAudioConsumer(AudioDestinationConsumer*); |
| 97 const HeapHashSet<Member<AudioDestinationConsumer>>& audioConsumers() { retu
rn m_audioConsumers; } | 96 const HeapHashSet<Member<AudioDestinationConsumer>>& audioConsumers() { retu
rn m_audioConsumers; } |
| 98 | 97 |
| 98 // |m_extraData| may hold pointers to GC objects, and it may touch them in d
estruction. |
| 99 // So this class is eagerly finalized to finalize |m_extraData| promptly. |
| 100 EAGERLY_FINALIZE(); |
| 99 DECLARE_TRACE(); | 101 DECLARE_TRACE(); |
| 100 | 102 |
| 101 private: | 103 private: |
| 102 MediaStreamSource(const String& id, StreamType, const String& name, bool rem
ote, ReadyState, bool requiresConsumer); | 104 MediaStreamSource(const String& id, StreamType, const String& name, bool rem
ote, ReadyState, bool requiresConsumer); |
| 103 | 105 |
| 104 String m_id; | 106 String m_id; |
| 105 StreamType m_type; | 107 StreamType m_type; |
| 106 String m_name; | 108 String m_name; |
| 107 bool m_remote; | 109 bool m_remote; |
| 108 ReadyState m_readyState; | 110 ReadyState m_readyState; |
| 109 bool m_requiresConsumer; | 111 bool m_requiresConsumer; |
| 110 HeapHashSet<WeakMember<Observer>> m_observers; | 112 HeapHashSet<WeakMember<Observer>> m_observers; |
| 111 Mutex m_audioConsumersLock; | 113 Mutex m_audioConsumersLock; |
| 112 HeapHashSet<Member<AudioDestinationConsumer>> m_audioConsumers; | 114 HeapHashSet<Member<AudioDestinationConsumer>> m_audioConsumers; |
| 113 OwnPtr<ExtraData> m_extraData; | 115 OwnPtr<ExtraData> m_extraData; |
| 114 WebMediaConstraints m_constraints; | 116 WebMediaConstraints m_constraints; |
| 115 }; | 117 }; |
| 116 | 118 |
| 117 typedef HeapVector<Member<MediaStreamSource>> MediaStreamSourceVector; | 119 typedef HeapVector<Member<MediaStreamSource>> MediaStreamSourceVector; |
| 118 | 120 |
| 119 } // namespace blink | 121 } // namespace blink |
| 120 | 122 |
| 121 #endif // MediaStreamSource_h | 123 #endif // MediaStreamSource_h |
| OLD | NEW |