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

Expose remote audio sample buffers on RTCAudioTrack #84

Merged
merged 17 commits into from
Aug 24, 2023
11 changes: 7 additions & 4 deletions sdk/objc/api/peerconnection/RTCAudioTrack.mm
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,26 @@ void OnData(const void *audio_data,
absl::optional<int64_t> absolute_capture_timestamp_ms) override {
/*
* Convert to CMSampleBuffer
* TODO: Handle case which number_of_channels could be 2 or more.
*/
int64_t elapsed_time_ms =
absolute_capture_timestamp_ms ? absolute_capture_timestamp_ms.value() : rtc::TimeMillis();

OSStatus status;

// Only mono or stereo is supported currently.
assert(number_of_channels == 1 || number_of_channels == 2);
Copy link
Member

Choose a reason for hiding this comment

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

this would crash the app right? should it fail gracefully?


AudioChannelLayout acl;
bzero(&acl, sizeof(acl));
acl.mChannelLayoutTag = kAudioChannelLayoutTag_Mono;
acl.mChannelLayoutTag =
number_of_channels == 2 ? kAudioChannelLayoutTag_Stereo : kAudioChannelLayoutTag_Mono;

AudioStreamBasicDescription audioFormat;
audioFormat.mSampleRate = sample_rate;
audioFormat.mFormatID = kAudioFormatLinearPCM;
audioFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
audioFormat.mFramesPerPacket = 1;
audioFormat.mChannelsPerFrame = 1;
audioFormat.mFramesPerPacket = number_of_frames;
audioFormat.mChannelsPerFrame = number_of_channels;
audioFormat.mBitsPerChannel = 16;
audioFormat.mBytesPerPacket = audioFormat.mFramesPerPacket * audioFormat.mChannelsPerFrame *
audioFormat.mBitsPerChannel / 8;
Expand Down