homebridge#StreamRequestTypes TypeScript Examples

The following examples show how to use homebridge#StreamRequestTypes. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: new-streaming-delegate.ts    From homebridge-plugin-eufy-security with Apache License 2.0 6 votes vote down vote up
handleStreamRequest(
    request: StreamingRequest,
    callback: StreamRequestCallback,
  ): void {
    switch (request.type) {
      case StreamRequestTypes.START:
        this.startStream(request, callback);
        break;
      case StreamRequestTypes.RECONFIGURE:
        this.log.debug(
          'Received request to reconfigure: ' +
            request.video.width +
            ' x ' +
            request.video.height +
            ', ' +
            request.video.fps +
            ' fps, ' +
            request.video.max_bit_rate +
            ' kbps (Ignored)',
          this.cameraName,
          this.debug,
        );
        callback();
        break;
      case StreamRequestTypes.STOP:
        this.stopStream(request.sessionID);
        callback();
        break;
    }
  }
Example #2
Source File: streamingDelegate.ts    From homebridge-eufy-security with Apache License 2.0 6 votes vote down vote up
handleStreamRequest(request: StreamingRequest, callback: StreamRequestCallback): void {
    switch (request.type) {
      case StreamRequestTypes.START:
        this.startStream(request, callback);
        break;
      case StreamRequestTypes.RECONFIGURE:
        this.log.debug('Received request to reconfigure: ' + request.video.width + ' x ' + request.video.height + ', ' +
          request.video.fps + ' fps, ' + request.video.max_bit_rate + ' kbps (Ignored)', this.cameraName, this.videoConfig.debug);
        callback();
        break;
      case StreamRequestTypes.STOP:
        this.stopStream(request.sessionID);
        callback();
        break;
    }
  }
Example #3
Source File: streaming-delegate.ts    From homebridge-nest-cam with GNU General Public License v3.0 4 votes vote down vote up
handleStreamRequest(request: StreamingRequest, callback: StreamRequestCallback): void {
    const sessionId = request.sessionID;

    switch (request.type) {
      case StreamRequestTypes.START:
        const sessionInfo = this.pendingSessions[sessionId];
        const video: VideoInfo = request.video;
        const audio: AudioInfo = request.audio;

        const address = sessionInfo.address;
        const audioSRTP = sessionInfo.audioSRTP.toString('base64');
        const twoWayAudioPort = sessionInfo.twoWayAudioPort;

        if (!this.ffmpegInstalled) {
          this.log.error('FFMPEG is not installed. Please install it and restart homebridge.');
          callback(new Error('FFmpeg not installed'));
          break;
        }

        const videoffmpegCommand = this.getVideoCommand(video, sessionId);
        const ffmpegVideo = new FfmpegProcess(
          'VIDEO',
          videoffmpegCommand,
          this.log,
          this,
          sessionId,
          false,
          this.customFfmpeg,
          (error) => {
            callback(error);
          },
        );

        let ffmpegAudio: FfmpegProcess | undefined;
        let ffmpegReturnAudio: FfmpegProcess | undefined;
        if (this.camera.info.properties['audio.enabled'] && this.camera.info.properties['streaming.enabled']) {
          if (this.ffmpegSupportsLibfdk_acc) {
            const audioffmpegCommand = this.getAudioCommand(audio, sessionId);
            if (audioffmpegCommand) {
              ffmpegAudio = new FfmpegProcess(
                'AUDIO',
                audioffmpegCommand,
                this.log,
                this,
                sessionId,
                false,
                this.customFfmpeg,
              );
            }

            if (this.ffmpegSupportsLibspeex) {
              const returnAudioffmpegCommand = this.getReturnAudioCommand(audio, sessionId);
              if (returnAudioffmpegCommand) {
                ffmpegReturnAudio = new FfmpegProcess(
                  'RETURN AUDIO',
                  returnAudioffmpegCommand,
                  this.log,
                  this,
                  sessionId,
                  false,
                  this.customFfmpeg,
                );
                const sdpReturnAudio = [
                  'v=0',
                  'o=- 0 0 IN IP4 127.0.0.1',
                  's=Talk',
                  `c=IN IP4 ${address}`,
                  't=0 0',
                  'a=tool:libavformat 58.38.100',
                  `m=audio ${twoWayAudioPort} RTP/AVP 110`,
                  'b=AS:24',
                  'a=rtpmap:110 MPEG4-GENERIC/16000/1',
                  'a=fmtp:110 profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3; config=F8F0212C00BC00',
                  `a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:${audioSRTP}`,
                ].join('\n');
                ffmpegReturnAudio.getStdin()?.write(sdpReturnAudio);
                ffmpegReturnAudio.getStdin()?.end();
              }
            } else {
              this.log.error(
                "This version of FFMPEG does not support the audio codec 'libspeex'. You may need to recompile FFMPEG using '--enable-libspeex' and restart homebridge.",
              );
            }
          } else {
            this.log.error(
              "This version of FFMPEG does not support the audio codec 'libfdk_aac'. You may need to recompile FFMPEG using '--enable-libfdk_aac' and restart homebridge.",
            );
          }
        }

        if (this.camera.info.properties['streaming.enabled'] && this.pendingSessions[sessionId]) {
          const streamer = new NexusStreamer(
            this.camera.info,
            this.config.access_token,
            this.config.options?.streamQuality || 3,
            ffmpegVideo,
            ffmpegAudio,
            ffmpegReturnAudio,
            this.log,
            this.config.nest_token !== undefined,
          );
          streamer.startPlayback();
          this.ongoingStreams[sessionId] = streamer;
        }

        // Used to switch offline/online stream on-the-fly
        // this.camera.on(NestCamEvents.CAMERA_STATE_CHANGED, (state) => {
        //   ffmpegVideo.stop();
        //   ffmpegAudio?.stop();
        //   ffmpegReturnAudio?.stop();
        //   const newVideoffmpegCommand = this.getVideoCommand(video, sessionId);
        //   const newFfmpegVideo = new FfmpegProcess(
        //     'VIDEO',
        //     newVideoffmpegCommand,
        //     this.log,
        //     undefined,
        //     this,
        //     sessionId,
        //     true,
        //     this.customFfmpeg,
        //   );
        //   this.ongoingSessions[sessionId] = [newFfmpegVideo, ffmpegAudio, ffmpegReturnAudio];

        //   if (state) {
        //     const streamer = new NexusStreamer(
        //       this.camera.info,
        //       this.config.access_token,
        //       this.log,
        //       this.config,
        //       newFfmpegVideo,
        //       ffmpegAudio,
        //       ffmpegReturnAudio,
        //     );
        //     streamer.startPlayback();
        //     this.ongoingStreams[sessionId] = streamer;
        //   } else {
        //     const streamer = this.ongoingStreams[sessionId];
        //     streamer.stopPlayback();
        //   }
        // });

        this.ongoingSessions[sessionId] = [ffmpegVideo, ffmpegAudio, ffmpegReturnAudio];
        break;
      case StreamRequestTypes.RECONFIGURE:
        // not implemented
        this.log.debug('(Not implemented) Received request to reconfigure to: ' + JSON.stringify(request.video));
        callback();
        break;
      case StreamRequestTypes.STOP:
        this.stopStream(sessionId);
        callback();
        break;
    }
  }