/*
Copyright (C) 2010, Heikki Salo
All rights reserved.
Distributed under the BSD license:
http://www.opensource.org/licenses/bsd-license.php
*/
#ifndef DP_MEDIA_HPP
#define DP_MEDIA_HPP
#include "stdafx.h"
#include <mfapi.h>
#include <mfidl.h>
#include <mferror.h>
#include <evr.h>
#include <Shlwapi.h>
const UINT WM_DP_MEDIAEVENT = WM_USER + 1;
class DPWindow;
class DPTexture;
class DPMedia : boost::noncopyable {
public:
~DPMedia();
DPMedia(python::object&, DPWindow*);
void play();
void setPosition(MFTIME);
void pause();
python::object getVideoSize();
DPTexture* getTexture();
UINT64 getPosition();
UINT64 getDuration();
python::object getEvents();
bool hasVideo() { return videoDisplay != 0;}
bool hasAudio() { return audioVolume != 0;}
float getVolume();
void setVolume(float);
void release();
void repaint();
void resize(UINT, UINT);
void onEvent(IMFMediaEvent*, MediaEventType);
DPWindow* getWindow() { return window; }
void setWindow(DPWindow* win) { window = win; }
private:
friend class DPMediaAsyncCallback;
void AddBranchToPartialTopology(IMFTopology*, IMFPresentationDescriptor*, DWORD, HWND);
void CreateSourceStreamNode(IMFMediaSource*, IMFPresentationDescriptor*, IMFStreamDescriptor*, IMFTopologyNode**);
void CreateOutputNode(IMFStreamDescriptor*, HWND, IMFTopologyNode**);
void topologyReady();
IMFMediaSession* mediaSession;
IMFMediaSource* mediaSource;
IMFVideoDisplayControl* videoDisplay;
IMFSimpleAudioVolume* audioVolume;
DPWindow* window;
};
class DPMediaAsyncCallback : public IMFAsyncCallback {
public:
static DPMediaAsyncCallback* createNew(DPMedia*);
STDMETHODIMP QueryInterface(REFIID, void**);
STDMETHODIMP_(ULONG) AddRef();
STDMETHODIMP_(ULONG) Release();
//Optional.
STDMETHODIMP GetParameters(DWORD*, DWORD*) { return E_NOTIMPL; }
STDMETHODIMP Invoke(IMFAsyncResult*);
private:
virtual ~DPMediaAsyncCallback();
DPMediaAsyncCallback(DPMedia* arg) { media = arg; refCount = 1; }
DPMedia* media;
long refCount;
};
#endif