How to play video file asychronously with chunk of buffer?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



hi,
I am playing video file synchronously on window mobile m 6.0.
I want to play video file asynchronously with chunk of buffer.
Does any have idea about that?

here is my code.


// ChildView.h : interface of the CChildView class
//


#ifndef __CHILDVIEW__
#define __CHILDVIEW__

#include <streams.h> // link against Strmiids.lib for IDD , CLSID

// CChildView window

class CChildView : public CWnd
{
// Construction
public:
CChildView();

// Attributes
public:

// Operations
public:

// Overrides
protected:
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);

// Implementation
public:
virtual ~CChildView();

// Generated message map functions
protected:
afx_msg void OnPaint();
afx_msg LRESULT OnGraphNotify(WPARAM, LPARAM);
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnVideoPlay();
afx_msg int OnCreate( LPCREATESTRUCT );
afx_msg void OnSize( UINT, int, int);

public:
HRESULT Initialize(LPCTSTR);
void CleanUp();
void ResizeVideoWindow();

private:
IGraphBuilder* m_pGraph;
IBaseFilter* m_pBaseFilter;
IFileSourceFilter* m_pSource;
IAsyncReader* m_pAsyncReader;
IMediaControl* m_pControl;
IMediaEventEx* m_pEvent;
IVideoWindow* m_pVideoWindow; // For full screen window.
public:
afx_msg void OnVideoPause();
afx_msg void OnVideoStop();
afx_msg void OnVideoOpen();
};

#endif // __CHILDVIEW__




// ChildView.cpp : implementation of the CChildView class
//

#include "stdafx.h"
#include "VideoTest1.h"
#include "ChildView.h"

#define WM_GRAPHNOTIFY WM_APP + 1

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CChildView
CChildView::CChildView()
:m_pGraph(NULL),
m_pControl(NULL),
m_pEvent(NULL),
m_pVideoWindow(NULL)
{
}



CChildView::~CChildView()
{
CleanUp();
}



BEGIN_MESSAGE_MAP(CChildView, CWnd)
ON_WM_PAINT()
ON_WM_CREATE()
ON_WM_SIZE()
ON_COMMAND(ID_VIDEO_PLAY, &CChildView::OnVideoPlay)
ON_MESSAGE(WM_GRAPHNOTIFY, &CChildView::OnGraphNotify)
ON_COMMAND(ID_VIDEO_PAUSE, &CChildView::OnVideoPause)
ON_COMMAND(ID_VIDEO_STOP, &CChildView::OnVideoStop)
ON_COMMAND(ID_VIDEO_OPEN, &CChildView::OnVideoOpen)
END_MESSAGE_MAP()



// CChildView message handlers

BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs)
{
if (!CWnd::PreCreateWindow(cs))
return FALSE;

cs.style &= ~WS_BORDER;
cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS,
::LoadCursor(NULL, IDC_ARROW), reinterpret_cast<HBRUSH>(COLOR_WINDOW+1),
NULL);

return TRUE;
}

void CChildView::OnPaint()
{
CPaintDC dc(this); // device context for painting

// TODO: Add your message handler code here

// Do not call CWnd::OnPaint() for painting messages
}


LRESULT CChildView::OnGraphNotify(WPARAM wParam, LPARAM lParam)
{
if( m_pEvent == NULL){
return 0;
}
long evCode, param1, param2;
HRESULT hr;
while (hr = m_pEvent->GetEvent(&evCode, &param1, &param2, 0), SUCCEEDED(hr))
{
hr = m_pEvent->FreeEventParams(evCode, param1, param2);
switch(evCode)
{
case EC_COMPLETE:
case EC_USERABORT:
case EC_ERRORABORT:
{
CleanUp();
break;
}
default:
break;
}
}
return 0;
}





int CChildView::OnCreate( LPCREATESTRUCT lpStruct)
{
if ( CWnd::OnCreate(lpStruct) != 0)
return (-1);
return 0;
}


