summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
Diffstat (limited to 'media')
-rw-r--r--media/media.gyp2
-rw-r--r--media/tools/player_x11/data_source_logger.cc74
-rw-r--r--media/tools/player_x11/data_source_logger.h42
-rw-r--r--media/tools/player_x11/player_x11.cc58
4 files changed, 146 insertions, 30 deletions
diff --git a/media/media.gyp b/media/media.gyp
index cbbfec7..0b3785d 100644
--- a/media/media.gyp
+++ b/media/media.gyp
@@ -835,6 +835,8 @@
],
},
'sources': [
+ 'tools/player_x11/data_source_logger.cc',
+ 'tools/player_x11/data_source_logger.h',
'tools/player_x11/gl_video_renderer.cc',
'tools/player_x11/gl_video_renderer.h',
'tools/player_x11/player_x11.cc',
diff --git a/media/tools/player_x11/data_source_logger.cc b/media/tools/player_x11/data_source_logger.cc
new file mode 100644
index 0000000..8e1df01
--- /dev/null
+++ b/media/tools/player_x11/data_source_logger.cc
@@ -0,0 +1,74 @@
+// 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.
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "media/tools/player_x11/data_source_logger.h"
+
+static void LogAndRunStopClosure(const base::Closure& closure) {
+ VLOG(1) << "Stop() finished";
+ closure.Run();
+}
+
+static void LogAndRunReadCallback(
+ int64 position, size_t size,
+ const media::DataSource::ReadCallback& read_cb, size_t result) {
+ VLOG(1) << "Read(" << position << ", " << size << ") -> " << result;
+ read_cb.Run(result);
+}
+
+DataSourceLogger::DataSourceLogger(
+ const scoped_refptr<media::DataSource>& data_source,
+ bool streaming)
+ : data_source_(data_source),
+ streaming_(streaming) {
+}
+
+DataSourceLogger::~DataSourceLogger() {}
+
+void DataSourceLogger::set_host(media::DataSourceHost* host) {
+ VLOG(1) << "set_host(" << host << ")";
+ data_source_->set_host(host);
+}
+
+void DataSourceLogger::Stop(const base::Closure& closure) {
+ VLOG(1) << "Stop() started";
+ data_source_->Stop(base::Bind(&LogAndRunStopClosure, closure));
+}
+
+void DataSourceLogger::Read(
+ int64 position, size_t size, uint8* data,
+ const media::DataSource::ReadCallback& read_cb) {
+ VLOG(1) << "Read(" << position << ", " << size << ")";
+ data_source_->Read(position, size, data, base::Bind(
+ &LogAndRunReadCallback, position, size, read_cb));
+}
+
+bool DataSourceLogger::GetSize(int64* size_out) {
+ bool success = data_source_->GetSize(size_out);
+ VLOG(1) << "GetSize() -> " << (success ? "true" : "false")
+ << ", " << *size_out;
+ return success;
+}
+
+bool DataSourceLogger::IsStreaming() {
+ if (streaming_) {
+ VLOG(1) << "IsStreaming() -> true (overridden)";
+ return true;
+ }
+
+ bool streaming = data_source_->IsStreaming();
+ VLOG(1) << "IsStreaming() -> " << (streaming ? "true" : "false");
+ return streaming;
+}
+
+void DataSourceLogger::SetPreload(media::Preload preload) {
+ VLOG(1) << "SetPreload(" << preload << ")";
+ data_source_->SetPreload(preload);
+}
+
+void DataSourceLogger::SetBitrate(int bitrate) {
+ VLOG(1) << "SetBitrate(" << bitrate << ")";
+ data_source_->SetBitrate(bitrate);
+}
diff --git a/media/tools/player_x11/data_source_logger.h b/media/tools/player_x11/data_source_logger.h
new file mode 100644
index 0000000..af01e13
--- /dev/null
+++ b/media/tools/player_x11/data_source_logger.h
@@ -0,0 +1,42 @@
+// 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.
+
+#ifndef MEDIA_TOOLS_PLAYER_X11_DATA_SOURCE_LOGGER_H_
+#define MEDIA_TOOLS_PLAYER_X11_DATA_SOURCE_LOGGER_H_
+
+#include "media/base/data_source.h"
+
+// Logs all DataSource operations to VLOG(1) for debugging purposes.
+class DataSourceLogger : public media::DataSource {
+ public:
+ // Constructs a DataSourceLogger to log operations against another DataSource.
+ //
+ // |data_source| must be initialized in advance.
+ //
+ // |streaming| when set to true will override the implementation
+ // IsStreaming() to always return true, otherwise it will delegate to
+ // |data_source|.
+ DataSourceLogger(const scoped_refptr<DataSource>& data_source,
+ bool force_streaming);
+ virtual ~DataSourceLogger();
+
+ // media::DataSource implementation.
+ virtual void set_host(media::DataSourceHost* host) OVERRIDE;
+ virtual void Stop(const base::Closure& closure) OVERRIDE;
+ virtual void Read(
+ int64 position, size_t size, uint8* data,
+ const media::DataSource::ReadCallback& read_cb) OVERRIDE;
+ virtual bool GetSize(int64* size_out) OVERRIDE;
+ virtual bool IsStreaming() OVERRIDE;
+ virtual void SetPreload(media::Preload preload) OVERRIDE;
+ virtual void SetBitrate(int bitrate) OVERRIDE;
+
+ private:
+ scoped_refptr<media::DataSource> data_source_;
+ bool streaming_;
+
+ DISALLOW_COPY_AND_ASSIGN(DataSourceLogger);
+};
+
+#endif // MEDIA_TOOLS_PLAYER_X11_DATA_SOURCE_LOGGER_H_
diff --git a/media/tools/player_x11/player_x11.cc b/media/tools/player_x11/player_x11.cc
index 42919ba..3cbe6c6 100644
--- a/media/tools/player_x11/player_x11.cc
+++ b/media/tools/player_x11/player_x11.cc
@@ -29,6 +29,7 @@
#include "media/filters/file_data_source.h"
#include "media/filters/null_audio_renderer.h"
#include "media/filters/video_renderer_base.h"
+#include "media/tools/player_x11/data_source_logger.h"
#include "media/tools/player_x11/gl_video_renderer.h"
#include "media/tools/player_x11/x11_video_renderer.h"
@@ -52,6 +53,14 @@ class MessageLoopQuitter {
DISALLOW_COPY_AND_ASSIGN(MessageLoopQuitter);
};
+scoped_refptr<media::FileDataSource> CreateFileDataSource(
+ const std::string& file) {
+ scoped_refptr<media::FileDataSource> file_data_source(
+ new media::FileDataSource());
+ CHECK_EQ(file_data_source->Initialize(file), media::PIPELINE_OK);
+ return file_data_source;
+}
+
// Initialize X11. Returns true if successful. This method creates the X11
// window. Further initialization is done in X11VideoRenderer.
bool InitX11() {
@@ -97,7 +106,7 @@ void Paint(MessageLoop* message_loop, const PaintCB& paint_cb) {
// TODO(vrk): Re-enabled audio. (crbug.com/112159)
bool InitPipeline(MessageLoop* message_loop,
- const char* filename,
+ const scoped_refptr<media::DataSource>& data_source,
const PaintCB& paint_cb,
bool /* enable_audio */,
scoped_refptr<media::Pipeline>* pipeline,
@@ -109,13 +118,6 @@ bool InitPipeline(MessageLoop* message_loop,
return false;
}
- // Open the file.
- scoped_refptr<media::FileDataSource> data_source =
- new media::FileDataSource();
- if (data_source->Initialize(filename) != media::PIPELINE_OK) {
- return false;
- }
-
// Create our filter factories.
scoped_ptr<media::FilterCollection> collection(
new media::FilterCollection());
@@ -138,7 +140,7 @@ bool InitPipeline(MessageLoop* message_loop,
*pipeline = new media::Pipeline(message_loop, new media::MediaLog());
media::PipelineStatusNotification note;
(*pipeline)->Start(
- collection.Pass(), filename, media::PipelineStatusCB(),
+ collection.Pass(), "", media::PipelineStatusCB(),
media::PipelineStatusCB(), media::NetworkEventCB(),
note.Callback());
@@ -225,31 +227,26 @@ void PeriodicalUpdate(
int main(int argc, char** argv) {
base::AtExitManager at_exit;
+ CommandLine::Init(argc, argv);
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ std::string filename = command_line->GetSwitchValueASCII("file");
- scoped_refptr<AudioManager> audio_manager(AudioManager::Create());
- g_audio_manager = audio_manager;
-
- // Read arguments.
- if (argc == 1) {
+ if (filename.empty()) {
std::cout << "Usage: " << argv[0] << " --file=FILE" << std::endl
<< std::endl
<< "Optional arguments:" << std::endl
<< " [--audio]"
<< " [--alsa-device=DEVICE]"
- << " [--use-gl]" << std::endl
+ << " [--use-gl]"
+ << " [--streaming]" << std::endl
<< " Press [ESC] to stop" << std::endl
<< " Press [SPACE] to toggle pause/play" << std::endl
<< " Press mouse left button to seek" << std::endl;
return 1;
}
- // Read command line.
- CommandLine::Init(argc, argv);
- std::string filename =
- CommandLine::ForCurrentProcess()->GetSwitchValueASCII("file");
- bool enable_audio = CommandLine::ForCurrentProcess()->HasSwitch("audio");
- bool use_gl = CommandLine::ForCurrentProcess()->HasSwitch("use-gl");
- bool audio_only = false;
+ scoped_refptr<AudioManager> audio_manager(AudioManager::Create());
+ g_audio_manager = audio_manager;
logging::InitLogging(
NULL,
@@ -276,7 +273,7 @@ int main(int argc, char** argv) {
thread->Start();
PaintCB paint_cb;
- if (use_gl) {
+ if (command_line->HasSwitch("use-gl")) {
paint_cb = base::Bind(
&GlVideoRenderer::Paint, new GlVideoRenderer(g_display, g_window));
} else {
@@ -284,17 +281,18 @@ int main(int argc, char** argv) {
&X11VideoRenderer::Paint, new X11VideoRenderer(g_display, g_window));
}
- if (InitPipeline(thread->message_loop(), filename.c_str(),
- paint_cb, enable_audio, &pipeline, &message_loop,
- message_loop_factory.get())) {
+ scoped_refptr<media::DataSource> data_source(
+ new DataSourceLogger(CreateFileDataSource(filename),
+ command_line->HasSwitch("streaming")));
+
+ if (InitPipeline(thread->message_loop(), data_source,
+ paint_cb, command_line->HasSwitch("audio"),
+ &pipeline, &message_loop, message_loop_factory.get())) {
// Main loop of the application.
g_running = true;
- // Check if video is present.
- audio_only = !pipeline->HasVideo();
-
message_loop.PostTask(FROM_HERE, base::Bind(
- &PeriodicalUpdate, pipeline, &message_loop, audio_only));
+ &PeriodicalUpdate, pipeline, &message_loop, !pipeline->HasVideo()));
message_loop.Run();
} else {
std::cout << "Pipeline initialization failed..." << std::endl;