another small ttx subtitles fix
[enigma2.git] / lib / dvb / pmt.cpp
index 842d6979a3e1c227af1bdd316379e5de8011cc2e..279ec74f723eb5e1092f32b79ea833d6cebb669d 100644 (file)
@@ -16,6 +16,7 @@
 #include <dvbsi++/stream_identifier_descriptor.h>
 #include <dvbsi++/subtitling_descriptor.h>
 #include <dvbsi++/teletext_descriptor.h>
+#include <dvbsi++/video_stream_descriptor.h>
 
 eDVBServicePMTHandler::eDVBServicePMTHandler()
        :m_ca_servicePtr(0), m_dvb_scan(0), m_decode_demux_num(0xFF)
@@ -50,10 +51,13 @@ void eDVBServicePMTHandler::channelStateChanged(iDVBChannel *channel)
                {
                        eDebug("ok ... now we start!!");
 
-                       if (m_pmt_pid == -1)
-                               m_PAT.begin(eApp, eDVBPATSpec(), m_demux);
-                       else
-                               m_PMT.begin(eApp, eDVBPMTSpec(m_pmt_pid, m_reference.getServiceID().get()), m_demux);
+                       if (!m_service || m_service->usePMT())
+                       {
+                               if (m_pmt_pid == -1)
+                                       m_PAT.begin(eApp, eDVBPATSpec(), m_demux);
+                               else
+                                       m_PMT.begin(eApp, eDVBPMTSpec(m_pmt_pid, m_reference.getServiceID().get()), m_demux);
+                       }
 
                        if ( m_service && !m_service->cacheEmpty() )
                                serviceEvent(eventNewProgramInfo);
@@ -214,25 +218,49 @@ int eDVBServicePMTHandler::getProgramInfo(struct program &program)
                                        audioStream audio;
                                        audio.component_tag=video.component_tag=-1;
                                        video.type = videoStream::vtMPEG2;
+                                       audio.type = audioStream::atMPEG;
 
                                        switch ((*es)->getType())
                                        {
                                        case 0x1b: // AVC Video Stream (MPEG4 H264)
                                                video.type = videoStream::vtMPEG4_H264;
+                                               isvideo = 1;
+                                               //break; fall through !!!
+                                       case 0x10: // MPEG 4 Part 2
+                                               if (!isvideo)
+                                               {
+                                                       video.type = videoStream::vtMPEG4_Part2;
+                                                       isvideo = 1;
+                                               }
+                                               //break; fall through !!!
                                        case 0x01: // MPEG 1 video
+                                               if (!isvideo)
+                                                       video.type = videoStream::vtMPEG1;
+                                               //break; fall through !!!
                                        case 0x02: // MPEG 2 video
                                                isvideo = 1;
                                                //break; fall through !!!
                                        case 0x03: // MPEG 1 audio
                                        case 0x04: // MPEG 2 audio:
                                                if (!isvideo)
+                                                       isaudio = 1;
+                                               //break; fall through !!!
+                                       case 0x0f: // MPEG 2 AAC
+                                               if (!isvideo && !isaudio)
                                                {
                                                        isaudio = 1;
-                                                       audio.type = audioStream::atMPEG;
+                                                       audio.type = audioStream::atAAC;
                                                }
                                                //break; fall through !!!
+                                       case 0x11: // MPEG 4 AAC
+                                               if (!isvideo && !isaudio)
+                                               {
+                                                       isaudio = 1;
+                                                       audio.type = audioStream::atAACHE;
+                                               }
                                        case 0x06: // PES Private
                                        case 0x81: // user private
+                                       case 0xEA: // TS_PSI_ST_SMPTE_VC1
                                                for (DescriptorConstIterator desc = (*es)->getDescriptors()->begin();
                                                                desc != (*es)->getDescriptors()->end(); ++desc)
                                                {
@@ -243,6 +271,17 @@ int eDVBServicePMTHandler::getProgramInfo(struct program &program)
                                                                   check descriptors to get the exakt type. */
                                                                switch (tag)
                                                                {
+                                                               case AUDIO_STREAM_DESCRIPTOR:
+                                                                       isaudio = 1;
+                                                                       break;
+                                                               case VIDEO_STREAM_DESCRIPTOR:
+                                                               {
+                                                                       isvideo = 1;
+                                                                       VideoStreamDescriptor *d = (VideoStreamDescriptor*)(*desc);
+                                                                       if (d->getMpeg1OnlyFlag())
+                                                                               video.type = videoStream::vtMPEG1;
+                                                                       break;
+                                                               }
                                                                case SUBTITLING_DESCRIPTOR:
                                                                {
                                                                        SubtitlingDescriptor *d = (SubtitlingDescriptor*)(*desc);
@@ -301,9 +340,14 @@ int eDVBServicePMTHandler::getProgramInfo(struct program &program)
                                                                        isaudio = 1;
                                                                        audio.type = audioStream::atDTS;
                                                                        break;
+                                                               case 0x2B: // TS_PSI_DT_MPEG2_AAC
+                                                                       isaudio = 1;
+                                                                       audio.type = audioStream::atAAC; // MPEG2-AAC
+                                                                       break;
+                                                               case 0x1C: // TS_PSI_DT_MPEG4_Audio
                                                                case AAC_DESCRIPTOR:
                                                                        isaudio = 1;
-                                                                       audio.type = audioStream::atAAC;
+                                                                       audio.type = audioStream::atAACHE; // MPEG4-AAC
                                                                        break;
                                                                case AC3_DESCRIPTOR:
                                                                        isaudio = 1;
@@ -312,7 +356,7 @@ int eDVBServicePMTHandler::getProgramInfo(struct program &program)
                                                                case REGISTRATION_DESCRIPTOR: /* some services don't have a separate AC3 descriptor */
                                                                {
                                                                                /* libdvbsi++ doesn't yet support this descriptor type, so work around. */
-                                                                       if ((*desc)->getLength() != 4)
+                                                                       if ((*desc)->getLength() < 4)
                                                                                break;
                                                                        unsigned char descr[6];
                                                                        (*desc)->writeToBuffer(descr);
@@ -323,11 +367,29 @@ int eDVBServicePMTHandler::getProgramInfo(struct program &program)
                                                                                isaudio = 1;
                                                                                audio.type = audioStream::atAC3;
                                                                                break;
+                                                                       case 0x56432d31:
+                                                                               if (descr[6] == 0x01) // subdescriptor tag
+                                                                               {
+                                                                                       if (descr[7] >= 0x90) // profile_level
+                                                                                               video.type = videoStream::vtVC1; // advanced profile
+                                                                                       else
+                                                                                               video.type = videoStream::vtVC1_SM; // simple main
+                                                                                       isvideo = 1;
+                                                                               }
+                                                                               break;
                                                                        default:
                                                                                break;
                                                                        }
                                                                        break;
                                                                }
+                                                               case 0x28: // TS_PSI_DT_AVC
+                                                                       isvideo = 1;
+                                                                       video.type = videoStream::vtMPEG4_H264;
+                                                                       break;
+                                                               case 0x1B: // TS_PSI_DT_MPEG4_Video
+                                                                       isvideo = 1;
+                                                                       video.type = videoStream::vtMPEG4_Part2;
+                                                                       break;
                                                                default:
                                                                        break;
                                                                }
@@ -1143,8 +1205,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 +1216,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 +1247,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;
 }