void CChildView ::ResizeVideoWindow()
{
// resize it.
if ( m_pVideoWindow ){
// resize it.
CRect window_rect;
GetWindowRect(&window_rect);
// caculte new position for video window.
window_rect.top += static_cast<int>(window_rect.Height()*0.05);
window_rect.left += static_cast<int>(window_rect.Width()*0.05);
window_rect.bottom = window_rect.top +
static_cast<int>(window_rect.Height()*0.85);
window_rect.right = window_rect.left +
static_cast<int>(window_rect.Width()*0.85);
m_pVideoWindow->SetWindowPosition(window_rect.left, window_rect.top,
window_rect.Width(), window_rect.Height());
}
}



void CChildView::OnSize( UINT, int, int)
{
ResizeVideoWindow();
}



//
HRESULT CChildView::Initialize(LPCTSTR aFilePath)
{
// Initialize the COM library.
HRESULT hr = CoInitialize(NULL);
if (FAILED(hr)){
// ERROR - Could not initialize COM library;
return(-1);
}

// Create the filter graph manager and query for interfaces.
hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
IID_IGraphBuilder, (void **)&m_pGraph);
if (FAILED(hr)){
// "ERROR - Could not create the Filter Graph Manager.";
CleanUp();
return(-1);
}

hr = m_pGraph->QueryInterface(IID_IMediaControl, (void **)&m_pControl);
if (FAILED(hr)){
// "ERROR - Could not create media control.";
CleanUp();
return(-1);
}
/*

//
hr = CoCreateInstance(CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER,
IID_IBaseFilter, (void **)&m_pBaseFilter);
if (FAILED(hr)){
// ERROR - Could not create media control event.;
CleanUp();
return(-1);
}

// add filter.
hr = m_pGraph->AddFilter(m_pBaseFilter, NULL);
if (FAILED(hr)){
// ERROR - Could not create media control event.;
CleanUp();
return(-1);
}
//
hr = m_pBaseFilter->QueryInterface(IID_IFileSourceFilter, (void
**)&m_pSource);
if (FAILED(hr)){
// ERROR - Could not create media control event.;
CleanUp();
return(-1);
}
*/

hr = m_pGraph->QueryInterface(IID_IMediaEvent, (void **)&m_pEvent);
if (FAILED(hr)){
// ERROR - Could not create media control event.;
CleanUp();
return(-1);
}

// Set the owner window to receive event notices.
m_pEvent->SetNotifyWindow((OAHWND)GetSafeHwnd(), WM_GRAPHNOTIFY, 0);

// Build the graph. IMPORTANT: Change this string to a file on your system.
//hr = m_pGraph->RenderFile(L"\\My Documents\\My Pictures\\VIDEO_001.mp4",
NULL);
hr = m_pGraph->RenderFile(aFilePath, NULL);
//hr = m_pSource->Load(aFilePath, NULL);
if (FAILED(hr)){
// "ERROR - Could not create graph." ;
CleanUp();
return(-1);
}

/*
IEnumPins *pEnum = NULL;
IPin *pPin = NULL;
PIN_DIRECTION PinDirThis = PINDIR_INPUT;

m_pBaseFilter->EnumPins(&pEnum);
while(pEnum->Next(1, &pPin, 0) == S_OK)
{
pPin->QueryDirection(&PinDirThis);
if (PINDIR_OUTPUT == PinDirThis)
{
hr = m_pGraph->Render(pPin);
if (FAILED(hr)){
pPin->Release();
// "ERROR - Could not create graph." ;
CleanUp();
return(-1);
}
}
pPin->Release();
}
*/

// get video window.
hr = m_pGraph->QueryInterface(IID_IVideoWindow, (LPVOID *)&m_pVideoWindow);
if (FAILED(hr)){
// "ERROR - Could not create video window." ;
CleanUp();
return(-1);
}
// set video window owner.
m_pVideoWindow->put_Owner((OAHWND)GetSafeHwnd());
// set video window style.
m_pVideoWindow->put_WindowStyle( WS_CHILD | WS_CLIPSIBLINGS);
// resize video window.
ResizeVideoWindow();
// sucess.
return 0;
}



