Skip to content

Commit

Permalink
amcrest: fix two way audio termination
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Mar 27, 2024
1 parent ec6d617 commit 5e58b14
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
4 changes: 2 additions & 2 deletions plugins/amcrest/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugins/amcrest/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@scrypted/amcrest",
"version": "0.0.140",
"version": "0.0.141",
"description": "Amcrest Plugin for Scrypted",
"author": "Scrypted",
"license": "Apache",
Expand Down
19 changes: 17 additions & 2 deletions plugins/amcrest/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,16 @@ class AmcrestCamera extends RtspSmartCamera implements VideoCameraConfiguration,
'pipe:3',
);
contentType = 'Audio/AAC';
// args.push(
// "-vn",
// '-acodec', 'pcm_mulaw',
// '-ac', '1',
// '-ar', '8000',
// '-sample_fmt', 's16',
// '-f', 'mulaw',
// 'pipe:3',
// );
// contentType = 'Audio/G.711A';
}

this.console.log('ffmpeg intercom', args);
Expand All @@ -618,15 +628,19 @@ class AmcrestCamera extends RtspSmartCamera implements VideoCameraConfiguration,
// seems the dahua doorbells preferred 1024 chunks. should investigate adts
// parsing and sending multipart chunks instead.
const passthrough = new PassThrough();
const abortController = new AbortController();
this.getClient().request({
url,
method: 'POST',
headers: {
'Content-Type': contentType,
'Content-Length': '9999999',
},
signal: abortController.signal,
responseType: 'readable',
}, passthrough);
}, passthrough)
.catch(() => { })
.finally(() => this.console.log('request finished'))

try {
while (true) {
Expand All @@ -638,7 +652,8 @@ class AmcrestCamera extends RtspSmartCamera implements VideoCameraConfiguration,
}
finally {
this.console.log('audio finished');
passthrough.end();
passthrough.destroy();
abortController.abort();
}

this.stopIntercom();
Expand Down
4 changes: 2 additions & 2 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions server/src/fetch/http-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ export async function httpFetch<T extends HttpFetchOptions<Readable>>(options: T
timeout: options.timeout,
});

options.signal?.addEventListener('abort', () => request.destroy(new Error('abort')));

if (body)
body.pipe(request);
else
Expand Down
3 changes: 2 additions & 1 deletion server/src/fetch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface HttpFetchOptionsBase<B> {
family?: 4 | 6;
method?: string;
headers?: HeadersInit;
signal?: AbortSignal,
timeout?: number;
rejectUnauthorized?: boolean;
ignoreStatusCode?: boolean;
Expand Down Expand Up @@ -128,7 +129,7 @@ export async function domFetch<T extends HttpFetchOptions<BodyInit>>(options: T)
method: getFetchMethod(options),
credentials: options.withCredentials ? 'include' : undefined,
headers,
signal: options.timeout ? AbortSignal.timeout(options.timeout) : undefined,
signal: options.signal || options.timeout ? AbortSignal.timeout(options.timeout) : undefined,
body,
});

Expand Down

0 comments on commit 5e58b14

Please sign in to comment.