Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to by pass audio encoder if pre-encoded set #120

Draft
wants to merge 4 commits into
base: m114_release
Choose a base branch
from

Conversation

kuba--
Copy link

@kuba-- kuba-- commented May 24, 2024

This draft PR is an experiment to by-pass audio encoder if pre_encoded audio option was set.

static_cast<uint32_t>(AudioProcessing::NativeRate::kSampleRate8kHz));

// 100 = 1 second / data duration (10 ms).
RTC_DCHECK_EQ(nSamples * 100, samplesPerSec);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these checks prevent using pre-encoded data? Since it's on the receive end, seems like this should be unaffected? In particular, dropping the 10ms rule seems like a pretty big deal since it's assumed fairly throughout the system that play data would be given in 10ms chunks.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll double check the samples one (it should be fine). For sure if you link rust-sdk examples with debug version of webrtc it will crash in this place, so I commented this block for testing purpose.

#
# Fatal error in: ../../../../_source/macos_arm64/webrtc/src/audio/audio_transport_impl.cc, line 213
# last system error: 0
# Check failed: sizeof(int16_t) * nChannels == nBytesPerSample (4 vs. 2)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also worried about OggReader where we have:

const OGG_PAGE_DURATION: Duration = Duration::from_millis(20);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can change that to be 10. since webrtc's internal clock for audio is 10ms

const size_t old_size = encoded->size();
for (const int16_t it : audio) {
uint8_t arr[2] = {
static_cast<uint8_t>((it >> 8) & 0x00ff),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is endianess an issue here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed we will have decoder (and this is how I tested), so the most important was to be consistent with decoder.
Otherwise, this is good question. I think I'll convert it to Little Endian (as more popular architecture). Another alternative is to rely on real architecture (by using C like union implementation) or expose this information as part of API, but It may look too complicated, because who knows what output SDP device will decode it.

@kuba--
Copy link
Author

kuba-- commented Jun 1, 2024

I uncommented most of checks in AudioTransportImpl::NeedMorePlayData. I left commented the only one, which crashes our example:

// RTC_DCHECK_EQ(sizeof(int16_t) * nChannels, nBytesPerSample);

I've also refined encoding. Made it more platform generic (instead of hardcoded big endian).

@davidliu
Copy link
Contributor

davidliu commented Jun 2, 2024

Endian I think would work as platform generic? Checked the network code and I think it expects platform endianess anyways.

For the nChannels vs. nBytesPerSample check, is this something we can address?

@kuba--
Copy link
Author

kuba-- commented Jun 2, 2024

For the nChannels vs. nBytesPerSample check, is this something we can address?

I'm not 100% sure if it has any impact on workflow (because nBytesPerSample is only used in the assert check), but I found the root cause. It's because in rust-sdks AudioDevice wrapper we have hardcoded values.

I've sent PR with fix: livekit/rust-sdks#344

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants