From d8bbc7858622b6d9c278469aab701ca0b609cddf Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 15 May 2024 05:35:49 +0200 Subject: Merging upstream version 126.0. Signed-off-by: Daniel Baumann --- .../api/peerconnection/RTCPeerConnectionFactory.mm | 3 +- .../objc/api/peerconnection/RTCStatisticsReport.mm | 187 ++++++++++----------- .../sdk/objc/native/src/audio/audio_device_ios.h | 4 + .../sdk/objc/native/src/audio/audio_device_ios.mm | 12 +- 4 files changed, 103 insertions(+), 103 deletions(-) (limited to 'third_party/libwebrtc/sdk') diff --git a/third_party/libwebrtc/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.mm b/third_party/libwebrtc/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.mm index 15f9eb9ee4..445006f0d0 100644 --- a/third_party/libwebrtc/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.mm +++ b/third_party/libwebrtc/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.mm @@ -206,8 +206,7 @@ dependencies.audio_processing = webrtc::AudioProcessingBuilder().Create(); } webrtc::EnableMedia(dependencies); - dependencies.event_log_factory = - std::make_unique(dependencies.task_queue_factory.get()); + dependencies.event_log_factory = std::make_unique(); dependencies.network_controller_factory = std::move(networkControllerFactory); _nativeFactory = webrtc::CreateModularPeerConnectionFactory(std::move(dependencies)); NSAssert(_nativeFactory, @"Failed to initialize PeerConnectionFactory!"); diff --git a/third_party/libwebrtc/sdk/objc/api/peerconnection/RTCStatisticsReport.mm b/third_party/libwebrtc/sdk/objc/api/peerconnection/RTCStatisticsReport.mm index bfe2424553..eaf2097cce 100644 --- a/third_party/libwebrtc/sdk/objc/api/peerconnection/RTCStatisticsReport.mm +++ b/third_party/libwebrtc/sdk/objc/api/peerconnection/RTCStatisticsReport.mm @@ -17,105 +17,91 @@ namespace webrtc { /** Converts a single value to a suitable NSNumber, NSString or NSArray containing NSNumbers or NSStrings, or NSDictionary of NSString keys to NSNumber values.*/ -NSObject *ValueFromStatsMember(const RTCStatsMemberInterface *member) { - if (member->is_defined()) { - switch (member->type()) { - case RTCStatsMemberInterface::kBool: - return [NSNumber numberWithBool:*member->cast_to>()]; - case RTCStatsMemberInterface::kInt32: - return [NSNumber numberWithInt:*member->cast_to>()]; - case RTCStatsMemberInterface::kUint32: - return [NSNumber numberWithUnsignedInt:*member->cast_to>()]; - case RTCStatsMemberInterface::kInt64: - return [NSNumber numberWithLong:*member->cast_to>()]; - case RTCStatsMemberInterface::kUint64: - return [NSNumber numberWithUnsignedLong:*member->cast_to>()]; - case RTCStatsMemberInterface::kDouble: - return [NSNumber numberWithDouble:*member->cast_to>()]; - case RTCStatsMemberInterface::kString: - return [NSString stringForStdString:*member->cast_to>()]; - case RTCStatsMemberInterface::kSequenceBool: { - std::vector sequence = *member->cast_to>>(); - NSMutableArray *array = [NSMutableArray arrayWithCapacity:sequence.size()]; - for (auto item : sequence) { - [array addObject:[NSNumber numberWithBool:item]]; - } - return [array copy]; - } - case RTCStatsMemberInterface::kSequenceInt32: { - std::vector sequence = *member->cast_to>>(); - NSMutableArray *array = [NSMutableArray arrayWithCapacity:sequence.size()]; - for (const auto &item : sequence) { - [array addObject:[NSNumber numberWithInt:item]]; - } - return [array copy]; - } - case RTCStatsMemberInterface::kSequenceUint32: { - std::vector sequence = *member->cast_to>>(); - NSMutableArray *array = [NSMutableArray arrayWithCapacity:sequence.size()]; - for (const auto &item : sequence) { - [array addObject:[NSNumber numberWithUnsignedInt:item]]; - } - return [array copy]; - } - case RTCStatsMemberInterface::kSequenceInt64: { - std::vector sequence = *member->cast_to>>(); - NSMutableArray *array = [NSMutableArray arrayWithCapacity:sequence.size()]; - for (const auto &item : sequence) { - [array addObject:[NSNumber numberWithLong:item]]; - } - return [array copy]; - } - case RTCStatsMemberInterface::kSequenceUint64: { - std::vector sequence = *member->cast_to>>(); - NSMutableArray *array = [NSMutableArray arrayWithCapacity:sequence.size()]; - for (const auto &item : sequence) { - [array addObject:[NSNumber numberWithUnsignedLong:item]]; - } - return [array copy]; - } - case RTCStatsMemberInterface::kSequenceDouble: { - std::vector sequence = *member->cast_to>>(); - NSMutableArray *array = [NSMutableArray arrayWithCapacity:sequence.size()]; - for (const auto &item : sequence) { - [array addObject:[NSNumber numberWithDouble:item]]; - } - return [array copy]; - } - case RTCStatsMemberInterface::kSequenceString: { - std::vector sequence = - *member->cast_to>>(); - NSMutableArray *array = [NSMutableArray arrayWithCapacity:sequence.size()]; - for (const auto &item : sequence) { - [array addObject:[NSString stringForStdString:item]]; - } - return [array copy]; - } - case RTCStatsMemberInterface::kMapStringUint64: { - std::map map = - *member->cast_to>>(); - NSMutableDictionary *dictionary = - [NSMutableDictionary dictionaryWithCapacity:map.size()]; - for (const auto &item : map) { - dictionary[[NSString stringForStdString:item.first]] = @(item.second); - } - return [dictionary copy]; - } - case RTCStatsMemberInterface::kMapStringDouble: { - std::map map = - *member->cast_to>>(); - NSMutableDictionary *dictionary = - [NSMutableDictionary dictionaryWithCapacity:map.size()]; - for (const auto &item : map) { - dictionary[[NSString stringForStdString:item.first]] = @(item.second); - } - return [dictionary copy]; - } - default: - RTC_DCHECK_NOTREACHED(); +NSObject *ValueFromStatsAttribute(const Attribute &attribute) { + if (!attribute.has_value()) { + return nil; + } + if (attribute.holds_alternative()) { + return [NSNumber numberWithBool:attribute.get()]; + } else if (attribute.holds_alternative()) { + return [NSNumber numberWithInt:attribute.get()]; + } else if (attribute.holds_alternative()) { + return [NSNumber numberWithUnsignedInt:attribute.get()]; + } else if (attribute.holds_alternative()) { + return [NSNumber numberWithLong:attribute.get()]; + } else if (attribute.holds_alternative()) { + return [NSNumber numberWithUnsignedLong:attribute.get()]; + } else if (attribute.holds_alternative()) { + return [NSNumber numberWithDouble:attribute.get()]; + } else if (attribute.holds_alternative()) { + return [NSString stringForStdString:attribute.get()]; + } else if (attribute.holds_alternative>()) { + std::vector sequence = attribute.get>(); + NSMutableArray *array = [NSMutableArray arrayWithCapacity:sequence.size()]; + for (auto item : sequence) { + [array addObject:[NSNumber numberWithBool:item]]; } + return [array copy]; + } else if (attribute.holds_alternative>()) { + std::vector sequence = attribute.get>(); + NSMutableArray *array = [NSMutableArray arrayWithCapacity:sequence.size()]; + for (const auto &item : sequence) { + [array addObject:[NSNumber numberWithInt:item]]; + } + return [array copy]; + } else if (attribute.holds_alternative>()) { + std::vector sequence = attribute.get>(); + NSMutableArray *array = [NSMutableArray arrayWithCapacity:sequence.size()]; + for (const auto &item : sequence) { + [array addObject:[NSNumber numberWithUnsignedInt:item]]; + } + return [array copy]; + } else if (attribute.holds_alternative>()) { + std::vector sequence = attribute.get>(); + NSMutableArray *array = [NSMutableArray arrayWithCapacity:sequence.size()]; + for (const auto &item : sequence) { + [array addObject:[NSNumber numberWithLong:item]]; + } + return [array copy]; + } else if (attribute.holds_alternative>()) { + std::vector sequence = attribute.get>(); + NSMutableArray *array = [NSMutableArray arrayWithCapacity:sequence.size()]; + for (const auto &item : sequence) { + [array addObject:[NSNumber numberWithUnsignedLong:item]]; + } + return [array copy]; + } else if (attribute.holds_alternative>()) { + std::vector sequence = attribute.get>(); + NSMutableArray *array = [NSMutableArray arrayWithCapacity:sequence.size()]; + for (const auto &item : sequence) { + [array addObject:[NSNumber numberWithDouble:item]]; + } + return [array copy]; + } else if (attribute.holds_alternative>()) { + std::vector sequence = attribute.get>(); + NSMutableArray *array = [NSMutableArray arrayWithCapacity:sequence.size()]; + for (const auto &item : sequence) { + [array addObject:[NSString stringForStdString:item]]; + } + return [array copy]; + } else if (attribute.holds_alternative>()) { + std::map map = attribute.get>(); + NSMutableDictionary *dictionary = + [NSMutableDictionary dictionaryWithCapacity:map.size()]; + for (const auto &item : map) { + dictionary[[NSString stringForStdString:item.first]] = @(item.second); + } + return [dictionary copy]; + } else if (attribute.holds_alternative>()) { + std::map map = attribute.get>(); + NSMutableDictionary *dictionary = + [NSMutableDictionary dictionaryWithCapacity:map.size()]; + for (const auto &item : map) { + dictionary[[NSString stringForStdString:item.first]] = @(item.second); + } + return [dictionary copy]; } - + RTC_DCHECK_NOTREACHED(); return nil; } } // namespace webrtc @@ -134,10 +120,11 @@ NSObject *ValueFromStatsMember(const RTCStatsMemberInterface *member) { _type = [NSString stringWithCString:statistics.type() encoding:NSUTF8StringEncoding]; NSMutableDictionary *values = [NSMutableDictionary dictionary]; - for (const webrtc::RTCStatsMemberInterface *member : statistics.Members()) { - NSObject *value = ValueFromStatsMember(member); + for (const auto &attribute : statistics.Attributes()) { + NSObject *value = ValueFromStatsAttribute(attribute); if (value) { - NSString *name = [NSString stringWithCString:member->name() encoding:NSUTF8StringEncoding]; + NSString *name = [NSString stringWithCString:attribute.name() + encoding:NSUTF8StringEncoding]; RTC_DCHECK(name.length > 0); RTC_DCHECK(!values[name]); values[name] = value; diff --git a/third_party/libwebrtc/sdk/objc/native/src/audio/audio_device_ios.h b/third_party/libwebrtc/sdk/objc/native/src/audio/audio_device_ios.h index a86acb56fe..4ef4d0b5df 100644 --- a/third_party/libwebrtc/sdk/objc/native/src/audio/audio_device_ios.h +++ b/third_party/libwebrtc/sdk/objc/native/src/audio/audio_device_ios.h @@ -299,6 +299,10 @@ class AudioDeviceIOS : public AudioDeviceGeneric, // Avoids running pending task after `this` is Terminated. rtc::scoped_refptr safety_ = PendingTaskSafetyFlag::Create(); + + // Ratio between mach tick units and nanosecond. Used to change mach tick + // units to nanoseconds. + double machTickUnitsToNanoseconds_; }; } // namespace ios_adm } // namespace webrtc diff --git a/third_party/libwebrtc/sdk/objc/native/src/audio/audio_device_ios.mm b/third_party/libwebrtc/sdk/objc/native/src/audio/audio_device_ios.mm index dd2c11bdd2..78420ec232 100644 --- a/third_party/libwebrtc/sdk/objc/native/src/audio/audio_device_ios.mm +++ b/third_party/libwebrtc/sdk/objc/native/src/audio/audio_device_ios.mm @@ -13,6 +13,7 @@ #include "audio_device_ios.h" +#include #include #include "api/array_view.h" @@ -110,6 +111,9 @@ AudioDeviceIOS::AudioDeviceIOS(bool bypass_voice_processing) thread_ = rtc::Thread::Current(); audio_session_observer_ = [[RTCNativeAudioSessionDelegateAdapter alloc] initWithObserver:this]; + mach_timebase_info_data_t tinfo; + mach_timebase_info(&tinfo); + machTickUnitsToNanoseconds_ = (double)tinfo.numer / tinfo.denom; } AudioDeviceIOS::~AudioDeviceIOS() { @@ -376,6 +380,11 @@ OSStatus AudioDeviceIOS::OnDeliverRecordedData(AudioUnitRenderActionFlags* flags record_audio_buffer_.Clear(); record_audio_buffer_.SetSize(num_frames); + // Get audio timestamp for the audio. + // The timestamp will not have NTP time epoch, but that will be addressed by + // the TimeStampAligner in AudioDeviceBuffer::SetRecordedBuffer(). + SInt64 capture_timestamp_ns = time_stamp->mHostTime * machTickUnitsToNanoseconds_; + // Allocate AudioBuffers to be used as storage for the received audio. // The AudioBufferList structure works as a placeholder for the // AudioBuffer structure, which holds a pointer to the actual data buffer @@ -404,7 +413,8 @@ OSStatus AudioDeviceIOS::OnDeliverRecordedData(AudioUnitRenderActionFlags* flags // Get a pointer to the recorded audio and send it to the WebRTC ADB. // Use the FineAudioBuffer instance to convert between native buffer size // and the 10ms buffer size used by WebRTC. - fine_audio_buffer_->DeliverRecordedData(record_audio_buffer_, kFixedRecordDelayEstimate); + fine_audio_buffer_->DeliverRecordedData( + record_audio_buffer_, kFixedRecordDelayEstimate, capture_timestamp_ns); return noErr; } -- cgit v1.2.3