DVD development

zhaozj2021-02-08  309

This is a long time ago, and those places are inaccurate. Please forgive me.

DVD program development

This section describes a simple way to write a desktop DVD decoding application. The main steps of creating a DVD application with C .

1, DVD program basic concept

When writing a DVD program, developers not only need to provide user interface code, but also need to call Microsoft DirectShow application interface to control DVD playback and navigation commands. This method involves calling the CocreateInstance method of the component object model and the DVDGraphBuilder object. DVDGraphBuilder will create a DVD filtering graphic. When the filter graphics will be created, the pointer to the interface IDVDControl2 and IDVDInfo2 will be obtained. You can connect your users. Interface to DVD navigation commands such as play, pause, etc. This processing is very simple and creating other DirectShow applications. If the reader is unclear with DirectShow, please refer to DirectX8.0 development documentation.

2, configure the filter graphics of DVD

Typically, application developers do not need to care about DVD filtering graphics because it is automatically created. However, if you need to create a personal filtering, please refer to DirectX8.0 reference, which is not detailed here. The following illustration shows a typical DVD filtering graphic.

DVD navigator is the first filter person of DVD playback filtering graphics, which is mainly to process the following tasks:

· Read navigation information and video data from the disc.

· Separate the video with audio, separating the subgraph data into a separate data stream.

• Apply the extracted stream data to the chart for future processing and final rendering.

· Notify the DVD application related events.

In the audio stream, the DVD navigator is connected to the underlying audio decoding, and the audio decoding is connected to the default audio processing of the default DirectShow filtering device. In the video and subtraction, the underlying filtration is a third-party video decoding, Overlay Mixer, and video rendering. If the application processes the LINE21 decoding filtering to close the title data, you must increase the DirectShow line21 decoding to filter to the appropriate graphics, including a single method call, the filter will automatically connect video decoding and overlay mixer.

The application communicates and controls DVD navigation by customizing the "set" member function of IdvdControl2 in DVD navigation and "get" member functions in IDVDInfo2. Filtering graphics must control other graphic controls such as stopping, playback by IMEDIACONTROL interfaces. Developers may need to control other separate filters, such as Overlay Mixer filtering between windows and full screen, you can see iMixERPInfig2 usage. The accurate configuration of the graph will determine whether the LINE21 Closed-Captioned data and other factors are processed with the type MPEG2 decoding.

3, establish DVD filter graphics

A simple way to create a callback filtering is to let the DVDGraphBuilder objects automatically create, which is close to the example DVD applications below the presentation. If you need to manually establish a DVD filtering graph, you must follow the basic rules of DirectShow, usually, in the graphic established by DVDGraphBuilder, should not be manually loaded, deleted, connected, or disconnected separately, because this may make it Clear code confusion.

After creating a DVDGraphBuilder object instance, the application can simply call the IDVDGraphbuilder :: RenderDvdvideovolume member function, which will create filter graphics from the local valid DirectShow filtering and MPEG2 decoding.

After establishing a filter graph, the application obtains the DVD wizard control, the pointer to the graphics management, and video windows. The following code is the most septus of the error papers and other unrelated code, the basic steps. The full code can be found in the DVD routine (DirectX8 SDK DXF / Samples / Multimedia / DSHOW / DVD Directory) // Create An Instance of The DVD Graph Builder Object.

HRESULT HR;

HR = CoCreateInstance (CLSID_DVDGRAPHBUILDER,

NULL,

CLSCTX_INPROC_SERVER,

IID_IDVDGRAPHBUILDER,

Reinterpret_cast (& m_pidvdgb));

// Build The DVD Filter Graph.

AM_DVD_RENDERSTATUS BuildStatus;

HR = m_pidvdgb-> renderdvdvideovolume (pszwdiscpath, m_dwrenderflags, & buildstatus);

// Get The Pointers to the DVD Navigator Interfaces.

HR = m_pidvdgb-> getdvdinterface (IID_IDVDINFO2, ReinterPret_cast (& m_pidvdi2));

