Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Unified Diff: LayoutTests/http/tests/media/resources/media-source/generate-config-change-tests.py

Issue 17338002: Add LayoutTests for MediaSource codec config changes. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: LayoutTests/http/tests/media/resources/media-source/generate-config-change-tests.py
diff --git a/LayoutTests/http/tests/media/resources/media-source/generate-config-change-tests.py b/LayoutTests/http/tests/media/resources/media-source/generate-config-change-tests.py
new file mode 100755
index 0000000000000000000000000000000000000000..d8543b6a2abb617c06a7dc486033c3a581710f3e
--- /dev/null
+++ b/LayoutTests/http/tests/media/resources/media-source/generate-config-change-tests.py
@@ -0,0 +1,209 @@
+#!/usr/bin/python
+# Copyright 2013 Google Inc. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# This is a script that generates the content and HTML files for Media Source
scherkus (not reviewing) 2013/06/18 01:22:09 this is usually a """triple quote string containin
acolwell GONE FROM CHROMIUM 2013/06/18 16:33:45 Done.
+# codec config change LayoutTests.
+import os
+
+duration = 2
scherkus (not reviewing) 2013/06/18 01:22:09 constants are ALL_CAPS
acolwell GONE FROM CHROMIUM 2013/06/18 16:33:45 Done.
+formats = ['webm', 'mp4']
+encode_settings = [
+ ## Video-only files
+ # Frame rate changes
+ { 'fs': '320x240', 'fr': 24, 'kfr': 8, 'c': '#ff0000', 'vbr': 128, 'abr': 0, 'asr': 0, 'ach': 0, 'afreq': 0 },
+ { 'fs': '320x240', 'fr': 30, 'kfr': 10, 'c': '#ff0000', 'vbr': 128, 'abr': 0, 'asr': 0, 'ach': 0, 'afreq': 0 },
+ # Frame size change
+ { 'fs': '640x480', 'fr': 30, 'kfr': 10, 'c': '#00ff00', 'vbr': 128, 'abr': 0, 'asr': 0, 'ach': 0, 'afreq': 0 },
+ # Bitrate change
+ { 'fs': '320x240', 'fr': 30, 'kfr': 10, 'c': '#ff00ff', 'vbr': 256, 'abr': 0, 'asr': 0, 'ach': 0, 'afreq': 0 },
+
+ ## Audio-only files
+ # Bitrate/Codebook changes
+ { 'fs': '0x0', 'fr': 0, 'kfr': 0, 'c': '#000000', 'vbr': 0, 'abr': 128, 'asr': 44100, 'ach': 1, 'afreq': 2000 },
+ { 'fs': '0x0', 'fr': 0, 'kfr': 0, 'c': '#000000', 'vbr': 0, 'abr': 192, 'asr': 44100, 'ach': 1, 'afreq': 4000 },
+
+ ## Audio-Video files
+ # Frame size change.
+ { 'fs': '320x240', 'fr': 30, 'kfr': 10, 'c': '#ff0000', 'vbr': 256, 'abr': 128, 'asr': 44100, 'ach': 1, 'afreq': 2000 },
+ { 'fs': '640x480', 'fr': 30, 'kfr': 10, 'c': '#00ff00', 'vbr': 256, 'abr': 128, 'asr': 44100, 'ach': 1, 'afreq': 2000 },
+ # Audio bitrate change.
+ { 'fs': '640x480', 'fr': 30, 'kfr': 10, 'c': '#00ff00', 'vbr': 256, 'abr': 192, 'asr': 44100, 'ach': 1, 'afreq': 4000 },
+ # Video bitrate change.
+ { 'fs': '640x480', 'fr': 30, 'kfr': 10, 'c': '#00ffff', 'vbr': 512, 'abr': 128, 'asr': 44100, 'ach': 1, 'afreq': 2000 },
+]
+
+config_change_tests = [
+ ["v-framerate", 0, 1, "Tests %s video-only frame rate changes."],
+ ["v-framesize", 1, 2, "Tests %s video-only frame size changes."],
+ ["v-bitrate", 1, 3, "Tests %s video-only bitrate changes."],
+ ["a-bitrate", 4, 5, "Tests %s audio-only bitrate changes."],
+ ["av-framesize", 6, 7, "Tests %s frame size changes in multiplexed content."],
+ ["av-audio-bitrate", 7, 8, "Tests %s audio bitrate changes in multiplexed content."],
+ ["av-video-bitrate", 7, 9, "Tests %s video bitrate changes in multiplexed content."]
+];
+
+encoding_ids = []
+
+def Run(cmdline):
scherkus (not reviewing) 2013/06/18 01:22:09 the pythonic way of doing command lines is typical
acolwell GONE FROM CHROMIUM 2013/06/18 16:33:45 Done. Used += [...] form in most places since it s
+ print cmdline
+ os.system(cmdline)
+
+def GenerateManifest(filename, format, has_audio, has_video):
+ # Create JSON manifest
scherkus (not reviewing) 2013/06/18 01:22:09 import json module?
acolwell GONE FROM CHROMIUM 2013/06/18 16:33:45 Done.
+ manifest = "{\n"
+ manifest += " \"url\": \"" + media_filename + "\",\n"
+
+ codecInfo = {
+ "mp4": { "audio": "mp4a.40.2", "video": "avc1.4D4001" },
+ "webm": { "audio": "vorbis", "video": "vp8" }
+ }
+
+ type = ""
+ if has_video :
+ type += "video"
+ else:
+ type += "audio"
+
+ type += "/" + format + ";codecs=\\\""
+ codecs = []
+ if has_video:
+ codecs.append(codecInfo[format]["video"]);
+
+ if has_audio:
+ codecs.append(codecInfo[format]["audio"]);
+
+ type += ",".join(codecs) + "\\\""
+ manifest += " \"type\": \"" + type + "\"\n"
+ manifest += "}\n"
+ f = open(filename, "wb")
+ f.write(manifest)
+ f.close()
+
+def GenerateTestHTML(format, config_change_tests, encoding_ids):
+ template = "<!DOCTYPE html>\n"
scherkus (not reviewing) 2013/06/18 01:22:09 this can be a """triple quote string""" and you ca
acolwell GONE FROM CHROMIUM 2013/06/18 16:33:45 Done.
+ template += "<html>\n"
+ template += " <head>\n"
+ template += " <script src='/w3c/resources/testharness.js'></script>\n"
+ template += " <script src='/w3c/resources/testharnessreport.js'></script>\n"
+ template += " <script src='mediasource-util.js'></script>\n"
+ template += " <script src='mediasource-config-changes.js'></script>\n"
+ template += " <link rel='stylesheet' href='/w3c/resources/testharness.css'>\n"
+ template += " </head>\n"
+ template += " <body>\n"
+ template += " <div id='log'></div>\n"
+ template += " <script>\n"
+ template += " mediasource_configchange_test('%s', '%s', '%s', '%s');\n"
scherkus (not reviewing) 2013/06/18 01:22:09 given this is a pretty hefty string with a couple
acolwell GONE FROM CHROMIUM 2013/06/18 16:33:45 Done.
+ template += " </script>\n"
+ template += " </body>\n"
+ template += "</html>\n"
+ for test_info in config_change_tests :
+ filename = "../../media-source/mediasource-config-change-%s-%s.html" % (format, test_info[0])
+ idA = encoding_ids[test_info[1]]
+ idB = encoding_ids[test_info[2]]
+ description = test_info[3] % (format)
+ html = template % (format, idA, idB, description)
+ f = open(filename, "wb")
+ f.write(html)
+ f.close()
+
+
+for format in formats:
+ Run("mkdir " + format)
+
+ for settings in encode_settings:
+ video_bitrate = settings['vbr']
+ has_video = (video_bitrate > 0)
+
+ audio_bitrate = settings['abr']
+ has_audio = (audio_bitrate > 0)
+ bitrate = video_bitrate + audio_bitrate
+
+ frame_size = settings['fs']
+ frame_rate = settings['fr']
+ keyframe_rate = settings['kfr']
+ color = settings['c']
+
+ sample_rate = settings['asr']
+ channels = settings['ach']
+ frequency = settings['afreq']
+
+ cmdline = "ffmpeg -y"
+
+ id_prefix = ""
+ id_params = "";
+ if has_audio:
+ id_prefix += "a"
+ id_params += "-%sHz-%sch" % (sample_rate, channels)
+
+ channel_layout = "FC"
+ sin_func = "sin(%s*2*PI*t)" % frequency
+ func = sin_func
+ if channels == 2:
+ channel_layout += "|BC"
+ func += "|" + sin_func
+
+ cmdline += " -f lavfi -i aevalsrc=\"%s:s=%s:c=%s:d=%s\"" % (func, sample_rate, channel_layout, duration)
+
+ if has_video:
+ id_prefix += "v"
+ id_params += "-%s-%sfps-%skfr" % (frame_size, frame_rate, keyframe_rate)
+
+ cmdline += " -f lavfi -i color=%s:duration=%s:size=%s:rate=%s" % (color, duration, frame_size, frame_rate)
+
+ if has_audio:
+ cmdline += " -b:a %sk" % audio_bitrate
+
+ if has_video:
+ cmdline += " -b:v %sk" % video_bitrate
+ cmdline += " -keyint_min %s" % keyframe_rate
+ cmdline += " -g %s" % keyframe_rate
+
+ cmdline += " -vf 'drawtext=fontfile=Mono:fontsize=32:text=Time\\\\:\\\\ %{pts}"
+ cmdline += ",drawtext=fontfile=Mono:fontsize=32:y=32:text=Size\\\\:\\\\ %s" % (frame_size)
+ cmdline += ",drawtext=fontfile=Mono:fontsize=32:y=64:text=Bitrate\\\\:\\\\ %s" % (bitrate)
+ cmdline += ",drawtext=fontfile=Mono:fontsize=32:y=96:text=FrameRate\\\\:\\\\ %s" % (frame_rate)
+ cmdline += ",drawtext=fontfile=Mono:fontsize=32:y=128:text=KeyFrameRate\\\\:\\\\ %s" % (keyframe_rate)
+
+ if has_audio:
+ cmdline += ",drawtext=fontfile=Mono:fontsize=32:y=160:text=SampleRate\\\\:\\\\ %s" % (sample_rate)
+ cmdline += ",drawtext=fontfile=Mono:fontsize=32:y=192:text=Channels\\\\:\\\\ %s" % (channels)
+
+ cmdline += "'"
+
+ encoding_id = "%s-%sk%s" % (id_prefix, bitrate, id_params)
+
+ if len(encoding_ids) < len(encode_settings) :
scherkus (not reviewing) 2013/06/18 01:22:09 remove space before :
acolwell GONE FROM CHROMIUM 2013/06/18 16:33:45 Done.
+ encoding_ids.append(encoding_id)
+
+ filename_base = "%s/test-%s" % (format, encoding_id)
+ media_filename = filename_base + "." + format
+ manifest_filename = filename_base + "-manifest.json"
+
+ cmdline += " " + media_filename
+ Run(cmdline)
+
+ # Remux file so it conforms to MSE bytestream requirements.
+ if format == "webm":
+ tmp_filename = media_filename + ".tmp"
+ Run("mse_webm_remuxer " + media_filename + " " + tmp_filename)
+ Run("mv " + tmp_filename + " " + media_filename)
+ elif format == "mp4":
+ Run("MP4Box -dash 250 -rap " + media_filename)
+ Run("mv " + filename_base + "_dash.mp4" + " " + media_filename)
+ Run("rm " + filename_base + "_dash.mpd")
+
+ GenerateManifest(manifest_filename, format, has_audio, has_video)
+
+ GenerateTestHTML(format, config_change_tests, encoding_ids)

Powered by Google App Engine
This is Rietveld 408576698