| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 { | 293 { |
| 294 ASSERT(m_isAddedToRegistry); | 294 ASSERT(m_isAddedToRegistry); |
| 295 m_isAddedToRegistry = false; | 295 m_isAddedToRegistry = false; |
| 296 } | 296 } |
| 297 | 297 |
| 298 double MediaSource::duration() const | 298 double MediaSource::duration() const |
| 299 { | 299 { |
| 300 return isClosed() ? std::numeric_limits<float>::quiet_NaN() : m_webMediaSour
ce->duration(); | 300 return isClosed() ? std::numeric_limits<float>::quiet_NaN() : m_webMediaSour
ce->duration(); |
| 301 } | 301 } |
| 302 | 302 |
| 303 PassRefPtrWillBeRawPtr<TimeRanges> MediaSource::buffered() const | 303 TimeRanges* MediaSource::buffered() const |
| 304 { | 304 { |
| 305 // Implements MediaSource algorithm for HTMLMediaElement.buffered. | 305 // Implements MediaSource algorithm for HTMLMediaElement.buffered. |
| 306 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou
rce.html#htmlmediaelement-extensions | 306 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou
rce.html#htmlmediaelement-extensions |
| 307 WillBeHeapVector<RefPtrWillBeMember<TimeRanges>> ranges(m_activeSourceBuffer
s->length()); | 307 HeapVector<Member<TimeRanges>> ranges(m_activeSourceBuffers->length()); |
| 308 for (size_t i = 0; i < m_activeSourceBuffers->length(); ++i) | 308 for (size_t i = 0; i < m_activeSourceBuffers->length(); ++i) |
| 309 ranges[i] = m_activeSourceBuffers->item(i)->buffered(ASSERT_NO_EXCEPTION
); | 309 ranges[i] = m_activeSourceBuffers->item(i)->buffered(ASSERT_NO_EXCEPTION
); |
| 310 | 310 |
| 311 // 1. If activeSourceBuffers.length equals 0 then return an empty TimeRanges
object and abort these steps. | 311 // 1. If activeSourceBuffers.length equals 0 then return an empty TimeRanges
object and abort these steps. |
| 312 if (ranges.isEmpty()) | 312 if (ranges.isEmpty()) |
| 313 return TimeRanges::create(); | 313 return TimeRanges::create(); |
| 314 | 314 |
| 315 // 2. Let active ranges be the ranges returned by buffered for each SourceBu
ffer object in activeSourceBuffers. | 315 // 2. Let active ranges be the ranges returned by buffered for each SourceBu
ffer object in activeSourceBuffers. |
| 316 // 3. Let highest end time be the largest range end time in the active range
s. | 316 // 3. Let highest end time be the largest range end time in the active range
s. |
| 317 double highestEndTime = -1; | 317 double highestEndTime = -1; |
| 318 for (size_t i = 0; i < ranges.size(); ++i) { | 318 for (size_t i = 0; i < ranges.size(); ++i) { |
| 319 unsigned length = ranges[i]->length(); | 319 unsigned length = ranges[i]->length(); |
| 320 if (length) | 320 if (length) |
| 321 highestEndTime = std::max(highestEndTime, ranges[i]->end(length - 1,
ASSERT_NO_EXCEPTION)); | 321 highestEndTime = std::max(highestEndTime, ranges[i]->end(length - 1,
ASSERT_NO_EXCEPTION)); |
| 322 } | 322 } |
| 323 | 323 |
| 324 // Return an empty range if all ranges are empty. | 324 // Return an empty range if all ranges are empty. |
| 325 if (highestEndTime < 0) | 325 if (highestEndTime < 0) |
| 326 return TimeRanges::create(); | 326 return TimeRanges::create(); |
| 327 | 327 |
| 328 // 4. Let intersection ranges equal a TimeRange object containing a single r
ange from 0 to highest end time. | 328 // 4. Let intersection ranges equal a TimeRange object containing a single r
ange from 0 to highest end time. |
| 329 RefPtrWillBeRawPtr<TimeRanges> intersectionRanges = TimeRanges::create(0, hi
ghestEndTime); | 329 TimeRanges* intersectionRanges = TimeRanges::create(0, highestEndTime); |
| 330 | 330 |
| 331 // 5. For each SourceBuffer object in activeSourceBuffers run the following
steps: | 331 // 5. For each SourceBuffer object in activeSourceBuffers run the following
steps: |
| 332 bool ended = readyState() == endedKeyword(); | 332 bool ended = readyState() == endedKeyword(); |
| 333 for (size_t i = 0; i < ranges.size(); ++i) { | 333 for (size_t i = 0; i < ranges.size(); ++i) { |
| 334 // 5.1 Let source ranges equal the ranges returned by the buffered attri
bute on the current SourceBuffer. | 334 // 5.1 Let source ranges equal the ranges returned by the buffered attri
bute on the current SourceBuffer. |
| 335 TimeRanges* sourceRanges = ranges[i].get(); | 335 TimeRanges* sourceRanges = ranges[i].get(); |
| 336 | 336 |
| 337 // 5.2 If readyState is "ended", then set the end time on the last range
in source ranges to highest end time. | 337 // 5.2 If readyState is "ended", then set the end time on the last range
in source ranges to highest end time. |
| 338 if (ended && sourceRanges->length()) | 338 if (ended && sourceRanges->length()) |
| 339 sourceRanges->add(sourceRanges->start(sourceRanges->length() - 1, AS
SERT_NO_EXCEPTION), highestEndTime); | 339 sourceRanges->add(sourceRanges->start(sourceRanges->length() - 1, AS
SERT_NO_EXCEPTION), highestEndTime); |
| 340 | 340 |
| 341 // 5.3 Let new intersection ranges equal the the intersection between th
e intersection ranges and the source ranges. | 341 // 5.3 Let new intersection ranges equal the the intersection between th
e intersection ranges and the source ranges. |
| 342 // 5.4 Replace the ranges in intersection ranges with the new intersecti
on ranges. | 342 // 5.4 Replace the ranges in intersection ranges with the new intersecti
on ranges. |
| 343 intersectionRanges->intersectWith(sourceRanges); | 343 intersectionRanges->intersectWith(sourceRanges); |
| 344 } | 344 } |
| 345 | 345 |
| 346 return intersectionRanges.release(); | 346 return intersectionRanges; |
| 347 } | 347 } |
| 348 | 348 |
| 349 PassRefPtrWillBeRawPtr<TimeRanges> MediaSource::seekable() const | 349 TimeRanges* MediaSource::seekable() const |
| 350 { | 350 { |
| 351 // Implements MediaSource algorithm for HTMLMediaElement.seekable. | 351 // Implements MediaSource algorithm for HTMLMediaElement.seekable. |
| 352 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou
rce.html#htmlmediaelement-extensions | 352 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou
rce.html#htmlmediaelement-extensions |
| 353 | 353 |
| 354 double sourceDuration = duration(); | 354 double sourceDuration = duration(); |
| 355 // If duration equals NaN: Return an empty TimeRanges object. | 355 // If duration equals NaN: Return an empty TimeRanges object. |
| 356 if (std::isnan(sourceDuration)) | 356 if (std::isnan(sourceDuration)) |
| 357 return TimeRanges::create(); | 357 return TimeRanges::create(); |
| 358 | 358 |
| 359 // If duration equals positive Infinity: | 359 // If duration equals positive Infinity: |
| 360 if (sourceDuration == std::numeric_limits<double>::infinity()) { | 360 if (sourceDuration == std::numeric_limits<double>::infinity()) { |
| 361 RefPtrWillBeRawPtr<TimeRanges> buffered = m_attachedElement->buffered(); | 361 TimeRanges* buffered = m_attachedElement->buffered(); |
| 362 | 362 |
| 363 // 1. If the HTMLMediaElement.buffered attribute returns an empty TimeRa
nges object, then | 363 // 1. If the HTMLMediaElement.buffered attribute returns an empty TimeRa
nges object, then |
| 364 // return an empty TimeRanges object and abort these steps. | 364 // return an empty TimeRanges object and abort these steps. |
| 365 if (buffered->length() == 0) | 365 if (buffered->length() == 0) |
| 366 return TimeRanges::create(); | 366 return TimeRanges::create(); |
| 367 | 367 |
| 368 // 2. Return a single range with a start time of 0 and an end time equal
to the highest end | 368 // 2. Return a single range with a start time of 0 and an end time equal
to the highest end |
| 369 // time reported by the HTMLMediaElement.buffered attribute. | 369 // time reported by the HTMLMediaElement.buffered attribute. |
| 370 return TimeRanges::create(0, buffered->end(buffered->length() - 1, ASSER
T_NO_EXCEPTION)); | 370 return TimeRanges::create(0, buffered->end(buffered->length() - 1, ASSER
T_NO_EXCEPTION)); |
| 371 } | 371 } |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 | 598 |
| 599 m_asyncEventQueue->enqueueEvent(event.release()); | 599 m_asyncEventQueue->enqueueEvent(event.release()); |
| 600 } | 600 } |
| 601 | 601 |
| 602 URLRegistry& MediaSource::registry() const | 602 URLRegistry& MediaSource::registry() const |
| 603 { | 603 { |
| 604 return MediaSourceRegistry::registry(); | 604 return MediaSourceRegistry::registry(); |
| 605 } | 605 } |
| 606 | 606 |
| 607 } // namespace blink | 607 } // namespace blink |
| OLD | NEW |