Debian Codegraph @

xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxClient.cpp

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
1 /*
2 * Copyright (C) 2012-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9 #include "DVDDemuxClient.h"
10
11 #include "DVDDemuxUtils.h"
12 #include "DVDInputStreams/DVDInputStream.h"
13 #include "cores/FFmpeg.h"
14 #include "cores/VideoPlayer/Interface/TimingConstants.h"
15 #include "utils/log.h"
16
17 #include <memory>
18 #include <tuple>
19 #include <type_traits>
20 #include <utility>
21
22 class CDemuxStreamClientInternal
23 {
24 public:
25 ~CDemuxStreamClientInternal()
26 {
27 DisposeParser();
28 }
29
30 void DisposeParser()
31 {
32 if (m_parser)
33 {
34 av_parser_close(m_parser);
35 m_parser = nullptr;
36 }
37 if (m_context)
38 {
39 avcodec_free_context(&m_context);
40 m_context = nullptr;
41 }
42 }
43
44 AVCodecParserContext *m_parser = nullptr;
45 AVCodecContext *m_context = nullptr;
46 bool m_parser_split = false;
47 };
48
49 template <class T>
50 class CDemuxStreamClientInternalTpl : public CDemuxStreamClientInternal, public T
51 {
52 };
53
54 CDVDDemuxClient::CDVDDemuxClient() : CDVDDemux()
55 {
56 m_streams.clear();
57 }
58
59 CDVDDemuxClient::~CDVDDemuxClient()
60 {
61 Dispose();
62 }
63
64 bool CDVDDemuxClient::Open(std::shared_ptr<CDVDInputStream> pInput)
65 {
66 Abort();
67
68 m_pInput = std::move(pInput);
69 m_IDemux = std::dynamic_pointer_cast<CDVDInputStream::IDemux>(m_pInput);
70 if (!m_IDemux)
71 return false;
72
73 if (!m_IDemux->OpenDemux())
74 return false;
75
76 RequestStreams();
77
78 m_displayTime = 0;
79 m_dtsAtDisplayTime = DVD_NOPTS_VALUE;
80 return true;
81 }
82
83 void CDVDDemuxClient::Dispose()
84 {
85 DisposeStreams();
86
87 m_pInput = nullptr;
88 m_IDemux = nullptr;
89 }
90
91 void CDVDDemuxClient::DisposeStreams()
92 {
93 m_streams.clear();
94 m_videoStreamPlaying = -1;
95 }
96
97 bool CDVDDemuxClient::Reset()
98 {
99 std::shared_ptr<CDVDInputStream> pInputStream = m_pInput;
100 Dispose();
101 return Open(pInputStream);
102 }
103
104 void CDVDDemuxClient::Abort()
105 {
106 if (m_IDemux)
107 m_IDemux->AbortDemux();
108 }
109
110 void CDVDDemuxClient::Flush()
111 {
112 if (m_IDemux)
113 m_IDemux->FlushDemux();
114
115 m_displayTime = 0;
116 m_dtsAtDisplayTime = DVD_NOPTS_VALUE;
117 }
118
119 bool CDVDDemuxClient::ParsePacket(DemuxPacket* pkt)
120 {
121 bool change = false;
122
123 CDemuxStream* st = GetStream(pkt->iStreamId);
124 if (st == nullptr || st->changes < 0 || st->extraData || !CodecHasExtraData(st->codec))
125 return change;
126
127 CDemuxStreamClientInternal* stream = dynamic_cast<CDemuxStreamClientInternal*>(st);
128
129 if (stream == nullptr ||
130 stream->m_parser == nullptr)
131 return change;
132
133 if (stream->m_context == nullptr)
134 {
135 const AVCodec* codec = avcodec_find_decoder(st->codec);
136 if (codec == nullptr)
137 {
138 CLog::Log(LOGERROR, "{} - can't find decoder", __FUNCTION__);
139 stream->DisposeParser();
140 return change;
141 }
142
143 stream->m_context = avcodec_alloc_context3(codec);
144 if (stream->m_context == nullptr)
145 {
146 CLog::Log(LOGERROR, "{} - can't allocate context", __FUNCTION__);
147 stream->DisposeParser();
148 return change;
149 }
150 stream->m_context->time_base.num = 1;
151 stream->m_context->time_base.den = DVD_TIME_BASE;
152 }
153
154 if (stream->m_parser_split && stream->m_parser && stream->m_parser->parser)
155 {
156 AVPacket* avpkt = av_packet_alloc();
157 if (!avpkt)
158 {
159 CLog::LogF(LOGERROR, "av_packet_alloc failed: {}", strerror(errno));
160 return false;
161 }
162
163 avpkt->data = pkt->pData;
164 avpkt->size = pkt->iSize;
165 avpkt->dts = avpkt->pts = AV_NOPTS_VALUE;
166
167 constexpr auto codecParDeleter = [](AVCodecParameters* p) { avcodec_parameters_free(&p); };
168 auto codecPar = std::unique_ptr<AVCodecParameters, decltype(codecParDeleter)>(
169 avcodec_parameters_alloc(), codecParDeleter);
170 int ret = avcodec_parameters_from_context(codecPar.get(), stream->m_context);
171 if (ret < 0)
172 {
173 CLog::LogF(LOGERROR, "avcodec_parameters_from_context failed");
174 return false;
175 }
176
177 FFmpegExtraData retExtraData = GetPacketExtradata(avpkt, codecPar.get());
178 if (retExtraData)
179 {
180 st->changes++;
181 st->disabled = false;
182 st->extraData = std::move(retExtraData);
183 stream->m_parser_split = false;
184 change = true;
185 CLog::Log(LOGDEBUG, "CDVDDemuxClient::ParsePacket - split extradata");
186
187 // Allow ffmpeg to transport codec information to stream->m_context
188 if (!avcodec_open2(stream->m_context, stream->m_context->codec, nullptr))
189 {
190 avcodec_send_packet(stream->m_context, avpkt);
191 avcodec_close(stream->m_context);
192 }
193 }
194 av_packet_free(&avpkt);
195 }
196
197 uint8_t *outbuf = nullptr;
198 int outbuf_size = 0;
199 int len = av_parser_parse2(stream->m_parser,
200 stream->m_context, &outbuf, &outbuf_size,
201 pkt->pData, pkt->iSize,
202 (int64_t)(pkt->pts * DVD_TIME_BASE),
203 (int64_t)(pkt->dts * DVD_TIME_BASE),
204 0);
205
206 // our parse is setup to parse complete frames, so we don't care about outbufs
207 if (len >= 0)
208 {
209 if (stream->m_context->profile != st->profile &&
210 stream->m_context->profile != FF_PROFILE_UNKNOWN)
211 {
212 CLog::Log(LOGDEBUG, "CDVDDemuxClient::ParsePacket - ({}) profile changed from {} to {}", st->uniqueId, st->profile, stream->m_context->profile);
213 st->profile = stream->m_context->profile;
214 st->changes++;
215 st->disabled = false;
216 }
217
218 if (stream->m_context->level != st->level &&
219 stream->m_context->level != FF_LEVEL_UNKNOWN)
220 {
221 CLog::Log(LOGDEBUG, "CDVDDemuxClient::ParsePacket - ({}) level changed from {} to {}", st->uniqueId, st->level, stream->m_context->level);
222 st->level = stream->m_context->level;
223 st->changes++;
224 st->disabled = false;
225 }
226
227 switch (st->type)
228 {
229 case STREAM_AUDIO:
230 {
231 CDemuxStreamClientInternalTpl<CDemuxStreamAudio>* sta = static_cast<CDemuxStreamClientInternalTpl<CDemuxStreamAudio>*>(st);
232 int streamChannels = stream->m_context->ch_layout.nb_channels;
233 if (streamChannels != sta->iChannels && streamChannels != 0)
234 {
235 CLog::Log(LOGDEBUG, "CDVDDemuxClient::ParsePacket - ({}) channels changed from {} to {}",
236 st->uniqueId, sta->iChannels, streamChannels);
237 sta->iChannels = streamChannels;
238 sta->changes++;
239 sta->disabled = false;
240 }
241 if (stream->m_context->sample_rate != sta->iSampleRate &&
242 stream->m_context->sample_rate != 0)
243 {
244 CLog::Log(LOGDEBUG, "CDVDDemuxClient::ParsePacket - ({}) samplerate changed from {} to {}", st->uniqueId, sta->iSampleRate, stream->m_context->sample_rate);
245 sta->iSampleRate = stream->m_context->sample_rate;
246 sta->changes++;
247 sta->disabled = false;
248 }
249 if (streamChannels)
250 st->changes = -1; // stop parsing
251 break;
252 }
253 case STREAM_VIDEO:
254 {
255 CDemuxStreamClientInternalTpl<CDemuxStreamVideo>* stv = static_cast<CDemuxStreamClientInternalTpl<CDemuxStreamVideo>*>(st);
256 if (stream->m_parser->width != stv->iWidth && stream->m_parser->width != 0)
257 {
258 CLog::Log(LOGDEBUG, "CDVDDemuxClient::ParsePacket - ({}) width changed from {} to {}",
259 st->uniqueId, stv->iWidth, stream->m_parser->width);
260 stv->iWidth = stream->m_parser->width;
261 stv->changes++;
262 stv->disabled = false;
263 }
264 if (stream->m_parser->height != stv->iHeight && stream->m_parser->height != 0)
265 {
266 CLog::Log(LOGDEBUG, "CDVDDemuxClient::ParsePacket - ({}) height changed from {} to {}",
267 st->uniqueId, stv->iHeight, stream->m_parser->height);
268 stv->iHeight = stream->m_parser->height;
269 stv->changes++;
270 stv->disabled = false;
271 }
272 if (stream->m_context->sample_aspect_ratio.num && stream->m_context->height)
273 {
274 double fAspect =
275 (av_q2d(stream->m_context->sample_aspect_ratio) * stream->m_context->width) /
276 stream->m_context->height;
277 if (abs(fAspect - stv->fAspect) > 0.001 && fAspect >= 0.001)
278 {
279 CLog::Log(LOGDEBUG, "CDVDDemuxClient::ParsePacket - ({}) aspect changed from {} to {}",
280 st->uniqueId, stv->fAspect, fAspect);
281 stv->fAspect = fAspect;
282 stv->changes++;
283 stv->disabled = false;
284 }
285 }
286 if (stream->m_context->framerate.num &&
287 (stv->iFpsRate != stream->m_context->framerate.num ||
288 stv->iFpsScale != stream->m_context->framerate.den))
289 {
290 CLog::Log(LOGDEBUG, "CDVDDemuxClient::ParsePacket - ({}) fps changed from {}/{} to {}/{}",
291 st->uniqueId, stv->iFpsRate, stv->iFpsScale, stream->m_context->framerate.num,
292 stream->m_context->framerate.den);
293 stv->iFpsRate = stream->m_context->framerate.num;
294 stv->iFpsScale = stream->m_context->framerate.den;
295 stv->changes++;
296 stv->disabled = false;
297 }
298
299 break;
300 }
301
302 default:
303 break;
304 }
305 }
306 else
307 CLog::Log(LOGDEBUG, "{} - parser returned error {}", __FUNCTION__, len);
308
309 return change;
310 }
311
312 DemuxPacket* CDVDDemuxClient::Read()
313 {
314 if (!m_IDemux)
315 return nullptr;
316
317 if (m_packet)
318 return m_packet.release();
319
320 m_packet.reset(m_IDemux->ReadDemux());
321 if (!m_packet)
322 {
323 return nullptr;
324 }
325
326 if (m_packet->iStreamId == DMX_SPECIALID_STREAMINFO)
327 {
328 RequestStreams();
329 CDVDDemuxUtils::FreeDemuxPacket(m_packet.release());
330 return CDVDDemuxUtils::AllocateDemuxPacket(0);
331 }
332 else if (m_packet->iStreamId == DMX_SPECIALID_STREAMCHANGE)
333 {
334 RequestStreams();
335 }
336 else if (m_packet->iStreamId >= 0 && m_streams.count(m_packet->iStreamId) > 0)
337 {
338 if (ParsePacket(m_packet.get()))
339 {
340 RequestStreams();
341 DemuxPacket *pPacket = CDVDDemuxUtils::AllocateDemuxPacket(0);
342 pPacket->iStreamId = DMX_SPECIALID_STREAMCHANGE;
343 pPacket->demuxerId = m_demuxerId;
344 return pPacket;
345 }
346 }
347
348 if (!IsVideoReady())
349 {
350 CDVDDemuxUtils::FreeDemuxPacket(m_packet.release());
351 DemuxPacket *pPacket = CDVDDemuxUtils::AllocateDemuxPacket(0);
352 pPacket->demuxerId = m_demuxerId;
353 return pPacket;
354 }
355
356 //! @todo drop this block
357 CDVDInputStream::IDisplayTime *inputStream = m_pInput->GetIDisplayTime();
358 if (inputStream)
359 {
360 int dispTime = inputStream->GetTime();
361 if (m_displayTime != dispTime)
362 {
363 m_displayTime = dispTime;
364 if (m_packet->dts != DVD_NOPTS_VALUE)
365 {
366 m_dtsAtDisplayTime = m_packet->dts;
367 }
368 }
369 if (m_dtsAtDisplayTime != DVD_NOPTS_VALUE && m_packet->dts != DVD_NOPTS_VALUE)
370 {
371 m_packet->dispTime = m_displayTime;
372 m_packet->dispTime += DVD_TIME_TO_MSEC(m_packet->dts - m_dtsAtDisplayTime);
373 }
374 }
375
376 return m_packet.release();
377 }
378
379 CDemuxStream* CDVDDemuxClient::GetStream(int iStreamId) const
380 {
381 auto stream = m_streams.find(iStreamId);
382 if (stream == m_streams.end())
383 return nullptr;
384
385 return stream->second.get();
386 }
387
388 std::vector<CDemuxStream*> CDVDDemuxClient::GetStreams() const
389 {
390 std::vector<CDemuxStream*> streams;
391
392 streams.reserve(m_streams.size());
393 for (auto &st : m_streams)
394 streams.push_back(st.second.get());
395
396 return streams;
397 }
398
399 void CDVDDemuxClient::RequestStreams()
400 {
401 std::map<int, std::shared_ptr<CDemuxStream>> newStreamMap;
402 for (auto stream : m_IDemux->GetStreams())
403 SetStreamProps(stream, newStreamMap, false);
404 m_streams = newStreamMap;
405 }
406
407 void CDVDDemuxClient::SetStreamProps(CDemuxStream *stream, std::map<int, std::shared_ptr<CDemuxStream>> &map, bool forceInit)
408 {
409 if (!stream)
410 {
411 CLog::Log(LOGERROR, "CDVDDemuxClient::RequestStream - invalid stream");
412 DisposeStreams();
413 return;
414 }
415
416 std::shared_ptr<CDemuxStream> currentStream(GetStreamInternal(stream->uniqueId));
417 std::shared_ptr<CDemuxStream> toStream;
418
419 if (stream->type == STREAM_AUDIO)
420 {
421 CDemuxStreamAudio *source = dynamic_cast<CDemuxStreamAudio*>(stream);
422 if (!source)
423 {
424 CLog::Log(LOGERROR, "CDVDDemuxClient::RequestStream - invalid audio stream with id {}",
425 stream->uniqueId);
426 DisposeStreams();
427 return;
428 }
429
430 std::shared_ptr<CDemuxStreamClientInternalTpl<CDemuxStreamAudio>> streamAudio;
431 if (currentStream)
432 streamAudio = std::dynamic_pointer_cast<CDemuxStreamClientInternalTpl<CDemuxStreamAudio>>(currentStream);
433 if (forceInit || !streamAudio || streamAudio->codec != source->codec)
434 {
435 streamAudio = std::make_shared<CDemuxStreamClientInternalTpl<CDemuxStreamAudio>>();
436 streamAudio->m_parser = av_parser_init(source->codec);
437 if (streamAudio->m_parser)
438 streamAudio->m_parser->flags |= PARSER_FLAG_COMPLETE_FRAMES;
439 streamAudio->iSampleRate = source->iSampleRate;
440 streamAudio->iChannels = source->iChannels;
441 }
442
443 streamAudio->iBlockAlign = source->iBlockAlign;
444 streamAudio->iBitRate = source->iBitRate;
445 streamAudio->iBitsPerSample = source->iBitsPerSample;
446 if (source->extraData)
447 {
448 streamAudio->extraData = source->extraData;
449 }
450 streamAudio->m_parser_split = true;
451 streamAudio->changes++;
452 map[stream->uniqueId] = streamAudio;
453 toStream = streamAudio;
454 }
455 else if (stream->type == STREAM_VIDEO)
456 {
457 CDemuxStreamVideo *source = dynamic_cast<CDemuxStreamVideo*>(stream);
458
459 if (!source)
460 {
461 CLog::Log(LOGERROR, "CDVDDemuxClient::RequestStream - invalid video stream with id {}",
462 stream->uniqueId);
463 DisposeStreams();
464 return;
465 }
466
467 std::shared_ptr<CDemuxStreamClientInternalTpl<CDemuxStreamVideo>> streamVideo;
468 if (currentStream)
469 streamVideo = std::dynamic_pointer_cast<CDemuxStreamClientInternalTpl<CDemuxStreamVideo>>(currentStream);
470 if (forceInit || !streamVideo || streamVideo->codec != source->codec)
471 {
472 streamVideo = std::make_shared<CDemuxStreamClientInternalTpl<CDemuxStreamVideo>>();
473 streamVideo->m_parser = av_parser_init(source->codec);
474 if (streamVideo->m_parser)
475 streamVideo->m_parser->flags |= PARSER_FLAG_COMPLETE_FRAMES;
476 streamVideo->iHeight = source->iHeight;
477 streamVideo->iWidth = source->iWidth;
478 streamVideo->fAspect = source->fAspect;
479 streamVideo->iFpsScale = source->iFpsScale;
480 streamVideo->iFpsRate = source->iFpsRate;
481 }
482 streamVideo->iBitRate = source->iBitRate;
483 if (source->extraData)
484 {
485 streamVideo->extraData = source->extraData;
486 }
487 streamVideo->colorPrimaries = source->colorPrimaries;
488 streamVideo->colorRange = source->colorRange;
489 streamVideo->colorSpace = source->colorSpace;
490 streamVideo->colorTransferCharacteristic = source->colorTransferCharacteristic;
491 streamVideo->masteringMetaData = source->masteringMetaData;
492 streamVideo->contentLightMetaData = source->contentLightMetaData;
493
494 streamVideo->m_parser_split = true;
495 streamVideo->changes++;
496 map[stream->uniqueId] = streamVideo;
497 toStream = streamVideo;
498 }
499 else if (stream->type == STREAM_SUBTITLE)
500 {
501 CDemuxStreamSubtitle *source = dynamic_cast<CDemuxStreamSubtitle*>(stream);
502
503 if (!source)
504 {
505 CLog::Log(LOGERROR, "CDVDDemuxClient::RequestStream - invalid subtitle stream with id {}",
506 stream->uniqueId);
507 DisposeStreams();
508 return;
509 }
510
511 std::shared_ptr<CDemuxStreamClientInternalTpl<CDemuxStreamSubtitle>> streamSubtitle;
512 if (currentStream)
513 streamSubtitle = std::dynamic_pointer_cast<CDemuxStreamClientInternalTpl<CDemuxStreamSubtitle>>(currentStream);
514 if (!streamSubtitle || streamSubtitle->codec != source->codec)
515 {
516 streamSubtitle = std::make_shared<CDemuxStreamClientInternalTpl<CDemuxStreamSubtitle>>();
517 streamSubtitle->m_parser = av_parser_init(source->codec);
518 if (streamSubtitle->m_parser)
519 streamSubtitle->m_parser->flags |= PARSER_FLAG_COMPLETE_FRAMES;
520 }
521
522 if (source->extraData.GetSize() == 4)
523 {
524 streamSubtitle->extraData = source->extraData;
525 }
526 map[stream->uniqueId] = streamSubtitle;
527 toStream = streamSubtitle;
528 }
529 else if (stream->type == STREAM_TELETEXT)
530 {
531 CDemuxStreamTeletext *source = dynamic_cast<CDemuxStreamTeletext*>(stream);
532
533 if (!source)
534 {
535 CLog::Log(LOGERROR, "CDVDDemuxClient::RequestStream - invalid teletext stream with id {}",
536 stream->uniqueId);
537 DisposeStreams();
538 return;
539 }
540
541 std::shared_ptr<CDemuxStreamClientInternalTpl<CDemuxStreamTeletext>> streamTeletext;
542 if (currentStream)
543 streamTeletext = std::dynamic_pointer_cast<CDemuxStreamClientInternalTpl<CDemuxStreamTeletext>>(currentStream);
544 if (!streamTeletext || streamTeletext->codec != source->codec)
545 {
546 streamTeletext = std::make_shared<CDemuxStreamClientInternalTpl<CDemuxStreamTeletext>>();
547 }
548
549 map[stream->uniqueId] = streamTeletext;
550 toStream = streamTeletext;
551 }
552 else if (stream->type == STREAM_RADIO_RDS)
553 {
554 CDemuxStreamRadioRDS *source = dynamic_cast<CDemuxStreamRadioRDS*>(stream);
555
556 if (!source)
557 {
558 CLog::Log(LOGERROR, "CDVDDemuxClient::RequestStream - invalid radio-rds stream with id {}",
559 stream->uniqueId);
560 DisposeStreams();
561 return;
562 }
563
564 std::shared_ptr<CDemuxStreamClientInternalTpl<CDemuxStreamRadioRDS>> streamRDS;
565 if (currentStream)
566 streamRDS = std::dynamic_pointer_cast<CDemuxStreamClientInternalTpl<CDemuxStreamRadioRDS>>(currentStream);
567 if (!streamRDS || streamRDS->codec != source->codec)
568 {
569 streamRDS = std::make_shared<CDemuxStreamClientInternalTpl<CDemuxStreamRadioRDS>>();
570 }
571
572 map[stream->uniqueId] = streamRDS;
573 toStream = streamRDS;
574 }
575 else if (stream->type == STREAM_AUDIO_ID3)
576 {
577 CDemuxStreamAudioID3* source = dynamic_cast<CDemuxStreamAudioID3*>(stream);
578
579 if (!source)
580 {
581 CLog::Log(LOGERROR, "CDVDDemuxClient::RequestStream - invalid audio ID3 stream with id {}",
582 stream->uniqueId);
583 DisposeStreams();
584 return;
585 }
586
587 std::shared_ptr<CDemuxStreamClientInternalTpl<CDemuxStreamAudioID3>> streamID3;
588 if (currentStream)
589 streamID3 = std::dynamic_pointer_cast<CDemuxStreamClientInternalTpl<CDemuxStreamAudioID3>>(
590 currentStream);
591 if (!streamID3 || streamID3->codec != source->codec)
592 {
593 streamID3 = std::make_shared<CDemuxStreamClientInternalTpl<CDemuxStreamAudioID3>>();
594 }
595
596 map[stream->uniqueId] = streamID3;
597 toStream = streamID3;
598 }
599 else
600 {
601 std::shared_ptr<CDemuxStreamClientInternalTpl<CDemuxStream>> streamGen;
602 streamGen = std::make_shared<CDemuxStreamClientInternalTpl<CDemuxStream>>();
603 map[stream->uniqueId] = streamGen;
604 toStream = streamGen;
605 }
606
607 // only update profile / level if we create a new stream or has been reset stream properties
608 // existing streams may be corrected by ParsePacket
609 if (!currentStream || forceInit)
610 {
611 toStream->profile = stream->profile;
612 toStream->level = stream->level;
613 }
614
615 toStream->uniqueId = stream->uniqueId;
616 toStream->codec = stream->codec;
617 toStream->codecName = stream->codecName;
618 toStream->codec_fourcc = stream->codec_fourcc;
619 toStream->flags = stream->flags;
620 toStream->cryptoSession = stream->cryptoSession;
621 toStream->externalInterfaces = stream->externalInterfaces;
622 toStream->language = stream->language;
623 toStream->name = stream->name;
624
625 CLog::Log(LOGDEBUG, "CDVDDemuxClient::RequestStream(): added/updated stream {} with codec_id {}",
626 toStream->uniqueId, toStream->codec);
627 }
628
629 std::shared_ptr<CDemuxStream> CDVDDemuxClient::GetStreamInternal(int iStreamId)
630 {
631 auto stream = m_streams.find(iStreamId);
632 if (stream != m_streams.end())
633 {
634 return stream->second;
635 }
636 else
637 return nullptr;
638 }
639
640 int CDVDDemuxClient::GetNrOfStreams() const
641 {
642 return m_streams.size();
643 }
644
645 bool CDVDDemuxClient::IsVideoReady()
646 {
647 for (const auto& stream : m_streams)
648 {
649 if (stream.first == m_videoStreamPlaying && stream.second->type == STREAM_VIDEO &&
650 CodecHasExtraData(stream.second->codec) && !stream.second->extraData)
651 return false;
652 }
653 return true;
654 }
655
656 std::string CDVDDemuxClient::GetFileName()
657 {
658 if (m_pInput)
659 return m_pInput->GetFileName();
660 else
661 return "";
662 }
663
664 std::string CDVDDemuxClient::GetStreamCodecName(int iStreamId)
665 {
666 CDemuxStream *stream = GetStream(iStreamId);
667 std::string strName;
668 if (stream)
669 {
670 if (stream->codec == AV_CODEC_ID_AC3)
671 strName = "ac3";
672 else if (stream->codec == AV_CODEC_ID_MP2)
673 strName = "mp2";
674 else if (stream->codec == AV_CODEC_ID_AAC)
675 strName = "aac";
676 else if (stream->codec == AV_CODEC_ID_DTS)
677 strName = "dca";
678 else if (stream->codec == AV_CODEC_ID_MPEG2VIDEO)
679 strName = "mpeg2video";
680 else if (stream->codec == AV_CODEC_ID_H264)
681 strName = "h264";
682 else if (stream->codec == AV_CODEC_ID_EAC3)
683 strName = "eac3";
684 else if (stream->codec == AV_CODEC_ID_VP8)
685 strName = "vp8";
686 else if (stream->codec == AV_CODEC_ID_VP9)
687 strName = "vp9";
688 else if (stream->codec == AV_CODEC_ID_HEVC)
689 strName = "hevc";
690 else if (stream->codec == AV_CODEC_ID_AV1)
691 strName = "av1";
692 }
693 return strName;
694 }
695
696 bool CDVDDemuxClient::SeekTime(double timems, bool backwards, double *startpts)
697 {
698 if (m_IDemux)
699 {
700 m_displayTime = 0;
701 m_dtsAtDisplayTime = DVD_NOPTS_VALUE;
702 return m_IDemux->SeekTime(timems, backwards, startpts);
703 }
704 return false;
705 }
706
707 void CDVDDemuxClient::SetSpeed (int speed)
708 {
709 if (m_IDemux)
710 {
711 m_IDemux->SetSpeed(speed);
712 }
713 }
714
715 void CDVDDemuxClient::FillBuffer(bool mode)
716 {
717 if (m_IDemux)
718 {
719 m_IDemux->FillBuffer(mode);
720 }
721 }
722
723 void CDVDDemuxClient::EnableStream(int id, bool enable)
724 {
725 if (m_IDemux)
726 {
727 m_IDemux->EnableStream(id, enable);
728 }
729 }
730
731 void CDVDDemuxClient::OpenStream(int id)
732 {
733 // OpenStream may change some parameters
734 // in this case we need to reset our stream properties
735 if (m_IDemux)
736 {
737 bool bOpenStream = m_IDemux->OpenStream(id);
738
739 CDemuxStream *stream(m_IDemux->GetStream(id));
740 if (stream && stream->type == STREAM_VIDEO)
741 m_videoStreamPlaying = id;
742
743 if (bOpenStream)
744 SetStreamProps(stream, m_streams, true);
745 }
746 }
747
748 void CDVDDemuxClient::SetVideoResolution(unsigned int width, unsigned int height)
749 {
750 if (m_IDemux)
751 {
752 m_IDemux->SetVideoResolution(width, height, width, height);
753 }
754 }
755
756 bool CDVDDemuxClient::CodecHasExtraData(AVCodecID id)
757 {
758 switch (id)
759 {
760 case AV_CODEC_ID_VP9:
761 return false;
762 default:
763 return true;
764 }
765 }