Fix crackling audio with pipewire and only add empty audio packets until the first packet arrives
This commit is contained in:
parent
f490abb67e
commit
4917c0406c
1
TODO
1
TODO
@ -11,3 +11,4 @@ See https://trac.ffmpeg.org/wiki/EncodingForStreamingSites for optimizing stream
|
|||||||
Add -ma option to merge all audio tracks into one (muxing?).
|
Add -ma option to merge all audio tracks into one (muxing?).
|
||||||
Look at VK_EXT_external_memory_dma_buf.
|
Look at VK_EXT_external_memory_dma_buf.
|
||||||
Allow setting a different output resolution than the input resolution.
|
Allow setting a different output resolution than the input resolution.
|
||||||
|
Use mov+faststart.
|
||||||
|
10
src/main.cpp
10
src/main.cpp
@ -1322,6 +1322,7 @@ int main(int argc, char **argv) {
|
|||||||
std::deque<uint8_t*> buffered_audio;
|
std::deque<uint8_t*> buffered_audio;
|
||||||
std::mutex buffered_audio_mutex;
|
std::mutex buffered_audio_mutex;
|
||||||
std::condition_variable buffered_audio_cv;
|
std::condition_variable buffered_audio_cv;
|
||||||
|
bool got_first_batch = false;
|
||||||
|
|
||||||
// TODO: Make the sound device read async instead of using a thread
|
// TODO: Make the sound device read async instead of using a thread
|
||||||
std::thread sound_read_thread([&](){
|
std::thread sound_read_thread([&](){
|
||||||
@ -1344,9 +1345,13 @@ int main(int argc, char **argv) {
|
|||||||
uint8_t *audio_buffer;
|
uint8_t *audio_buffer;
|
||||||
bool free_audio;
|
bool free_audio;
|
||||||
{
|
{
|
||||||
// TODO: Not a good solution to lack of audio as it causes dropped frames, but it's better then complete audio desync
|
// TODO: Not a good solution to lack of audio as it causes dropped frames, but it's better then complete audio desync.
|
||||||
|
// The first packet is delayed for some reason...
|
||||||
std::unique_lock<std::mutex> lock(buffered_audio_mutex);
|
std::unique_lock<std::mutex> lock(buffered_audio_mutex);
|
||||||
buffered_audio_cv.wait_for(lock, std::chrono::milliseconds(30), [&]{ return !running || !buffered_audio.empty(); });
|
if(got_first_batch)
|
||||||
|
buffered_audio_cv.wait(lock, [&]{ return !running || !buffered_audio.empty(); });
|
||||||
|
else
|
||||||
|
buffered_audio_cv.wait_for(lock, std::chrono::milliseconds(21), [&]{ return !running || !buffered_audio.empty(); });
|
||||||
if(!running)
|
if(!running)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1357,6 +1362,7 @@ int main(int argc, char **argv) {
|
|||||||
audio_buffer = buffered_audio.front();
|
audio_buffer = buffered_audio.front();
|
||||||
buffered_audio.pop_front();
|
buffered_audio.pop_front();
|
||||||
free_audio = true;
|
free_audio = true;
|
||||||
|
got_first_batch = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user