HR = m_pidvdgb-> getdvdinterface (IID_IDVDCONTROL2, ReinterPret_cast (& M_PIDVDC2));

...

// Get a pointer to the filter graph manager.

HR = m_pdvdgb-> getfiltergraph (& M_PGRAPH);

...

// Use the graph pointer to get a pointer to iMediacontrol,

// use for controling the filter graph as a.

HR = m_pgraph-> queryinterface (IID_IMEDIACONTROL, ReinterPret_cast (& m_pimc));

...

// Get a Pointer to IMEDIAEVENTEX,

// use for handling DVD AND Other Filter Graph Events.

HR = m_pgraph-> queryinterface (IID_IMEDIAEVENTEX, (LPVOID *) & M_PME);

...

// use the graph builder Pointer Again to get the ivideoWindow Interface,

// use to set the window style and message-handling behavior of the video renderer filter.

HR = m_pidvdgb-> getdvdinterface (IID_IVideoWindow, ReinterPret_cast (& M_PIVW));

HR = m_pdvdgb-> getdvdinterface (IID_iamline21decoder, (lpvoid *) & pl21dec);

4, handle DVD notification events

When a certain event occurs, the DVD navigation will send a notification event to the specified window of the application, such as the DVD area change, encounter a new parent management layer. Additional information, error messages, and warnings that are usually used by event parameters, are usually transmitted. The application's specified window will handle the notification event via the IMDeiAeventEx pointer to call SetNotifyWindow. Such as: hr = m_pime-> setNotifyWindow (ReinterPret_cast (M_HWND), WM_DVD_EVENT, 0);

In the above example, m_hwnd is a window handle that receives messages and WM_DVD_EVENT, WM_DVD_EVENT is a message that the application defined by a tag DVD event occurs. The event itself is received by the application call IMEDIAEvent :: getEvent. Because there may be more than one event in the message loop, and it will increase at any time, so the application must call the getEvent loop for reception until all events are received, as shown below:

While (succeeded (m_pime-> getEvent (& Levent, & lParam1, & lparam2, ltimeout))))))

