-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdllmain.cpp
67 lines (61 loc) · 2.46 KB
/
dllmain.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// dllmain.cpp : The entry of the dll program.
#include "stdafx.h"
#include "MpegPyd.h"
/*****************************************************************************
* The initialization of the module. Would be invoked when using import.
*****************************************************************************/
PyMODINIT_FUNC // == __decslpec(dllexport) PyObject*, Define the exported main function.
PyInit_mpegCoder(void) { // The external module name is: --CppClass
import_array();
/* Initialize libavcodec, and register all codecs and formats. */
// Register everything
#ifndef FFMPG3_4
av_register_all();
#endif
#ifndef FFMPG4_0
avformat_network_init();
#endif
PyObject* pReturn = 0;
// Configure the __new__ method as the default method. This method is used for building the instances.
C_MPDC_ClassInfo.tp_new = PyType_GenericNew;
C_MPEC_ClassInfo.tp_new = PyType_GenericNew;
C_MPCT_ClassInfo.tp_new = PyType_GenericNew;
C_MPSV_ClassInfo.tp_new = PyType_GenericNew;
/* Finish the initialization, including the derivations.
* When success, return 0; Otherwise, return -1 and throw errors. */
if (PyType_Ready(&C_MPDC_ClassInfo) < 0)
return nullptr;
if (PyType_Ready(&C_MPEC_ClassInfo) < 0)
return nullptr;
if (PyType_Ready(&C_MPCT_ClassInfo) < 0)
return nullptr;
if (PyType_Ready(&C_MPSV_ClassInfo) < 0)
return nullptr;
pReturn = PyModule_Create(&ModuleInfo); // Create the module according to the module info.
if (pReturn == 0)
return nullptr;
Py_INCREF(&ModuleInfo); // Because the module is not registered to the python counter, Py_INCREF is required to be invoked.
PyModule_AddFunctions(pReturn, C_MPC_MethodMembers); // Add the global method members.
PyModule_AddObject(pReturn, "MpegDecoder", (PyObject*)&C_MPDC_ClassInfo); // Add the class as one module member.
PyModule_AddObject(pReturn, "MpegEncoder", (PyObject*)&C_MPEC_ClassInfo);
PyModule_AddObject(pReturn, "MpegClient", (PyObject*)&C_MPCT_ClassInfo);
PyModule_AddObject(pReturn, "MpegServer", (PyObject*)&C_MPSV_ClassInfo);
return pReturn;
}
/*
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
*/