diff options
| author | manuel <manuel@mausz.at> | 2015-03-04 00:23:39 +0100 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2015-03-04 00:23:39 +0100 |
| commit | 9d11b08ad61b1f0d6d7023ce403285d8662efaed (patch) | |
| tree | 5bc0c947d9e10d3e8c9dc1e6b26f3d6599f0cea1 /xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxHTSP.cpp | |
| parent | c159d9f91f1573901868100a9464527a5a71575b (diff) | |
| download | kodi-pvr-build-9d11b08ad61b1f0d6d7023ce403285d8662efaed.tar.gz kodi-pvr-build-9d11b08ad61b1f0d6d7023ce403285d8662efaed.tar.bz2 kodi-pvr-build-9d11b08ad61b1f0d6d7023ce403285d8662efaed.zip | |
sync with upstream
Diffstat (limited to 'xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxHTSP.cpp')
| -rw-r--r-- | xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxHTSP.cpp | 391 |
1 files changed, 0 insertions, 391 deletions
diff --git a/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxHTSP.cpp b/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxHTSP.cpp deleted file mode 100644 index 3674416..0000000 --- a/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxHTSP.cpp +++ /dev/null | |||
| @@ -1,391 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2005-2013 Team XBMC | ||
| 3 | * http://xbmc.org | ||
| 4 | * | ||
| 5 | * This Program is free software; you can redistribute it and/or modify | ||
| 6 | * it under the terms of the GNU General Public License as published by | ||
| 7 | * the Free Software Foundation; either version 2, or (at your option) | ||
| 8 | * any later version. | ||
| 9 | * | ||
| 10 | * This Program is distributed in the hope that it will be useful, | ||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | * GNU General Public License for more details. | ||
| 14 | * | ||
| 15 | * You should have received a copy of the GNU General Public License | ||
| 16 | * along with XBMC; see the file COPYING. If not, see | ||
| 17 | * <http://www.gnu.org/licenses/>. | ||
| 18 | * | ||
| 19 | */ | ||
| 20 | |||
| 21 | |||
| 22 | #include "DVDCodecs/DVDCodecs.h" | ||
| 23 | #include "DVDInputStreams/DVDInputStream.h" | ||
| 24 | #include "DVDInputStreams/DVDInputStreamHTSP.h" | ||
| 25 | #include "DVDDemuxHTSP.h" | ||
| 26 | #include "DVDDemuxUtils.h" | ||
| 27 | #include "DVDClock.h" | ||
| 28 | #include "dialogs/GUIDialogKaiToast.h" | ||
| 29 | #include "utils/log.h" | ||
| 30 | #include "utils/StringUtils.h" | ||
| 31 | #include <arpa/inet.h> | ||
| 32 | |||
| 33 | extern "C" { | ||
| 34 | #include "lib/libhts/net.h" | ||
| 35 | #include "lib/libhts/htsmsg.h" | ||
| 36 | #include "lib/libhts/htsmsg_binary.h" | ||
| 37 | } | ||
| 38 | |||
| 39 | using namespace std; | ||
| 40 | using namespace HTSP; | ||
| 41 | |||
| 42 | class CDemuxStreamVideoHTSP | ||
| 43 | : public CDemuxStreamVideo | ||
| 44 | { | ||
| 45 | CDVDDemuxHTSP *m_parent; | ||
| 46 | string m_codec; | ||
| 47 | public: | ||
| 48 | CDemuxStreamVideoHTSP(CDVDDemuxHTSP *parent, const string& codec) | ||
| 49 | : m_parent(parent) | ||
| 50 | , m_codec(codec) | ||
| 51 | {} | ||
| 52 | void GetStreamInfo(std::string& strInfo) | ||
| 53 | { | ||
| 54 | strInfo = StringUtils::Format("%s, delay: %u, drops: %ub %up %ui" | ||
| 55 | , m_codec.c_str() | ||
| 56 | , m_parent->m_QueueStatus.delay | ||
| 57 | , m_parent->m_QueueStatus.bdrops | ||
| 58 | , m_parent->m_QueueStatus.pdrops | ||
| 59 | , m_parent->m_QueueStatus.idrops); | ||
| 60 | } | ||
| 61 | }; | ||
| 62 | |||
| 63 | class CDemuxStreamAudioHTSP | ||
| 64 | : public CDemuxStreamAudio | ||
| 65 | { | ||
| 66 | CDVDDemuxHTSP *m_parent; | ||
| 67 | string m_codec; | ||
| 68 | public: | ||
| 69 | CDemuxStreamAudioHTSP(CDVDDemuxHTSP *parent, const string& codec) | ||
| 70 | : m_parent(parent) | ||
| 71 | , m_codec(codec) | ||
| 72 | |||
| 73 | {} | ||
| 74 | void GetStreamInfo(string& strInfo) | ||
| 75 | { | ||
| 76 | strInfo = StringUtils::Format("%s", m_codec.c_str()); | ||
| 77 | } | ||
| 78 | }; | ||
| 79 | |||
| 80 | CDVDDemuxHTSP::CDVDDemuxHTSP() | ||
| 81 | : CDVDDemux() | ||
| 82 | , m_Input(NULL) | ||
| 83 | , m_StatusCount(0) | ||
| 84 | { | ||
| 85 | } | ||
| 86 | |||
| 87 | CDVDDemuxHTSP::~CDVDDemuxHTSP() | ||
| 88 | { | ||
| 89 | Dispose(); | ||
| 90 | } | ||
| 91 | |||
| 92 | bool CDVDDemuxHTSP::Open(CDVDInputStream* input) | ||
| 93 | { | ||
| 94 | Dispose(); | ||
| 95 | |||
| 96 | if(!input->IsStreamType(DVDSTREAM_TYPE_HTSP)) | ||
| 97 | return false; | ||
| 98 | |||
| 99 | m_Input = (CDVDInputStreamHTSP*)input; | ||
| 100 | m_StatusCount = 0; | ||
| 101 | |||
| 102 | while(m_Streams.empty() && m_StatusCount == 0) | ||
| 103 | { | ||
| 104 | DemuxPacket* pkg = Read(); | ||
| 105 | if(!pkg) | ||
| 106 | return false; | ||
| 107 | CDVDDemuxUtils::FreeDemuxPacket(pkg); | ||
| 108 | } | ||
| 109 | |||
| 110 | return true; | ||
| 111 | } | ||
| 112 | |||
| 113 | void CDVDDemuxHTSP::Dispose() | ||
| 114 | { | ||
| 115 | } | ||
| 116 | |||
| 117 | void CDVDDemuxHTSP::Reset() | ||
| 118 | { | ||
| 119 | } | ||
| 120 | |||
| 121 | |||
| 122 | void CDVDDemuxHTSP::Flush() | ||
| 123 | { | ||
| 124 | } | ||
| 125 | |||
| 126 | bool CDVDDemuxHTSP::ReadStream(uint8_t* buf, int len) | ||
| 127 | { | ||
| 128 | while(len > 0) | ||
| 129 | { | ||
| 130 | int ret = m_Input->Read(buf, len); | ||
| 131 | if(ret <= 0) | ||
| 132 | return false; | ||
| 133 | len -= ret; | ||
| 134 | buf += ret; | ||
| 135 | } | ||
| 136 | return true; | ||
| 137 | } | ||
| 138 | |||
| 139 | htsmsg_t* CDVDDemuxHTSP::ReadStream() | ||
| 140 | { | ||
| 141 | if(m_Input->IsStreamType(DVDSTREAM_TYPE_HTSP)) | ||
| 142 | return ((CDVDInputStreamHTSP*)m_Input)->ReadStream(); | ||
| 143 | |||
| 144 | uint32_t l; | ||
| 145 | if(!ReadStream((uint8_t*)&l, 4)) | ||
| 146 | return NULL; | ||
| 147 | |||
| 148 | l = ntohl(l); | ||
| 149 | if(l == 0) | ||
| 150 | return htsmsg_create_map(); | ||
| 151 | |||
| 152 | uint8_t* buf = (uint8_t*)malloc(l); | ||
| 153 | if(!buf) | ||
| 154 | return NULL; | ||
| 155 | |||
| 156 | if(!ReadStream(buf, l)) | ||
| 157 | return NULL; | ||
| 158 | |||
| 159 | return htsmsg_binary_deserialize(buf, l, buf); /* consumes 'buf' */ | ||
| 160 | } | ||
| 161 | |||
| 162 | DemuxPacket* CDVDDemuxHTSP::Read() | ||
| 163 | { | ||
| 164 | htsmsg_t * msg; | ||
| 165 | while((msg = ReadStream())) | ||
| 166 | { | ||
| 167 | const char* method = htsmsg_get_str(msg, "method"); | ||
| 168 | if(method == NULL) | ||
| 169 | break; | ||
| 170 | |||
| 171 | if (strcmp("subscriptionStart", method) == 0) | ||
| 172 | SubscriptionStart(msg); | ||
| 173 | else if(strcmp("subscriptionStop", method) == 0) | ||
| 174 | SubscriptionStop (msg); | ||
| 175 | else if(strcmp("subscriptionStatus", method) == 0) | ||
| 176 | SubscriptionStatus(msg); | ||
| 177 | else if(strcmp("queueStatus" , method) == 0) | ||
| 178 | CHTSPSession::ParseQueueStatus(msg, m_QueueStatus); | ||
| 179 | else if(strcmp("muxpkt" , method) == 0) | ||
| 180 | { | ||
| 181 | uint32_t index, duration; | ||
| 182 | const void* bin; | ||
| 183 | size_t binlen; | ||
| 184 | int64_t ts; | ||
| 185 | |||
| 186 | if(htsmsg_get_u32(msg, "stream" , &index) || | ||
| 187 | htsmsg_get_bin(msg, "payload", &bin, &binlen)) | ||
| 188 | break; | ||
| 189 | |||
| 190 | DemuxPacket* pkt = CDVDDemuxUtils::AllocateDemuxPacket(binlen); | ||
| 191 | |||
| 192 | memcpy(pkt->pData, bin, binlen); | ||
| 193 | pkt->iSize = binlen; | ||
| 194 | |||
| 195 | if(!htsmsg_get_u32(msg, "duration", &duration)) | ||
| 196 | pkt->duration = (double)duration * DVD_TIME_BASE / 1000000; | ||
| 197 | |||
| 198 | if(!htsmsg_get_s64(msg, "dts", &ts)) | ||
| 199 | pkt->dts = (double)ts * DVD_TIME_BASE / 1000000; | ||
| 200 | else | ||
| 201 | pkt->dts = DVD_NOPTS_VALUE; | ||
| 202 | |||
| 203 | if(!htsmsg_get_s64(msg, "pts", &ts)) | ||
| 204 | pkt->pts = (double)ts * DVD_TIME_BASE / 1000000; | ||
| 205 | else | ||
| 206 | pkt->pts = DVD_NOPTS_VALUE; | ||
| 207 | |||
| 208 | pkt->iStreamId = -1; | ||
| 209 | for(int i = 0; i < (int)m_Streams.size(); i++) | ||
| 210 | { | ||
| 211 | if(m_Streams[i]->iPhysicalId == (int)index) | ||
| 212 | { | ||
| 213 | pkt->iStreamId = i; | ||
| 214 | break; | ||
| 215 | } | ||
| 216 | } | ||
| 217 | |||
| 218 | htsmsg_destroy(msg); | ||
| 219 | return pkt; | ||
| 220 | } | ||
| 221 | |||
| 222 | break; | ||
| 223 | } | ||
| 224 | |||
| 225 | if(msg) | ||
| 226 | { | ||
| 227 | htsmsg_destroy(msg); | ||
| 228 | return CDVDDemuxUtils::AllocateDemuxPacket(0); | ||
| 229 | } | ||
| 230 | return NULL; | ||
| 231 | } | ||
| 232 | |||
| 233 | void CDVDDemuxHTSP::SubscriptionStart (htsmsg_t *m) | ||
| 234 | { | ||
| 235 | htsmsg_t *streams; | ||
| 236 | htsmsg_t *info; | ||
| 237 | htsmsg_field_t *f; | ||
| 238 | |||
| 239 | if((info = htsmsg_get_map(m, "sourceinfo"))) | ||
| 240 | { | ||
| 241 | HTSMSG_FOREACH(f, info) | ||
| 242 | { | ||
| 243 | if(f->hmf_type != HMF_STR) | ||
| 244 | continue; | ||
| 245 | CLog::Log(LOGDEBUG, "CDVDDemuxHTSP::SubscriptionStart - %s: %s", f->hmf_name, htsmsg_field_get_string(f)); | ||
| 246 | } | ||
| 247 | } | ||
| 248 | |||
| 249 | if((streams = htsmsg_get_list(m, "streams")) == NULL) | ||
| 250 | { | ||
| 251 | CLog::Log(LOGERROR, "CDVDDemuxHTSP::SubscriptionStart - malformed message"); | ||
| 252 | return; | ||
| 253 | } | ||
| 254 | |||
| 255 | for(int i = 0; i < (int)m_Streams.size(); i++) | ||
| 256 | delete m_Streams[i]; | ||
| 257 | m_Streams.clear(); | ||
| 258 | |||
| 259 | HTSMSG_FOREACH(f, streams) | ||
| 260 | { | ||
| 261 | uint32_t index; | ||
| 262 | const char* type; | ||
| 263 | const char* lang; | ||
| 264 | htsmsg_t* sub; | ||
| 265 | |||
| 266 | if(f->hmf_type != HMF_MAP) | ||
| 267 | continue; | ||
| 268 | sub = &f->hmf_msg; | ||
| 269 | |||
| 270 | if((type = htsmsg_get_str(sub, "type")) == NULL) | ||
| 271 | continue; | ||
| 272 | |||
| 273 | if(htsmsg_get_u32(sub, "index", &index)) | ||
| 274 | continue; | ||
| 275 | |||
| 276 | union { | ||
| 277 | CDemuxStream* g; | ||
| 278 | CDemuxStreamAudio* a; | ||
| 279 | CDemuxStreamVideo* v; | ||
| 280 | CDemuxStreamSubtitle* s; | ||
| 281 | CDemuxStreamTeletext* t; | ||
| 282 | } st; | ||
| 283 | |||
| 284 | CLog::Log(LOGDEBUG, "CDVDDemuxHTSP::SubscriptionStart - id: %d, type: %s", index, type); | ||
| 285 | |||
| 286 | if(!strcmp(type, "AC3")) { | ||
| 287 | st.a = new CDemuxStreamAudioHTSP(this, type); | ||
| 288 | st.a->codec = AV_CODEC_ID_AC3; | ||
| 289 | } else if(!strcmp(type, "EAC3")) { | ||
| 290 | st.a = new CDemuxStreamAudioHTSP(this, type); | ||
| 291 | st.a->codec = AV_CODEC_ID_EAC3; | ||
| 292 | } else if(!strcmp(type, "MPEG2AUDIO")) { | ||
| 293 | st.a = new CDemuxStreamAudioHTSP(this, type); | ||
| 294 | st.a->codec = AV_CODEC_ID_MP2; | ||
| 295 | } else if(!strcmp(type, "AAC")) { | ||
| 296 | st.a = new CDemuxStreamAudioHTSP(this, type); | ||
| 297 | st.a->codec = AV_CODEC_ID_AAC; | ||
| 298 | } else if(!strcmp(type, "MPEG2VIDEO")) { | ||
| 299 | st.v = new CDemuxStreamVideoHTSP(this, type); | ||
| 300 | st.v->codec = AV_CODEC_ID_MPEG2VIDEO; | ||
| 301 | st.v->iWidth = htsmsg_get_u32_or_default(sub, "width" , 0); | ||
| 302 | st.v->iHeight = htsmsg_get_u32_or_default(sub, "height", 0); | ||
| 303 | } else if(!strcmp(type, "H264")) { | ||
| 304 | st.v = new CDemuxStreamVideoHTSP(this, type); | ||
| 305 | st.v->codec = AV_CODEC_ID_H264; | ||
| 306 | st.v->iWidth = htsmsg_get_u32_or_default(sub, "width" , 0); | ||
| 307 | st.v->iHeight = htsmsg_get_u32_or_default(sub, "height", 0); | ||
| 308 | } else if(!strcmp(type, "DVBSUB")) { | ||
| 309 | st.s = new CDemuxStreamSubtitle(); | ||
| 310 | st.s->codec = AV_CODEC_ID_DVB_SUBTITLE; | ||
| 311 | uint32_t composition_id = 0, ancillary_id = 0; | ||
| 312 | htsmsg_get_u32(sub, "composition_id", &composition_id); | ||
| 313 | htsmsg_get_u32(sub, "ancillary_id" , &ancillary_id); | ||
| 314 | if(composition_id || ancillary_id) | ||
| 315 | { | ||
| 316 | st.s->ExtraData = new uint8_t[4]; | ||
| 317 | st.s->ExtraSize = 4; | ||
| 318 | st.s->ExtraData[0] = (composition_id >> 8) & 0xff; | ||
| 319 | st.s->ExtraData[1] = (composition_id >> 0) & 0xff; | ||
| 320 | st.s->ExtraData[2] = (ancillary_id >> 8) & 0xff; | ||
| 321 | st.s->ExtraData[3] = (ancillary_id >> 0) & 0xff; | ||
| 322 | } | ||
| 323 | } else if(!strcmp(type, "TEXTSUB")) { | ||
| 324 | st.s = new CDemuxStreamSubtitle(); | ||
| 325 | st.s->codec = AV_CODEC_ID_TEXT; | ||
| 326 | } else if(!strcmp(type, "TELETEXT")) { | ||
| 327 | st.t = new CDemuxStreamTeletext(); | ||
| 328 | st.t->codec = AV_CODEC_ID_DVB_TELETEXT; | ||
| 329 | } else { | ||
| 330 | continue; | ||
| 331 | } | ||
| 332 | |||
| 333 | if((lang = htsmsg_get_str(sub, "language"))) | ||
| 334 | { | ||
| 335 | strncpy(st.g->language, lang, sizeof(st.g->language)); | ||
| 336 | st.g->language[sizeof(st.g->language) - 1] = '\0'; | ||
| 337 | } | ||
| 338 | |||
| 339 | st.g->iId = m_Streams.size(); | ||
| 340 | st.g->iPhysicalId = index; | ||
| 341 | m_Streams.push_back(st.g); | ||
| 342 | } | ||
| 343 | } | ||
| 344 | void CDVDDemuxHTSP::SubscriptionStop (htsmsg_t *m) | ||
| 345 | { | ||
| 346 | for(int i = 0; i < (int)m_Streams.size(); i++) | ||
| 347 | delete m_Streams[i]; | ||
| 348 | m_Streams.clear(); | ||
| 349 | } | ||
| 350 | |||
| 351 | void CDVDDemuxHTSP::SubscriptionStatus(htsmsg_t *m) | ||
| 352 | { | ||
| 353 | const char* status; | ||
| 354 | status = htsmsg_get_str(m, "status"); | ||
| 355 | if(status == NULL) | ||
| 356 | m_Status = ""; | ||
| 357 | else | ||
| 358 | { | ||
| 359 | m_StatusCount++; | ||
| 360 | m_Status = status; | ||
| 361 | CLog::Log(LOGDEBUG, "CDVDDemuxHTSP::SubscriptionStatus - %s", status); | ||
| 362 | CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Info, "TVHeadend Status", status, TOAST_DISPLAY_TIME, false); | ||
| 363 | } | ||
| 364 | } | ||
| 365 | |||
| 366 | CDemuxStream* CDVDDemuxHTSP::GetStream(int iStreamId) | ||
| 367 | { | ||
| 368 | if(iStreamId >= 0 && iStreamId < (int)m_Streams.size()) | ||
| 369 | return m_Streams[iStreamId]; | ||
| 370 | |||
| 371 | return NULL; | ||
| 372 | } | ||
| 373 | |||
| 374 | int CDVDDemuxHTSP::GetNrOfStreams() | ||
| 375 | { | ||
| 376 | return m_Streams.size(); | ||
| 377 | } | ||
| 378 | |||
| 379 | std::string CDVDDemuxHTSP::GetFileName() | ||
| 380 | { | ||
| 381 | if(m_Input) | ||
| 382 | return m_Input->GetFileName(); | ||
| 383 | else | ||
| 384 | return ""; | ||
| 385 | } | ||
| 386 | |||
| 387 | void CDVDDemuxHTSP::Abort() | ||
| 388 | { | ||
| 389 | if(m_Input) | ||
| 390 | return m_Input->Abort(); | ||
| 391 | } | ||
