blob: 8403a76ec200ff89c3dc3e5953f58d0cc7e93c40 [file] [log] [blame]
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import logging
import os
from autotest_lib.client.bin import utils
from autotest_lib.client.common_lib import error
from import audio_helper
from import cmd_utils
from import cras_utils
class audio_YoutubePlayback(audio_helper.chrome_rms_test):
"""Verifies if youtube playback can be captured."""
version = 1
def play_video(self, tab, video_url):
"""Plays a Youtube video to record audio samples.
@param tab: the tab to load and play the video.
def player_is_ready():
"""Returns whether the player is ready."""
return tab.EvaluateJavaScript('typeof player != "undefined"')
exception=error.TestError('Failed to load the Youtube player'))
# Make sure the video is playing
def get_current_time():
"""Returns current time."""
return tab.EvaluateJavaScript('player.getCurrentTime()')
old_time = get_current_time()
condition=lambda: get_current_time() > old_time,
exception=error.TestError('Video is not played until timeout'))
def run_once(self):
"""Entry point of this test."""
video_url =
os.path.join(self.bindir, 'youtube.html'))'Playing back youtube media file %s.', video_url)
noise_file = os.path.join(self.resultsdir, "noise.wav")
recorded_file = os.path.join(self.resultsdir, "recorded.wav")
loopback_file = os.path.join(self.resultsdir, "loopback.wav")
# Record a sample of "silence" to use as a noise profile.
cras_utils.capture(noise_file, duration=3)
# Play a video and record the audio output
self.play_video([0], video_url)
p1 = cmd_utils.popen(cras_utils.capture_cmd(
recorded_file, duration=TEST_DURATION))
p2 = cmd_utils.popen(cras_utils.loopback_cmd(
loopback_file, duration=TEST_DURATION))
cmd_utils.wait_and_check_returncode(p1, p2)
# See if we recorded something
loopback_stats = [audio_helper.get_channel_sox_stat(
loopback_file, i) for i in (1, 2)]'loopback stats: %s', [str(s) for s in loopback_stats])
rms_value = audio_helper.reduce_noise_and_get_rms(
recorded_file, noise_file)[0]
self.write_perf_keyval({'rms_value': rms_value})