Skip to content

Commit

Permalink
fix bug for python args parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
neptune46 committed Feb 2, 2018
1 parent 8f8d5d4 commit 50db2f6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/pyva_dx11/test_valib_dx11/test_valib_dx11.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def getProfile(profiles):
def createDecoder(codec, w, h):
ret = pyva.init()
if ret == 0:
ret = pyva.createDecoder(w, h)
ret = pyva.createDecoder(codec, w, h)
if ret == 0:
print("create video decoder: succeed")
else:
Expand Down
27 changes: 21 additions & 6 deletions src/pyva_dx11/valib_dx11/valib_dx11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,30 @@ PyObject *decoderProfile(PyObject *, PyObject* o)
guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
}

PyObject *createVideoDecoder(PyObject *, PyObject* w, PyObject* h)
PyObject *createVideoDecoder(PyObject *self, PyObject *args)
{
std::string codecName = "h264"; // PyUnicode_AsUTF8(codec);
uint32_t width = 1920; // PyLong_AsLong(w);
uint32_t height = 1080; // PyLong_AsLong(h);
GUID profile = guidMap.getGuid(codecName);
uint32_t ret = -1;
const char* strCodec = nullptr;
uint32_t width = 0;
uint32_t height = 0;

// METH_O: Method 1
//const char* p2 = PyUnicode_AsUTF8(codec);

// METH_O: Method 2
//PyObject* bytes = PyUnicode_AsUTF8String(codec);
//std::string file_name = PyBytes_AsString(bytes);
//if (PyErr_Occurred())
// return NULL;

// METH_VARARGS: Method 3
if (!PyArg_ParseTuple(args, "sII", &strCodec, &width, &height))
return PyLong_FromLong(ret);

GUID profile = guidMap.getGuid(strCodec);
HRESULT hr = decoderObj.createVideoDecoder(profile, width, height);
uint32_t ret = SUCCEEDED(hr) ? 0 : -1;
ret = SUCCEEDED(hr) ? 0 : -1;

return PyLong_FromLong(ret);
}

Expand Down

0 comments on commit 50db2f6

Please sign in to comment.