mirror of
https://github.com/LizardByte/Sunshine.git
synced 2025-02-28 12:40:33 +00:00
Merge branch 'master' into rumble
This commit is contained in:
commit
63b920cd7b
@ -87,11 +87,14 @@ void encodeThread(sample_queue_t samples, config_t config, void *channel_data) {
|
|||||||
OPUS_APPLICATION_AUDIO,
|
OPUS_APPLICATION_AUDIO,
|
||||||
nullptr) };
|
nullptr) };
|
||||||
|
|
||||||
opus_multistream_encoder_ctl(opus.get(), OPUS_SET_VBR(0));
|
// For some reason, audio is crackling when the encoder is set to constant bitstream.
|
||||||
|
// We simulate a constant bitstream with OPUS_SET_BITRATE(OPUS_BITRATE_MAX) -->
|
||||||
|
// which tries to occupy as much space as possible in the packet
|
||||||
|
opus_multistream_encoder_ctl(opus.get(), OPUS_SET_BITRATE(OPUS_BITRATE_MAX));
|
||||||
|
|
||||||
auto frame_size = config.packetDuration * stream->sampleRate / 1000;
|
auto frame_size = config.packetDuration * stream->sampleRate / 1000;
|
||||||
while(auto sample = samples->pop()) {
|
while(auto sample = samples->pop()) {
|
||||||
buffer_t packet { 1024 }; // 1KB
|
buffer_t packet { 1400 }; // 1KB
|
||||||
|
|
||||||
int bytes = opus_multistream_encode(opus.get(), sample->data(), frame_size, std::begin(packet), packet.size());
|
int bytes = opus_multistream_encode(opus.get(), sample->data(), frame_size, std::begin(packet), packet.size());
|
||||||
if(bytes < 0) {
|
if(bytes < 0) {
|
||||||
@ -101,6 +104,14 @@ void encodeThread(sample_queue_t samples, config_t config, void *channel_data) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Even with OPUS_SET_BITRATE(OPUS_BITRATE_MAX), silent packets are smaller than the rest
|
||||||
|
// Drop silent packets to ensure Moonlight won't complain
|
||||||
|
// A packet size of 128 seems a reasonable enough threshold
|
||||||
|
if(bytes < 128) {
|
||||||
|
BOOST_LOG(verbose) << "Dropped silent packet"sv;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
packet.fake_resize(bytes);
|
packet.fake_resize(bytes);
|
||||||
packets->raise(channel_data, std::move(packet));
|
packets->raise(channel_data, std::move(packet));
|
||||||
}
|
}
|
||||||
|
@ -1038,8 +1038,7 @@ void encode_run(
|
|||||||
std::this_thread::sleep_until(next_frame);
|
std::this_thread::sleep_until(next_frame);
|
||||||
next_frame += delay;
|
next_frame += delay;
|
||||||
|
|
||||||
// When Moonlight request an IDR frame, send frames even if there is no new captured frame
|
if(images->peek()) {
|
||||||
if(!frame->key_frame || images->peek()) {
|
|
||||||
if(auto img = images->pop(delay)) {
|
if(auto img = images->pop(delay)) {
|
||||||
session->device->convert(*img);
|
session->device->convert(*img);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user