Fix client freeze when exiting
This commit is contained in:
@@ -67,7 +67,7 @@ void wivrn::android::audio::output(AAudioStream * stream, const xrt::drivers::wi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!quit)
|
while (!exiting)
|
||||||
{
|
{
|
||||||
auto packet = output_buffer.pop();
|
auto packet = output_buffer.pop();
|
||||||
auto &buffer = packet.payload;
|
auto &buffer = packet.payload;
|
||||||
@@ -83,7 +83,7 @@ void wivrn::android::audio::output(AAudioStream * stream, const xrt::drivers::wi
|
|||||||
catch (std::exception & e)
|
catch (std::exception & e)
|
||||||
{
|
{
|
||||||
spdlog::error("Error in audio output thread: {}", e.what());
|
spdlog::error("Error in audio output thread: {}", e.what());
|
||||||
quit = true;
|
exit();
|
||||||
}
|
}
|
||||||
AAudioStream_close(stream);
|
AAudioStream_close(stream);
|
||||||
}
|
}
|
||||||
@@ -104,7 +104,7 @@ void wivrn::android::audio::input(AAudioStream * stream, const xrt::drivers::wiv
|
|||||||
const int frame_size = format.num_channels * sizeof(int16_t);
|
const int frame_size = format.num_channels * sizeof(int16_t);
|
||||||
const int max_frames = (format.sample_rate * 10) / 1000; // 10ms
|
const int max_frames = (format.sample_rate * 10) / 1000; // 10ms
|
||||||
|
|
||||||
while (!quit)
|
while (!exiting)
|
||||||
{
|
{
|
||||||
packet.payload.resize(frame_size * max_frames);
|
packet.payload.resize(frame_size * max_frames);
|
||||||
result = AAudioStream_read(stream, packet.payload.data(), max_frames, 1'000'000'000);
|
result = AAudioStream_read(stream, packet.payload.data(), max_frames, 1'000'000'000);
|
||||||
@@ -119,12 +119,18 @@ void wivrn::android::audio::input(AAudioStream * stream, const xrt::drivers::wiv
|
|||||||
catch (std::exception & e)
|
catch (std::exception & e)
|
||||||
{
|
{
|
||||||
spdlog::error("Error in audio input thread: {}", e.what());
|
spdlog::error("Error in audio input thread: {}", e.what());
|
||||||
quit = true;
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
AAudioStream_close(stream);
|
AAudioStream_close(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wivrn::android::audio::exit()
|
||||||
|
{
|
||||||
|
exiting = true;
|
||||||
|
output_buffer.close();
|
||||||
|
}
|
||||||
|
|
||||||
wivrn::android::audio::audio(const xrt::drivers::wivrn::to_headset::audio_stream_description & desc, wivrn_session& session, xr::instance& instance): session(session), instance(instance)
|
wivrn::android::audio::audio(const xrt::drivers::wivrn::to_headset::audio_stream_description & desc, wivrn_session& session, xr::instance& instance): session(session), instance(instance)
|
||||||
{
|
{
|
||||||
AAudioStreamBuilder * builder;
|
AAudioStreamBuilder * builder;
|
||||||
@@ -173,7 +179,7 @@ wivrn::android::audio::audio(const xrt::drivers::wivrn::to_headset::audio_stream
|
|||||||
|
|
||||||
wivrn::android::audio::~audio()
|
wivrn::android::audio::~audio()
|
||||||
{
|
{
|
||||||
quit = true;
|
exit();
|
||||||
|
|
||||||
if (input_thread.joinable())
|
if (input_thread.joinable())
|
||||||
input_thread.join();
|
input_thread.join();
|
||||||
|
|||||||
@@ -47,9 +47,11 @@ class audio
|
|||||||
wivrn_session & session;
|
wivrn_session & session;
|
||||||
xr::instance & instance;
|
xr::instance & instance;
|
||||||
|
|
||||||
std::atomic<bool> quit = false;
|
std::atomic<bool> exiting = false;
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
|
|
||||||
|
void exit();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
audio(const audio &) = delete;
|
audio(const audio &) = delete;
|
||||||
audio & operator=(const audio &) = delete;
|
audio & operator=(const audio &) = delete;
|
||||||
|
|||||||
@@ -128,8 +128,7 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
|||||||
scenes::stream::~stream()
|
scenes::stream::~stream()
|
||||||
{
|
{
|
||||||
cleanup();
|
cleanup();
|
||||||
exiting = true;
|
exit();
|
||||||
shard_queue.close();
|
|
||||||
|
|
||||||
video_thread.join();
|
video_thread.join();
|
||||||
if (tracking_thread)
|
if (tracking_thread)
|
||||||
@@ -405,6 +404,13 @@ void scenes::stream::render()
|
|||||||
read_actions();
|
read_actions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void scenes::stream::exit()
|
||||||
|
{
|
||||||
|
exiting = true;
|
||||||
|
audio_handle.reset();
|
||||||
|
shard_queue.close();
|
||||||
|
}
|
||||||
|
|
||||||
void scenes::stream::cleanup()
|
void scenes::stream::cleanup()
|
||||||
{
|
{
|
||||||
// Assumes decoder_mutex is locked
|
// Assumes decoder_mutex is locked
|
||||||
@@ -556,7 +562,7 @@ void scenes::stream::video()
|
|||||||
catch (std::exception & e)
|
catch (std::exception & e)
|
||||||
{
|
{
|
||||||
spdlog::error("Exception in video thread: {}", e.what());
|
spdlog::error("Exception in video thread: {}", e.what());
|
||||||
exiting = true;
|
exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ private:
|
|||||||
void read_actions();
|
void read_actions();
|
||||||
|
|
||||||
void setup(const to_headset::video_stream_description &);
|
void setup(const to_headset::video_stream_description &);
|
||||||
|
void exit();
|
||||||
void cleanup();
|
void cleanup();
|
||||||
};
|
};
|
||||||
} // namespace scenes
|
} // namespace scenes
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ void scenes::stream::process_packets()
|
|||||||
catch (std::exception & e)
|
catch (std::exception & e)
|
||||||
{
|
{
|
||||||
spdlog::info("Exception in network thread, exiting: {}", e.what());
|
spdlog::info("Exception in network thread, exiting: {}", e.what());
|
||||||
exiting = true;
|
exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ void scenes::stream::tracking()
|
|||||||
catch (std::exception & e)
|
catch (std::exception & e)
|
||||||
{
|
{
|
||||||
spdlog::info("Exception in tracking thread, exiting: {}", e.what());
|
spdlog::info("Exception in tracking thread, exiting: {}", e.what());
|
||||||
exiting = true;
|
exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user