Advertisement
Guest User

XBMC TVHeadend Transcoding

a guest
Jul 15th, 2012
619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 9.32 KB | None | 0 0
  1. diff --git a/addons/pvr.hts/resources/language/English/strings.xml b/addons/pvr.hts/resources/language/English/strings.xml
  2. index 5b69906..d05fdfd 100644
  3. --- a/addons/pvr.hts/resources/language/English/strings.xml
  4. +++ b/addons/pvr.hts/resources/language/English/strings.xml
  5. @@ -8,6 +8,14 @@
  6.      <string id="30004">Password</string>
  7.      <string id="30006">Connect timeout in seconds</string>
  8.      <string id="30007">Response timeout in seconds</string>
  9. +    <string id="30008">Enable transcoding</string>
  10. +    <string id="30009">Audio codec</string>
  11. +    <string id="30010">Video codec</string>
  12. +    <string id="30011">Resolution</string>
  13. +
  14. +    <!-- category labels -->
  15. +    <string id="30040">Connection</string>
  16. +    <string id="30041">Transcoding</string>
  17.  
  18.      <!-- notifications -->
  19.      <string id="30500">Disconnected from '%s'</string>
  20. diff --git a/addons/pvr.hts/resources/settings.xml b/addons/pvr.hts/resources/settings.xml
  21. index 3ef0839..43aa760 100644
  22. --- a/addons/pvr.hts/resources/settings.xml
  23. +++ b/addons/pvr.hts/resources/settings.xml
  24. @@ -1,5 +1,8 @@
  25.  <?xml version="1.0" encoding="utf-8" standalone="yes"?>
  26.  <settings>
  27. +
  28. +  <!-- Connection -->
  29. +  <category label="30040">
  30.      <setting id="host" type="text" label="30000" default="127.0.0.1" />
  31.      <setting id="http_port" type="number" label="30001" default="9981" />
  32.      <setting id="htsp_port" type="number" label="30002" default="9982" />
  33. @@ -7,4 +10,13 @@
  34.      <setting id="pass" type="text" label="30004" option="hidden" default="" />
  35.      <setting id="connect_timeout" type="enum" label="30006" values="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" default="29" />
  36.      <setting id="response_timeout" type="enum" label="30007" values="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" default="1" />
  37. +  </category>
  38. +
  39. +  <!-- Transcoding -->
  40. +  <category label="30041">
  41. +    <setting id="transcode" type="bool" label="30008" default="false" />
  42. +    <setting id="audio_codec" type="enum" label="30009" values="MPEG2 Audio|AAC" default="1"/>
  43. +    <setting id="video_codec" type="enum" label="30010" values="MPEG2 Video|H264" default="1"/>
  44. +    <setting id="video_res" type="enum" label="30011" values="288p|384p|480p|576p|720p|1080p" default="2"/>
  45. +  </category>
  46.  </settings>
  47. diff --git a/xbmc/pvrclients/tvheadend/HTSPDemux.cpp b/xbmc/pvrclients/tvheadend/HTSPDemux.cpp
  48. index ce11fc1..25a4cdb 100644
  49. --- a/xbmc/pvrclients/tvheadend/HTSPDemux.cpp
  50. +++ b/xbmc/pvrclients/tvheadend/HTSPDemux.cpp
  51. @@ -444,6 +444,13 @@ bool CHTSPDemux::SendSubscribe(int subscription, int channel)
  52.    htsmsg_add_str(m, "method"        , "subscribe");
  53.    htsmsg_add_s32(m, "channelId"     , channel);
  54.    htsmsg_add_s32(m, "subscriptionId", subscription);
  55. +  if(g_bTranscode)
  56. +  {
  57. +    htsmsg_add_u32(m, "maxWidth"    , g_iResolution * 16 / 9);
  58. +    htsmsg_add_u32(m, "maxHeight"   , g_iResolution);
  59. +    htsmsg_add_str(m, "audioCodec"  , g_strAudioCodec.c_str());
  60. +    htsmsg_add_str(m, "videoCodec"  , g_strVideoCodec.c_str());
  61. +  }
  62.    return m_session->ReadSuccess(m, true, "subscribe to channel");
  63.  }
  64.  
  65. diff --git a/xbmc/pvrclients/tvheadend/client.cpp b/xbmc/pvrclients/tvheadend/client.cpp
  66. index d9a89e6..5602fa4 100644
  67. --- a/xbmc/pvrclients/tvheadend/client.cpp
  68. +++ b/xbmc/pvrclients/tvheadend/client.cpp
  69. @@ -45,21 +45,34 @@ std::string g_strUsername             = "";
  70.  std::string g_strPassword             = "";
  71.  std::string g_strUserPath             = "";
  72.  std::string g_strClientPath           = "";
  73. +bool        g_bTranscode              = DEFAULT_TRANSCODE;
  74. +std::string g_strAudioCodec           = "";
  75. +std::string g_strVideoCodec           = "";
  76. +int         g_iResolution             = DEFAULT_RESOLUTION;
  77.  
  78.  CHelper_libXBMC_addon *XBMC           = NULL;
  79.  CHelper_libXBMC_pvr   *PVR            = NULL;
  80.  CHTSPDemux *           HTSPDemuxer    = NULL;
  81.  CHTSPData *            HTSPData       = NULL;
  82.  
  83. +#define VIDEO_CODEC_LIST_SIZE 2
  84. +#define AUDIO_CODEC_LIST_SIZE 2
  85. +#define RESOLUTION_LIST_SIZE 6
  86. +
  87. +static const char *pVideoCodecList[VIDEO_CODEC_LIST_SIZE] = {"MPEG2VIDEO", "H264"};
  88. +static const char *pAudioCodecList[AUDIO_CODEC_LIST_SIZE] = {"MPEG2AUDIO", "AAC"};
  89. +static const int   pResolutionList[RESOLUTION_LIST_SIZE]  = {288, 384, 480, 576, 720, 1080};
  90. +
  91.  extern "C" {
  92.  
  93.  void ADDON_ReadSettings(void)
  94.  {
  95. -  /* read setting "host" from settings.xml */
  96. +  uint32_t iEnumIndex;
  97.    char * buffer;
  98.    buffer = (char*) malloc (1024);
  99.    buffer[0] = 0; /* Set the end of string */
  100.  
  101. +  /* read setting "host" from settings.xml */
  102.    if (XBMC->GetSetting("host", buffer))
  103.      g_strHostname = buffer;
  104.    else
  105. @@ -96,6 +109,34 @@ void ADDON_ReadSettings(void)
  106.    /* read setting "read_timeout" from settings.xml */
  107.    if (!XBMC->GetSetting("response_timeout", &g_iResponseTimeout))
  108.      g_iResponseTimeout = DEFAULT_RESPONSE_TIMEOUT;
  109. +
  110. +  /* read setting "transcode" from settings.xml */
  111. +  if (!XBMC->GetSetting("transcode", &g_bTranscode))
  112. +    g_bTranscode = DEFAULT_TRANSCODE;
  113. +
  114. +  /* read setting "audio_codec" from settings.xml */
  115. +  if (!XBMC->GetSetting("audio_codec", &iEnumIndex))
  116. +    g_strAudioCodec = "";
  117. +  else if (iEnumIndex < AUDIO_CODEC_LIST_SIZE)
  118. +    g_strAudioCodec = pAudioCodecList[iEnumIndex];
  119. +  else
  120. +    g_strAudioCodec = "";
  121. +
  122. +  /* read setting "video_codec" from settings.xml */
  123. +  if (!XBMC->GetSetting("video_codec", &iEnumIndex))
  124. +    g_strVideoCodec = "";
  125. +  else if (iEnumIndex < VIDEO_CODEC_LIST_SIZE)
  126. +    g_strVideoCodec = pVideoCodecList[iEnumIndex];
  127. +  else
  128. +    g_strVideoCodec = "";
  129. +
  130. +  /* read setting "video_res" from settings.xml */
  131. +  if (!XBMC->GetSetting("video_res", &iEnumIndex))
  132. +    g_iResolution = DEFAULT_RESOLUTION;
  133. +  else if (iEnumIndex < RESOLUTION_LIST_SIZE)
  134. +    g_iResolution = pResolutionList[iEnumIndex];
  135. +  else
  136. +    g_iResolution = DEFAULT_RESOLUTION;
  137.  }
  138.  
  139.  ADDON_STATUS ADDON_Create(void* hdl, void* props)
  140. @@ -266,6 +307,67 @@ ADDON_STATUS ADDON_SetSetting(const char *settingName, const void *settingValue)
  141.        return ADDON_STATUS_OK;
  142.      }
  143.    }
  144. +  else if (str == "transcode")
  145. +  {
  146. +    bool bNewValue = *(bool*) settingValue;
  147. +    if (g_bTranscode != bNewValue)
  148. +    {
  149. +      XBMC->Log(LOG_INFO, "%s - Changed Setting 'transcode' from %u to %u", __FUNCTION__, g_bTranscode, bNewValue);
  150. +      g_bTranscode = bNewValue;
  151. +      return ADDON_STATUS_OK;
  152. +    }
  153. +  }
  154. +  else if (str == "audio_codec")
  155. +  {
  156. +    uint32_t iEnumIndex = *(uint32_t*) settingValue;
  157. +    string tmp_sAudioCodec = g_strAudioCodec;
  158. +
  159. +    if (iEnumIndex < AUDIO_CODEC_LIST_SIZE)
  160. +      tmp_sAudioCodec = pAudioCodecList[iEnumIndex];
  161. +    else
  162. +      tmp_sAudioCodec = "";
  163. +
  164. +    if (tmp_sAudioCodec != g_strAudioCodec)
  165. +    {
  166. +      XBMC->Log(LOG_INFO, "%s - Changed Setting 'audio_codec' from %s to %s", __FUNCTION__, tmp_sAudioCodec.c_str(), g_strAudioCodec.c_str());
  167. +      g_strAudioCodec = tmp_sAudioCodec;
  168. +      return ADDON_STATUS_OK;
  169. +    }
  170. +  }
  171. +  else if (str == "video_codec")
  172. +  {
  173. +    uint32_t iEnumIndex = *(uint32_t*) settingValue;
  174. +    string tmp_sVideoCodec = g_strVideoCodec;
  175. +
  176. +    if (iEnumIndex < VIDEO_CODEC_LIST_SIZE)
  177. +      tmp_sVideoCodec = pVideoCodecList[iEnumIndex];
  178. +    else
  179. +      tmp_sVideoCodec = "";
  180. +
  181. +    if (tmp_sVideoCodec != g_strVideoCodec)
  182. +    {
  183. +      XBMC->Log(LOG_INFO, "%s - Changed Setting 'video_codec' from %s to %s", __FUNCTION__, tmp_sVideoCodec.c_str(), g_strVideoCodec.c_str());
  184. +      g_strVideoCodec = tmp_sVideoCodec;
  185. +      return ADDON_STATUS_OK;
  186. +    }
  187. +  }
  188. +  else if (str == "video_res")
  189. +  {
  190. +    uint32_t iEnumIndex = *(uint32_t*) settingValue;
  191. +    int iNewValue = g_iResolution;
  192. +
  193. +    if (iEnumIndex < RESOLUTION_LIST_SIZE)
  194. +      iNewValue = pResolutionList[iEnumIndex];
  195. +    else
  196. +      iNewValue = DEFAULT_RESOLUTION;
  197. +
  198. +    if (g_iResolution != iNewValue)
  199. +    {
  200. +      XBMC->Log(LOG_INFO, "%s - Changed Setting 'video_res' from %u to %u", __FUNCTION__, g_iResolution, iNewValue);
  201. +      g_iResolution = iNewValue;
  202. +      return ADDON_STATUS_OK;
  203. +    }
  204. +  }
  205.    return ADDON_STATUS_OK;
  206.  }
  207.  
  208. diff --git a/xbmc/pvrclients/tvheadend/client.h b/xbmc/pvrclients/tvheadend/client.h
  209. index 27c8a81..f812c88 100644
  210. --- a/xbmc/pvrclients/tvheadend/client.h
  211. +++ b/xbmc/pvrclients/tvheadend/client.h
  212. @@ -28,6 +28,8 @@
  213.  #define DEFAULT_HTSP_PORT        9982
  214.  #define DEFAULT_CONNECT_TIMEOUT  30
  215.  #define DEFAULT_RESPONSE_TIMEOUT 3
  216. +#define DEFAULT_TRANSCODE        false
  217. +#define DEFAULT_RESOLUTION       480
  218.  
  219.  extern bool                      m_bCreated;
  220.  extern std::string               g_strHostname;
  221. @@ -37,6 +39,10 @@ extern std::string               g_strUsername;
  222.  extern std::string               g_strPassword;
  223.  extern int                       g_iConnectTimeout;
  224.  extern int                       g_iResponseTimeout;
  225. +extern bool                      g_bTranscode;
  226. +extern std::string               g_strAudioCodec;
  227. +extern std::string               g_strVideoCodec;
  228. +extern int                       g_iResolution;
  229.  extern int                       g_iClientId;
  230.  extern unsigned int              g_iPacketSequence;
  231.  extern bool                      g_bShowTimerNotifications;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement