कैमरा डिवाइस टाइप को दो ट्रेट का इस्तेमाल करके लागू किया जाता है:
PushAvStreamTransport,
यह पुश-आधारित प्रोटोकॉल का इस्तेमाल करके, ऑडियो और वीडियो स्ट्रीम को ट्रांसफ़र करता है. साथ ही,
WebRtcLiveView,
यह लाइव स्ट्रीम और टॉकबैक को कंट्रोल करने की सुविधा देता है.
किसी भी सुविधा का इस्तेमाल करने या एट्रिब्यूट अपडेट करने से पहले, हमेशा यह जांच करें कि डिवाइस के लिए एट्रिब्यूट और कमांड काम करती हैं या नहीं. ज़्यादा जानकारी के लिए, Androidपर डिवाइसों को कंट्रोल करना लेख पढ़ें.
| Home APIs डिवाइस टाइप | विशेषताएं | Kotlin का सैंपल ऐप्लिकेशन | इस्तेमाल का उदाहरण |
|---|---|---|---|
कैमरा
ऐसा डिवाइस जो फ़ोटो या वीडियो रिकॉर्ड करता है. कैमरों में, सुलभ लाइवस्ट्रीम, बातचीत करने की सुविधा या गतिविधियों का पता लगाने की सुविधा हो सकती है. |
ज़रूरी एट्रिब्यूट google PushAvStreamTransport google WebRtcLiveView |
कैमरा |
लाइव स्ट्रीम शुरू करना
लाइव स्ट्रीम शुरू करने के लिए, Session Description Protocol (SDP) स्ट्रिंग को WebRtcLiveView ट्रेट के startLiveView() तरीके पर भेजें. इससे WebRtcLiveViewTrait.StartLiveViewCommand.Response मिलता है, जिसमें ये तीन वैल्यू होती हैं:
- सेशन के लिए एसडीपी.
- सत्र की अवधि, सेकंड में.
- यह सेशन आईडी है. इसका इस्तेमाल सेशन को बढ़ाने या खत्म करने के लिए किया जा सकता है.
suspend fun getWebRtcLiveViewTrait(cameraDevice: HomeDevice) { return cameraDevice.type(GoogleCameraDevice).trait(WebRtcLiveView).first { it?.metadata?.sourceConnectivity?.connectivityState == ConnectivityState.ONLINE } } // Start the live view suspend fun startCameraStream(trait: WebRtcLiveView, offerSdp: String) { val response = trait.startLiveView(offerSdp) // Response contains three fields (see below) return response } ... // This is used to manage the WebRTC connection val peerConnection: RTCPeerConnection = ... ... val startResponse = startCameraStream(sdp) val answerSdp = startResponse?.answerSdp val sessionDuration = startResponse?.liveSessionDurationSeconds val mediaSessionId = startResponse?.mediaSessionId peerConnection.setRemoteDescription(SessionDescription.Type.ANSWER, answerSdp)
लाइव स्ट्रीम की अवधि बढ़ाना
लाइव स्ट्रीम की अवधि पहले से तय होती है. इसके बाद, वे खत्म हो जाती हैं. चालू स्ट्रीम की अवधि बढ़ाने के लिए, WebRtcLiveView.extendLiveView() तरीके का इस्तेमाल करके, अवधि बढ़ाने का अनुरोध करें:
// Assuming camera stream has just been started suspend fun scheduleExtension(trait: WebRtcLiveView, mediaSessionId: String, liveSessionDurationSeconds: UShort ) { delay(liveSessionDurationSeconds - BUFFER_SECONDS * 1000) val response = trait.extendLiveView(mediaSessionId) // returns how long the session will be live for return response.liveSessionDurationSeconds }
TalkBack को चालू और बंद करना
TalkBack की सुविधा शुरू करने के लिए, WebRtcLiveView
ट्रेट के startTalkback()
तरीके को कॉल करें. इसे बंद करने के लिए, stopTalkback() का इस्तेमाल करें.
// Make sure camera stream is on suspend fun setTalkback(isOn: Boolean, trait: WebRtcLiveView, mediaSessionId: String) { if(isOn) { trait.startTalkback(mediaSessionId) } else { trait.stopTalkback(mediaSessionId) } }
रिकॉर्डिंग की सुविधा को चालू और बंद करना
कैमरे की रिकॉर्डिंग की सुविधा चालू करने के लिए, PushAvStreamTransport ट्रेट के setTransportStatus() तरीके में TransportStatusEnum.Active पास करें. रिकॉर्डिंग की सुविधा बंद करने के लिए, इसे TransportStatusEnum.Inactive पर सेट करें.
यहां दिए गए उदाहरण में, हमने इन कॉल को एक ही कॉल में रैप किया है. इसमें रिकॉर्डिंग की सुविधा को टॉगल करने के लिए, Boolean का इस्तेमाल किया गया है:
// Start or stop recording for all connections. suspend fun setCameraRecording(trait: PushAvStreamTransport, isOn: Boolean) { if(isOn) { trait.setTransportStatus(TransportStatusEnum.Active) } else { trait.setTransportStatus(TransportStatusEnum.Inactive) } }
कैमरे की रिकॉर्डिंग की सुविधा को चालू या बंद करना, कैमरे के वीडियो को चालू या बंद करने जैसा ही है. जब कैमरे का वीडियो चालू होता है, तब वह रिकॉर्डिंग कर रहा होता है. ऐसा इवेंट और उनसे जुड़ी क्लिप के लिए किया जाता है.
जब रिकॉर्डिंग की सुविधा बंद हो (कैमरे का वीडियो बंद हो):
connectivityStateके हिसाब से, कैमरा अब भी ऑनलाइन दिख सकता है डिवाइस टाइप.- लाइव स्ट्रीम को ऐक्सेस नहीं किया जा सकता. साथ ही, कैमरा किसी भी क्लाउड इवेंट का पता नहीं लगाता.
देखें कि रिकॉर्डिंग की सुविधा चालू है या नहीं
यह पता लगाने के लिए कि कैमरे की रिकॉर्डिंग की सुविधा चालू है या नहीं, देखें कि कोई कनेक्शन चालू है या नहीं. यहां दिए गए उदाहरण में, ऐसा करने के लिए दो फ़ंक्शन तय किए गए हैं:
// Get the on/off state suspend fun onOffState(pushAvStreamTransport: PushAvStreamTransport) { return pushAvStreamTransport .currentConnections?.any { it.transportStatus == TransportStatusEnum.Active } ?: false } // Check if the camera's recording capability is enabled fun PushAvStreamTransport.recordModeActive(): Boolean { return currentConnections?.any { it.transportStatus == TransportStatusEnum.Active } ?: false }
जांच करने का एक और तरीका है. इसके लिए, प्रेडिकेट के साथ findTransport() फ़ंक्शन का इस्तेमाल करें:
// Fetch the current connections suspend fun queryRecordModeState(trait: PushAvStreamTransport) { return trait.findTransport().let { it.transportConfigurations.any { it.transportStatus == TransportStatusEnum.Active } }
ऑडियो सेटिंग
Home APIs की मदद से, कैमरे की ऑडियो सेटिंग को कंट्रोल किया जा सकता है.
माइक्रोफ़ोन चालू या बंद करना
डिवाइस के माइक्रोफ़ोन को चालू या बंद करने के लिए, setMicrophoneMuted Kotlin फ़ंक्शन का इस्तेमाल करके, CameraAvStreamManagement ट्रेट के microphoneMuted एट्रिब्यूट को अपडेट करें:
// Turn the device's microphone on or off suspend fun turnOffMicrophone(disableMicrophone: Boolean, trait: CameraAvStreamManagement) { trait.update { setMicrophoneMuted(disableMicrophone) } }
ऑडियो रिकॉर्डिंग की सुविधा चालू या बंद करना
डिवाइस के लिए ऑडियो रिकॉर्डिंग की सुविधा चालू या बंद करने के लिए, CameraAvStreamManagement ट्रेट के recordingMicrophoneMuted एट्रिब्यूट को अपडेट करें. इसके लिए, setRecordingMicrophoneMuted Kotlin फ़ंक्शन का इस्तेमाल करें:
// Turn audio recording on or off for the device suspend fun turnOffAudioRecording(disableAudioRecording: Boolean, trait: CameraAvStreamManagement) { trait.update { setRecordingMicrophoneMuted(disableAudioRecording) } }
स्पीकर की आवाज़ कम या ज़्यादा करना
डिवाइस के स्पीकर का वॉल्यूम घटाने या बढ़ाने के लिए, CameraAvStreamManagement ट्रेट के speakerVolumeLevel एट्रिब्यूट को अपडेट करें. इसके लिए, setSpeakerVolumeLevel Kotlin फ़ंक्शन का इस्तेमाल करें:
// Adjust the camera speaker volume suspend fun adjustSpeakerVolume(volume: Int, trait: CameraAvStreamManagement) { trait.update { setSpeakerVolumeLevel(volume.toUbyte()) } }
अन्य सेटिंग
Home API की मदद से, कैमरे की अन्य सेटिंग को कंट्रोल किया जा सकता है.
इमेज का ओरिएंटेशन बदलना
कैमरे की इमेज (वीडियो) के ओरिएंटेशन को घुमाया जा सकता है. वीडियो को सिर्फ़ 180 डिग्री घुमाया जा सकता है.
कैमरे की इमेज ओरिएंटेशन बदलने के लिए, CameraAvStreamManagement ट्रेट के imageRotation एट्रिब्यूट को अपडेट करें. इसके लिए, बिल्ट-इन setImageRotation Kotlin फ़ंक्शन का इस्तेमाल करें:
// Change the camera's image orientation val isRotated = false cameraAvStreamManagement.update { setImageRotation(if (isRotated) 180.toUShort() else 0.toUShort()) }
नाइट विज़न मोड को चालू या बंद करना
कैमरे के लिए नाइट विज़न की सुविधा चालू या बंद करने के लिए, TriStateAutoEnum का इस्तेमाल करके, CameraAvStreamManagement ट्रेट के nightVision एट्रिब्यूट को अपडेट करें. इसके लिए, setNightVision Kotlin फ़ंक्शन का इस्तेमाल करें:
// Turn night vision on cameraAvStreamManagement.update { setNightVision(CameraAvStreamManagementTrait.TriStateAutoEnum.On) } // Turn night vision off CameraAvStreamManagement.update { setNightVision(CameraAvStreamManagementTrait.TriStateAutoEnum.Off) }
स्टेटस एलईडी की चमक बदलना
स्टेटस एलईडी की चमक बदलने के लिए, ThreeLevelAutoEnum का इस्तेमाल करें. इससे CameraAvStreamManagement ट्रेट के statusLightBrightness एट्रिब्यूट को अपडेट किया जा सकता है. इसके लिए, setStatusLightBrightness Kotlin फ़ंक्शन का इस्तेमाल करें:
// Set the LED brightness to high cameraAvStreamManagement.update { setStatusLightBrightness(CameraAvStreamManagementTrait.ThreeLevelAutoEnum.High) } // Set the LED brightness to low cameraAvStreamManagement.update { setStatusLightBrightness(CameraAvStreamManagementTrait.ThreeLevelAutoEnum.Low) }
कैमरे का व्यूपोर्ट बदलना
कैमरे का व्यू पोर्ट, Nest Cam के वीडियो को ज़ूम और बेहतर बनाएं सहायता लेख में बताई गई ज़ूम और क्रॉप करने की सुविधा की तरह ही होता है.
व्यूपोर्ट को ViewportStruct में तय किया जाता है. इसमें चार वैल्यू होती हैं. इनका इस्तेमाल व्यूपोर्ट के निर्देशांकों के तौर पर किया जाता है. कोऑर्डिनेट को इस तरह से तय किया जाता है:
(x1,y1) -- (x2,y1) | | (x1,y2) -- (x2,y2)
ViewportStruct के लिए वैल्यू तय करना, ऐप्लिकेशन के यूज़र इंटरफ़ेस (यूआई) और कैमरे को लागू करने के तरीके पर निर्भर करता है. कैमरे के वीडियो का व्यूपोर्ट सेट करने के लिए, CameraAvStreamManagement ट्रेट के viewport एट्रिब्यूट को ViewportStruct से अपडेट करें. इसके लिए, बिल्ट-इन setViewport Kotlin फ़ंक्शन का इस्तेमाल करें:
cameraAvStreamManagement .update { setViewport( CameraAvStreamManagementTrait.ViewportStruct( x1 = horizontalRange.rangeStart.roundToInt().toUShort(), x2 = horizontalRange.rangeEnd.roundToInt().toUShort(), y1 = verticalRange.rangeStart.roundToInt().toUShort(), y2 = verticalRange.rangeEnd.roundToInt().toUShort(), ) ) }
डिवाइस के वेक-अप होने की सेंसिटिविटी को अडजस्ट करना
डिवाइस के वेक-अप सेंसर की संवेदनशीलता का इस्तेमाल, बैटरी बचाने के लिए किया जाता है. इसके लिए, डिवाइस की गतिविधि का पता लगाने की रेंज को कम किया जाता है. साथ ही, गतिविधि का पता चलने के बाद डिवाइस के वेक अप होने के समय को बढ़ाया जाता है.
Home API में, इसे डिवाइस के transportOptions में मौजूद triggerOptions की motionSensitivity प्रॉपर्टी का इस्तेमाल करके सेट किया जा सकता है. ये विकल्प, हर डिवाइस के लिए PushAvStreamTransport ट्रेट में तय किए जाते हैं.
डिवाइस को जगाने की सुविधा के लिए, संवेदनशीलता को सिर्फ़ इन वैल्यू पर सेट किया जा सकता है:
- 1 = कम
- 5 = मीडियम
- 10 = ज़्यादा
अपडेट करने के लिए, findTransport कमांड का इस्तेमाल करके, चालू रिकॉर्डिंग स्ट्रीम के लिए ट्रांसपोर्ट कॉन्फ़िगरेशन ढूंढें. इसके बाद, modifyPushTransport कमांड का इस्तेमाल करके, कॉन्फ़िगरेशन में नई संवेदनशीलता वैल्यू डालें:
// Create a struct with the new wake-up sensitivity val toUpdate = TransportOptionsStruct( triggerOptions = TransportTriggerOptionsStruct( motionSensitivity = OptionalValue.present(wakeUpSensitivity.toUByte()) ) ) // Get the configurations for active connections val connections = pushAvStreamTransport.findTransport().transportConfigurations // Update all recording streams with the new transport options. for (connection in connections) { if (connection.transportOptions.getOrNull()?.streamUsage == StreamUsageEnum.Recording) { trait.modifyPushTransport( connectionId = connection.connectionId, transportOptions = toUpdate, ) } }
इवेंट की ज़्यादा से ज़्यादा अवधि में बदलाव करना
इवेंट की ज़्यादा से ज़्यादा अवधि का मतलब है कि कैमरा किसी इवेंट के लिए कितने समय तक क्लिप रिकॉर्ड करेगा. होम एपीआई के ज़रिए, इसे हर डिवाइस के लिए कॉन्फ़िगर किया जा सकता है. इसके लिए, GHA के बराबर समयसीमा तय की जा सकती है. यह समयसीमा सेकंड के हिसाब से तय की जाती है:
- 10 सेकंड
- 15 सेकंड
- 30 सेकंड
- 60 सेकंड (1 मिनट)
- 120 सेकंड (दो मिनट)
- 180 सेकंड (3 मिनट)
Home API में, इसे डिवाइस के transportOptions में मौजूद triggerOptions की motionTimeControl प्रॉपर्टी का इस्तेमाल करके सेट किया जा सकता है. ये विकल्प, हर डिवाइस के लिए PushAvStreamTransport ट्रेट में तय किए जाते हैं.
अपडेट करने के लिए, findTransport कमांड का इस्तेमाल करके, चालू रिकॉर्डिंग स्ट्रीम के लिए ट्रांसपोर्ट कॉन्फ़िगरेशन ढूंढें. इसके बाद, modifyPushTransport कमांड का इस्तेमाल करके, कॉन्फ़िगरेशन में इवेंट की नई अवधि की वैल्यू में बदलाव करें:
// Create a struct with the new max event length // where maxDuration is the length in seconds val toUpdate = TransportOptionsStruct( triggerOptions = TransportTriggerOptionsStruct( motionTimeControl = OptionalValue.present( TransportMotionTriggerTimeControlStruct(maxDuration = it.toUInt()) ) ) ) // Get the configurations for active connections val connections = pushAvStreamTransport.findTransport().transportConfigurations // Update all recording streams with the new transport options. for (connection in connections) { if (connection.transportOptions.getOrNull()?.streamUsage == StreamUsageEnum.Recording) { trait.modifyPushTransport( connectionId = connection.connectionId, transportOptions = toUpdate, ) } }