void CChildView::CleanUp()
{
if( m_pVideoWindow ){
m_pControl->Stop();
m_pVideoWindow->put_Visible(OAFALSE);
m_pVideoWindow->put_Owner(NULL);
m_pVideoWindow->Release();
m_pVideoWindow = NULL;
}
if( m_pControl){
m_pControl->Release();
m_pControl = NULL;
}
if( m_pEvent ){
// Disable event notification before releasing the graph.
m_pEvent->SetNotifyWindow( NULL, 0 ,0);
m_pEvent->Release();
m_pEvent = NULL;
}
if( m_pGraph ){
m_pGraph->Release();
m_pGraph = NULL;
}
if( m_pBaseFilter ){
m_pBaseFilter->Release();
m_pBaseFilter = NULL;
}
if( m_pSource ){
m_pSource->Release();
m_pSource = NULL;
}
if( m_pAsyncReader ){
m_pAsyncReader->Release();
m_pAsyncReader = NULL;
}
::CoUninitialize();
}



void CChildView::OnVideoPause()
{
// TODO: Add your command handler code here
HRESULT hr = NULL;
hr = m_pControl->Pause();
}



void CChildView::OnVideoStop()
{
// TODO: Add your command handler code here
HRESULT hr = NULL;
hr = m_pControl->Stop();
CleanUp();
}



void CChildView::OnVideoPlay()
{
HRESULT hr = NULL;
if ( m_pControl )
hr = m_pControl->Run();
}

void CChildView::OnVideoOpen()
{
// TODO: Add your command handler code here
// file filter.
CString filter_text = TEXT("Video Files (*.mp4; *.3gp)|*.mp4; *.3gp;||");
// create file open dialog.
CFileDialog file_open_dlg( TRUE, // "open" dialog.
NULL,
NULL,
(OFN_EXPLORER|OFN_OVERWRITEPROMPT),
filter_text,
NULL,
NULL );
// store path.
CString media_file_path;
// check selection.
if( file_open_dlg.DoModal() != IDOK ){
return;
}
// if file selected.
media_file_path = file_open_dlg.GetPathName();
// first do clean up.
CleanUp();
// initialize.
if ( Initialize(media_file_path) != 0){
CleanUp();
return;
}
}

.



Relevant Pages

  • Windowless mode doesnt work
    ... I'm trying to render video to user window control, ... HRESULT DSPlayer::InitWindowlessVMR( ...
    (microsoft.public.win32.programmer.directx.video)
  • How to play video file asynchronously as chunk of buffer ?
    ... I am playing video file synchronously on window mobile m 6.0. ... I want to play video file asynchronously with chunk of buffer. ... afx_msg void OnVideoPlay; ... HRESULT Initialize; ...
    (microsoft.public.win32.programmer.directx.managed)
  • Re: Supplying a Custom Allocator-Presenter for VMR-9
    ... video isn't playing. ... HRESULT AVIClass::OpenFile ... //set the window to our main window ... //create the inteface to get events from the movie ...
    (microsoft.public.win32.programmer.directx.video)
  • Re: DOS windowed session not working
    ... this was another seen thing on this 'new' Depot serviced mainboard I'm dealing with DOS VDM irregularities in an earlier thread here. ... I noticed that although the Scitech video configuration window did have all the screen font change options and color depth selection, the monitor selection panel was blank. ... So in reading the complete installation notes for MCP2 that you can get from the help pane in the troubleshooting, ...
    (comp.os.os2.bugs)
  • Re: Pointer to my dialog
    ... I gave a modeless dialog solution; ... MyDialog dlg; ... Invoking a modal dialog means that the main application window is disabled. ... void CMyMainWindow::OnCheckNow ...
    (microsoft.public.vc.mfc)