MCPcopy Create free account
hub / github.com/SFML/SFML / onGetData

Method onGetData

examples/voip/Server.cpp:76–102  ·  view source on GitHub ↗

/////////////////////////////////////////////////////// /see SoundStream::OnGetData ///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

74 ///
75 ////////////////////////////////////////////////////////////
76 bool onGetData(sf::SoundStream::Chunk& data) override
77 {
78 // We have reached the end of the buffer and all audio data have been played: we can stop playback
79 if ((m_offset >= m_samples.size()) && m_hasFinished)
80 return false;
81
82 // No new data has arrived since last update: wait until we get some
83 while ((m_offset >= m_samples.size()) && !m_hasFinished)
84 sf::sleep(sf::milliseconds(10));
85
86 // Copy samples into a local buffer to avoid synchronization problems
87 // (don't forget that we run in two separate threads)
88 {
89 const std::lock_guard lock(m_mutex);
90 m_tempBuffer.assign(m_samples.begin() + static_cast<std::vector<std::int16_t>::difference_type>(m_offset),
91 m_samples.end());
92 }
93
94 // Fill audio data to pass to the stream
95 data.samples = m_tempBuffer.data();
96 data.sampleCount = m_tempBuffer.size();
97
98 // Update the playing offset
99 m_offset += m_tempBuffer.size();
100
101 return true;
102 }
103
104 ////////////////////////////////////////////////////////////
105 /// /see SoundStream::OnSeek

Callers

nothing calls this directly

Calls 4

sleepFunction · 0.85
assignMethod · 0.80
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected