586 | | this, new_timestamp, ts, m_buffer_next_tail_timestamp, m_dll_e2, rate); |
---|
| 581 | this, new_timestamp, ts, m_buffer_next_tail_timestamp, m_dll_e2, m_nominal_rate); |
---|
| 582 | |
---|
| 583 | } |
---|
| 584 | |
---|
| 585 | /** |
---|
| 586 | * @brief Sets the buffer head timestamp. |
---|
| 587 | * |
---|
| 588 | * Set the buffer tail timestamp such that the buffer head timestamp becomes |
---|
| 589 | * \ref new_timestamp. This does not consider offsets, because it's use is to |
---|
| 590 | * make sure the following is true after setBufferHeadTimestamp(x): |
---|
| 591 | * x == getBufferHeadTimestamp() |
---|
| 592 | * |
---|
| 593 | * This is thread safe. |
---|
| 594 | * |
---|
| 595 | * @param new_timestamp |
---|
| 596 | */ |
---|
| 597 | void TimestampedBuffer::setBufferHeadTimestamp(uint64_t new_timestamp) { |
---|
| 598 | |
---|
| 599 | #ifdef DEBUG |
---|
| 600 | if (new_timestamp >= m_wrap_at) { |
---|
| 601 | debugWarning("timestamp not wrapped: %llu\n",new_timestamp); |
---|
| 602 | } |
---|
| 603 | #endif |
---|
| 604 | |
---|
| 605 | int64_t ts=new_timestamp; |
---|
| 606 | |
---|
| 607 | int64_t diff=m_buffer_next_tail_timestamp - m_buffer_tail_timestamp; |
---|
| 608 | if (diff < 0) diff += m_wrap_at; |
---|
| 609 | |
---|
| 610 | pthread_mutex_lock(&m_framecounter_lock); |
---|
| 611 | |
---|
| 612 | // add the time |
---|
| 613 | ts += (int64_t)(m_nominal_rate * (float)m_framecounter); |
---|
| 614 | |
---|
| 615 | if (ts >= (int64_t)m_wrap_at) { |
---|
| 616 | ts -= m_wrap_at; |
---|
| 617 | } else if (ts < 0) { |
---|
| 618 | ts += m_wrap_at; |
---|
| 619 | } |
---|
| 620 | |
---|
| 621 | m_buffer_tail_timestamp = ts; |
---|
| 622 | |
---|
| 623 | m_dll_e2=m_update_period * m_nominal_rate; |
---|
| 624 | m_buffer_next_tail_timestamp = (uint64_t)((float)m_buffer_tail_timestamp + m_dll_e2); |
---|
| 625 | |
---|
| 626 | pthread_mutex_unlock(&m_framecounter_lock); |
---|
| 627 | |
---|
| 628 | debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "Set buffer head timestamp for (%p) to %11llu => %11lld, NTS=%llu, DLL2=%f, RATE=%f\n", |
---|
| 629 | this, new_timestamp, ts, m_buffer_next_tail_timestamp, m_dll_e2, m_nominal_rate); |
---|