homebridge#AudioInfo TypeScript Examples
The following examples show how to use
homebridge#AudioInfo.
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: streaming-delegate.ts From homebridge-nest-cam with GNU General Public License v3.0 | 6 votes |
private getReturnAudioCommand(info: AudioInfo, sessionId: string): Array<string> | undefined {
const sessionInfo = this.pendingSessions[sessionId];
if (!sessionInfo) {
return;
}
return [
'-hide_banner',
'-protocol_whitelist',
'pipe,udp,rtp,file,crypto',
'-f',
'sdp',
'-c:a',
'libfdk_aac',
'-i',
'pipe:0',
'-map',
'0:0',
'-c:a',
'libspeex',
'-frames_per_packet',
'4',
'-ac',
'1',
'-vn',
'-ar',
`16k`,
'-f',
'data',
'pipe:1',
];
}
Example #2
Source File: streaming-delegate.ts From homebridge-nest-cam with GNU General Public License v3.0 | 5 votes |
private getAudioCommand(info: AudioInfo, sessionId: string): Array<string> | undefined {
const sessionInfo = this.pendingSessions[sessionId];
if (!sessionInfo) {
return;
}
const address = sessionInfo.address;
const audioPort = sessionInfo.audioPort;
const returnAudioPort = sessionInfo.returnAudioPort;
const audioSsrc = sessionInfo.audioSSRC;
const audioSRTP = sessionInfo.audioSRTP.toString('base64');
const audioPayloadType = info.pt;
const audioMaxBitrate = info.max_bit_rate;
const sampleRate = info.sample_rate;
return [
'-c:a',
'libfdk_aac',
'-i',
'pipe:',
'-c:a',
'libfdk_aac',
'-profile:a',
'aac_eld',
'-ac',
'1',
'-vn',
'-ar',
`${sampleRate}k`,
'-b:a',
`${audioMaxBitrate}k`,
'-flags',
'+global_header',
'-payload_type',
audioPayloadType.toString(),
'-ssrc',
audioSsrc.toString(),
'-f',
'rtp',
'-srtp_out_suite',
'AES_CM_128_HMAC_SHA1_80',
'-srtp_out_params',
audioSRTP,
`srtp://${address}:${audioPort}?rtcpport=${audioPort}&localrtcpport=${returnAudioPort}&pkt_size=188`,
];
}
Example #3
Source File: streaming-delegate.ts From homebridge-nest-cam with GNU General Public License v3.0 | 4 votes |
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;
}
}