some refcounting fixes and speedups
authorghost <andreas.monzner@multimedia-labs.de>
Tue, 25 Nov 2008 18:07:44 +0000 (19:07 +0100)
committerghost <andreas.monzner@multimedia-labs.de>
Tue, 25 Nov 2008 18:07:44 +0000 (19:07 +0100)
lib/dvb/pmt.cpp
lib/service/servicedvb.cpp
lib/service/servicedvbrecord.cpp

index 842d697..25ac546 100644 (file)
@@ -1143,8 +1143,8 @@ void eDVBCAService::sendCAPMT()
 static PyObject *createTuple(int pid, const char *type)
 {
        PyObject *r = PyTuple_New(2);
-       PyTuple_SetItem(r, 0, PyInt_FromLong(pid));
-       PyTuple_SetItem(r, 1, PyString_FromString(type));
+       PyTuple_SET_ITEM(r, 0, PyInt_FromLong(pid));
+       PyTuple_SET_ITEM(r, 1, PyString_FromString(type));
        return r;
 }
 
@@ -1154,17 +1154,18 @@ static inline void PyList_AppendSteal(PyObject *list, PyObject *item)
        Py_DECREF(item);
 }
 
+extern void PutToDict(ePyObject &dict, const char*key, ePyObject item); // defined in dvb/frontend.cpp
+
 PyObject *eDVBServicePMTHandler::program::createPythonObject()
 {
-       PyObject *r = PyDict_New();
+       ePyObject r = PyDict_New();
+       ePyObject l = PyList_New(0);
 
-       PyObject *l = PyList_New(0);
-       
        PyList_AppendSteal(l, createTuple(0, "pat"));
 
        if (pmtPid != -1)
                PyList_AppendSteal(l, createTuple(pmtPid, "pmt"));
-       
+
        for (std::vector<eDVBServicePMTHandler::videoStream>::const_iterator
                        i(videoStreams.begin()); 
                        i != videoStreams.end(); ++i)
@@ -1184,7 +1185,8 @@ PyObject *eDVBServicePMTHandler::program::createPythonObject()
 
        if (textPid != -1)
                PyList_AppendSteal(l, createTuple(textPid, "text"));
-               
-       PyDict_SetItemString(r, "pids", l);
+
+       PutToDict(r, "pids", l);
+
        return r;
 }
index 4141236..f3183fe 100644 (file)
@@ -109,7 +109,7 @@ static void PutToDict(ePyObject &dict, const char*key, long value)
                eDebug("could not create PyObject for %s", key);
 }
 
-extern void PutToDict(ePyObject &dict, const char*key, const char *value);
+extern void PutToDict(ePyObject &dict, const char*key, const char *value); // defined in dvb/frontend.cpp
 
 void PutSatelliteDataToDict(ePyObject &dict, eDVBFrontendParametersSatellite &feparm)
 {
@@ -2197,8 +2197,8 @@ PyObject *eDVBServicePlay::getCutList()
        for (std::multiset<struct cueEntry>::iterator i(m_cue_entries.begin()); i != m_cue_entries.end(); ++i)
        {
                ePyObject tuple = PyTuple_New(2);
-               PyTuple_SetItem(tuple, 0, PyLong_FromLongLong(i->where));
-               PyTuple_SetItem(tuple, 1, PyInt_FromLong(i->what));
+               PyTuple_SET_ITEM(tuple, 0, PyLong_FromLongLong(i->where));
+               PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(i->what));
                PyList_Append(list, tuple);
                Py_DECREF(tuple);
        }
@@ -3020,23 +3020,23 @@ RESULT eDVBServicePlay::stream(ePtr<iStreamableService> &ptr)
        return 0;
 }
 
+extern void PutToDict(ePyObject &dict, const char*key, ePyObject item); // defined in dvb/frontend.cpp
+
 PyObject *eDVBServicePlay::getStreamingData()
 {
        eDVBServicePMTHandler::program program;
        if (m_service_handler.getProgramInfo(program))
        {
-               Py_INCREF(Py_None);
-               return Py_None;
+               Py_RETURN_NONE;
        }
 
-       PyObject *r = program.createPythonObject();
+       ePyObject r = program.createPythonObject();
        ePtr<iDVBDemux> demux;
        if (!m_service_handler.getDataDemux(demux))
        {
                uint8_t demux_id;
-               demux->getCADemuxID(demux_id);
-               
-               PyDict_SetItemString(r, "demux", PyInt_FromLong(demux_id));
+               if (!demux->getCADemuxID(demux_id))
+                       PutToDict(r, "demux", PyInt_FromLong(demux_id));
        }
 
        return r;
index 89d022c..b63776d 100644 (file)
@@ -363,23 +363,23 @@ RESULT eDVBServiceRecord::stream(ePtr<iStreamableService> &ptr)
        return 0;
 }
 
+extern void PutToDict(ePyObject &dict, const char*key, ePyObject item);  // defined in dvb/frontend.cpp
+
 PyObject *eDVBServiceRecord::getStreamingData()
 {
        eDVBServicePMTHandler::program program;
        if (!m_tuned || m_service_handler.getProgramInfo(program))
        {
-               Py_INCREF(Py_None);
-               return Py_None;
+               Py_RETURN_NONE;
        }
 
-       PyObject *r = program.createPythonObject();
+       ePyObject r = program.createPythonObject();
        ePtr<iDVBDemux> demux;
        if (!m_service_handler.getDataDemux(demux))
        {
                uint8_t demux_id;
-               demux->getCADemuxID(demux_id);
-               
-               PyDict_SetItemString(r, "demux", PyInt_FromLong(demux_id));
+               if (!demux->getCADemuxID(demux_id))
+                       PutToDict(r, "demux", PyInt_FromLong(demux_id));
        }
 
        return r;