Ticket #9429: 0001-Filter-and-sort-DVD-subtitle-tracks-so-that-only-the.patch
File 0001-Filter-and-sort-DVD-subtitle-tracks-so-that-only-the.patch, 9.8 KB (added by , 11 years ago) |
---|
-
mythtv/libs/libmythtv/DVD/avformatdecoderdvd.cpp
From 928733bfca6416f09a84f2ec15330fdfe1945e76 Mon Sep 17 00:00:00 2001 From: Richard <peper03@yahoo.com> Date: Fri, 31 May 2013 21:56:27 +0200 Subject: [PATCH 2/2] Filter and sort DVD subtitle tracks so that only the tracks mapped into the current program chain are shown. This patch also adds the subtitle streams that are mapped but have not yet been physically read. This allows the user to select the language without having to wait for the first subtitle packet (and therefore miss it). --- mythtv/libs/libmythtv/DVD/avformatdecoderdvd.cpp | 87 +++++++++++++++++++--- mythtv/libs/libmythtv/DVD/dvdringbuffer.cpp | 8 ++ mythtv/libs/libmythtv/DVD/dvdringbuffer.h | 1 + mythtv/libs/libmythtv/DVD/mythdvdplayer.cpp | 13 +++- mythtv/libs/libmythtv/avformatdecoder.cpp | 3 - mythtv/libs/libmythtv/decoderbase.cpp | 10 ++- 6 files changed, 104 insertions(+), 18 deletions(-) diff --git a/mythtv/libs/libmythtv/DVD/avformatdecoderdvd.cpp b/mythtv/libs/libmythtv/DVD/avformatdecoderdvd.cpp index 1abf566..04777d2 100644
a b void AvFormatDecoderDVD::PostProcessTracks(void) 118 118 119 119 if (tracks[kTrackTypeSubtitle].size() > 0) 120 120 { 121 map<int,uint> lang_sub_cnt; 122 map<int,int> stream2idx; 123 124 // First, create a map containing stream id -> track index 125 // of the subtitle streams that have been found so far. 126 for (uint n = 0; n < GetTrackCount(kTrackTypeSubtitle); n++) 127 { 128 int stream_id = tracks[kTrackTypeSubtitle][n].stream_id & 0x1f; 129 130 stream2idx[stream_id] = n; 131 } 132 133 // Get all subtitle tracks from the DVD and filter out any that 134 // are not mapped in the current program chain. 135 sinfo_vec_t filteredTracks; 136 137 if (!ringBuffer->DVD()->IsInMenu()) 138 { 139 for (uint i = 0; i < 32; ++i) 140 { 141 int streamid = ringBuffer->DVD()->GetSubtitleTrackNum(i); 142 if (streamid >= 0) 143 { 144 // This stream is mapped in the current program chain 145 int lang = ringBuffer->DVD()->GetSubtitleLanguage(i); 146 int lang_indx = lang_sub_cnt[lang]++; 147 int trackNo = -1; 148 149 if (stream2idx.count(streamid) != 0) 150 trackNo = stream2idx[streamid]; 151 152 if (trackNo == -1) 153 { 154 // Create a dummy track if the physical stream has not 155 // yet been seen. 156 filteredTracks.push_back(StreamInfo(-1, lang, lang_indx, 157 streamid, 0, 0, false, false, false)); 158 } 159 else 160 { 161 // Otherwise use the real data 162 filteredTracks.push_back(tracks[kTrackTypeSubtitle][trackNo]); 163 filteredTracks.back().stream_id &= 0x1f; 164 filteredTracks.back().language = lang; 165 filteredTracks.back().language_index = lang_indx; 166 } 167 } 168 } 169 } 170 tracks[kTrackTypeSubtitle] = filteredTracks; 171 121 172 stable_sort(tracks[kTrackTypeSubtitle].begin(), 122 173 tracks[kTrackTypeSubtitle].end()); 123 sinfo_vec_t::iterator it = tracks[kTrackTypeSubtitle].begin(); 124 for(; it != tracks[kTrackTypeSubtitle].end(); ++it) 174 175 int trackNo = -1; 176 int selectedStream = ringBuffer->DVD()->GetTrack(kTrackTypeSubtitle); 177 178 // Now iterate over the sorted list and try to find the index of the 179 // currently selected track. 180 for (uint idx = 0; idx < GetTrackCount(kTrackTypeSubtitle); idx++) 125 181 { 182 const StreamInfo& stream = tracks[kTrackTypeSubtitle][idx]; 183 int avidx = stream.av_stream_index; 184 QString mpegstream; 185 186 if (avidx >= 0) 187 mpegstream = QString( "0x%1").arg(ic->streams[avidx]->id,0,16); 188 else 189 mpegstream = "n/a"; 190 126 191 LOG(VB_PLAYBACK, LOG_INFO, LOC + 127 QString("DVD Subtitle Track Map Stream id #%1 ") 128 .arg(it->stream_id)); 192 QString("DVD Subtitle Track Map Stream id #%1, av_stream_idx %2, MPEG #%3, lang %4") 193 .arg(stream.stream_id) 194 .arg(stream.av_stream_index) 195 .arg(mpegstream) 196 .arg(iso639_key_toName(stream.language))); 197 198 if ((selectedStream != -1) && (stream.stream_id == selectedStream)) 199 trackNo = (int)idx; 129 200 } 130 stable_sort(tracks[kTrackTypeSubtitle].begin(), 131 tracks[kTrackTypeSubtitle].end()); 132 int trackNo = ringBuffer->DVD()->GetTrack(kTrackTypeSubtitle); 201 133 202 uint captionmode = m_parent->GetCaptionMode(); 134 203 int trackcount = (int)GetTrackCount(kTrackTypeSubtitle); 204 135 205 if (captionmode == kDisplayAVSubtitle && 136 206 (trackNo < 0 || trackNo >= trackcount)) 137 207 { 138 208 m_parent->EnableSubtitles(false); 139 209 } 140 else if (trackNo >= 0 && trackNo < trackcount && 141 !ringBuffer->IsInDiscMenuOrStillFrame()) 210 else if (trackNo >= 0 && trackNo < trackcount) 142 211 { 143 212 SetTrack(kTrackTypeSubtitle, trackNo); 144 213 m_parent->EnableSubtitles(true); -
mythtv/libs/libmythtv/DVD/dvdringbuffer.cpp
diff --git a/mythtv/libs/libmythtv/DVD/dvdringbuffer.cpp b/mythtv/libs/libmythtv/DVD/dvdringbuffer.cpp index 361e883..5ca2bee 100644
a b uint DVDRingBuffer::GetSubtitleLanguage(int id) 1664 1664 return ConvertLangCode(lang); 1665 1665 } 1666 1666 1667 /** \brief get the logical subtitle track/stream number from the dvd 1668 * \param stream_id the stream id, range 0-31 1669 */ 1670 int DVDRingBuffer::GetSubtitleTrackNum(uint stream_id) 1671 { 1672 return dvdnav_get_spu_logical_stream(m_dvdnav, stream_id); 1673 } 1674 1667 1675 /** \brief converts the subtitle/audio lang code to iso639. 1668 1676 */ 1669 1677 uint DVDRingBuffer::ConvertLangCode(uint16_t code) -
mythtv/libs/libmythtv/DVD/dvdringbuffer.h
diff --git a/mythtv/libs/libmythtv/DVD/dvdringbuffer.h b/mythtv/libs/libmythtv/DVD/dvdringbuffer.h index 05809b7..33c83c4 100644
a b class MTV_PUBLIC DVDRingBuffer : public RingBuffer 90 90 91 91 // Subtitles 92 92 uint GetSubtitleLanguage(int key); 93 int GetSubtitleTrackNum(uint stream_id); 93 94 bool DecodeSubtitles(AVSubtitle * sub, int * gotSubtitles, 94 95 const uint8_t * buf, int buf_size, uint32_t startTime); 95 96 -
mythtv/libs/libmythtv/DVD/mythdvdplayer.cpp
diff --git a/mythtv/libs/libmythtv/DVD/mythdvdplayer.cpp b/mythtv/libs/libmythtv/DVD/mythdvdplayer.cpp index 2bfbd11..9612b78 100644
a b void MythDVDPlayer::DisableCaptions(uint mode, bool osd_msg) 50 50 void MythDVDPlayer::EnableCaptions(uint mode, bool osd_msg) 51 51 { 52 52 if ((kDisplayAVSubtitle & mode) && player_ctx->buffer->IsDVD()) 53 player_ctx->buffer->DVD()->SetTrack(kTrackTypeSubtitle, 54 GetTrack(kTrackTypeSubtitle)); 53 { 54 int track = GetTrack(kTrackTypeSubtitle); 55 if (track >= 0 && track < (int)decoder->GetTrackCount(kTrackTypeSubtitle)) 56 { 57 StreamInfo stream = decoder->GetTrackInfo(kTrackTypeSubtitle, 58 track); 59 player_ctx->buffer->DVD()->SetTrack(kTrackTypeSubtitle, 60 stream.stream_id); 61 } 62 } 55 63 MythPlayer::EnableCaptions(mode, osd_msg); 56 64 } 57 65 … … void MythDVDPlayer::DisplayDVDButton(void) 549 557 // clear any buttons 550 558 if (!numbuttons || !dvdSubtitle || (buttonversion == 0) || expired) 551 559 { 552 SetCaptionsEnabled(false, false);553 560 osdLock.lock(); 554 561 if (osd) 555 562 osd->ClearSubtitles(); -
mythtv/libs/libmythtv/avformatdecoder.cpp
diff --git a/mythtv/libs/libmythtv/avformatdecoder.cpp b/mythtv/libs/libmythtv/avformatdecoder.cpp index 2d71ec9..0b410f1 100644
a b QString AvFormatDecoder::GetTrackDesc(uint type, uint trackNo) const 3877 3877 } 3878 3878 else if (kTrackTypeSubtitle == type) 3879 3879 { 3880 if (ringBuffer->IsDVD())3881 lang_key = ringBuffer->DVD()->GetSubtitleLanguage(trackNo);3882 3883 3880 return QObject::tr("Subtitle") + QString(" %1: %2%3") 3884 3881 .arg(trackNo + 1).arg(iso639_key_toName(lang_key)) 3885 3882 .arg(forcedString); -
mythtv/libs/libmythtv/decoderbase.cpp
diff --git a/mythtv/libs/libmythtv/decoderbase.cpp b/mythtv/libs/libmythtv/decoderbase.cpp index f181d2f..00f436d 100644
a b int DecoderBase::AutoSelectTrack(uint type) 1052 1052 for (uint i = 0; i < numStreams; i++) 1053 1053 { 1054 1054 if (wlang == tracks[type][i].language) 1055 { 1055 1056 selTrack = i; 1056 if (windx == tracks[type][i].language_index) 1057 break; 1057 1058 if (windx == tracks[type][i].language_index) 1059 break; 1060 } 1058 1061 } 1059 1062 } 1060 1063 … … int DecoderBase::AutoSelectTrack(uint type) 1106 1109 1107 1110 int lang = tracks[type][currentTrack[type]].language; 1108 1111 LOG(VB_PLAYBACK, LOG_INFO, LOC + 1109 QString("Selected track #%1 in the %2 language(%3)")1112 QString("Selected track #%1 (type %2) in the %3 language(%4)") 1110 1113 .arg(currentTrack[type]+1) 1114 .arg(type) 1111 1115 .arg(iso639_key_toName(lang)).arg(lang)); 1112 1116 1113 1117 if (m_parent && (oldTrack != currentTrack[type]))