summaryrefslogtreecommitdiffstats
path: root/media/player
diff options
context:
space:
mode:
authorfbarchard@chromium.org <fbarchard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-04 21:12:08 +0000
committerfbarchard@chromium.org <fbarchard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-04 21:12:08 +0000
commitfee00934a491edf64b615cc5d34a01de17736fec (patch)
treefcbf3eb74162a4117ad34ef9f72b7ea0a4f82f0e /media/player
parentbfe979e1cc07e94096dd4a63f013c907d1d986a6 (diff)
downloadchromium_src-fee00934a491edf64b615cc5d34a01de17736fec.zip
chromium_src-fee00934a491edf64b615cc5d34a01de17736fec.tar.gz
chromium_src-fee00934a491edf64b615cc5d34a01de17736fec.tar.bz2
media player movie functions to bind WTL menu events to pipeline.
Review URL: http://codereview.chromium.org/102002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15240 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/player')
-rw-r--r--media/player/movie.cc111
-rw-r--r--media/player/movie.h62
-rw-r--r--media/player/view.h25
3 files changed, 192 insertions, 6 deletions
diff --git a/media/player/movie.cc b/media/player/movie.cc
new file mode 100644
index 0000000..08651cc
--- /dev/null
+++ b/media/player/movie.cc
@@ -0,0 +1,111 @@
+// Copyright (c) 2009 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/at_exit.h"
+#include "base/string_util.h"
+#include "media/base/factory.h"
+#include "media/base/pipeline_impl.h"
+#include "media/filters/audio_renderer_impl.h"
+#include "media/filters/ffmpeg_audio_decoder.h"
+#include "media/filters/ffmpeg_demuxer.h"
+#include "media/filters/ffmpeg_video_decoder.h"
+#include "media/filters/file_data_source.h"
+#include "media/filters/null_audio_renderer.h"
+#include "media/player/movie.h"
+#include "media/player/stdafx.h"
+#include "media/player/wtl_renderer.h"
+// view.h must come after wtl_renderer.h.
+#include "media/player/view.h"
+
+using media::AudioRendererImpl;
+using media::FFmpegAudioDecoder;
+using media::FFmpegDemuxer;
+using media::FFmpegVideoDecoder;
+using media::FileDataSource;
+using media::FilterFactoryCollection;
+using media::PipelineImpl;
+
+namespace media {
+
+Movie::Movie()
+ : enable_audio_(true),
+ play_rate_(1.0f),
+ movie_dib_(NULL),
+ movie_hwnd_(0) {
+}
+
+Movie::~Movie() {
+}
+
+bool Movie::IsOpen() {
+ return pipeline_.get() != NULL;
+}
+
+void Movie::SetFrameBuffer(HBITMAP hbmp, HWND hwnd) {
+ movie_dib_ = hbmp;
+ movie_hwnd_ = hwnd;
+}
+
+bool Movie::Open(const wchar_t* url, WtlVideoRenderer* video_renderer) {
+ // Close previous movie.
+ if (pipeline_.get()) {
+ Close();
+ }
+
+ // Create our filter factories.
+ scoped_refptr<FilterFactoryCollection> factories =
+ new FilterFactoryCollection();
+ factories->AddFactory(FileDataSource::CreateFactory());
+ factories->AddFactory(FFmpegAudioDecoder::CreateFactory());
+ factories->AddFactory(FFmpegDemuxer::CreateFilterFactory());
+ factories->AddFactory(FFmpegVideoDecoder::CreateFactory());
+
+ if (enable_audio_) {
+ factories->AddFactory(AudioRendererImpl::CreateFilterFactory());
+ } else {
+ factories->AddFactory(media::NullAudioRenderer::CreateFilterFactory());
+ }
+ factories->AddFactory(
+ new media::InstanceFilterFactory<WtlVideoRenderer>(video_renderer));
+
+ pipeline_.reset(new PipelineImpl());
+
+ // Create and start our pipeline.
+ pipeline_->Start(factories.get(), WideToUTF8(std::wstring(url)), NULL);
+ while (true) {
+ PlatformThread::Sleep(100);
+ if (pipeline_->IsInitialized())
+ break;
+ if (pipeline_->GetError() != media::PIPELINE_OK)
+ return false;
+ }
+ pipeline_->SetPlaybackRate(play_rate_);
+ return true;
+}
+
+void Movie::Play(float rate) {
+ // Begin playback.
+ if (pipeline_.get())
+ pipeline_->SetPlaybackRate(rate);
+ if (rate > 0.0f)
+ play_rate_ = rate;
+}
+
+void Movie::SetAudioEnable(bool enable_audio) {
+ enable_audio_ = enable_audio;
+}
+
+bool Movie::GetAudioEnable() {
+ return enable_audio_;
+}
+
+// Teardown.
+void Movie::Close() {
+ if (pipeline_.get()) {
+ pipeline_->Stop();
+ pipeline_.reset();
+ }
+}
+
+} // namespace media
diff --git a/media/player/movie.h b/media/player/movie.h
new file mode 100644
index 0000000..f6d79be
--- /dev/null
+++ b/media/player/movie.h
@@ -0,0 +1,62 @@
+// Copyright (c) 2009 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.
+
+// Movie class for WTL forms to call to control the media pipeline.
+
+#ifndef MEDIA_PLAYER_MOVIE_H_
+#define MEDIA_PLAYER_MOVIE_H_
+
+#include <tchar.h>
+
+#include "base/scoped_ptr.h"
+#include "base/singleton.h"
+
+class WtlVideoRenderer;
+
+namespace media {
+
+class PipelineImpl;
+
+class Movie : public Singleton<Movie> {
+ public:
+ // Open a movie.
+ bool Open(const wchar_t* url, WtlVideoRenderer* video_renderer);
+
+ // Set playback rate.
+ void Play(float rate);
+
+ // Enable/Disable audio.
+ void SetAudioEnable(bool enable_audio);
+
+ // Get Enable/Disable audio state.
+ bool GetAudioEnable();
+
+ // Set buffer to render into.
+ void SetFrameBuffer(HBITMAP hbmp, HWND hwnd);
+
+ // Close movie.
+ void Close();
+
+ // Query if movie is currently open.
+ bool IsOpen();
+
+ private:
+ // Only allow Singleton to create and delete Movie.
+ friend struct DefaultSingletonTraits<Movie>;
+ Movie();
+ virtual ~Movie();
+
+ scoped_ptr<PipelineImpl> pipeline_;
+ HBITMAP movie_dib_;
+ HWND movie_hwnd_;
+ bool enable_audio_;
+ float play_rate_;
+
+ DISALLOW_COPY_AND_ASSIGN(Movie);
+};
+
+} // namespace media
+
+#endif // MEDIA_PLAYER_MOVIE_H_
+
diff --git a/media/player/view.h b/media/player/view.h
index fb4c5b4..6d36c92 100644
--- a/media/player/view.h
+++ b/media/player/view.h
@@ -29,8 +29,6 @@
#include "media/base/yuv_scale.h"
#include "media/player/wtl_renderer.h"
-#include "media/player/movie.h"
-
#ifdef TESTING
// Fetch current time as milliseconds.
// Return as double for high duration and precision.
@@ -45,7 +43,6 @@ static inline double GetTime() {
extern bool g_enableswscaler;
extern bool g_enabledraw;
extern bool g_enabledump_yuv_file;
-extern int g_view_size;
class WtlVideoWindow : public CScrollWindowImpl<WtlVideoWindow> {
public:
@@ -59,8 +56,10 @@ class WtlVideoWindow : public CScrollWindowImpl<WtlVideoWindow> {
WtlVideoWindow() {
size_.cx = 0;
size_.cy = 0;
+ view_size_ = 1;
renderer_ = new WtlVideoRenderer(this);
last_frame_ = NULL;
+ hbmp_ = NULL;
}
BOOL PreTranslateMessage(MSG* /*msg*/) {
@@ -162,7 +161,7 @@ class WtlVideoWindow : public CScrollWindowImpl<WtlVideoWindow> {
int scaled_width = clipped_width;
int scaled_height = clipped_height;
- switch (g_view_size) {
+ switch (view_size_) {
case 0:
scaled_width = clipped_width / 2;
scaled_height = clipped_height / 2;
@@ -266,7 +265,7 @@ class WtlVideoWindow : public CScrollWindowImpl<WtlVideoWindow> {
#endif
CDC dcMem;
dcMem.CreateCompatibleDC(dc);
- HBITMAP hBmpOld = dcMem.SelectBitmap(bmp_);
+ HBITMAP hBmpOld = hbmp_ ? hbmp_: dcMem.SelectBitmap(bmp_);
dc.BitBlt(0, 0, size_.cx, size_.cy, dcMem, 0, 0, SRCCOPY);
dcMem.SelectBitmap(hBmpOld);
#ifdef TESTING
@@ -288,11 +287,25 @@ class WtlVideoWindow : public CScrollWindowImpl<WtlVideoWindow> {
}
} // End of DoPaint function.
+ void SetViewSize(int view_size) {
+ view_size_ = view_size;
+ }
+
+ int GetViewSize() {
+ return view_size_;
+ }
+
+ void SetBitmap(HBITMAP hbmp) {
+ hbmp_ = hbmp;
+ }
+
CBitmap bmp_; // Used by mainfrm.h.
SIZE size_; // Used by WtlVideoWindow.
scoped_refptr<WtlVideoRenderer> renderer_; // Used by WtlVideoWindow.
private:
+ HBITMAP hbmp_; // For Images
+ int view_size_; // View Size. 0=0.5, 1=normal, 2=2x, 3=fit, 4=full
// Draw a frame of YUV to an RGB buffer with scaling.
// Handles different YUV formats.
@@ -304,7 +317,7 @@ class WtlVideoWindow : public CScrollWindowImpl<WtlVideoWindow> {
int scaled_width,
int scaled_height) {
// Normal size
- if (g_view_size == 1) {
+ if (view_size_ == 1) {
if (frame_in.format == media::VideoSurface::YV16) {
// Temporary cast, til we use uint8 for VideoFrame.
media::ConvertYV16ToRGB32((const uint8*)frame_in.data[0],