mirror of
https://github.com/home-assistant/iOS.git
synced 2026-04-12 15:26:45 -05:00
<!-- Thank you for submitting a Pull Request and helping to improve Home Assistant. Please complete the following sections to help the processing and review of your changes. Please do not delete anything from this template. --> ## Summary <!-- Provide a brief summary of the changes you have made and most importantly what they aim to achieve --> ## Screenshots <img width="704" alt="Screenshot 2024-04-04 at 12 56 36" src="https://github.com/home-assistant/iOS/assets/5808343/134c4206-d837-4a4e-83b2-0e199be0eca9"> <img width="204" alt="Screenshot 2024-04-04 at 12 56 40" src="https://github.com/home-assistant/iOS/assets/5808343/a7637388-3ad4-4e60-a7a4-774c37694592"> <img width="1512" alt="Screenshot 2024-04-04 at 11 14 14" src="https://github.com/home-assistant/iOS/assets/5808343/a70e07b1-c5a1-47bc-b027-ca0beac36c64"> ## Link to pull request in Documentation repository <!-- Pull requests that add, change or remove functionality must have a corresponding pull request in the Companion App Documentation repository (https://github.com/home-assistant/companion.home-assistant). Please add the number of this pull request after the "#" --> Documentation: home-assistant/companion.home-assistant# ## Any other notes <!-- If there is any other information of note, like if this Pull Request is part of a bigger change, please include it here. -->
30 lines
902 B
Swift
30 lines
902 B
Swift
import CoreMedia
|
|
import Foundation
|
|
import Shared
|
|
|
|
extension CMSampleBuffer {
|
|
func audioSamples() -> Data? {
|
|
guard let audioBuffer = CMSampleBufferGetDataBuffer(self) else {
|
|
Current.Log.error("Failed to get audio data buffer from sample buffer.")
|
|
return nil
|
|
}
|
|
|
|
var audioBufferDataPointer: UnsafeMutablePointer<Int8>?
|
|
var audioBufferDataLength = 0
|
|
|
|
let status = CMBlockBufferGetDataPointer(
|
|
audioBuffer,
|
|
atOffset: 0,
|
|
lengthAtOffsetOut: nil,
|
|
totalLengthOut: &audioBufferDataLength,
|
|
dataPointerOut: &audioBufferDataPointer
|
|
)
|
|
guard status == kCMBlockBufferNoErr else {
|
|
Current.Log.error("Failed to access audio data pointer.")
|
|
return nil
|
|
}
|
|
|
|
return Data(bytes: audioBufferDataPointer!, count: audioBufferDataLength)
|
|
}
|
|
}
|