Skip to content

Commit

Permalink
fix: 오디오 샘플이 저장된 stream과 writeStream을 pipeline으로 연결시킨다. #312
Browse files Browse the repository at this point in the history
음성 녹음 시, 강의가 종료되기 전까지 발표자의 음성 샘플 데이터를 계속 가지고 있어 메모리를 계속 점유하고 있었다. 따라서 쓰기 스트림과 연결 시켜 destroy 되도록 구성한다.
  • Loading branch information
platinouss committed Mar 13, 2024
1 parent 622ae13 commit dea2ba2
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions mediaServer/src/utils/media-converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ClovaApiReponse } from '../dto/clova-api-response.dto';
import { ClovaApiRequest } from '../dto/clova-api-request.dto';
import { AUDIO_OUTPUT_DIR } from '../constants/media-converter.constant';
import { runFfmpegCommand } from './ffmpeg';
import { pipeline } from 'stream';
ffmpeg.setFfmpegPath(ffmpegPath.path);

class MediaConverter {
Expand Down Expand Up @@ -42,6 +43,7 @@ class MediaConverter {
presenterStreamInfo.replaceAudioSink(audioSink);
} else {
this._presenterStreamInfoList.set(roomId, new PeerStreamInfo(audioSink, roomId));
this.pipeMediaStreamToFile(roomId);
}
audioSink.ondata = ({ samples: { buffer } }) => {
const stream = this._presenterStreamInfoList.get(roomId) as PeerStreamInfo;
Expand All @@ -61,7 +63,6 @@ class MediaConverter {
console.log('해당 강의실 발표자가 존재하지 않습니다.');
return;
}
this.pipeMediaStreamToFile(roomId);
runFfmpegCommand(
this.getAbsoluteOutputPath(streamInfo.audioTempFileName),
this.getAbsoluteOutputPath(streamInfo.recordFileName),
Expand All @@ -73,8 +74,15 @@ class MediaConverter {

pipeMediaStreamToFile = (roomId: string) => {
const streamInfo = this._presenterStreamInfoList.get(roomId) as PeerStreamInfo;
const outputFile = fs.createWriteStream(this.getAbsoluteOutputPath(streamInfo.audioTempFileName));
streamInfo.audio.pipe(outputFile);
pipeline(
streamInfo.audio,
fs.createWriteStream(this.getAbsoluteOutputPath(streamInfo.audioTempFileName)),
(err) => {
if (err) {
console.log(err);
}
}
);
};

finalizeRecording = async (roomId: string) => {
Expand Down

0 comments on commit dea2ba2

Please sign in to comment.