| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 60 |
| 61 SourceBuffer::SourceBuffer(PassOwnPtr<SourceBufferPrivate> sourceBufferPrivate,
MediaSource* source, GenericEventQueue* asyncEventQueue) | 61 SourceBuffer::SourceBuffer(PassOwnPtr<SourceBufferPrivate> sourceBufferPrivate,
MediaSource* source, GenericEventQueue* asyncEventQueue) |
| 62 : ActiveDOMObject(source->executionContext()) | 62 : ActiveDOMObject(source->executionContext()) |
| 63 , m_private(sourceBufferPrivate) | 63 , m_private(sourceBufferPrivate) |
| 64 , m_source(source) | 64 , m_source(source) |
| 65 , m_asyncEventQueue(asyncEventQueue) | 65 , m_asyncEventQueue(asyncEventQueue) |
| 66 , m_updating(false) | 66 , m_updating(false) |
| 67 , m_timestampOffset(0) | 67 , m_timestampOffset(0) |
| 68 , m_appendWindowStart(0) | 68 , m_appendWindowStart(0) |
| 69 , m_appendWindowEnd(std::numeric_limits<double>::infinity()) | 69 , m_appendWindowEnd(std::numeric_limits<double>::infinity()) |
| 70 , m_appendBufferTimer(this, &SourceBuffer::appendBufferTimerFired) | 70 , m_appendBufferAsyncPartRunner(this, &SourceBuffer::appendBufferAsyncPart) |
| 71 , m_removeTimer(this, &SourceBuffer::removeTimerFired) | 71 , m_removeAsyncPartRunner(this, &SourceBuffer::removeAsyncPart) |
| 72 , m_pendingRemoveStart(-1) | 72 , m_pendingRemoveStart(-1) |
| 73 , m_pendingRemoveEnd(-1) | 73 , m_pendingRemoveEnd(-1) |
| 74 , m_streamMaxSizeValid(false) | 74 , m_streamMaxSizeValid(false) |
| 75 , m_streamMaxSize(0) | 75 , m_streamMaxSize(0) |
| 76 , m_appendStreamTimer(this, &SourceBuffer::appendStreamTimerFired) | 76 , m_appendStreamAsyncPartRunner(this, &SourceBuffer::appendStreamAsyncPart) |
| 77 { | 77 { |
| 78 ASSERT(m_private); | 78 ASSERT(m_private); |
| 79 ASSERT(m_source); | 79 ASSERT(m_source); |
| 80 ScriptWrappable::init(this); | 80 ScriptWrappable::init(this); |
| 81 } | 81 } |
| 82 | 82 |
| 83 SourceBuffer::~SourceBuffer() | 83 SourceBuffer::~SourceBuffer() |
| 84 { | 84 { |
| 85 ASSERT(isRemoved()); | 85 ASSERT(isRemoved()); |
| 86 ASSERT(!m_loader); | 86 ASSERT(!m_loader); |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 | 296 |
| 297 // 6. Set the updating attribute to true. | 297 // 6. Set the updating attribute to true. |
| 298 m_updating = true; | 298 m_updating = true; |
| 299 | 299 |
| 300 // 7. Queue a task to fire a simple event named updatestart at this SourceBu
ffer object. | 300 // 7. Queue a task to fire a simple event named updatestart at this SourceBu
ffer object. |
| 301 scheduleEvent(EventTypeNames::updatestart); | 301 scheduleEvent(EventTypeNames::updatestart); |
| 302 | 302 |
| 303 // 8. Return control to the caller and run the rest of the steps asynchronou
sly. | 303 // 8. Return control to the caller and run the rest of the steps asynchronou
sly. |
| 304 m_pendingRemoveStart = start; | 304 m_pendingRemoveStart = start; |
| 305 m_pendingRemoveEnd = end; | 305 m_pendingRemoveEnd = end; |
| 306 m_removeTimer.startOneShot(0); | 306 m_removeAsyncPartRunner.runAsync(); |
| 307 } | 307 } |
| 308 | 308 |
| 309 void SourceBuffer::abortIfUpdating() | 309 void SourceBuffer::abortIfUpdating() |
| 310 { | 310 { |
| 311 // Section 3.2 abort() method step 3 substeps. | 311 // Section 3.2 abort() method step 3 substeps. |
| 312 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou
rce.html#widl-SourceBuffer-abort-void | 312 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou
rce.html#widl-SourceBuffer-abort-void |
| 313 | 313 |
| 314 if (!m_updating) | 314 if (!m_updating) |
| 315 return; | 315 return; |
| 316 | 316 |
| 317 const char* traceEventName = 0; | 317 const char* traceEventName = 0; |
| 318 if (!m_pendingAppendData.isEmpty()) { | 318 if (!m_pendingAppendData.isEmpty()) { |
| 319 traceEventName = "SourceBuffer::appendBuffer"; | 319 traceEventName = "SourceBuffer::appendBuffer"; |
| 320 } else if (m_stream) { | 320 } else if (m_stream) { |
| 321 traceEventName = "SourceBuffer::appendStream"; | 321 traceEventName = "SourceBuffer::appendStream"; |
| 322 } else if (m_pendingRemoveStart != -1) { | 322 } else if (m_pendingRemoveStart != -1) { |
| 323 traceEventName = "SourceBuffer::remove"; | 323 traceEventName = "SourceBuffer::remove"; |
| 324 } else { | 324 } else { |
| 325 ASSERT_NOT_REACHED(); | 325 ASSERT_NOT_REACHED(); |
| 326 } | 326 } |
| 327 | 327 |
| 328 // 3.1. Abort the buffer append and stream append loop algorithms if they ar
e running. | 328 // 3.1. Abort the buffer append and stream append loop algorithms if they ar
e running. |
| 329 m_appendBufferTimer.stop(); | 329 m_appendBufferAsyncPartRunner.stop(); |
| 330 m_pendingAppendData.clear(); | 330 m_pendingAppendData.clear(); |
| 331 | 331 |
| 332 m_removeTimer.stop(); | 332 m_removeAsyncPartRunner.stop(); |
| 333 m_pendingRemoveStart = -1; | 333 m_pendingRemoveStart = -1; |
| 334 m_pendingRemoveEnd = -1; | 334 m_pendingRemoveEnd = -1; |
| 335 | 335 |
| 336 m_appendStreamTimer.stop(); | 336 m_appendStreamAsyncPartRunner.stop(); |
| 337 clearAppendStreamState(); | 337 clearAppendStreamState(); |
| 338 | 338 |
| 339 // 3.2. Set the updating attribute to false. | 339 // 3.2. Set the updating attribute to false. |
| 340 m_updating = false; | 340 m_updating = false; |
| 341 | 341 |
| 342 // 3.3. Queue a task to fire a simple event named abort at this SourceBuffer
object. | 342 // 3.3. Queue a task to fire a simple event named abort at this SourceBuffer
object. |
| 343 scheduleEvent(EventTypeNames::abort); | 343 scheduleEvent(EventTypeNames::abort); |
| 344 | 344 |
| 345 // 3.4. Queue a task to fire a simple event named updateend at this SourceBu
ffer object. | 345 // 3.4. Queue a task to fire a simple event named updateend at this SourceBu
ffer object. |
| 346 scheduleEvent(EventTypeNames::updateend); | 346 scheduleEvent(EventTypeNames::updateend); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 358 m_private->removedFromMediaSource(); | 358 m_private->removedFromMediaSource(); |
| 359 m_source = 0; | 359 m_source = 0; |
| 360 m_asyncEventQueue = 0; | 360 m_asyncEventQueue = 0; |
| 361 } | 361 } |
| 362 | 362 |
| 363 bool SourceBuffer::hasPendingActivity() const | 363 bool SourceBuffer::hasPendingActivity() const |
| 364 { | 364 { |
| 365 return m_source; | 365 return m_source; |
| 366 } | 366 } |
| 367 | 367 |
| 368 void SourceBuffer::suspend() |
| 369 { |
| 370 m_appendBufferAsyncPartRunner.suspend(); |
| 371 m_removeAsyncPartRunner.suspend(); |
| 372 m_appendStreamAsyncPartRunner.suspend(); |
| 373 } |
| 374 |
| 375 void SourceBuffer::resume() |
| 376 { |
| 377 m_appendBufferAsyncPartRunner.resume(); |
| 378 m_removeAsyncPartRunner.resume(); |
| 379 m_appendStreamAsyncPartRunner.resume(); |
| 380 } |
| 381 |
| 368 void SourceBuffer::stop() | 382 void SourceBuffer::stop() |
| 369 { | 383 { |
| 370 m_appendBufferTimer.stop(); | 384 m_appendBufferAsyncPartRunner.stop(); |
| 371 m_removeTimer.stop(); | 385 m_removeAsyncPartRunner.stop(); |
| 372 m_appendStreamTimer.stop(); | 386 m_appendStreamAsyncPartRunner.stop(); |
| 373 } | 387 } |
| 374 | 388 |
| 375 ExecutionContext* SourceBuffer::executionContext() const | 389 ExecutionContext* SourceBuffer::executionContext() const |
| 376 { | 390 { |
| 377 return ActiveDOMObject::executionContext(); | 391 return ActiveDOMObject::executionContext(); |
| 378 } | 392 } |
| 379 | 393 |
| 380 const AtomicString& SourceBuffer::interfaceName() const | 394 const AtomicString& SourceBuffer::interfaceName() const |
| 381 { | 395 { |
| 382 return EventTargetNames::SourceBuffer; | 396 return EventTargetNames::SourceBuffer; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 // 7. Add data to the end of the input buffer. | 434 // 7. Add data to the end of the input buffer. |
| 421 m_pendingAppendData.append(data, size); | 435 m_pendingAppendData.append(data, size); |
| 422 | 436 |
| 423 // 8. Set the updating attribute to true. | 437 // 8. Set the updating attribute to true. |
| 424 m_updating = true; | 438 m_updating = true; |
| 425 | 439 |
| 426 // 9. Queue a task to fire a simple event named updatestart at this SourceBu
ffer object. | 440 // 9. Queue a task to fire a simple event named updatestart at this SourceBu
ffer object. |
| 427 scheduleEvent(EventTypeNames::updatestart); | 441 scheduleEvent(EventTypeNames::updatestart); |
| 428 | 442 |
| 429 // 10. Asynchronously run the buffer append algorithm. | 443 // 10. Asynchronously run the buffer append algorithm. |
| 430 m_appendBufferTimer.startOneShot(0); | 444 m_appendBufferAsyncPartRunner.runAsync(); |
| 431 | 445 |
| 432 TRACE_EVENT_ASYNC_STEP0("media", "SourceBuffer::appendBuffer", this, "waitin
g"); | 446 TRACE_EVENT_ASYNC_STEP0("media", "SourceBuffer::appendBuffer", this, "waitin
g"); |
| 433 } | 447 } |
| 434 | 448 |
| 435 void SourceBuffer::appendBufferTimerFired(Timer<SourceBuffer>*) | 449 void SourceBuffer::appendBufferAsyncPart() |
| 436 { | 450 { |
| 437 ASSERT(m_updating); | 451 ASSERT(m_updating); |
| 438 | 452 |
| 439 TRACE_EVENT_ASYNC_STEP0("media", "SourceBuffer::appendBuffer", this, "append
ing"); | 453 TRACE_EVENT_ASYNC_STEP0("media", "SourceBuffer::appendBuffer", this, "append
ing"); |
| 440 | 454 |
| 441 // Section 3.5.4 Buffer Append Algorithm | 455 // Section 3.5.4 Buffer Append Algorithm |
| 442 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou
rce.html#sourcebuffer-buffer-append | 456 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou
rce.html#sourcebuffer-buffer-append |
| 443 | 457 |
| 444 // 1. Run the segment parser loop algorithm. | 458 // 1. Run the segment parser loop algorithm. |
| 445 // Step 2 doesn't apply since we run Step 1 synchronously here. | 459 // Step 2 doesn't apply since we run Step 1 synchronously here. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 457 m_pendingAppendData.clear(); | 471 m_pendingAppendData.clear(); |
| 458 | 472 |
| 459 // 4. Queue a task to fire a simple event named update at this SourceBuffer
object. | 473 // 4. Queue a task to fire a simple event named update at this SourceBuffer
object. |
| 460 scheduleEvent(EventTypeNames::update); | 474 scheduleEvent(EventTypeNames::update); |
| 461 | 475 |
| 462 // 5. Queue a task to fire a simple event named updateend at this SourceBuff
er object. | 476 // 5. Queue a task to fire a simple event named updateend at this SourceBuff
er object. |
| 463 scheduleEvent(EventTypeNames::updateend); | 477 scheduleEvent(EventTypeNames::updateend); |
| 464 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendBuffer", this); | 478 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendBuffer", this); |
| 465 } | 479 } |
| 466 | 480 |
| 467 void SourceBuffer::removeTimerFired(Timer<SourceBuffer>*) | 481 void SourceBuffer::removeAsyncPart() |
| 468 { | 482 { |
| 469 ASSERT(m_updating); | 483 ASSERT(m_updating); |
| 470 ASSERT(m_pendingRemoveStart >= 0); | 484 ASSERT(m_pendingRemoveStart >= 0); |
| 471 ASSERT(m_pendingRemoveStart < m_pendingRemoveEnd); | 485 ASSERT(m_pendingRemoveStart < m_pendingRemoveEnd); |
| 472 | 486 |
| 473 // Section 3.2 remove() method steps | 487 // Section 3.2 remove() method steps |
| 474 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou
rce.html#widl-SourceBuffer-remove-void-double-start-double-end | 488 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou
rce.html#widl-SourceBuffer-remove-void-double-start-double-end |
| 475 | 489 |
| 476 // 9. Run the coded frame removal algorithm with start and end as the start
and end of the removal range. | 490 // 9. Run the coded frame removal algorithm with start and end as the start
and end of the removal range. |
| 477 m_private->remove(m_pendingRemoveStart, m_pendingRemoveEnd); | 491 m_private->remove(m_pendingRemoveStart, m_pendingRemoveEnd); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 m_updating = true; | 533 m_updating = true; |
| 520 | 534 |
| 521 // 4. Queue a task to fire a simple event named updatestart at this SourceBu
ffer object. | 535 // 4. Queue a task to fire a simple event named updatestart at this SourceBu
ffer object. |
| 522 scheduleEvent(EventTypeNames::updatestart); | 536 scheduleEvent(EventTypeNames::updatestart); |
| 523 | 537 |
| 524 // 5. Asynchronously run the stream append loop algorithm with stream and ma
xSize. | 538 // 5. Asynchronously run the stream append loop algorithm with stream and ma
xSize. |
| 525 | 539 |
| 526 stream->neuter(); | 540 stream->neuter(); |
| 527 m_loader = adoptPtr(new FileReaderLoader(FileReaderLoader::ReadByClient, thi
s)); | 541 m_loader = adoptPtr(new FileReaderLoader(FileReaderLoader::ReadByClient, thi
s)); |
| 528 m_stream = stream; | 542 m_stream = stream; |
| 529 m_appendStreamTimer.startOneShot(0); | 543 m_appendStreamAsyncPartRunner.runAsync(); |
| 530 } | 544 } |
| 531 | 545 |
| 532 void SourceBuffer::appendStreamTimerFired(Timer<SourceBuffer>*) | 546 void SourceBuffer::appendStreamAsyncPart() |
| 533 { | 547 { |
| 534 ASSERT(m_updating); | 548 ASSERT(m_updating); |
| 535 ASSERT(m_loader); | 549 ASSERT(m_loader); |
| 536 ASSERT(m_stream); | 550 ASSERT(m_stream); |
| 537 | 551 |
| 538 // Section 3.5.6 Stream Append Loop | 552 // Section 3.5.6 Stream Append Loop |
| 539 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou
rce.html#sourcebuffer-stream-append-loop | 553 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou
rce.html#sourcebuffer-stream-append-loop |
| 540 | 554 |
| 541 // 1. If maxSize is set, then let bytesLeft equal maxSize. | 555 // 1. If maxSize is set, then let bytesLeft equal maxSize. |
| 542 // 2. Loop Top: If maxSize is set and bytesLeft equals 0, then jump to the l
oop done step below. | 556 // 2. Loop Top: If maxSize is set and bytesLeft equals 0, then jump to the l
oop done step below. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 569 // 3. Queue a task to fire a simple event named error at this SourceBuff
er object. | 583 // 3. Queue a task to fire a simple event named error at this SourceBuff
er object. |
| 570 scheduleEvent(EventTypeNames::error); | 584 scheduleEvent(EventTypeNames::error); |
| 571 | 585 |
| 572 // 4. Queue a task to fire a simple event named updateend at this Source
Buffer object. | 586 // 4. Queue a task to fire a simple event named updateend at this Source
Buffer object. |
| 573 scheduleEvent(EventTypeNames::updateend); | 587 scheduleEvent(EventTypeNames::updateend); |
| 574 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this); | 588 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this); |
| 575 return; | 589 return; |
| 576 } | 590 } |
| 577 | 591 |
| 578 // Section 3.5.6 Stream Append Loop | 592 // Section 3.5.6 Stream Append Loop |
| 579 // Steps 1-11 are handled by appendStreamTimerFired(), |m_loader|, and |m_pr
ivate|. | 593 // Steps 1-11 are handled by appendStreamAsyncPart(), |m_loader|, and |m_pri
vate|. |
| 580 // 12. Loop Done: Set the updating attribute to false. | 594 // 12. Loop Done: Set the updating attribute to false. |
| 581 m_updating = false; | 595 m_updating = false; |
| 582 | 596 |
| 583 // 13. Queue a task to fire a simple event named update at this SourceBuffer
object. | 597 // 13. Queue a task to fire a simple event named update at this SourceBuffer
object. |
| 584 scheduleEvent(EventTypeNames::update); | 598 scheduleEvent(EventTypeNames::update); |
| 585 | 599 |
| 586 // 14. Queue a task to fire a simple event named updateend at this SourceBuf
fer object. | 600 // 14. Queue a task to fire a simple event named updateend at this SourceBuf
fer object. |
| 587 scheduleEvent(EventTypeNames::updateend); | 601 scheduleEvent(EventTypeNames::updateend); |
| 588 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this); | 602 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this); |
| 589 } | 603 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 616 appendStreamDone(true); | 630 appendStreamDone(true); |
| 617 } | 631 } |
| 618 | 632 |
| 619 void SourceBuffer::didFail(FileError::ErrorCode errorCode) | 633 void SourceBuffer::didFail(FileError::ErrorCode errorCode) |
| 620 { | 634 { |
| 621 LOG(Media, "SourceBuffer::didFail(%d) %p", errorCode, this); | 635 LOG(Media, "SourceBuffer::didFail(%d) %p", errorCode, this); |
| 622 appendStreamDone(false); | 636 appendStreamDone(false); |
| 623 } | 637 } |
| 624 | 638 |
| 625 } // namespace WebCore | 639 } // namespace WebCore |
| OLD | NEW |