Decode the video and delay loading library of Hai Kang camera

Source: Internet
Author: User

Use Hoi Hong's decoding library Playctrl.dll to decode the hoi Hong Video. The following code is for informational purposes only.

The following code demonstrates a mechanism: when sharing code in multiple projects, some projects need to call some libraries, some projects do not need to, but because the source code mutual references cause even if the program is not used in a library, you need to accompany the release of the library, or the program will be launched when the error can not find the specified library.

One way to solve this problem is to use dynamic loading, using LoadLibrary to dynamically load the library, using GetProcAddress to get the address of the function to be called, and call it with a function pointer. But this method is more troublesome.

The following code solves the problem by using the delayed load (delayload) mechanism and using LoadLibrary to determine if there is a library.

(1) Use the delay loading library to avoid the need to start the library

#pragma COMMENT (linker, "/delayload:playctrl.dll")
#pragma comment (lib, "Delayimp.lib")

(2) When the function is executed into the library, it will be automatically delayed loading (if the library can not load the program will be error)

Inside the program code are the functions of the direct static link call library.

(3) But before execution, the dynamic loading method is used to determine if there is a library, if not, then return failure, do not continue

#ifndef __hss_hik_mp4_hss__#define__hss_hik_mp4_hss__/************************************************************************************************** * 2012-09-13 Play Hoi Hong Video usage: int __stdcall auto_hikmp4_callback_imp (LPARAM LPARAM, DWORD Dwtick, Lpbitmapinfoheader Pbih, Lpbyte pBi TS) {if (Dwtick = = 0) {//play stopped} else {Processrgb (0, LParam        , Dwtick, Pbih, Pbits, pbih->bisizeimage, 0, 0);    } return 0;    } Auto_hikmp4 Ahk;    Ahk.param.pCallback = Auto_hikmp4_callback_imp;    Ahk.param.lParma = (LPARAM) this; Ahk.    Open (Pszfile); Ahk. Close (); \**************************************************************************************************/#include<auto_dll.h>#include<auto_yuv.h>#include<HBuffer.h>#include<auto_bitmap_file.h>#include<StringN.h>#include"PlayM4.h"#pragmaComment (lib, "\\hss\\R2\\Projects\\Common\\hikmp4\\PlayCtrl.lib")#pragmaComment (linker, "/delayload:playctrl.dll")#pragmaComment (lib, "Delayimp.lib")typedefint(__stdcall *auto_hikmp4_callback) (LPARAM LPARAM, DWORD Dwtick, Lpbitmapinfoheader Pbih, Lpbyte pbits);classauto_hikmp4{ Public: Auto_hikmp4 () {M_blibok=0; M_lport= -1; M_dwplaytick=0; M_dwframecount=0;    __memzero (param); }    ~Auto_hikmp4 () {Close (); }    struct{auto_hikmp4_callback pcallback;        LPARAM LPARAM; DWORD bplayfastest:1;//April 28, 2013 maximum speed playback, no control frame rate}param; Public: BOOL Open (LPCTSTR pszfile) {Close (); if(!M_blibok)            {Auto_lib lib; //since the call to the PlayCtrl.dll library is delayed-loaded (delayload), even without this library, the program//can also start normally, but will cause an error when executing to a function inside the call library. So here we have to load this library dynamically .//If you do not have this library, the return failure does not continue. If there is a library, then the dynamic load is released here, the following call the function inside the library//when the delayload mechanism works. //This approach avoids the complexity of the dynamic loader, and also avoids the need to publish a static connection library with this library//Because there are many projects that share code, there may be projects that do not use this library, but the code is referenced to each other to include this code//This library does not use the program, do not have to publish the library, you can start the operation normally.             if(!lib. LoadLibrary ("PlayCtrl.dll"))                returnFALSE; Lib.            Release (); Sleep (Ten); M_blibok=TRUE;        } Auto_file af; if(!af. OpenRead (pszfile))returnFALSE; DWORD Mark=0; if(!af. Read (LPBYTE) &mark,4))            returnFALSE; if(Mark! = * (dword*)"4HKH"&& Mark! = * (dword*)"Imkh"            )        {            returnFALSE; } af.        Close (); Sleep (Ten); Playm4_getport (&m_lport); if(M_lport = =-1)            returnFALSE; Playm4_setdeccallbackmend (M_lport, Deccbfun, (Long) This); Playm4_setfileendcallback (M_lport, Fileendcallback, (void*) This); if(param.bplayfastest) {Playm4_setstreamopenmode (M_lport, streame_realtime); }        if(! Playm4_openfile (M_lport, (Char*) pszfile))returnFALSE; M_dwframecount=playm4_getfiletotalframes (M_lport); Playm4_play (M_lport,0); returnTRUE; }    voidCallbackdecode (frame_info* PFI, Lpbyte pbuffer,intnSize) {        if(Pfi->ntype! = t_yv12)//T_rgb32, T_uyvy            return; DWORD Dwtick=GetTickCount (); if(M_dwplaytick = =0) M_dwplaytick=Dwtick; if(!param.bplayfastest)//April 28, 2013        {             while(Dwtick +5< M_dwplaytick + pfi->Nstamp) {Sleep (5); Dwtick=GetTickCount (); }        }        intwidth = pfi->nwidth; intHeight = pfi->nheight;        Auto_bitmap_file ABF; LPBYTE PB= ABF. Getbitmap (&m_bufbmp, -, width, height); if(Pb = =0)            return;        m_yuv.i420 (pbuffer, Pb, Width, height); if(param.pcallback) {param.pcallback (Param.lparam, Dwtick, Abf.bih (), abf.bits ()); }    }    Static voidCALLBACK Deccbfun (LongNport,Char* PBuf,LongNSize, Frame_info * pframeinfo,LongNReserved1,LongnReserved2) {Auto_hikmp4* PhM = (auto_hikmp4*) nReserved1; if(PHM = =0)            return; ASSERT (Nport= = Phm->m_lport); PHM-Callbackdecode (Pframeinfo, (LPBYTE) PBuf, nSize); }    Static voidCALLBACK Fileendcallback (LongNport,void*puser) {Auto_hikmp4* PhM = (auto_hikmp4*) Puser; if(PHM = =0)            return; ASSERT (Nport= = Phm->m_lport); if(phm->param.pcallback) {PHM->param.pcallback (Phm->param.lparam,0,0,0); }    }    voidClose () {if(M_lport! =-1) {playm4_stop (m_lport);            Playm4_closefile (M_lport);            Playm4_freeport (M_lport); M_lport= -1; } M_dwplaytick=0; } Public: BOOL M_blibok;    LONG M_lport;    AUTO_YUV M_YUV;    Hbuffer m_bufbmp;    DWORD M_dwplaytick; DWORD M_dwframecount;};#endif

Decode the video and delay loading library of Hai Kang camera

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.