37 lines
2.0 KiB
JavaScript
37 lines
2.0 KiB
JavaScript
// Extract production queue/lifecycle/decoder functions; no model implementation.
|
|||
|
|
import fs from 'node:fs';
|
||
|
|
import path from 'node:path';
|
||
|
|
import crypto from 'node:crypto';
|
||
|
|
import {fileURLToPath} from 'node:url';
|
||
|
|
const here = path.dirname(fileURLToPath(import.meta.url));
|
||
|
|
const source = path.resolve(here, '../components/volc_conv_ai/src/transports/high_quality/src/volc_rtc.c');
|
||
|
|
const raw = fs.readFileSync(source);
|
||
|
|
const text = raw.toString('utf8').replaceAll('\r\n', '\n');
|
||
|
|
function between(start, end) {
|
||
|
|
const a=text.indexOf(start), b=text.indexOf(end,a);
|
||
|
|
if(a<0 || b<0) throw new Error(`Missing production marker ${start}`);
|
||
|
|
return text.slice(a,b+end.length);
|
||
|
|
}
|
||
|
|
function func(signature, terminator='\n}') { return between(signature,terminator); }
|
||
|
|
const production = [
|
||
|
|
between('/* Own complete transport packets:', '} rtc_rx_packet_t;'),
|
||
|
|
between('typedef struct {\n bool b_pipeline_started;', '} rtc_impl_t;'),
|
||
|
|
func('static void __send_data_2_user('),
|
||
|
|
func('static void _send_message_2_user('),
|
||
|
|
between('/* RTC_RX_HOST_BEGIN:', '/* RTC_RX_HOST_END */'),
|
||
|
|
func('static int __rtc_start('),
|
||
|
|
func('static int __rtc_stop('),
|
||
|
|
func('static void _on_audio_data(', '\n};'),
|
||
|
|
func('static void _on_message_received(', '\n};'),
|
||
|
|
].join('\n\n');
|
||
|
|
const template = fs.readFileSync(path.join(here,'test_rtc_rx_host.c.in'),'utf8');
|
||
|
|
if(template.split('/* @PRODUCTION@ */').length!==2) throw new Error('Invalid host template');
|
||
|
|
const output = path.resolve(process.argv[2] ?? path.join(here,'rtc-rx-host.c'));
|
||
|
|
fs.mkdirSync(path.dirname(output),{recursive:true});
|
||
|
|
fs.writeFileSync(output, template.replace('/* @PRODUCTION@ */',production));
|
||
|
|
const manifest={source,source_sha256:crypto.createHash('sha256').update(raw).digest('hex'),output,
|
||
|
|
host_sha256:crypto.createHash('sha256').update(fs.readFileSync(output)).digest('hex'),
|
||
|
|
build:'gcc -std=c11 -D_POSIX_C_SOURCE=200809L -g -O1 -fsanitize=address,undefined -fno-omit-frame-pointer -pthread rtc-rx-host.c -o rtc-rx-host'};
|
||
|
|
fs.writeFileSync(output+'.json',JSON.stringify(manifest,null,2)+'\n');
|
||
|
|
console.log(JSON.stringify(manifest));
|