kodi-pvr / pvr.vuplus

Kodi's Enigma2 client add-on
GNU General Public License v2.0
56 stars 55 forks source link

Set the program number #195

Closed joaoppp closed 5 years ago

joaoppp commented 5 years ago

I'm requesting that for each channel the mpegts program number be included too if exists at m3u EXTVLCOPT:program, so it would then be picked by kodi at:

  // in case of mpegts and we have not seen pat/pmt, defer creation of streams
  if (!skipCreateStreams || m_pFormatContext->nb_programs > 0)
  {
    unsigned int nProgram = UINT_MAX;
    if (m_pFormatContext->nb_programs > 0)
    {
      // select the correct program if requested
      CVariant programProp(pInput->GetProperty("program"));
      if (!programProp.isNull())
      {
        int programNumber = static_cast<int>(programProp.asInteger());

        for (unsigned int i = 0; i < m_pFormatContext->nb_programs; ++i)
        {
          if (m_pFormatContext->programs[i]->program_num == programNumber)
          {
            nProgram = i;
            break;
          }
        }
      }
phunkyfish commented 5 years ago

Then it’s just one bug to file luckily.

What I don’t understand is why more users don’t have the same issue.

joaoppp commented 5 years ago

I have a workaround. Not as fast and with many features as you @phunkyfish have it now, and for that you are doing a good job. The workaround is a old version of this plugin with PVR API 5.10.1 (https://github.com/kodi-pvr/pvr.vuplus/tree/e2efab9eecfce2fc4feefa2f47250e4dc5eb7a60) with this patch:

--- src/client.cpp
+++ src/client.cpp
@@ -26,6 +26,7 @@
 #include "VuData.h"
 #include <p8-platform/util/StringUtils.h>
 #include "p8-platform/util/util.h"
+#include <regex>

 using namespace std;
 using namespace ADDON;
@@ -408,6 +409,15 @@
   strncpy(properties[1].strName, PVR_STREAM_PROPERTY_ISREALTIMESTREAM, sizeof(properties[1].strName) - 1);
   strncpy(properties[1].strValue, "true", sizeof(properties[1].strValue) - 1);
   *iPropertiesCount = 2;
+
+  std::cmatch cm; 
+  if (std::regex_match(strStreamURL.c_str(), cm, std::regex("https?://[^/]+/[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:([0-9a-f]+):.*?", std::regex_constants::icase))) {
+    XBMC->Log(LOG_INFO, "%s - Set program to %s.", __FUNCTION__, std::to_string(strtol(cm.str(1).c_str(), NULL, 16)).c_str());
+    strncpy(properties[2].strName, "program", sizeof(properties[2].strName) - 1);
+    strncpy(properties[2].strValue, std::to_string(strtol(cm.str(1).c_str(), NULL, 16)).c_str(), sizeof(properties[2].strValue) - 1);
+    (*iPropertiesCount)++;
+  }
+
   return PVR_ERROR_NO_ERROR;
 }

@FernetMenta This problem have a simple fix at kodi, and don't envolves changing nothing in this plugin or in any kodi API. In 2017 I shared with the community this peace of code accepted by you:

        // skip programs without or empty audio/video streams
        for (unsigned int i = 0; nProgram == UINT_MAX && i < m_pFormatContext->nb_programs; i++)
        {
          for (unsigned int j = 0; j < m_pFormatContext->programs[i]->nb_stream_indexes; j++)
          {
            int idx = m_pFormatContext->programs[i]->stream_index[j];
            AVStream *st = m_pFormatContext->streams[idx];
            if ((st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->codec_info_nb_frames > 0) ||
                (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->sample_rate > 0))
            {
              nProgram = i;
              break;
            }
          }
        }

but it requires a avformat_find_stream_info() before. A simple patch for this:

--- xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp
+++ xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp
@@ -459,7 +459,7 @@
   m_bAVI = strcmp(m_pFormatContext->iformat->name, "avi") == 0;
   m_bSup = strcmp(m_pFormatContext->iformat->name, "sup") == 0;

-  if (m_streaminfo)
+  if (m_streaminfo || m_pFormatContext->nb_programs > 0)
   {
     /* to speed up dvd switches, only analyse very short */
     if(m_pInput->IsStreamType(DVDSTREAM_TYPE_DVD))

@phunkyfish I will try to explore the openATV source to understand what's going on, and then report the bug. Can you point me where to look?

FernetMenta commented 5 years ago

@joaoppp this patch is wrong. nb_programs is greater 0 for a lot of cases streaminfo is not desired. btw: in order to fix some other issues, streaminfo needs to be skipped for all mpegts.

joaoppp commented 5 years ago

@joaoppp this patch is wrong. nb_programs is greater 0 for a lot of cases streaminfo is not desired. btw: in order to fix some other issues, streaminfo needs to be skipped for all mpegts.

@FernetMenta But if avformat_find_stream_info() is skipped how would this work?

        // skip programs without or empty audio/video streams
        for (unsigned int i = 0; nProgram == UINT_MAX && i < m_pFormatContext->nb_programs; i++)
        {
          for (unsigned int j = 0; j < m_pFormatContext->programs[i]->nb_stream_indexes; j++)
          {
            int idx = m_pFormatContext->programs[i]->stream_index[j];
            AVStream *st = m_pFormatContext->streams[idx];
            if ((st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->codec_info_nb_frames > 0) ||
                (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->sample_rate > 0))
            {
              nProgram = i;
              break;
            }
          }
        }

Is there any better way?

FernetMenta commented 5 years ago

try moving this code to CDVDDemuxFFmpeg::CreateStreams. this method gets called after every streamchange.

phunkyfish commented 5 years ago

@phunkyfish I will try to explore the openATV source to understand what's going on, and then report the bug. Can you point me where to look?

Afraid I don't know @joaoppp. With Enigma2 I usually post in the images forum and track down the component to report the bug in from there. I assume this would be a core issue.

joaoppp commented 5 years ago

@FernetMenta What about replace this:

        // skip programs without or empty audio/video streams
        for (unsigned int i = 0; nProgram == UINT_MAX && i < m_pFormatContext->nb_programs; i++)
        {
          for (unsigned int j = 0; j < m_pFormatContext->programs[i]->nb_stream_indexes; j++)
          {
            int idx = m_pFormatContext->programs[i]->stream_index[j];
            AVStream *st = m_pFormatContext->streams[idx];
            if ((st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->codec_info_nb_frames > 0) ||
                (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->sample_rate > 0))
            {
              nProgram = i;
              break;
            }
          }
        }

by this: (tested and working)

        // select the program of the first audio or video stream packet found (FIFO)
        AVStream *st;
        unsigned int maxpkts = 25;
        while (nProgram == UINT_MAX && maxpkts-- && (m_pkt.result = av_read_frame(m_pFormatContext, &m_pkt.pkt)) >= 0)
        {
          st = m_pFormatContext->streams[m_pkt.pkt.stream_index];
          if (st->codecpar && (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO))
          {
            for (unsigned int i = 0; nProgram == UINT_MAX && i < m_pFormatContext->nb_programs; i++)
            {
              for (unsigned int j = 0; j < m_pFormatContext->programs[i]->nb_stream_indexes; j++)
              {
                if ((int)m_pFormatContext->programs[i]->stream_index[j] == m_pkt.pkt.stream_index)
                {
                  nProgram = i;
                  break;
                }
              }
            }
          }
          m_pkt.result = -1;
          av_packet_unref(&m_pkt.pkt);
        }
joaoppp commented 5 years ago

@phunkyfish I will try to explore the openATV source to understand what's going on, and then report the bug. Can you point me where to look?

Afraid I don't know @joaoppp. With Enigma2 I usually post in the images forum and track down the component to report the bug in from there. I assume this would be a core issue.

I will investigate this thanks.

phunkyfish commented 5 years ago

@joaoppp have you tried transcoding yet?

phunkyfish commented 5 years ago

I wonder is this the same issue as #208

So an MPTS stream, can you check if you can playback a recording from your STB?

phunkyfish commented 5 years ago

@joaoppp?

phunkyfish commented 5 years ago

@joaoppp are you still there?

phunkyfish commented 5 years ago

Have created two PR's one for Leia (#230) and one for matrix (#229).

@joaoppp can you test either of these?

phunkyfish commented 5 years ago

Closing, please see #237 for solution.