From 11883849004bdead3af9e2e51ea3f40d5f985169 Mon Sep 17 00:00:00 2001 From: "fischman@chromium.org" Date: Wed, 8 Feb 2012 00:10:45 +0000 Subject: seek_tester is born: a standalone binary for exploring seek behavior. I got tired of hacking logging into chrome every time I want to answer this question. BUG=none TEST=none Review URL: http://codereview.chromium.org/9355001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@120870 0039d316-1c4b-4281-b951-d872f2087c98 --- media/media.gyp | 11 +++++ media/tools/seek_tester/seek_tester.cc | 85 ++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 media/tools/seek_tester/seek_tester.cc (limited to 'media') diff --git a/media/media.gyp b/media/media.gyp index 242a039..215191b 100644 --- a/media/media.gyp +++ b/media/media.gyp @@ -697,6 +697,17 @@ 'tools/qt_faststart/qt_faststart.c' ], }, + { + 'target_name': 'seek_tester', + 'type': 'executable', + 'dependencies': [ + 'media', + '../base/base.gyp:base', + ], + 'sources': [ + 'tools/seek_tester/seek_tester.cc', + ], + }, ], 'conditions': [ ['OS=="win"', { diff --git a/media/tools/seek_tester/seek_tester.cc b/media/tools/seek_tester/seek_tester.cc new file mode 100644 index 0000000..17b03ea --- /dev/null +++ b/media/tools/seek_tester/seek_tester.cc @@ -0,0 +1,85 @@ +// 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. +// +// This standalone binary is a helper for diagnosing seek behavior of the +// demuxer setup in media/ code. It answers the question: "if I ask the demuxer +// to Seek to X ms, where will it actually seek to? (necessitating +// frame-dropping until the original seek target is reached)". Sample run: +// +// $ ./out/Debug/seek_tester .../LayoutTests/media/content/test.ogv 6300 +// [0207/130327:INFO:seek_tester.cc(63)] Requested: 6123ms +// [0207/130327:INFO:seek_tester.cc(68)] audio seeked to: 5526ms +// [0207/130327:INFO:seek_tester.cc(74)] video seeked to: 5577ms + + +#include "base/at_exit.h" +#include "base/bind.h" +#include "base/logging.h" +#include "base/message_loop.h" +#include "base/string_number_conversions.h" +#include "media/base/media.h" +#include "media/filters/ffmpeg_demuxer.h" +#include "media/filters/file_data_source.h" + +void QuitMessageLoop(MessageLoop* loop, media::PipelineStatus status) { + CHECK_EQ(status, media::PIPELINE_OK); + loop->PostTask(FROM_HERE, MessageLoop::QuitClosure()); +} + +void TimestampExtractor(uint64* timestamp_ms, + MessageLoop* loop, + const scoped_refptr& buffer) { + if (buffer->GetTimestamp() == media::kNoTimestamp()) + *timestamp_ms = -1; + else + *timestamp_ms = buffer->GetTimestamp().InMillisecondsF(); + loop->PostTask(FROM_HERE, MessageLoop::QuitClosure()); +} + +int main(int argc, char** argv) { + base::AtExitManager at_exit; + media::InitializeMediaLibraryForTesting(); + + CHECK_EQ(argc, 3) << "\nUsage: " << argv[0] << " "; + uint64 seek_target_ms; + CHECK(base::StringToUint64(argv[2], &seek_target_ms)); + scoped_refptr file_data_source( + new media::FileDataSource()); + CHECK_EQ(file_data_source->Initialize(argv[1]), media::PIPELINE_OK); + + MessageLoop loop; + media::PipelineStatusCB quitter = base::Bind(&QuitMessageLoop, &loop); + scoped_refptr demuxer( + new media::FFmpegDemuxer(&loop, true)); + demuxer->Initialize(file_data_source, quitter); + loop.Run(); + + demuxer->Seek(base::TimeDelta::FromMilliseconds(seek_target_ms), quitter); + loop.Run(); + + uint64 audio_seeked_to_ms; + uint64 video_seeked_to_ms; + scoped_refptr audio_stream( + demuxer->GetStream(media::DemuxerStream::AUDIO)); + scoped_refptr video_stream( + demuxer->GetStream(media::DemuxerStream::VIDEO)); + LOG(INFO) << "Requested: " << seek_target_ms << "ms"; + if (audio_stream) { + audio_stream->Read(base::Bind( + &TimestampExtractor, &audio_seeked_to_ms, &loop)); + loop.Run(); + LOG(INFO) << " audio seeked to: " << audio_seeked_to_ms << "ms"; + } + if (video_stream) { + video_stream->Read( + base::Bind(&TimestampExtractor, &video_seeked_to_ms, &loop)); + loop.Run(); + LOG(INFO) << " video seeked to: " << video_seeked_to_ms << "ms"; + } + + demuxer->Stop(base::Bind(&MessageLoop::Quit, base::Unretained(&loop))); + loop.Run(); + + return 0; +} -- cgit v1.1