All checks were successful
Validate and publish Kaleido / android (push) Successful in 3m4s
129 lines
9 KiB
Python
129 lines
9 KiB
Python
"""Exercise real Plex playback through Kaleido's opt-in debug validation mode.
|
|
|
|
One device at a time. No timeline/scrobble writes in validation mode. Raw reports
|
|
and screenshots remain private; source media and track preferences are untouched.
|
|
"""
|
|
import argparse,json,os,pathlib,subprocess,time
|
|
if pathlib.Path('/etc/ssl/cert.pem').exists():os.environ.setdefault('SSL_CERT_FILE','/etc/ssl/cert.pem')
|
|
from device import adb,DEVICE,OUT
|
|
from inspect_server import get
|
|
|
|
def audit():
|
|
try:raw=adb('exec-out','run-as','tv.kaleido.app','cat','files/playback-validation.jsonl')
|
|
except RuntimeError:return b'',[]
|
|
records=[]
|
|
for line in raw.splitlines():
|
|
try:records.append(json.loads(line))
|
|
except json.JSONDecodeError:pass # The writer can be appending its last line.
|
|
return raw,records
|
|
|
|
def snapshot_signal():
|
|
command='for p in /sys/class/amhdmitx/amhdmitx0/attr /sys/class/amhdmitx/amhdmitx0/hdmi_hdr_status /sys/class/amhdmitx/amhdmitx0/hdr_status /sys/class/video/frame_format /sys/module/amdolby_vision/parameters/dolby_vision_status /sys/module/amdolby_vision/parameters/dolby_vision_mode; do if [ -r "$p" ]; then printf "%s=" "$p"; cat "$p"; fi; done'
|
|
return adb('shell',command)
|
|
|
|
def watched(item):return {k:item.get(k) for k in ('viewOffset','viewCount','lastViewedAt')}
|
|
|
|
def main():
|
|
parser=argparse.ArgumentParser()
|
|
parser.add_argument('id');parser.add_argument('label');parser.add_argument('--mode',type=int,default=-1)
|
|
parser.add_argument('--seconds',type=float,default=12);parser.add_argument('--offset',type=int,default=90000)
|
|
parser.add_argument('--seek',action='store_true');parser.add_argument('--screenshot',action='store_true')
|
|
parser.add_argument('--observe-hdmi',action='store_true',help='Read the already tuned TCL debug HDMI observer during ONN playback')
|
|
parser.add_argument('--fixture',type=pathlib.Path,help='Private local test media with a matching .json metadata file; bypasses Plex transport')
|
|
parser.add_argument('--expect-mode',type=int,choices=(0,1,2))
|
|
parser.add_argument('--expect-width',type=int)
|
|
parser.add_argument('--expect-channels',type=int)
|
|
parser.add_argument('--expect-audio-encoding',type=int)
|
|
parser.add_argument('--fail-on-audio-underrun',action='store_true')
|
|
args=parser.parse_args()
|
|
folder=OUT/'playback-validation'/('onn' if DEVICE=='192.168.50.195:5555' else 'tcl')/args.label
|
|
folder.mkdir(parents=True,exist_ok=True)
|
|
before=json.loads(args.fixture.with_suffix('.json').read_text()) if args.fixture else get('/library/metadata/'+args.id)['Metadata'][0]
|
|
expects_video=any(m.get('videoCodec') for m in before.get('Media',[]))
|
|
(folder/'source.json').write_text(json.dumps(before,indent=2))
|
|
adb('shell','input','keyevent','KEYCODE_WAKEUP')
|
|
adb('shell','am','force-stop','tv.kaleido.app')
|
|
adb('shell','run-as','tv.kaleido.app','rm','-f','files/playback-validation.jsonl')
|
|
if args.fixture:
|
|
name=args.fixture.stem
|
|
if not name.replace('-','').isalnum() or name.lower()!=name:raise SystemExit('Use a lowercase alphanumeric fixture name')
|
|
adb('shell','run-as','tv.kaleido.app','mkdir','-p','files/validation')
|
|
for path in (args.fixture,args.fixture.with_suffix('.json')):
|
|
tmp='/data/local/tmp/kaleido-validation-'+path.name
|
|
adb('push',str(path),tmp)
|
|
adb('shell','run-as','tv.kaleido.app','cp',tmp,'files/validation/'+path.name)
|
|
adb('shell','rm','-f',tmp)
|
|
start=time.monotonic()
|
|
if args.fixture:adb('shell','am','start','-n','tv.kaleido.app/.MainActivity','--es','testFixture',args.fixture.stem)
|
|
else:adb('shell','am','start','-n','tv.kaleido.app/.MainActivity','--es','testTitleId',args.id,'--el','testOffset',str(args.offset),'--ei','testMode',str(args.mode),'--ez','testValidation','true')
|
|
ready=None;records=[]
|
|
while time.monotonic()-start<55:
|
|
_,records=audit()
|
|
if args.fixture and any(r['event'] in ('error','prepareFailure') for r in records):break
|
|
samples=[r for r in records if r['event']=='sample']
|
|
if samples:
|
|
last=samples[-1]
|
|
video=last.get('videoCounters',{})
|
|
if last.get('playing') and (video.get('rendered',0)>5 or not expects_video and any(r['event']=='audioAdvancing' for r in records)):
|
|
ready=round(time.monotonic()-start,2);break
|
|
time.sleep(.8)
|
|
if ready is not None:time.sleep(args.seconds)
|
|
raw,records=audit();(folder/'audit-steady.jsonl').write_bytes(raw)
|
|
(folder/'signal-steady.txt').write_bytes(snapshot_signal())
|
|
(folder/'surface-steady.txt').write_bytes(adb('shell','dumpsys','SurfaceFlinger'))
|
|
if args.observe_hdmi:
|
|
import device
|
|
original=device.DEVICE
|
|
try:
|
|
device.DEVICE='192.168.50.200:5555'
|
|
(folder/'tcl-hdmi.jsonl').write_bytes(adb('exec-out','run-as','tv.kaleido.app','cat','files/hdmi-validation.jsonl'))
|
|
(folder/'tcl-picture.png').write_bytes(adb('exec-out','screencap','-p'))
|
|
finally:device.DEVICE=original
|
|
if args.screenshot:(folder/'onn-picture.png').write_bytes(adb('exec-out','screencap','-p'))
|
|
seek_result=None
|
|
if args.seek and ready is not None:
|
|
adb('shell','input','keyevent','127');time.sleep(1.5)
|
|
_,paused=audit();old=[r for r in paused if r['event']=='sample'][-1]['position']
|
|
for _ in range(3):
|
|
_,current=audit();position=[r for r in current if r['event']=='sample'][-1]['position']
|
|
adb('shell','input','keyevent','89')
|
|
deadline=time.monotonic()+25
|
|
while time.monotonic()<deadline:
|
|
time.sleep(.8);_,check=audit();sample=[r for r in check if r['event']=='sample'][-1]
|
|
if sample['state']==3 and abs(sample['position']-(position-10000))<2200:break
|
|
_,rewound=audit();new=[r for r in rewound if r['event']=='sample'][-1]['position']
|
|
adb('shell','input','keyevent','126');time.sleep(3)
|
|
seek_result={'from':old,'to':new,'expectedDelta':-30000,'correct':abs((old-new)-30000)<2500}
|
|
for _ in range(3):
|
|
adb('shell','input','keyevent','4');time.sleep(.8)
|
|
_,r=audit()
|
|
if any(x['event']=='closed' for x in r):break
|
|
time.sleep(1)
|
|
raw,records=audit();(folder/'audit.jsonl').write_bytes(raw)
|
|
samples=[r for r in records if r['event']=='sample']
|
|
steady=[r for r in samples if r.get('playing')]
|
|
last=steady[-1] if steady else {}
|
|
after=before if args.fixture else get('/library/metadata/'+args.id)['Metadata'][0]
|
|
result={'label':args.label,'id':args.id,'device':DEVICE,'requestedMode':args.mode,'readySeconds':ready,
|
|
'firstFrame':any(r['event']=='firstFrame' for r in records),'audioAdvancing':any(r['event']=='audioAdvancing' for r in records),
|
|
'videoDecoders':[r['name'] for r in records if r['event']=='videoDecoder'],
|
|
'audioDecoders':[r['name'] for r in records if r['event']=='audioDecoder'],
|
|
'audioTracks':[r for r in records if r['event']=='audioTrack'],
|
|
'errors':[r['code'] for r in records if r['event']=='error'],'errorDetails':[r for r in records if r['event'] in ('error','prepareFailure')],'finalSample':last,'seek':seek_result,
|
|
'expectsVideo':expects_video,'videoRendered':not expects_video or any(r.get('videoCounters',{}).get('rendered',0)>5 for r in samples),
|
|
'closed':any(r['event']=='closed' for r in records),'before':watched(before),'after':watched(after),
|
|
'audioUnderruns':[r for r in records if r['event']=='audioUnderrun'],
|
|
'transport':'private-local-fixture' if args.fixture else 'Plex','progressUnchanged':None if args.fixture else watched(before)==watched(after)}
|
|
(folder/'result.json').write_text(json.dumps(result,indent=2))
|
|
print(json.dumps({k:result[k] for k in ('label','readySeconds','firstFrame','audioAdvancing','videoDecoders','errors','progressUnchanged')}),flush=True)
|
|
print('Output:',last.get('video'),last.get('audio'),'mode:',last.get('mode'),'seek:',seek_result,flush=True)
|
|
if ready is None:raise SystemExit('Playback did not become ready; see private evidence')
|
|
if args.fail_on_audio_underrun and result['audioUnderruns']:raise SystemExit('Audio underrun detected; see private evidence')
|
|
if not result['closed']:raise SystemExit('Player did not close cleanly')
|
|
if result['progressUnchanged'] is False:raise SystemExit('Unexpected progress change; see before/after evidence')
|
|
if args.seek and not seek_result['correct']:raise SystemExit('Seek did not reach the expected absolute position')
|
|
if args.expect_mode is not None and last.get('mode')!=args.expect_mode:raise SystemExit('Unexpected delivery mode')
|
|
if args.expect_width is not None and last.get('video',{}).get('width')!=args.expect_width:raise SystemExit('Unexpected delivered video width')
|
|
if args.expect_channels is not None and last.get('audio',{}).get('channels')!=args.expect_channels:raise SystemExit('Unexpected delivered audio channel count')
|
|
if args.expect_audio_encoding is not None and (not result['audioTracks'] or result['audioTracks'][-1]['encoding']!=args.expect_audio_encoding):raise SystemExit('Unexpected audio output encoding')
|
|
if __name__=='__main__':main()
|