bool SubtitleStream::fastForward(sf::Time targetPosition) { while(hasPackets()) { onGetData(); } std::list< std::shared_ptr<SubtitleData>>::iterator it = m_visibleSubtitles.begin(); while (it != m_visibleSubtitles.end()) { //erase subs that are deleted before the targetPosition if (it->get()->end<targetPosition) it = m_visibleSubtitles.erase(it); else ++it; } it = m_pendingSubtitles.begin(); while (it != m_pendingSubtitles.end()) { //erase subs that are deleted before the targetPosition if (it->get()->end<targetPosition) it = m_pendingSubtitles.erase(it); else ++it; } return true; }
bool SoundStream::fillAndPushBuffer(unsigned int bufferNum, bool immediateLoop) { bool requestStop = false; // Acquire audio data, also address EOF and error cases if they occur Chunk data = {NULL, 0}; for (Uint32 retryCount = 0; !onGetData(data) && (retryCount < BufferRetries); ++retryCount) { // Mark the buffer as the last one (so that we know when to reset the playing position) m_endBuffers[bufferNum] = true; // Check if the stream must loop or stop if (!m_loop) { // Not looping: request stop requestStop = true; break; } // Return to the beginning of the stream source onSeek(Time::Zero); // If we got data, break and process it, else try to fill the buffer once again if (data.samples && data.sampleCount) break; // If immediateLoop is specified, we have to immediately adjust the sample count if (immediateLoop) { // We just tried to begin preloading at EOF: reset the sample count m_samplesProcessed = 0; m_endBuffers[bufferNum] = false; } // We're a looping sound that got no data, so we retry onGetData() } // Fill the buffer if some data was returned if (data.samples && data.sampleCount) { unsigned int buffer = m_buffers[bufferNum]; // Fill the buffer ALsizei size = static_cast<ALsizei>(data.sampleCount) * sizeof(Int16); alCheck(alBufferData(buffer, m_format, data.samples, size, m_sampleRate)); // Push it into the sound queue alCheck(alSourceQueueBuffers(m_source, 1, &buffer)); } else { // If we get here, we most likely ran out of retries requestStop = true; } return requestStop; }
bool SoundStream::fillAndPushBuffer(unsigned int bufferNum) { bool requestStop = false; // Acquire audio data Chunk data = {NULL, 0}; if (!onGetData(data)) { // Mark the buffer as the last one (so that we know when to reset the playing position) m_endBuffers[bufferNum] = true; // Check if the stream must loop or stop if (m_loop) { // Return to the beginning of the stream source onSeek(Time::Zero); // If we previously had no data, try to fill the buffer once again if (!data.samples || (data.sampleCount == 0)) { return fillAndPushBuffer(bufferNum); } } else { // Not looping: request stop requestStop = true; } } // Fill the buffer if some data was returned if (data.samples && data.sampleCount) { unsigned int buffer = m_buffers[bufferNum]; // Fill the buffer ALsizei size = static_cast<ALsizei>(data.sampleCount) * sizeof(Int16); alCheck(alBufferData(buffer, m_format, data.samples, size, m_sampleRate)); // Push it into the sound queue alCheck(alSourceQueueBuffers(m_source, 1, &buffer)); } return requestStop; }
void SubtitleStream::update() { //only get new subtitles if we are running low if (m_status == Playing && hasPackets()) { if (!onGetData()) setStatus(Stopped); } if (!m_pendingSubtitles.empty()) { //activate subtitle if (m_pendingSubtitles.front()->start < m_timer->getOffset()) { std::shared_ptr<SubtitleData> iter = m_pendingSubtitles.front(); m_delegate.didUpdateSubtitle(*this, iter->sprites, iter->positions); m_visibleSubtitles.push_back(iter); m_pendingSubtitles.pop_front(); } } if (!m_visibleSubtitles.empty()) { //remove subtitle if (m_visibleSubtitles.front()->end < m_timer->getOffset()) { std::shared_ptr<SubtitleData> subtitle = m_visibleSubtitles.front(); m_visibleSubtitles.pop_front(); if (m_visibleSubtitles.empty()) { m_delegate.didWipeOutSubtitles(*this); } } } }