Wire legal idle variants and validate dance media offline
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Read-only partial v2 emotion gate by default; import/publish needs an external Pi pin."""
|
||||
"""Read-only v2 conversation/dance gate; partial-emotion import/publish needs an external Pi pin."""
|
||||
from pathlib import Path, PurePosixPath
|
||||
from decimal import Decimal
|
||||
from fractions import Fraction
|
||||
import argparse
|
||||
import array
|
||||
import hashlib
|
||||
import importlib.util
|
||||
import json
|
||||
import os
|
||||
import math
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
@@ -71,12 +73,52 @@ def probe_clip(path):
|
||||
return measured
|
||||
|
||||
|
||||
def probe_music_clip(path):
|
||||
"""Bounded offline decode, including presented AAC samples. No listening claim."""
|
||||
result=subprocess.run(['/home/ubuntu/miniconda3/envs/gori-speech/bin/ffprobe','-v','error',
|
||||
'-show_streams','-show_frames','-of','json',str(path)],capture_output=True,check=True,timeout=60)
|
||||
data=json.loads(result.stdout);streams=data['streams']
|
||||
require(len(streams)==2 and sorted(s['codec_type'] for s in streams)==['audio','video'],
|
||||
'dance requires exactly video+audio, no attached cover')
|
||||
v=next(s for s in streams if s['codec_type']=='video');a=next(s for s in streams if s['codec_type']=='audio')
|
||||
require(v['codec_name']=='h264' and (v['width'],v['height'])==(480,848) and
|
||||
not v.get('disposition',{}).get('attached_pic',0),'dance video codec/shape/cover')
|
||||
require(a['codec_name']=='aac' and a['channels'] in (1,2) and 8000<=int(a['sample_rate'])<=96000,'dance AAC format')
|
||||
us=lambda value:int((Decimal(value)*1_000_000).to_integral_value())
|
||||
duration=us(v['duration']);require(1_000_000<=duration<=90_000_000,'dance duration bound')
|
||||
frames=[f for f in data['frames'] if f['media_type']=='video']
|
||||
require(1<=len(frames)<=5400,'dance decoded frame bound')
|
||||
audio=[f for f in data['frames'] if f['media_type']=='audio']
|
||||
require(audio and us(a.get('start_time','0'))>=0,'dance decoded audio missing/start')
|
||||
decoded_end=max(us(f['best_effort_timestamp_time'])+int(round(int(f['nb_samples'])*1_000_000/int(a['sample_rate']))) for f in audio)
|
||||
# AAC final frames can include encoder padding beyond the MP4 presentation end.
|
||||
audio_end=us(a.get('start_time','0'))+us(a['duration'])
|
||||
require(1<=audio_end<=duration and decoded_end+2>=audio_end,'dance presented audio end')
|
||||
subprocess.run(['/home/ubuntu/gori-bin/ffmpeg','-v','error','-xerror','-i',str(path),
|
||||
'-map','0:v:0','-f','null','-'],capture_output=True,check=True,timeout=60)
|
||||
pcm=subprocess.run(['/home/ubuntu/gori-bin/ffmpeg','-v','error','-xerror','-i',str(path),
|
||||
'-map','0:a:0','-af','atrim=end='+str(Decimal(audio_end)/1_000_000),'-ac','2','-ar','48000',
|
||||
'-f','f32le','-'],capture_output=True,check=True,timeout=60).stdout
|
||||
require(0<len(pcm)<=90*48000*2*4 and len(pcm)%8==0,'dance PCM byte bound')
|
||||
samples=array.array('f');samples.frombytes(pcm)
|
||||
if sys.byteorder!='little': samples.byteswap()
|
||||
require(all(math.isfinite(x) for x in samples),'dance PCM nonfinite')
|
||||
rms=math.sqrt(sum(x*x for x in samples)/len(samples));peak=max(abs(x) for x in samples)
|
||||
require(rms>0.00001 and peak<=1.001,'dance silent/out-of-range audio')
|
||||
return {'ptsUs':[us(f['best_effort_timestamp_time']) for f in frames],
|
||||
'durationUs':duration,'fps':Fraction(v['r_frame_rate']),'audioEndUs':audio_end,
|
||||
'decodedAudioEndUs':decoded_end,'pcmFrames':len(samples)//2,'audioRms':rms,'audioPeak':peak,
|
||||
'nearFullScaleSamples':sum(abs(x)>=0.999 for x in samples),'humanListening':'not_run'}
|
||||
|
||||
|
||||
def check_bundle(manifest,expected,output):
|
||||
manifest=manifest.resolve(strict=True);root=manifest.parent
|
||||
require(re.fullmatch('[0-9a-f]{64}',expected) and file_sha(manifest)==expected,'candidate index drift')
|
||||
index=read_json(manifest)
|
||||
require(index['schemaVersion']==2 and index['identityId']=='a01' and index['packId']=='a01-expression-action-v1','index identity/schema')
|
||||
require(index['actions']==[],'this partial-emotion packer requires actions:[]; dance needs its separate audio gate')
|
||||
actions=index['actions']
|
||||
require(isinstance(actions,list) and (not actions or len(actions)==2 and
|
||||
{a['id'] for a in actions}=={'asset_01','asset_02'}),'actions require exactly asset_01/asset_02 or []')
|
||||
rows=index['conversationPackages'];require(1<=len(rows)<=12,'package count')
|
||||
files={};measurements={};runtimes=[]
|
||||
def add(name,digest,bound):
|
||||
@@ -107,6 +149,16 @@ def check_bundle(manifest,expected,output):
|
||||
require(len(measured['ptsUs'])==clip['frameCount'] and len(clip['ptsUs'])==clip['frameCount'],'decoded clip N mismatch: '+name)
|
||||
require(all(abs(a-b)<=2 for a,b in zip(measured['ptsUs'],clip['ptsUs'])),'decoded clip PTS mismatch: '+name)
|
||||
require(abs(measured['durationUs']-clip['durationUs'])<=2 and measured['fps']==Fraction(clip['fpsNumerator'],clip['fpsDenominator']),'decoded clip timing mismatch: '+name)
|
||||
action_measurements=[]
|
||||
for action in actions:
|
||||
clip=action['clip'];name=relative(clip['path']);path=add(name,clip['sha256'],128_000_000)
|
||||
require(clip['hasAudio'] is True,'dance requires actual audio')
|
||||
measured=probe_music_clip(path)
|
||||
require(len(measured['ptsUs'])==clip['frameCount'] and len(clip['ptsUs'])==clip['frameCount'], 'dance decoded N mismatch: '+name)
|
||||
require(all(abs(a-b)<=2 for a,b in zip(measured['ptsUs'],clip['ptsUs'])),'dance decoded PTS mismatch: '+name)
|
||||
require(abs(measured['durationUs']-clip['durationUs'])<=2 and measured['fps']==Fraction(clip['fpsNumerator'],clip['fpsDenominator']),'dance decoded timing mismatch: '+name)
|
||||
require(abs(measured['audioEndUs']-action['audioEndUs'])<=2,'dance audioEndUs mismatch: '+name)
|
||||
action_measurements.append({'id':action['id'],**{k:v for k,v in measured.items() if k!='fps'}})
|
||||
# Preview inventory is checked too, but only runtime-referenced files enter APK.
|
||||
declared=index['files']
|
||||
if isinstance(declared,dict): declared=[dict(v,path=k) for k,v in declared.items()]
|
||||
@@ -126,7 +178,8 @@ def check_bundle(manifest,expected,output):
|
||||
for name,row in files.items(): require(file_sha(locate(root,name))==row['sha256'],'bundle changed during gate')
|
||||
report={'status':'passed','scope':'read_only_machine_gate_no_approval_no_activation','manifest_sha256':expected,
|
||||
'runtime_packages':runtimes,'combined_rgba_bytes':rgba,'referenced_files':len(files),'preview_files_not_packaged':len(table.keys()-files.keys()),
|
||||
'edge_count':len(index['edges']),'action_count':0,'dance_available':False,'production_kotlin_index':'passed',
|
||||
'edge_count':len(index['edges']),'action_count':len(actions),'dance_available':False,
|
||||
'candidate_dance_validated':bool(actions),'action_measurements':action_measurements,'production_kotlin_index':'passed',
|
||||
'naturalness':'not_certified','real_device':'not_run','files':files}
|
||||
(output/'bundle-gate.json').write_text(json.dumps(report,indent=2)+'\n')
|
||||
return report
|
||||
@@ -271,6 +324,8 @@ def main():
|
||||
args=parser.parse_args();manifest=args.manifest.resolve(strict=True);output=args.output.resolve()
|
||||
require(not output.exists() and not output.is_relative_to(manifest.parent),'new evidence outside owner root required')
|
||||
if args.import_only or args.publish: require(args.pi_pin==args.sha256 and re.fullmatch('[0-9a-f]{64}',args.pi_pin or ''),'external Pi pin required')
|
||||
if args.import_only or args.publish:
|
||||
require(read_json(manifest)['actions']==[],'dance import/publication requires separately reviewed gateway capability admission; read-only gate supported')
|
||||
output.mkdir(parents=True)
|
||||
report=check_bundle(manifest,args.sha256,output)
|
||||
if args.import_only or args.publish:
|
||||
|
||||
Reference in New Issue
Block a user