Provide better diffs for MP4 failures.

If the user has the GPAC MP4 tools installed, this will use that to
provide a better, text-based diff of the MP4 files.  This makes looking
at test failures much better than just "binary files differ".

Change-Id: Ifdca54c02226a9f0fe9ddcf9c6b28e960e568111
This commit is contained in:
Jacob Trimble 2020-06-08 15:53:45 -07:00
parent 8913dbda85
commit 51fe84f9d5
1 changed files with 26 additions and 0 deletions

View File

@ -133,6 +133,15 @@ class DiffFilesPolicy(object):
output, error = self._GitDiff(expected_file, actual_file)
# If this is an MP4 file, get a better looking diff.
if ((output or error) and
os.path.splitext(actual_file)[1] in {'.mp4', '.m4s'}):
new_output, new_error = self._Mp4Diff(
out_dir, expected_file, actual_file)
output = new_output or output
error = new_error or error
if output:
failure_messages += [output.decode('utf8')]
@ -160,6 +169,23 @@ class DiffFilesPolicy(object):
p = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
return p.communicate()
def _Mp4Diff(self, out_dir, file_a, file_b):
dump_a = os.path.join(out_dir, os.path.basename(file_a) + '.dump.expected')
dump_b = os.path.join(out_dir, os.path.basename(file_b) + '.dump.actual')
try:
cmd = ['mp4dump', '--verbosity', '2', file_a]
with open(dump_a, 'w') as f:
subprocess.check_call(cmd, stdout=f)
cmd = ['mp4dump', '--verbosity', '2', file_b]
with open(dump_b, 'w') as f:
subprocess.check_call(cmd, stdout=f)
except (OSError, subprocess.CalledProcessError):
# If the program isn't available or returns an error, just ignore it and
# use the normal diff.
return None, None
return self._GitDiff(dump_a, dump_b)
def _UpdateGold(self, out_dir, gold_dir):
if os.path.exists(gold_dir):
shutil.rmtree(gold_dir)