Support bounded 720x1280 avatar shapes through GLES and production gates
This commit is contained in:
@@ -13,6 +13,7 @@ import sys
|
||||
from PIL import Image
|
||||
|
||||
ROOT=Path(__file__).resolve().parents[1]
|
||||
SUPPORTED_SHAPES={(480,848),(720,1280)}
|
||||
|
||||
def require(value,reason):
|
||||
if not value: raise ValueError(reason)
|
||||
@@ -49,7 +50,7 @@ def check_runtime(manifest_path, expected_sha, kotlin=True):
|
||||
decoded=json.loads(probe.stdout);streams=decoded['streams'];frames=decoded['frames']
|
||||
require(len(streams)==1 and streams[0]['codec_type']=='video' and body['hasAudio'] is False,'conversation must be silent video')
|
||||
stream=streams[0]
|
||||
require(stream['codec_name']=='h264' and (stream['width'],stream['height'])==(body['width'],body['height'])==(480,848),'codec/shape mismatch')
|
||||
require(stream['codec_name']=='h264' and (stream['width'],stream['height'])==(body['width'],body['height']) and (body['width'],body['height']) in (SUPPORTED_SHAPES if dynamic else {(480,848)}),'codec/shape mismatch')
|
||||
require(Fraction(stream['r_frame_rate'])==Fraction(body['fpsNumerator'],body['fpsDenominator']),'measured nominal fps mismatch')
|
||||
require(len(frames)==count,'decoded actual N mismatch')
|
||||
pts=[int((Decimal(frame['best_effort_timestamp_time'])*1_000_000).to_integral_value()) for frame in frames]
|
||||
@@ -65,6 +66,8 @@ def check_runtime(manifest_path, expected_sha, kotlin=True):
|
||||
if dynamic: require(patch['ptsUs']==expected[i],'schema2 exact patch PTS binding')
|
||||
width,height=patch['width'],patch['height']
|
||||
require(type(width) is int and type(height) is int and 1<=width<=128 and 1<=height<=128,'patch shape bound')
|
||||
require(all(isinstance(patch[k],(int,float)) and not isinstance(patch[k],bool) for k in ('x','y')) and
|
||||
0<=patch['x']<=body['width']-width and 0<=patch['y']<=body['height']-height,'patch pixel bounds')
|
||||
levels=patch['levels'] if aperture else [patch]
|
||||
require(len(levels)==(5 if aperture else 1),'five own levels required')
|
||||
for level in levels:
|
||||
@@ -82,7 +85,7 @@ def check_runtime(manifest_path, expected_sha, kotlin=True):
|
||||
for name,sha in verified.items():
|
||||
require(hashlib.sha256((directory/name).read_bytes()).hexdigest()==sha,'asset changed during gate')
|
||||
evidence={'status':'passed','scope':'read_only_machine_gate_no_approval_no_activation','manifest_sha256':digest,
|
||||
'body_sha256':body['sha256'],'schema_version':manifest['schemaVersion'],'actual_frame_count':count,
|
||||
'body_sha256':body['sha256'],'schema_version':manifest['schemaVersion'],'body_shape':[body['width'],body['height']],'actual_frame_count':count,
|
||||
'actual_pts_count':len(pts),'actual_duration_us':duration,'patch_images':len(paths),'rgba_cache_bytes':rgba,
|
||||
'verified_files':len(verified),'full_decode':'passed','production_kotlin_parser':'passed' if kotlin else 'checked_by_bundle_parser','naturalness':'pending','real_device':'not_run'}
|
||||
return evidence, verified
|
||||
|
||||
@@ -13,11 +13,12 @@ def bilinear(image,x,y):
|
||||
return (image[iy,ix]*(1-fx)+image[iy,jx]*fx)*(1-fy)+(image[jy,ix]*(1-fx)+image[jy,jx]*fx)*fy
|
||||
|
||||
def golden(body,patch,x,y,opacity,w,h,crop):
|
||||
scale=min(w/480,h/848);left=(w-480*scale)/2;top=(h-848*scale)/2
|
||||
bh,bw=body.shape[:2]
|
||||
scale=min(w/bw,h/bh);left=(w-bw*scale)/2;top=(h-bh*scale)/2
|
||||
yy,xx=np.mgrid[:h,:w];px=(xx+.5-left)/scale;py=(yy+.5-top)/scale
|
||||
inside=(px>=0)&(px<480)&(py>=0)&(py<848)
|
||||
bx=px*(.98 if crop else 1)+(4.8 if crop else 0)-.5
|
||||
by=py*(.98 if crop else 1)+(8.48 if crop else 0)-.5
|
||||
inside=(px>=0)&(px<bw)&(py>=0)&(py<bh)
|
||||
bx=px*(.98 if crop else 1)+(bw*.01 if crop else 0)-.5
|
||||
by=py*(.98 if crop else 1)+(bh*.01 if crop else 0)-.5
|
||||
b=bilinear(body.astype(float),bx,by)
|
||||
localx=px-x;localy=py-y;ph,pw=patch.shape[:2]
|
||||
p=bilinear(patch.astype(float),localx-.5,localy-.5)
|
||||
@@ -27,9 +28,11 @@ def golden(body,patch,x,y,opacity,w,h,crop):
|
||||
return np.clip(np.floor(out+.5),0,255).astype(np.uint8)
|
||||
|
||||
def main():
|
||||
parser=argparse.ArgumentParser(description=__doc__);parser.add_argument('--runtime',type=Path,required=True);parser.add_argument('--output',type=Path,required=True)
|
||||
parser=argparse.ArgumentParser(description=__doc__);parser.add_argument('--runtime',type=Path);parser.add_argument('--synthetic-shape',choices=['480x848','720x1280'],default='720x1280');parser.add_argument('--output',type=Path,required=True)
|
||||
args=parser.parse_args();args.output.mkdir(parents=True,exist_ok=True)
|
||||
m=json.loads((args.runtime/'manifest.json').read_text());source=(ROOT/'app/src/main/java/com/gorios/lanvoice/avatar/ContinuousBodyRenderer.kt').read_text()
|
||||
m=json.loads((args.runtime/'manifest.json').read_text()) if args.runtime else None
|
||||
bw,bh=(m['body']['width'],m['body']['height']) if m else map(int,args.synthetic_shape.split('x'))
|
||||
source=(ROOT/'app/src/main/java/com/gorios/lanvoice/avatar/ContinuousBodyRenderer.kt').read_text()
|
||||
vertex=re.search(r'const val VERTEX="""([\s\S]*?)"""',source)[1]
|
||||
fragment=re.search(r'const val FRAGMENT="""([\s\S]*?)"""',source)[1]
|
||||
fragment=fragment.replace('#extension GL_OES_EGL_image_external : require','').replace('samplerExternalOES','sampler2D')
|
||||
@@ -40,38 +43,44 @@ def main():
|
||||
env=dict(os.environ,EGL_PLATFORM='surfaceless',LIBGL_ALWAYS_SOFTWARE='1')
|
||||
def check(body,patch,x,y,opacity,w,h,label,crop=0):
|
||||
(tmp/'body.rgba').write_bytes(body.tobytes());(tmp/'patch.rgba').write_bytes(patch.tobytes())
|
||||
p=subprocess.run([str(tmp/'golden'),str(tmp/'vertex'),str(tmp/'fragment'),str(tmp/'body.rgba'),str(tmp/'patch.rgba'),str(tmp/'out.rgba'),str(patch.shape[1]),str(patch.shape[0]),str(x),str(y),str(opacity),str(w),str(h),str(crop)],env=env,capture_output=True,text=True)
|
||||
p=subprocess.run([str(tmp/'golden'),str(tmp/'vertex'),str(tmp/'fragment'),str(tmp/'body.rgba'),str(tmp/'patch.rgba'),str(tmp/'out.rgba'),str(patch.shape[1]),str(patch.shape[0]),str(x),str(y),str(opacity),str(w),str(h),str(crop),str(body.shape[1]),str(body.shape[0])],env=env,capture_output=True,text=True)
|
||||
assert p.returncode==0,p.stderr
|
||||
actual=np.frombuffer((tmp/'out.rgba').read_bytes(),np.uint8).reshape(h,w,4)[::-1,:,:3]
|
||||
expected=golden(body,patch,x,y,opacity,w,h,crop);diff=np.abs(actual.astype(int)-expected.astype(int))
|
||||
row={'case':label,'maxAbsRGB':int(diff.max()),'meanAbsRGB':float(diff.mean()),'viewport':[w,h],'bodyTransformCrop':crop,'gl':p.stdout.strip()}
|
||||
row={'case':label,'maxAbsRGB':int(diff.max()),'meanAbsRGB':float(diff.mean()),'viewport':[w,h],'bodyShape':[body.shape[1],body.shape[0]],'bodyTransformCrop':crop,'gl':p.stdout.strip()}
|
||||
results.append(row)
|
||||
assert diff.max()<=2,row
|
||||
if opacity==0 and w==480 and h==848 and not crop:assert np.array_equal(actual,body[:,:,:3]),'Level0 must be exact decoded body'
|
||||
if opacity==0 and w==body.shape[1] and h==body.shape[0] and not crop:assert np.array_equal(actual,body[:,:,:3]),'Level0 must be exact decoded body'
|
||||
if label=='frame43-level2':Image.fromarray(actual[94:150,193:263]).resize((560,448)).save(args.output/'gles-frame43-level2-mouth.png')
|
||||
yy,xx=np.mgrid[:848,:480];body=np.empty((848,480,4),np.uint8)
|
||||
yy,xx=np.mgrid[:bh,:bw];body=np.empty((bh,bw,4),np.uint8)
|
||||
body[:,:,0]=xx%256;body[:,:,1]=yy%256;body[:,:,2]=((xx//16+yy//16)%2)*255;body[:,:,3]=255
|
||||
patch=np.zeros((22,40,4),np.uint8);patch[:,:,:3]=[211,70,39];patch[:,:,3]=np.arange(40,dtype=np.uint8)[None,:]*6
|
||||
for w,h in [(480,848),(360,800),(800,480)]:
|
||||
for w,h in [(bw,bh),(360,800),(800,480)]:
|
||||
for opacity in [0,.5,1]:check(body,patch,211.25,112.5,opacity,w,h,f'synthetic-{w}x{h}-opacity{opacity}')
|
||||
check(body,patch,211.25,112.5,1,480,848,'synthetic-transform-crop',1)
|
||||
pipe=subprocess.Popen(['/home/ubuntu/gori-bin/ffmpeg','-v','error','-i',str(args.runtime/m['body']['path']),'-f','rawvideo','-pix_fmt','rgba','-'],stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
||||
try:
|
||||
for i,row in enumerate(m['patches']):
|
||||
raw=pipe.stdout.read(480*848*4);assert len(raw)==480*848*4
|
||||
fixed=(0,26,43,52,69,96) if len(m['patches'])==97 else tuple(sorted({round(k*(len(m['patches'])-1)/5) for k in range(6)}))
|
||||
if i not in fixed:continue
|
||||
body=np.frombuffer(raw,np.uint8).reshape(848,480,4)
|
||||
for level in (0,1,2,3,4):
|
||||
patch=np.asarray(Image.open(args.runtime/row['levels'][level]['path']).convert('RGBA'))
|
||||
check(body,patch,row['x'],row['y'],0 if level==0 else 1,480,848,f'frame{i}-level{level}')
|
||||
assert pipe.stdout.read(1)==b'';assert pipe.wait(timeout=10)==0
|
||||
finally:
|
||||
if pipe.poll() is None:pipe.kill();pipe.wait()
|
||||
check(body,patch,211.25,112.5,1,bw,bh,'synthetic-transform-crop',1)
|
||||
if m is None:
|
||||
# Pixel-space beyond the legacy bounds, both edges and fractional origin.
|
||||
for x,y in [(bw-40.0,bh-22.0),(bw-40.25,bh-22.25),(0,0),(0.25,0.25)]:
|
||||
for opacity in [0,.25,.5,.75,1]:
|
||||
check(body,patch,x,y,opacity,bw,bh,f'edge-{x}-{y}-opacity{opacity}')
|
||||
else:
|
||||
pipe=subprocess.Popen(['/home/ubuntu/gori-bin/ffmpeg','-v','error','-i',str(args.runtime/m['body']['path']),'-f','rawvideo','-pix_fmt','rgba','-'],stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
||||
try:
|
||||
for i,row in enumerate(m['patches']):
|
||||
raw=pipe.stdout.read(bw*bh*4);assert len(raw)==bw*bh*4
|
||||
fixed=(0,26,43,52,69,96) if len(m['patches'])==97 else tuple(sorted({round(k*(len(m['patches'])-1)/5) for k in range(6)}))
|
||||
if i not in fixed:continue
|
||||
body=np.frombuffer(raw,np.uint8).reshape(bh,bw,4)
|
||||
for level in (0,1,2,3,4):
|
||||
patch=np.asarray(Image.open(args.runtime/row['levels'][level]['path']).convert('RGBA'))
|
||||
check(body,patch,row['x'],row['y'],0 if level==0 else 1,bw,bh,f'frame{i}-level{level}')
|
||||
assert pipe.stdout.read(1)==b'';assert pipe.wait(timeout=10)==0
|
||||
finally:
|
||||
if pipe.poll() is None:pipe.kill();pipe.wait()
|
||||
report={'status':'passed','shaderSourceSha':hashlib.sha256(source.encode()).hexdigest(),
|
||||
'harnessSha':hashlib.sha256((ROOT/'tests/avatar-pixels/gles-golden.c').read_bytes()).hexdigest(),
|
||||
'scope':'Production shader strings; body OES sampler substituted by2D, decoded ffmpeg/PIL straight bytes. Does not test Android Bitmap/OES/YUV/physicaldisplay.','cases':results}
|
||||
(args.output/'shader-golden.json').write_text(json.dumps(report,indent=2)+'\n')
|
||||
print('PASS:',len(results),'real offline EGL/GLES pixel golden cases: UV/top-bottom/Fit/nontrivial body transform/straight blend/alpha0/6fixedframes x5levels; Android device pending')
|
||||
print('PASS:',len(results),'real offline EGL/GLES pixel golden cases: UV/top-bottom/Fit/nontrivial body transform/straight blend/alpha0; '+('6 fixed frames x5 levels' if m else 'procedural edge/fractional-coordinate cases')+'; Android device pending')
|
||||
|
||||
if __name__=='__main__':main()
|
||||
|
||||
@@ -68,10 +68,10 @@ def probe_clip(path):
|
||||
data=json.loads(result.stdout)
|
||||
require(len(data['streams'])==1,'conversation/bridge must be silent video')
|
||||
v=data['streams'][0]
|
||||
require(v['codec_type']=='video' and v['codec_name']=='h264' and (v['width'],v['height'])==(480,848),'clip codec/shape')
|
||||
require(v['codec_type']=='video' and v['codec_name']=='h264' and (v['width'],v['height']) in runtime_gate.SUPPORTED_SHAPES,'clip codec/shape')
|
||||
us=lambda value:int((Decimal(value)*1_000_000).to_integral_value())
|
||||
measured={'ptsUs':[us(f['best_effort_timestamp_time']) for f in data['frames']],
|
||||
'durationUs':us(v['duration']),'fps':Fraction(v['r_frame_rate'])}
|
||||
'durationUs':us(v['duration']),'fps':Fraction(v['r_frame_rate']),'shape':(v['width'],v['height'])}
|
||||
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)
|
||||
return measured
|
||||
|
||||
@@ -84,7 +84,7 @@ def probe_music_clip(path):
|
||||
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
|
||||
require(v['codec_name']=='h264' and (v['width'],v['height']) in runtime_gate.SUPPORTED_SHAPES 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())
|
||||
@@ -110,7 +110,7 @@ def probe_music_clip(path):
|
||||
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,
|
||||
'shape':(v['width'],v['height']),'decodedAudioEndUs':decoded_end,'pcmFrames':len(samples)//2,'audioRms':rms,'audioPeak':peak,
|
||||
'nearFullScaleSamples':sum(abs(x)>=0.999 for x in samples),'humanListening':'not_run'}
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ def check_bundle(manifest,expected,output):
|
||||
m=read_json(path);prefix=PurePosixPath(ref['path']).parent
|
||||
for name,digest in verified.items(): add(str(prefix/name),digest,64_000_000 if name.endswith('.mp4') else 256_000)
|
||||
body=m['body'];measurements[str(prefix/body['path'])]={'ptsUs':body['ptsUs'] if m['schemaVersion']==2 else [i*1_000_000//24 for i in range(body['frameCount'])],
|
||||
'durationUs':body['durationUs'],'fps':Fraction(body['fpsNumerator'],body['fpsDenominator'])}
|
||||
'durationUs':body['durationUs'],'fps':Fraction(body['fpsNumerator'],body['fpsDenominator']),'shape':(body['width'],body['height'])}
|
||||
runtimes.append({'package_id':runtime_id,**evidence})
|
||||
rgba=sum(r['rgba_cache_bytes'] for r in runtimes);require(rgba<=32_000_000,'combined runtime cache bound')
|
||||
require(len(index['edges'])<=100,'edge count bound')
|
||||
@@ -149,6 +149,7 @@ def check_bundle(manifest,expected,output):
|
||||
require(clip['hasAudio'] is False,'conversation edge cannot have audio')
|
||||
measured=measurements.get(name)
|
||||
if measured is None: measured=measurements[name]=probe_clip(path)
|
||||
require(measured['shape']==(clip['width'],clip['height']),'decoded clip shape mismatch: '+name)
|
||||
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)
|
||||
@@ -157,6 +158,7 @@ def check_bundle(manifest,expected,output):
|
||||
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(measured['shape']==(clip['width'],clip['height']),'decoded clip shape mismatch: '+name)
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user