Background technology
Present most media player has all used the Directx technology, and for the most existing display card, can use Overlay (covering surfaces) the technology show events video of Directdraw.Covering surfaces is the surface with display card tenability, is generally used for show events video, recorded video or static bitmap.The support of described covering surfaces is that display card provides by hardware fully, and DirectDraw supports the characteristic that display device driver is supported, DirectDraw can not the emulation covering surfaces.
The principle of work of covering surfaces is very similar with the principle that transparent plastic paper covers, and described covering surfaces can be envisioned as a slice transparent plastic paper, and drawing on this sheet plastic paper also can place it in the display front.When plastic paper covers the display front, can see covering surfaces and first type surface, remove plastic paper after, first type surface does not change.When showing a covering surfaces, tell exactly as seen how where device driver make covering surfaces, when the display device sweep trace repaints on the display, check each pixel on the first type surface then, see that whether being capped the surface replaces; If, display card just extracts related pixel from covering surfaces data substitute, display card generates the synthetic surface of first type surface and covering surfaces on display, produce transparent and drawing effect and do not need to change each surperficial content, described synthetic surface is directly delivered to display by video data stream and is shown.
Because it is the operation of hardware level that covering surfaces processing and pixel substitute, can seamlessly synthesize first type surface and covering surfaces by enough different pixel formats, so there is not tangible performance loss.
Therefore, if player has adopted the mode displaying video of covering surfaces, video content appears on the covering surfaces, it is the video content that can't obtain covering surfaces that prior art is carried out the just simple first type surface of catching of screen capture, can cause like this to grasp video data and be not the desired video data even present a slice black in video window.
Prior art is that simple extracting on-screen data is kept at this locality, can not in time share and be distributed to other good friends, adds the Video Capture characteristic at instant communication situation, and the communication that can strengthen both sides is experienced; In addition, prior art can only grasp a two field picture at every turn, can not once grasp multiple image and conversion generation GIF (GIF(Graphic Interchange format)) file.
Summary of the invention
The invention provides a kind of method for acquiring covering surface video information, solve the problem that to catch the covering surfaces video data in the prior art.
For addressing the above problem, method for acquiring covering surface video information of the present invention may further comprise the steps: 1) set up new component object example in the process space of current application program; 2) from this New Parent object, obtain New Parent object model interface pointer; 3) be owner pointer with described New Parent object model interface pointer, enter chained list, seek the The Component Object Model interface of all preservations along chained list; 4) call current component object pointer and obtain the covering surfaces pointer; 5) utilize the covering surfaces pointer to obtain the video data and the characteristic information of this covering surfaces; 6) according to the video data of this covering surfaces and characteristic information reorganization reproduced image.
Further, comprise step 3), 4): whether the process identification (PID) of The Component Object Model interface of judging this preservation is identical with the process identification (PID) of current application program; If identical, then expression finds current process to use component object, returns the The Component Object Model interface pointer and the component object pointer of this preservation; If the process identification (PID) of the process identification (PID) of the The Component Object Model interface of preserving and current application program is inequality, the The Component Object Model interface pointer of then changing another version is as New Parent object model interface pointer execution in step 3).As seen whether the first type surface of judging this component object have covering surfaces sign and covering surfaces; If can, execution in step 4); If the first type surface of component object does not have covering surfaces to identify or covering surfaces is invisible, then return or grasp first type surface
Further, described video information is that single frames obtains, and then reproduced image is stored with bitmap format.
Further, described video information is that multiframe is obtained, then by predetermined frame number, the time interval, scaling repeating said steps 1) to 6), reproduced image is stored with GIF(Graphic Interchange format).
Further, described video data refer to can with the video chromatism data of the conversion in three primary colors space, the pointer that obtains the buffer zone of the video data of preserving this covering surfaces correspondence by the covering surfaces pointer obtains.
Further, carry out this method and comprise step before: set up system's hook program, the keyboard message of responding system; When after pressing the button of next appointment on the player, the hook program begins to carry out following step; Judge that whether current application program has used DirectDraw, if do not have, then returns; If have, then execution in step 1).
Compared with prior art, the present invention has the following advantages:
Can catch the video information of covering surfaces, and can finish static state and dynamically obtain;
The picture format that reproduces (static state is obtained the employing bitmap format, dynamically obtains and adopts GIF(Graphic Interchange format)) then reaches transmission and demonstration in the JICQ easily on the net.
Embodiment
The screen capture method is only operated first type surface in the prior art, when adopting covering surfaces to show, then can't obtain the video data of covering surfaces and can't obtain definite video data, can definitely obtain video data so must be able to get access to the video information of covering surfaces.
DirectDraw, create various different types of " surfaces " (Surface) by DirectDraw object (in the present specification with component object as its Chinese appellation), lip-deep content can freely be copied, be made up, and generates Protean figure.The DirectDraw object is used for representing viewing hardware, can be used to inquire about and obtain various supports The Component Object Model interface (com interface, the basis of being devoted to reuse the object-oriented system of interface resource), the cooperation grade is set, operation display mode and display surface.Each surface is represented by corresponding surface-object.By the entity of pointer to object access object and then access object representative, APIs (application programming interface) forms by object with based on com interface usually in DirectDraw.
DirectDraw can be surface creation in display memory (video memory) or Installed System Memory, and display memory is divided into conventional display memory and AGP Accelerated Graphics Port internal memory.Because the display memory capacity is limited, so which part storage area each surface specifically should be created in should make overall planning, generally will use frequently, need surface hardware-accelerated or the realization function be arranged in display memory.If you are the position of designated surface establishment not, DirectDraw will at first create the surface at conventional display memory, when conventional display memory is not enough, if the support AGP of system internal memory then uses the AGP internal memory earlier, final using system internal memory.
DirectDraw manages video memory, allows directly storage and manipulation bitmap in video memory.Utilize vision hardware Bliter (position piece transmitter) to carry out the Blit (position piece transmission) of bitmap in video memory inside.
Following several types is divided on described surface: (1) first type surface (Primary Surface): the surface that promptly shows on screen; Each DirectDraw object can only have a first type surface, and the size of first type surface, position and form can not be changed by the current display mode decision of system.
(2) off-screen surfaces (Off-screen Surface): this type of surface can not be directly visible.In general, the surface, backstage is often used for the memory buffer as parts such as the smart animation of recreation, background graphics.
(3) covering surfaces (Overlay Surface): being positioned at video memory, and can covering any position that is presented at first type surface, is a kind of surface by hardware supported, and DirectDraw can not emulation.Hide some pith such as menu, the dialog box etc. in the first type surface in order to prevent covering surfaces, covering surfaces is also high the chroma key function, when having only color value in the first type surface identical with the chroma key value, just covering surfaces covers first type surface.
When the beginning real-time video shows, at first start DirectDraw interface (being the The Component Object Model interface), create first type surface and covering surfaces, and write down the information of relevant covering surfaces, as size, data layout, memory address etc., select a color as chroma key for covering surfaces simultaneously, normally carmetta.According to the information initializing hardware device of covering surfaces, DMA (direct memory access (DMA)) equipment is directly sent into video data in the video memory at covering surfaces place then.When display window moved or change size, video capture engine can send the notice driver update and show that driver should be filled the color of chroma key in video window, and mobile covering surfaces makes it align with video window.
Please refer to shown in Figure 1ly, method for acquiring covering surface video information of the present invention may further comprise the steps:
1) in the process space of current application program, sets up new DirectDraw object (component object) example, because use the The Component Object Model interface must create the DirectDraw object earlier;
2) from this New Parent object, obtain New Parent object model interface pointer;
3) because the employed all The Component Object Model interface pointer of system are preserved in internal memory with the form of chained list, be owner pointer, enter chained list, seek the The Component Object Model interface of all preservations along chained list with described New Parent object model interface pointer;
4) judge whether the process identification (PID) of The Component Object Model interface of this preservation is identical with the process identification (PID) of current application program;
5) if identical, then expression finds current process to use component object, returns the The Component Object Model interface pointer and the component object pointer of this preservation; If different, the The Component Object Model interface pointer of then changing another version re-executes step 3) as New Parent object model interface pointer;
6) as seen whether the first type surface of judging this component object have covering surfaces sign and covering surfaces, because each DirectDraw object can only have a first type surface, exists so covering surfaces relies on first type surface;
7) if then call current component object pointer and obtain the covering surfaces pointer; If do not have covering surfaces sign or covering surfaces invisible, then return or grasp the first type surface video information;
8) utilize the covering surfaces pointer to obtain the video data and the characteristic information of this covering surfaces, described video data refer to can with the video chromatism data of the conversion in three primary colors space, the pointer that obtains the buffer zone of the video data of preserving this covering surfaces correspondence by the covering surfaces pointer obtains; Described characteristic information refers to form, the length of video data, width, highly, the color figure place of span, video data and the buffer pointer of preserving video data;
9) according to the video data of this covering surfaces and characteristic information reorganization reproduced image, the video data that corresponding corresponding format converts the video chromatism data to the three primary colors space is basis again.
Obtain if described video information is a single frames, then reproduced image is stored with bitmap format; (animation) obtains if described video information is multiframe, then by predetermined frame number, the time interval, scaling repeating said steps 1) to 9), reproduced image is stored with GIF(Graphic Interchange format) (GIF form).Can directly show animation at webpage like this; Also can in the JICQ of supporting the GIF form, show animation, pass to the good friend and watch.
Comprise step before carrying out this method: set up system's hook program, the keyboard message of responding system; When after pressing the button of next appointment on the player, the hook program begins to carry out following step; Judge that whether current application program has used DirectDraw, if do not have, then returns; If have, then execution in step 1).
In concrete the enforcement, adopt and realize as minor function:
Use DirectDrawCreate function creation component object.
IDirectDraw represents the com interface that DirectDraw provides, and IDirectdraw7 then represents the com interface of the 7th version; Call the DirectDrawCreate api function and can access newly-built component object pointer; Can call QueryInterface (IID_IDirectDraw7, (void then*) ﹠amp; M_pDirectDraw7)) function is obtained the The Component Object Model interface pointer of IDirectdraw7, i.e. New Parent object model interface pointer.
The Component Object Model interface pointer with acquisition IDirectdraw7 is an owner pointer, enters chained list, judges whether 12 bytes backward can visit; If can visit, judge then whether the content of preceding four bytes of this sheet internal memory is identical with the IDirectdraw7 object handle; If identical, then the region of memory of preserving the IDirectdraw7 object information is found in expression, calls pdwProcessID=(DWORD then*) (((LPBYTE) * (pdwDirectDraw+1))+0x14) can obtain using the process identification (PID) (ID) of this component object interface (being IDirectdraw7), wherein represents this sheet region of memory with pdwDirectDraw;
The acquisition methods of current process of application program sign (ID) is: DWORD dwProcessID=GetCurrentProcessId ();
Relatively judge process identification (PID) and the current process of application program sign of the IDirectdraw7 that obtains; If identical then expression finds current process to use component object, return the The Component Object Model interface pointer and the component object pointer of this preservation.
The EnumSurfaces of invocation component object obtains the covering surfaces pointer, specifically call into:
if(SUCCEEDED(pDirectDraw4->EnumSurfaces(
DDENUMSURFACES_DOESEXIST,
&ddsd2,
this,
EnumSurfacesCallback2)))
The covering surfaces pointer that obtains is saved in the m_m_pPrimaryDirectDrawSurface4 member variable.
Because the characteristic information of all surface is filled in DDSURFACEDESC structure and the DDPIXELFORMAT structure, can obtain characteristic information so call the GetSurfaceDesc method to covering surfaces, as:
DDSURFACEDESC2?ddsd2={0};
m_pPrimaryDirectDrawSurface4->GetSurfaceDesc(&ddsd2)
After extracting finishes, with the video chromatism data (YUV is generally YUV2, YV12, YUYV UYUV) is converted to RGB (three primary colors) data, preserve and copy to Clipboard in for the use.
Described YUV follows following formula to the conversion of RGB:
R=Y+1.403*(U-128)
G=Y-0.344*(U-128)-0.714*(V-128)
B=Y+1.773*(V-128)
If static state is captured (single frames obtains), only capture frame data of current broadcast, only the RGB data in the buffer zone need be generated BMP (bitmap) file, and store in the shear plate;
If dynamically grab screen pattern (multiframe is obtained), then the ratio of the data based application appointment of the RGB in the buffer zone is carried out convergent-divergent after, be inserted in the file object of GIF; Repeat to grab the screen process then, until generating the gif file of specifying frame number.
In sum, method for acquiring covering surface video information of the present invention can be caught the video information of covering surfaces, and can be by certain format reproduced image/animation.