Title: [125424] trunk/Source/WebCore
- Revision
- 125424
- Author
- [email protected]
- Date
- 2012-08-13 09:45:50 -0700 (Mon, 13 Aug 2012)
Log Message
Cap the number of SourceBuffers that may be added to a MediaSource.
https://bugs.webkit.org/show_bug.cgi?id=93406
Reviewed by Eric Carlson.
Make sure that no more SourceBuffer objects are added to a MediaSource
than can fit into the sourceBuffers SourceBufferList (internally stored
as a Vector). Also, make sure that new SourceBuffers are added with a
unique id even if the variable we are using to generate id wraps around.
No new tests. It would not be realistic to add so many SourceBuffers to
test the id variable wrapping. Existing tests should not be affected.
* Modules/mediasource/MediaSource.cpp:
(WebCore::MediaSource::MediaSource):
(WebCore::MediaSource::addSourceBuffer): Obtain a unique id before creating
a new SourceBuffer.
* Modules/mediasource/MediaSource.h:
* Modules/mediasource/SourceBufferList.cpp:
(WebCore::SourceBufferList::SourceBufferList):
(WebCore::SourceBufferList::generateUniqueId): Search for and generate a
unique id.
(WebCore):
(WebCore::SourceBufferList::contains): Check if a SourceBuffer with a
given id already exists in this SourceBufferList.
* Modules/mediasource/SourceBufferList.h:
(SourceBufferList):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (125423 => 125424)
--- trunk/Source/WebCore/ChangeLog 2012-08-13 16:41:34 UTC (rev 125423)
+++ trunk/Source/WebCore/ChangeLog 2012-08-13 16:45:50 UTC (rev 125424)
@@ -1,3 +1,33 @@
+2012-08-13 Anna Cavender <[email protected]>
+
+ Cap the number of SourceBuffers that may be added to a MediaSource.
+ https://bugs.webkit.org/show_bug.cgi?id=93406
+
+ Reviewed by Eric Carlson.
+
+ Make sure that no more SourceBuffer objects are added to a MediaSource
+ than can fit into the sourceBuffers SourceBufferList (internally stored
+ as a Vector). Also, make sure that new SourceBuffers are added with a
+ unique id even if the variable we are using to generate id wraps around.
+
+ No new tests. It would not be realistic to add so many SourceBuffers to
+ test the id variable wrapping. Existing tests should not be affected.
+
+ * Modules/mediasource/MediaSource.cpp:
+ (WebCore::MediaSource::MediaSource):
+ (WebCore::MediaSource::addSourceBuffer): Obtain a unique id before creating
+ a new SourceBuffer.
+ * Modules/mediasource/MediaSource.h:
+ * Modules/mediasource/SourceBufferList.cpp:
+ (WebCore::SourceBufferList::SourceBufferList):
+ (WebCore::SourceBufferList::generateUniqueId): Search for and generate a
+ unique id.
+ (WebCore):
+ (WebCore::SourceBufferList::contains): Check if a SourceBuffer with a
+ given id already exists in this SourceBufferList.
+ * Modules/mediasource/SourceBufferList.h:
+ (SourceBufferList):
+
2012-08-13 Andrey Kosyakov <[email protected]>
Web Inspector: when status bar is too narrow, cut panel status bar, not main status bar items
Modified: trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp (125423 => 125424)
--- trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp 2012-08-13 16:41:34 UTC (rev 125423)
+++ trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp 2012-08-13 16:45:50 UTC (rev 125424)
@@ -49,7 +49,6 @@
: ContextDestructionObserver(context)
, m_readyState(closedKeyword())
, m_player(0)
- , m_nextSourceBufferId(0)
{
m_sourceBuffers = SourceBufferList::create(scriptExecutionContext());
m_activeSourceBuffers = SourceBufferList::create(scriptExecutionContext());
@@ -94,8 +93,14 @@
}
// 5. Create a new SourceBuffer object and associated resources.
- RefPtr<SourceBuffer> buffer = SourceBuffer::create(String::number(++m_nextSourceBufferId), this);
+ String id = m_sourceBuffers->generateUniqueId();
+ if (id == emptyString()) {
+ ec = QUOTA_EXCEEDED_ERR;
+ return 0;
+ }
+ RefPtr<SourceBuffer> buffer = SourceBuffer::create(id, this);
+
switch (m_player->sourceAddId(buffer->id(), contentType.type(), codecs)) {
case MediaPlayer::Ok:
// 6. Add the new object to sourceBuffers and fire a addsourcebuffer on that object.
Modified: trunk/Source/WebCore/Modules/mediasource/MediaSource.h (125423 => 125424)
--- trunk/Source/WebCore/Modules/mediasource/MediaSource.h 2012-08-13 16:41:34 UTC (rev 125423)
+++ trunk/Source/WebCore/Modules/mediasource/MediaSource.h 2012-08-13 16:45:50 UTC (rev 125424)
@@ -104,7 +104,6 @@
RefPtr<SourceBufferList> m_sourceBuffers;
RefPtr<SourceBufferList> m_activeSourceBuffers;
- int m_nextSourceBufferId;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/Modules/mediasource/SourceBufferList.cpp (125423 => 125424)
--- trunk/Source/WebCore/Modules/mediasource/SourceBufferList.cpp 2012-08-13 16:41:34 UTC (rev 125423)
+++ trunk/Source/WebCore/Modules/mediasource/SourceBufferList.cpp 2012-08-13 16:45:50 UTC (rev 125424)
@@ -40,6 +40,7 @@
SourceBufferList::SourceBufferList(ScriptExecutionContext* context)
: m_scriptExecutionContext(context)
+ , m_lastSourceBufferId(0)
{
}
@@ -79,6 +80,34 @@
remove(m_list[i].get());
}
+String SourceBufferList::generateUniqueId()
+{
+ // Ensure a unique id. Until m_lastSourceBufferId wraps around (very unlikely),
+ // this loop will exit after one check. If m_lastSourceBufferId does wrap,
+ // this loop may run as many times as the size of m_list, but in most
+ // cases that should be less than 10. We may want to investigate a more
+ // efficient approach if many more SourceBuffers are allowed in the future.
+ size_t nextSourceBufferId = m_lastSourceBufferId + 1;
+
+ while (contains(nextSourceBufferId)) {
+ if (nextSourceBufferId == m_lastSourceBufferId)
+ return emptyString();
+ nextSourceBufferId++;
+ }
+ m_lastSourceBufferId = nextSourceBufferId;
+
+ return String::number(nextSourceBufferId);
+}
+
+bool SourceBufferList::contains(size_t id) const
+{
+ for (size_t i = 0; i < m_list.size(); ++i) {
+ if (m_list[i]->id() == String::number(id))
+ return true;
+ }
+ return false;
+}
+
void SourceBufferList::createAndFireEvent(const AtomicString& eventName)
{
RefPtr<Event> event = Event::create(eventName, false, false);
Modified: trunk/Source/WebCore/Modules/mediasource/SourceBufferList.h (125423 => 125424)
--- trunk/Source/WebCore/Modules/mediasource/SourceBufferList.h 2012-08-13 16:41:34 UTC (rev 125423)
+++ trunk/Source/WebCore/Modules/mediasource/SourceBufferList.h 2012-08-13 16:45:50 UTC (rev 125424)
@@ -56,6 +56,10 @@
bool remove(SourceBuffer*);
void clear();
+ // Generates an id for adding a new SourceBuffer. Returns an empty string
+ // if this SourceBufferList is full.
+ String generateUniqueId();
+
// EventTarget interface
virtual const AtomicString& interfaceName() const OVERRIDE;
virtual ScriptExecutionContext* scriptExecutionContext() const OVERRIDE;
@@ -70,6 +74,7 @@
private:
explicit SourceBufferList(ScriptExecutionContext*);
+ bool contains(size_t id) const;
void createAndFireEvent(const AtomicString&);
virtual void refEventTarget() OVERRIDE { ref(); }
@@ -79,6 +84,7 @@
ScriptExecutionContext* m_scriptExecutionContext;
Vector<RefPtr<SourceBuffer> > m_list;
+ size_t m_lastSourceBufferId;
};
} // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes