Use ATL to implement QuickTime multimedia file playback

zhaozj2021-02-17  67

Using ATL to implement QuickTime

Multimedia file play

Abstract This article mainly introduces the Visual C 6 on the Windows platform to develop play QuickTime multimedia software using the ATL library and QuickTime SDK. Provide reference and reference for multimedia playing developers.

Key words multimedia play QuickTime ATL

1 Introduction

In today's multimedia playing software, there are mainly Windows Media Player, Real Player and QuickTime. Apple's QuickTime debut in 1991, is the multimedia technology platform developed by Apple, Web website creation and CD-ROM content production, QuickTime supports almost all mainstream personal computer platforms, which is in the field of digital media. Industrial standards are important foundations for creating 3D animations, real-time effects, virtual reality, A / V and other digital streaming media.

Because many companies have the need for QuickTime Player applications, there is a related application of Windows SDK or MFC in relevant information at home and abroad. This article uses a small ATL library and QuickTime SDK development custom QuickTime multimedia play software to analyze.

2 An overview of the development of QuickTime Windows programs

2.1 Preparation before the development

Login Apple Official Website Download QuickTime SDK and understand technical information.

Since QuickTime is originally for Mac OS design, many of its concepts and functions in it are Mac.

Table 1 Comparison of windows and qtml terminology

Windows terminology

QtML corresponding terms

Message (MSG)

Event (EventRecord)

Graphics Device Interface (GDI)

QuickDraw

Device Context (DC)

Graphics Port (Cgrafport)

Window Handle (HWND)

Window Pointer (CWindowPtr)

Common Dialog Box Library

Standard File Package

For a Windows programmer, some of the most basic understanding of some QuickTime concepts can be developed relatively quick to develop the typical QuickTime Windows program.

2.2 Development Basic Steps

Developing a simple QuickTime Windows program must take the following basic steps to add to a Windows application.

2.2.1 Initializing the QuickTime Media Layer (InitializQTML) and QuickTime (Entermovies) at the beginning of the program.

2.2.2 and the CreateportAssociation of the graphics port 2.2.2 and the movie window.

2.2.3 Open the movie (OpenMovief) and get the movie's handle (NewMoviefRomfile).

2.2.4 Creating a control (NewMovieController) that displays a movie image on the screen.

2.2.5 In the Windows Processing function, the received Windows message is converted to the QTML event (WineventTomacevent) and transfer them to the MCISPLAYEREVENT.

2.2.6 If not, the movie handle (Disposemovie) and a movie control (DisposemovieController) are released.

2.2.7 When destroying the window, destroy the association of the movie graphics port.

3 Implement playback on ATL

3.1 Create a Windows window with ATL

Based on CWINDOWIMPL, write your own window CQTVideoWnd. And define macros to receive window messages.

#define my_qt_msg_handle (func) / {/

Bool bhandled = true; /

LRESULT; /

Func (UMSG, WPARAM, LPARAM, BHANDLED); /

IF (bhandled) /

Return True; /

}

Class CqtvideoWnd:

Public CWINDOWIMPL

{

PUBLIC:

CQTVideoWnd (HWND HParent, Rect & RC, IvideoPlayerNotifyink * pvpsink);

Virtual ~ cqtvideoownd ();

PUBLIC:

Begin_msg_map (CVIDEOPLAYERQT)

MY_QT_MSG_HANDLE (NewProc)

END_MSG_MAP ()

protected:

LRESULT NewProc (Uint Umsg, WPARAM WPARAM, LPARAM LPARAM, BOOL & BHANDED);

......

CquickTime M_QT;

......

}

CquickTime calls the author to call the QuickTime API auxiliary class, will be introduced later.

The NewProc member function calls different member function processing based on the different window messages.

Lresult CQTVideoWnd :: NewProc (uint UMSG, WPARAM WPARAM, LPARAM LPARAM, BOOL & BHANDED)

{

IF (UMSG == WM_ERaseBKGND)

{

BHANDLED = false;

LResult theurt = defWindowProc (UMSG, WPARAM, LPARAM);

m_qt.processmovieEvent (M_HWND, UMSG, WPARAM, LPARAM);

Return theurt;

}

Else

{

m_qt.processmovieEvent (M_HWND, UMSG, WPARAM, LPARAM);

Switch (UMSG)

{

Case WM_CREATE:

Oncreate (UMSG, WPARAM, LPARAM, BHANDED);

Break;

Case WM_Paint:

OnPaint (UMSG, WPARAM, LPARAM, BHANDLED);

Break;

Case WM_DESTROY:

OnDestroy (UMSG, WPARAM, LPARAM, BHANDLED);

Break;

DEFAULT:

BHANDLED = false;

Break;

}

}

Return 0;

}

The member functions such as OnCreate, OnPaint, OnDestroy will call the secondary CQUickTime processing according to 2.2. Such as

Lresult CqtvideoWnd :: Oncreate (Uint Umsg, WPARAM WPARAM, LPARAM LPARAM, BOOL & BHAND)

{

m_qt.onmoviewindowcreate (M_HWND, NULL);

Return 0;

}

3.2 CquickTime

CquickTime is a secondary class that calls the QuickTime API function.

3.2.1 Initialization and Exit Application

InitializeQT and Terminate are initialized QuickTime media layers and exit QuickTime media layers, respectively. They can start and end in the program. We call them in the constructor and destructor of CQTVideoWnd.

Bool CquickTime :: InitializeQt (iqteventsink * pqteventsink / * = null * /)

{

... oserr err = neoerr;

// Initialize QuickTime Media Layer

Err = INITIALIZEQTML (0);

// Initialize QuickTime

IF (Err == Noerr)

{

Err = Entermovies ();

}

Else

{

Err = Qt_noplayer;

}

IF (Err == Noerr)

{

// Because We can not distinguish the error from Which Object

// SO We Marked SetMoviesexyRrog

// SETMOVIESEERROC (MovieserRrorProc, (long);

}

Else

Err = qt_initial_err;

......

Return Err == NOERR? TRUE: FALSE;

}

If you want to get the quicktime error code, we can call the SetMovieserRrorProc function after initialization, but if there is a plurality of QuickTime movie objects. We will not distinguish from which object from it.

Void CquickTime :: Terminate ()

{

// Clean Up

Exitmovies ();

TERMINATEQTML ();

Debuginfo ("CquickTime :: Terminate this =% p, m_pqteventsink =% p", this, m_pqteventsink;

}

3.2.2 Get the handle of the movie

If the local file calls OpenLocalMovie, save M_Movie in the member variable after you get the handle. This function opens the movie to create a Movie Controller. Apple recommends usually play movies with Movie Controller.

Bool CquickTime :: OpenLocalMovie (LPCSTR FULLPATH)

{

_Asserte (fullpath && m_hviewwwnd);

IF (! fullpath ||! m_hviewWnd)

Return False;

Video_Statue OldState = m_enstate;

IF (Strlen (CHAR *) fullpath! = 0)

{

Oserr ERR;

Short nthefile = 0;

Long lcontrollerflags = 0L;

Fsspec sffile;

Short nmovieresfile;

Short nmovieresid;

Char thefullpath [255];

// Close Any Previously Opened Movie

Closemovie ();

// Make a Copy of Our Full Path Name

STRCPY (CHAR *) ThefullPath, (const char *) fullpath;

// convert thefullpath to pstring

C2pstr ((char *) thefullpath;

// Make a fsspec with a pascal string filename

FSmakefsspec (0,0l, (unsigned char *) thefullpath, & sffile);

// set the port

Setgworld (CGRAFPTR) gethwndport (M_HVIEWND), NIL); // Open the movie file

Err = OpenMovief (& SFFILE, & NMOVIERESFILE, FSRDPERM);

IF (Err == Noerr)

{

// Get the movie from the file

nmovieresId = 0;

Err = NewMoviefRomfile (& M_Movie, NMOVIERESFILE,

& nmovieresid,

NIL,

NewMovieACTIVE, / * FLAGS * /

NIL);

// Close the movie file

Closemoviefile (nmovieresfile);

IF (Err == Noerr)

{

SetMovietimescale (M_Movie, 1000);

m_bbeginedownload = true;

// Create The Movie Controller

CreateNewMovieController (M_HVIEWND, M_MOVIE, & M_MC);

P2CSTR ((unsigned char *) thefullpath);

IF (m_mc)

{

Return True;

}

}

}

}

Closemovie ();

Return False;

}

If it is a URL file, call OpenURLMOVIE, which is mainly divided by OpenLocalMovie mainly with newMoviefRomDataref to get the handle without newMoviefRomfile.

General Movies Call preprerollmovie after Creating Movie Controller.

Void CquickTime :: CreateNewMovieController (HWND HWND, MOVIE THEMOVIE, MOVIECONTROLLER * THEMC)

{

......

PrePrerollMovie (theMovie, GetMovieTime (theMovie, NULL), GetMoviePreferredRate (theMovie), NewMoviePrePrerollCompleteProc (QTPrePrerollCompleteProc), (void *) m_hViewWnd);

}

3.2.3 Close the movie

Void CquickTime :: Closemovie (Void)

{

IF (m_mc)

{

DisposemovieController (M_MC);

}

IF (m_movie)

{

Disposemovie (M_Movie);

}

m_movie = NULL;

M_MC = NULL;

}

3.2.4 Establishing and Cancelting Movie Window Association

Int CquickTime :: OnMoviewindowCreate (HWND HWND, CREATESTRUCT * LPCREATESTRUCT)

{

IF (hwnd! = null)

{

m_hviewWnd = hwnd; // the view's hwnd

// Create Grafport <-> hwnd association

CreateportAssociation (M_HVIEWND, NULL, KQTMLHANDLEPORTEVENTS);

}

Return 0;

}

Void CquickTime :: OnMoviewindowDestroy ()

{

IF (m_movie)

AbortpreprerollMovie (M_Movie, NOERR);

Cgrafptr WindowPort = null; // Close Any Movies Before Destroying PortasSocation

Closemovie ();

// destroy the view's grafport <-> hwnd association

IF (m_hviewWnd)

WINDOWPORT = (CGRAFPTR) gethWndport (M_HVIEWND);

IF (WindowPort)

Destroyportassociation (WindowPort);

}

3.2.5 Control movie playback

The author uses control McDoAction to control playback, which can be played, and of course, the API functions such as startMovie, StopMovie can be called. E.g,

Void CquickTime :: play ()

{

IF (m_movie)

{

McDoAction (M_MC, McActionPlay, (Void *) getMoviePreferRedrate (M_MOVIE));

Long Controllerflags;

McGgetControllerInfo (M_MC, & Controllerflags);

IF (Controllerflags & McInFoisplay))

// Now this is playing state.

}

}

4 review

Through the more detailed discussion for the establishment of a QuickTime window, open and control the basic concepts and basic processes of the QuickTime movie file, I think the application of QuickTime Player's platform in Windows will be more broad. At the same time, for Apple's efforts on multimedia playback.

转载请注明原文地址:https://www.9cbs.com/read-31139.html

New Post(0)