Ticket #1736: fix_enable_subtitles_by_default.diff
File fix_enable_subtitles_by_default.diff, 10.5 KB (added by , 19 years ago) |
---|
-
libs/libmythtv/NuppelVideoPlayer.cpp
If subtitles need to be enabled by default (DefaultCCMode setting), they weren't enabled in case the stream didn't have subtitles when InitVideo() was called. Subtitles need to be re-enabled as soon as subtitles are encountered. Fix: Always on subtitle stream change re-enable (and reselect) the subtitles.
old new 529 529 videoOutput->EmbedInWidget(embedid, embx, emby, embw, embh); 530 530 } 531 531 532 SetCaptionsEnabled(gContext->GetNumSetting("DefaultCCMode")); 532 if (m_wantSubtitles = gContext->GetNumSetting("DefaultCCMode")) 533 SetCaptionsEnabled(true, false); 533 534 534 535 return true; 535 536 } … … 1426 1427 } 1427 1428 } 1428 1429 1429 void NuppelVideoPlayer::EnableCaptions(uint mode )1430 void NuppelVideoPlayer::EnableCaptions(uint mode, bool osd_msg) 1430 1431 { 1431 QString msg = ""; 1432 if (kDisplaySubtitle & mode) 1433 { 1434 msg += decoder->GetTrackDesc(kTrackTypeSubtitle, 1435 GetTrack(kTrackTypeSubtitle)); 1436 } 1437 if (kDisplayNUVTeletextCaptions & mode) 1438 msg += QObject::tr("TXT") + QString(" %1").arg(ttPageNum, 3, 16); 1439 if (kDisplayCC608 & mode) 1440 { 1441 msg += decoder->GetTrackDesc(kTrackTypeCC608, 1442 GetTrack(kTrackTypeCC608)); 1443 } 1444 if (kDisplayCC708 & mode) 1445 { 1446 msg += decoder->GetTrackDesc(kTrackTypeCC708, 1447 GetTrack(kTrackTypeCC708)); 1448 } 1449 if (kDisplayTeletextCaptions & mode) 1432 textDisplayMode = mode; 1433 1434 if (osd_msg && osd) 1450 1435 { 1451 msg += decoder->GetTrackDesc(kTrackTypeTeletextCaptions,1452 GetTrack(kTrackTypeTeletextCaptions));1453 1454 TeletextViewer *tt_view = GetOSD()->GetTeletextViewer();1455 int page = decoder->GetTrackLanguageIndex(1456 kTrackTypeTeletextCaptions,1457 GetTrack(kTrackTypeTeletextCaptions));1458 1436 1459 if ((tt_view) && (page > 0)) 1460 { 1461 EnableTeletext(); 1462 tt_view->SetPage(page, -1); 1463 textDisplayMode = kDisplayTeletextCaptions; 1464 } 1465 } 1437 QString msg = ""; 1438 if (kDisplaySubtitle & mode) 1439 { 1440 msg += decoder->GetTrackDesc(kTrackTypeSubtitle, 1441 GetTrack(kTrackTypeSubtitle)); 1442 } 1443 if (kDisplayNUVTeletextCaptions & mode) 1444 msg += QObject::tr("TXT") + QString(" %1").arg(ttPageNum, 3, 16); 1445 if (kDisplayCC608 & mode) 1446 { 1447 msg += decoder->GetTrackDesc(kTrackTypeCC608, 1448 GetTrack(kTrackTypeCC608)); 1449 } 1450 if (kDisplayCC708 & mode) 1451 { 1452 msg += decoder->GetTrackDesc(kTrackTypeCC708, 1453 GetTrack(kTrackTypeCC708)); 1454 } 1455 if (kDisplayTeletextCaptions & mode) 1456 { 1457 msg += decoder->GetTrackDesc(kTrackTypeTeletextCaptions, 1458 GetTrack(kTrackTypeTeletextCaptions)); 1459 1460 TeletextViewer *tt_view = GetOSD()->GetTeletextViewer(); 1461 int page = decoder->GetTrackLanguageIndex( 1462 kTrackTypeTeletextCaptions, 1463 GetTrack(kTrackTypeTeletextCaptions)); 1464 1465 if ((tt_view) && (page > 0)) 1466 { 1467 EnableTeletext(); 1468 tt_view->SetPage(page, -1); 1469 textDisplayMode = kDisplayTeletextCaptions; 1470 } 1471 } 1466 1472 1467 1473 msg += " " + QObject::tr("On"); 1468 1474 1469 textDisplayMode = mode;1470 if (osd)1471 1475 osd->SetSettingsText(msg, 3 /* seconds until message timeout */); 1472 1476 } 1473 1477 } 1474 1478 1475 1479 void NuppelVideoPlayer::EnableTeletext(void) … … 1552 1556 return textDisplayMode; 1553 1557 } 1554 1558 1555 void NuppelVideoPlayer::SetCaptionsEnabled(bool enable )1559 void NuppelVideoPlayer::SetCaptionsEnabled(bool enable, bool showOsd) 1556 1560 { 1557 1561 uint origMode = textDisplayMode; 1558 1562 1559 1563 if (!enable) 1560 1564 { 1561 DisableCaptions(origMode); 1565 DisableCaptions(origMode, showOsd); 1566 m_wantSubtitles = false; 1562 1567 return; 1563 1568 } 1569 m_wantSubtitles = true; 1564 1570 1565 1571 // figure out which text type to enable.. 1566 1572 bool captions_found = true; 1567 if (decoder->GetTrackCount(kTrackTypeSubtitle)) 1568 EnableCaptions(kDisplaySubtitle); 1573 if (decoder->GetTrackCount(kTrackTypeSubtitle)) 1574 { 1575 decoder->AutoSelectTrack(kTrackTypeSubtitle); 1576 EnableCaptions(kDisplaySubtitle, showOsd); 1577 } 1569 1578 else if (decoder->GetTrackCount(kTrackTypeCC708)) 1570 EnableCaptions(kDisplayCC708 );1579 EnableCaptions(kDisplayCC708, showOsd); 1571 1580 else if (decoder->GetTrackCount(kTrackTypeTeletextCaptions)) 1572 EnableCaptions(kDisplayTeletextCaptions );1581 EnableCaptions(kDisplayTeletextCaptions, showOsd); 1573 1582 else if (vbimode == VBIMode::PAL_TT) 1574 EnableCaptions(kDisplayNUVTeletextCaptions );1583 EnableCaptions(kDisplayNUVTeletextCaptions, showOsd); 1575 1584 else if (vbimode == VBIMode::NTSC_CC) 1576 1585 { 1577 1586 if (decoder->GetTrackCount(kTrackTypeCC608)) 1578 EnableCaptions(kDisplayCC608 );1587 EnableCaptions(kDisplayCC608, showOsd); 1579 1588 else 1580 1589 captions_found = false; 1581 1590 } 1582 1591 else 1583 1592 captions_found = false; 1584 1593 1585 if (!captions_found && osd )1594 if (!captions_found && osd && showOsd) 1586 1595 { 1587 1596 QString msg = QObject::tr( 1588 1597 "No captions", "CC/Teletext/Subtitle text not available"); … … 5851 5860 subtitleLock.unlock(); 5852 5861 } 5853 5862 5863 /** \fn NuppelVideoPlayer::SubtitleTracksChanged() 5864 * \brief Used to notify of subtitle track changes. 5865 */ 5866 void NuppelVideoPlayer::SubtitleTracksChanged() 5867 { 5868 // this might be called before the decoder is initialized 5869 if (decoder == NULL) 5870 return; 5871 if (m_wantSubtitles) { 5872 SetCaptionsEnabled(m_wantSubtitles, false); 5873 } 5874 } 5875 5876 5854 5877 /** \fn NuppelVideoPlayer::SetDecoder(DecoderBase*) 5855 5878 * \brief Sets the stream decoder, deleting any existing recorder. 5856 5879 */ -
libs/libmythtv/NuppelVideoPlayer.h
old new 277 277 void AddTextData(unsigned char *buffer, int len, 278 278 long long timecode, char type); 279 279 void AddSubtitle(const AVSubtitle& subtitle); 280 void SubtitleTracksChanged(); 280 281 281 282 // Closed caption and teletext stuff 282 283 uint GetCaptionMode(void) const { return textDisplayMode; } 283 284 void ResetCaptions(uint mode_override = 0); 284 285 void DisableCaptions(uint mode, bool osd_msg = true); 285 void EnableCaptions(uint mode );286 void EnableCaptions(uint mode, bool osd_msg = true); 286 287 bool ToggleCaptions(void); 287 288 bool ToggleCaptions(uint mode); 288 void SetCaptionsEnabled(bool );289 void SetCaptionsEnabled(bool, bool showOsd = true); 289 290 290 291 // Teletext Menu and non-NUV teletext decoder 291 292 void EnableTeletext(void); … … 608 609 long long osdSubtitlesExpireAt; 609 610 MythDeque<AVSubtitle> nonDisplayedSubtitles; 610 611 612 /// Used for figuring out whether subtitles should be enabled 613 /// when they are encountered in the played stream. A workaround 614 /// for the case in which the subtitles are not available immediately 615 /// when loading the video, thus won't get enabled correctly. 616 bool m_wantSubtitles; 617 611 618 CC708Service CC708services[64]; 612 619 QString osdfontname; 613 620 QString osdccfontname; -
libs/libmythtv/avformatdecoder.cpp
old new 1179 1179 map<int,uint> lang_sub_cnt; 1180 1180 map<int,uint> lang_aud_cnt; 1181 1181 1182 bool subtitleTracksFound = false; 1182 1183 for (int i = 0; i < ic->nb_streams; i++) 1183 1184 { 1184 1185 AVCodecContext *enc = ic->streams[i]->codec; … … 1289 1290 } 1290 1291 case CODEC_TYPE_SUBTITLE: 1291 1292 { 1293 subtitleTracksFound = true; 1292 1294 bitrate += enc->bit_rate; 1293 1295 VERBOSE(VB_PLAYBACK, LOC + QString("subtitle codec (%1)") 1294 1296 .arg(codec_type_string(enc->codec_type))); … … 1432 1434 } 1433 1435 } 1434 1436 } 1435 } 1437 } 1436 1438 1437 1439 // Select a new track at the next opportunity. 1438 1440 ResetTracks(); 1439 1441 1442 if (subtitleTracksFound && GetNVP() != NULL) 1443 GetNVP()->SubtitleTracksChanged(); 1444 1440 1445 // We have to do this here to avoid the NVP getting stuck 1441 1446 // waiting on audio. 1442 1447 if (GetNVP()->HasAudioIn() && tracks[kTrackTypeAudio].empty()) -
libs/libmythtv/decoderbase.cpp
old new 819 819 { 820 820 QMutexLocker locker(&avcodeclock); 821 821 822 if (type == kTrackTypeSubtitle && GetNVP() != NULL) 823 GetNVP()->SubtitleTracksChanged(); 824 822 825 for (uint i = 0; i < tracks[type].size(); i++) 823 826 if (info.stream_id == tracks[type][i].stream_id) 824 827 return false; 825 828 826 829 tracks[type].push_back(info); 830 827 831 return true; 828 832 } 829 833 830 834 /** \fn DecoderBase::AutoSelectTrack(uint) 831 835 * \brief Select best track. 832 836 * 833 * I fcase there's only one track available, always choose it.837 * In case there's only one track available, always choose it. 834 838 * 835 839 * If there is a user selected track we try to find it. 836 840 * -
libs/libmythtv/decoderbase.h
old new 136 136 137 137 virtual bool SetAudioByComponentTag(int) { return false; } 138 138 virtual bool SetVideoByComponentTag(int) { return false; } 139 virtual int AutoSelectTrack(uint type); 139 140 140 141 protected: 141 virtual int AutoSelectTrack(uint type);142 142 inline void AutoSelectTracks(void); 143 143 inline void ResetTracks(void); 144 void AnnounceTrackTypeChange(uint type); 144 145 145 146 void FileChanged(void); 146 147 … … 245 246 246 247 inline void DecoderBase::ResetTracks(void) 247 248 { 248 for (uint i = 0; i < kTrackTypeCount; i++) 249 currentTrack[i] = -1; 249 for (uint i = 0; i < kTrackTypeCount; i++) 250 { 251 if (currentTrack[i] != -1) 252 { 253 if (i == kTrackTypeSubtitle && GetNVP() != NULL) 254 GetNVP()->SubtitleTracksChanged(); 255 currentTrack[i] = -1; 256 } 257 } 250 258 } 251 259 252 260 #endif