A device-free engine for host tests and agents.
# config/test.exs
config :mob_media, engine: MobMedia.Engine.FakeIt goes through the same MobMedia code as the platform engine (the
worker, the timeout, the temporary files), so a test sees exactly what a
phone would return for the same answer.
- WAV files are decoded for real:
inforeports their duration andaudio_pcmconverts them withMobMedia.PCM.convert/5, so a test can feed a recording through to transcription. 16-bit PCM only. A WAV has no video:frameis{:error, :no_video}. - Any path can be scripted with
script/2, which wins over the file's contents: give it the info, the audio and the frame it should answer with. That's how a test pretends a.mp4or.m4aexists. - Everything else is
{:error, :unsupported}.
Results are delivered from another process, as the platform engine does.
Summary
Types
@type script() :: [ info: map() | {:error, term()}, audio: {binary(), pos_integer(), pos_integer()} | {:error, term()}, frame: {binary(), pos_integer(), pos_integer()} | {:error, term()}, delay: non_neg_integer() ]
A scripted answer for a path; see script/2.
Functions
@spec reset() :: :ok
Forget every scripted path.
Script the answers for path (it must still exist: MobMedia checks that
first).
:info— a map merged into%{duration_ms: nil, width: nil, height: nil, has_audio: false, has_video: false, mime: nil}, or{:error, reason}.:audio—{pcm, rate, channels}, s16le, converted to whateverMobMedia.audio_pcm/2asks for; or{:error, reason}. Default{:error, :no_audio}.:frame—{jpeg, width, height}, returned as is whatever the options; or{:error, reason}. Default{:error, :no_video}.:delay— milliseconds before each answer (to exercise timeouts).