JPEG Image लाइव स्ट्रीमिंग
डिवाइस का JPEG live-stream mode शुरू करें और SDK से मिली हर पूरी JPEG image render करें।
आवश्यकताएँ
- डिवाइस connected और ready है तथा
LiveStreamingAPIके अनुरूप है। supportsJPEGImageLiveStreamingका मानtrueहै।- आपका UI data callback को block किए बिना images decode और replace कर सकता है।
API संदर्भ
Framework
AIBuds.xcframework
Import
- Swift
- Objective-C
import AIBuds
import UIKit#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>
#import <UIKit/UIKit.h>गुण
- Swift
- Objective-C
/// Whether JPEG image live streaming is supported
var supportsJPEGImageLiveStreaming: Bool { get }/// Whether JPEG image live streaming is supported.
@property(nonatomic, readonly) BOOL supportsJPEGImageLiveStreaming;Instance विधि
- Swift
- Objective-C
/// Start JPEG image live streaming
/// - Parameters:
/// - sessionStartCompletionHandler: Session start completion handler
/// - jpegDataReceivedHandler: JPEG data received handler
/// - sessionFinishHandler: Session finish handler
func startJPEGImageLiveStreaming(
withSessionStartCompletionHandler sessionStartCompletionHandler:
AIBudsLiveStreamingSessionStartCompletionHandler?,
jpegDataReceivedHandler: AIBudsLiveStreamingJpegDataReceivedHandler?,
sessionFinishHandler: AIBudsLiveStreamingSessionFinishHandler?
)/// Start JPEG image live streaming
/// - Parameters:
/// - sessionStartCompletionHandler: Session start completion handler
/// - jpegDataReceivedHandler: JPEG data received handler
/// - sessionFinishHandler: Session finish handler
- (void)
startJPEGImageLiveStreamingWithSessionStartCompletionHandler:
(AIBudsLiveStreamingSessionStartCompletionHandler _Nullable)sessionStartCompletionHandler
jpegDataReceivedHandler:
(AIBudsLiveStreamingJpegDataReceivedHandler _Nullable)
jpegDataReceivedHandler
sessionFinishHandler:
(AIBudsLiveStreamingSessionFinishHandler _Nullable)
sessionFinishHandler;startJPEGImageLiveStreaming देखें।
Callback मान
| Handler | मान | अर्थ |
|---|---|---|
sessionStartCompletionHandler | success, error | Live-stream session शुरू हुआ या नहीं बताता है। |
jpegDataReceivedHandler | jpegData | एक पूरी JPEG image को Data / NSData के रूप में देता है। |
sessionFinishHandler | isUserInitiatedStop, error | अंतिम session result और stop उपयोगकर्ता ने शुरू किया था या नहीं बताता है। |
Return मान
Method सीधे value return नहीं करता। Media और lifecycle results handlers से मिलते हैं।
उपयोग के उदाहरण
- Swift
- Objective-C
guard let streamingDevice = device as? LiveStreamingAPI,
streamingDevice.supportsJPEGImageLiveStreaming
else { return }
streamingDevice.startJPEGImageLiveStreaming(
withSessionStartCompletionHandler: { success, error in
DispatchQueue.main.async {
self.setStreamingActive(success)
if let error { self.show(error) }
}
},
jpegDataReceivedHandler: { jpegData in
// Decode away from the UI update, then assign the image on the main queue.
guard let image = UIImage(data: jpegData) else { return }
DispatchQueue.main.async {
self.imageView.image = image
}
},
sessionFinishHandler: { userStopped, error in
DispatchQueue.main.async {
self.setStreamingActive(false)
self.handleFinish(userStopped: userStopped, error: error)
}
}
)id<AIBudsLiveStreamingAPI> streamingDevice = (id<AIBudsLiveStreamingAPI>)self.device;
if (![streamingDevice conformsToProtocol:@protocol(AIBudsLiveStreamingAPI)] ||
!streamingDevice.supportsJPEGImageLiveStreaming) {
return;
}
__weak typeof(self) weakSelf = self;
[streamingDevice
startJPEGImageLiveStreamingWithSessionStartCompletionHandler:^(BOOL success, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf setStreamingActive:success];
if (error)
[weakSelf showError:error];
});
}
jpegDataReceivedHandler:^(NSData *jpegData) {
UIImage *image = [UIImage imageWithData:jpegData];
if (!image)
return;
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.imageView.image = image;
});
}
sessionFinishHandler:^(BOOL userStopped, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf setStreamingActive:NO];
[weakSelf handleFinishUserStopped:userStopped error:error];
});
}];त्रुटि प्रबंधन
- अंतिम valid image बदले बिना invalid JPEG data reject करें।
sessionStartCompletionHandlerfailure को failed session start मानें।sessionFinishHandlerमें user stop और interruption अलग करें और मौजूद होने परerrorउपयोग करें।- SDK callback sequence से आगे frame loss, frame rate या ordering guarantee का अनुमान न लगाएँ।
श्रेष्ठ अभ्यास
- हर JPEG frame न रखें; displayed image बदलें या bounded buffer उपयोग करें।
- Callback backlog से बचने के लिए image decoding और UI assignment हल्के रखें।
- नया session शुरू होने पर frame counters और presentation state साफ़ करें।
- Feature छोड़ते समय केवल image view छिपाने के बजाय
stopLiveStreaming()बुलाएँ।
नोट्स
- Public SDK fixed JPEG resolution या frame rate तय नहीं करता।
- JPEG mode को
AIBudsLiveStreamplayback classes की आवश्यकता नहीं है। jpegDataReceivedHandlercompressed JPEG data देता है, raw pixel buffers नहीं।