{

HRESULT HR;

Switch (Levent)

{

Case EC_DVD_CURRENT_HMSF_TIME:

{

DVD_HMSF_TIMECODE * PTC = Reinterpret_cast (& lparam1);

m_curtime = * PTC;

...

}

Break;

...

}

The DVD event may include additional information in LPARAM1 or LPARAM2, as shown in the above example, stored in LPARAM1. The above code is in DVDCore.cpp in the DVD routine. For a complete list of DVD events and other parameters, please refer to the DVD event notification code.

5, use the DVD menu to work

The DVD menu logic structure has a detailed discussion in the DVD navigation basis. Application To display the DVD menu is determined by calling the IDVDControl2 :: ShowMenu member function, then determined by the index of the menu you want to get.

To remember that a button is only caused by making its edges a highlighted state. In order to make the association command work, the button must be activated. An example of an activated DVD menu can be selected in the CDVDCore :: onmouseevent function in the DVD example.

The member function associated with the IDVDControl2 menu is used to programmatically control the DVD menu. The application controls highlight or selection buttons through mouse movement or user actions or other programming logic. The application can implement control of a custom menu or BMP-drawn button control. In the DVD example, the related menu button command is connected to the direction button of the keyboard. (See cdvdcore :: onkeyevent) You can use a different method to programmatically activate a button, but the button must be selected before being activated.

Audio and subtraction

The DVD disc can support 8 channel audio flow, the label is from 0-7, each with a discontinuous 6 channel. (Note that the audio and subtraction label are from 0-7, but the title, Angles, and the parent tag are starting from 1.) At the same time, these streams can have only one can be selected. For a sub-map, there can be 32 valid data streams, but only one can be activated at the same time. The disc usually uses the default audio and subtraction, but the application can make the user chooses a style of the style through a list of active flow. The basic processing steps and audio and subtraction are the same.

6, determine the number of effective flows.

The quality state of each stream can be obtained through the stream. After the language code returned by the local identifier is translated into a readable string. You can also allow users to select a preferred stream through a list or other user interface control. Basic steps in the CaudiolangDlg :: MakeaudioStreamList function in DIALOGS.CPP in DVD example applications. 7. Execute parent management

Any title or title in the DVD video disc can be given a general parent management (PML), marked from 1-8. When the content read by the DVD navigation contains PML, that is, it means in the parent block.

The parent block can consist of some chapters, multiple chapters or multiple titles. The DVD navigation itself cannot perform PML, which is just advertising the application when PML is encountered in the disc. The default mode will ignore this information directly to handle the highest level of content. To perform PMLs, the application must perform some password control logic layers associated with the user, inform the DVD navigation to send PML notification messages, and then respond to events, allow or reject. (When started, you should call the idvdcontrol2 :: setoption method, the parameter DVD_NOTIFYParentAllevel becomes true)

A DVD title can have a complete PML, but the disc producer can give a higher or more limitable PMLS to the title of the title, which requires calling the temporary PML command. These commands typically contain two branch structures: one is the interim PML command to be accepted by the application, and the other is that the command is rejected.

The event should follow the order. DVD navigation reads the video directory when encountered a temporary PML command. The internal flag is then detected to determine if the application requests to notify this event. If there is no setting, continue playing the DVD, and the subsequent parent layer changes will be rejected. If the logo exists, the DVD sends an EC_DVD_Parental_level_change event to the application, then paused until the response is received. When the application receives the event, you will use your own logic to decide whether to receive this command, and then call the set to become "true" or "false" IDVDControl2 :: AcceptParentAllevelChange. If set to true, the DVD navigation continues to play in the case where the parent layer is changed, and in turn, continues to play in the case where the parent layer refuses to change.

8, store and restore DVDSTATE objects

The DVDState object allows the application to save the snapshot of the user task, such as the current disc position, the personal feature parent layer is selected for information such as audio and subtraction. Therefore, users can save their positions to continue playback from customized places in the future.

The application cannot create a DVDState object. These objects are when the application call IDVDInfo2 :: getState, the DVD navigation is created inside it. The DVDState object reveals the IDVDState interface, which is mainly to allow the application to query some kind of information.

In the DVD case, CDVDCore :: RESTOREBOKMARK and CDVDCore :: Savebookmark function demonstrates how to save and restore DVDState objects.

9, DVD text management

DVD discs, especially karaoke discs, may contain a text information database that supports video and audio. For example, in the karaoke disc can contain song name, record text, etc. These texts can present more than one language information. These strings can be random, the disc itself does not require it, and is currently organized by the DVD volume mirroring method of the logical layer. Each string has a representator that indicates which part thereof is on the disc, or the index of these character content is given to the query. A subset of string types is defined as listed in DVD_TextStringType.

There are two basic types of text: structural identification and index characters. The type value is between 0x01 to 0x20, which is a structural identifier, which is used to identify what logical structure belongs to the index string. This structure is very similar to the logical structure index of the DVD disc: such as the volume label, title, chapter, etc. Index characters retain user interface display information. Accurately use index characters is difficult to define, so the manufacturer of DVD can use index characters through various methods. 10, play karaoke audio stream

DVD navigation can play the audio stream of the karaoke of the DVD disc, but karaoke playback requires support multi-channel karaoke mix decoding. The decoder must support the DVD karaoke property setting (AM_Property_Dvdkaraoke).

The karaoke disc is a DVD video disc, with the same navigation structure. Songs are generally formatted to title, and the settings of each title are based on performers, song types, or other standards. The difference between karaoke and other discs is mainly on the audio stream. The karaoke disc includes all multi-symbol flow, usually Dolby, AC-3. Channels 0 and 1 usually contain background music, channels 2 to 5 include binding voice, tone, sound effects. A karaoke application can control the volume of each auxiliary channel and a separate pronunciation unit.

When the DVD navigation detects the karaoke index and enters the karaoke mode, the decoder will notify the decoder three auxiliary channels, which should be muted until any one or all is explicitly opened through the application. The basic karaoke application handling task steps are as follows:

l Determine the number of secondary channels and their indexing used by IDVDInfo2 methods.

l Provide a user interface: Display channel index and allows users to control the auxiliary channels or off.

l Using the IDVDControl2 :: SelectkAokeAudiopresentationalModeMode member function.

Examples of the above steps in the GetAudioAttributes method of DVDCore.APP.

11, synchronous DVD command

Developers who are familiar with DVD navigation and require applications have special functions can be synchronized using the command. This feature can be discussed later for only the DVD navigation or the application does not require a synchronization command.

Different playback methods in IDVDControl2, PlayTitle is a non-synchronous representation. When the method is called, the result is immediately returned before it is executed. Between the method calls successfully returned and finally completed, other commands may boot DVD navigation to other DVD processing methods or newer status, which will hinder the process of calling all necessary steps. For example, assume that the application calls playtitle, the user immediately clicks the stop button. If the command does not synchronize the DVD navigation will handle the stop operation before the disc is played to the specified location. This is because PlayTitle has successfully returned before the operation is completely completed, so when the disc starts playing, the DVD navigation is no longer the correct state, and an error is generated.

Because many methods are called to rely on DVD navigation specific state, the application requires a synchronization command. This involves the following two functions.

It is important to know that when an asynchronous operation is completed, the return value of the final result and method call is completely different. The request can be handled by concurrent command until the DVD navigation is in the blocking state before its operation is completed. DVD navigation gives the application these capabilities and some synchronous command options. Each playback method has two parameters in iDVDControl2 to handle synchronization: one is a synchronous object interface pointer, a setting DVD command ID. Applications can use these parameters to achieve synchronization through different methods.

Step 1: Non-synchronous

In order to maintain a non-synchronous nature, the following syntax can be used, and PDVDControl2 is a pointer to IDVDControl2.

HRESULT HRES = PDVDControl2-> PlayTitle (Utitle,

DVD_cmd_flag_none, // = 0Null;

Step 2: Simple non-synchronous blocking

This step uses the DVD command identifier to implement a simple blocking of no synchronous command object management. This is the easiest way to implement synchronization, because you will not manage synchronous objects or process incidents, but this method cannot determine return status of any special command.

HRESULT HRES = PDVDControl2-> PlayTitle (Utitle,

EC_DVD_CMD_FLAG_BLOCK,

NULL);

Step 3: Use synchronization objects

The function of this step is equivalent to step 2. Another method is provided to handle blocking, and DVD navigation does not directly process incidents. When the application passes the pointer of the address, a synchronization object command associated with the specific command is received. The waitToEnd function called the object will block DVD navigation until this member function is completely successfully completed. During this time, the new command may be added to the command loop. Make sure the object is released when the processing is complete.

IDVDCMD * POBJ;

HRESULT HR = PDVDControl2-> PlayTitle (Utitle, 0, & Pobj);

En (ac))

{

POBJ-> WaitToend ();

POBJ-> Release ();

}

Step 4: Use the event to handle the synchronization of a command at the same time

If you set an EC_DVD_CMD_FLAG_SENDEVENTS flag by calling IDVDControl2 :: SetOption, the DVD navigation is not blocked when calling the Play method. Conversely, when the command starts and asynchronous operations, EC_DVD_CMD_START and EC_DVD_CMD_END in the application are sent to the application. This allows synchronization of individual events without having to manage IDVDCMD objects. However, if you do not use the IDVDCMD object, you cannot be sure that the command event is associated.

In many cases, there is no such information, so it is already possible to understand this layer.

// Call PlaychapterIntitle use "sendevents".

HRESULT HRES = PDVDControl2-> PlaychapterIntitle (utitle, 0x2,

DVD_CMD_FLAG_SENDEVENTS, NULL);

...

// in The Event Notification Handler Function

Switch (Levent)

{

Case EC_DVD_CMD_END:

DOSMETHINGEGENERIC ();

Break;

}

Step 5: Synchronize usage events and IDVDCMD objects

This method provides the maximum control of the command synchronization, but it is also quite complicated. Allow the application to get the associated event command, so the application can customize the response to the EC_DVD_CMD_END event. The first example demonstrates a single-threaded solution, and the second example demonstrates a multi-threaded solution.

// Global variable

IDVDCMD * PGLOBALOBJ = 0;

...

// pglobalobj is associgid by the navigator before the eve

// is Issued; Otherwise the Event Can Occur At (* 1) Before

// pglobalobj is associgment.

HRESULT HRES = PDVDControl2-> PlayTitle (Utitle,

DVD_CMD_FLAG_SENDEVENTS, & PGLOBALOBJ);

// (*1)

IF (Failed (HRES) {

PGLOBALOBJ = NULL;

}

...

Switch (Levent)

{

Case EC_DVD_CMD_END: ​​IDVDCMD * POBJ = getDvdcmd (lparam1);

HRESULT HRES = HRESULT (LPARAM2);

IF (NULL! = POBJ) {

IF (PGLOBALOBJ == Pobj) {

...

PGLOBALOBJ-> Release ();

PGLOBALOBJ = NULL;

}

POBJ-> Release ();

}

Break;

Use this approach when your event loop is on a Separate Thread.

// in Global Code

IDVDCMD * PGLOBALOBJ = 0;

Ccritsect Globalcritsect;

...

{

Cautolock (Globalcritsect);

HRESULT HRES = PDVDControl2-> PlayTitle (Utitle,

DVD_CMD_FLAG_SENDEVENTS, & PGLOBALOBJ);

IF (Failed (HRES) {

PGLOBALOBJ = NULL;

}

}

...

Switch (Levent)

{

Case EC_DVD_CMD_COMPLETE:

Case EC_DVD_CMD_CANCEL:

{

Cautolock (Globalcritsect);

IDVDCMD * POBJ = getDvdcmd (lparam1);

HRESULT HRES = HRESULT (LPARAM2);

IF (NULL! = POBJ) {

IF (pglobalobj == obj) {

...

PGLOBALOBJ-> Release ();

PGLOBALOBJ = NULL;

}

POBJ-> Release ();

}

Break;

}

12, DVD command sign

The DVD command flag is removed or replaced by the DWFlags parameter of SetOption or instead of the synchronous object. The use of DVD_cmd_flag_block As shown in step 2, DVD_CMD_FLAG_SENDEVENTS is illustrated in step 4 and 6. These flags can be brought about by other signs. DVD_CMD_FLAG_FLUSH causes the method to be executed immediately, no need to wait a video on the graphic shark buffer one or two seconds. Specifies that this flag will speed up the response to the user. It is best not to use this flag when you need a video segment. The four signs and its significance are as follows:

name

value

Comment

DVD_CMD_FLAG_NONE

0x00000000

No sign, that is, the buffer is not refreshed before the new command arrives. When the operation is completed, there is no event being discarded, and the DVD navigation is not blocked after the method returns.

DVD_CMD_FLAG_FLUSH

0x00000001

Cleaning the buffer and then start playing in a new location immediately.

DVD_CMD_FLAG_SENDEVENTS

0x00000002

DVD navigation is notified by sending an event to the application to complete the asynchronous operation and its return value.

DVD_CMD_FLAG_BLOCK

0x00000004

Block DVD navigation until the asynchronous operation is complete or abandoned.

13, handling disc popings

When the user pops up from the CD drive, the DVD navigation will be sent to the application an EC_DVD_DISC_EJECTED message. Applications can securely ignore this message and let DVD navigate the status of the graphic. When the disc pop-up, the application can also handle the EC_DVD_DISC_EIECTED method to implement custom behavior. If the message is processed, you must set the DVD_RESETONSTOP flag with the setOption method, and then call iMediaControl :: Stop before the application shutdown, or play another disc. The above is the process of preparation, I hope everyone will refer to the source code for understanding. Let's explain the programming of the WebDVD program and the pure DVD decoding section.

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

New Post(0)