Ticket #1736: fix_enable_subtitles_by_default.diff

File fix_enable_subtitles_by_default.diff, 10.5 KB (added by Pekka Jääskeläinen <pekka.jaaskelainen@…>, 18 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  
    529529        videoOutput->EmbedInWidget(embedid, embx, emby, embw, embh);
    530530    }
    531531
    532     SetCaptionsEnabled(gContext->GetNumSetting("DefaultCCMode"));
     532    if (m_wantSubtitles = gContext->GetNumSetting("DefaultCCMode"))
     533        SetCaptionsEnabled(true, false);
    533534
    534535    return true;
    535536}
     
    14261427    }
    14271428}
    14281429
    1429 void NuppelVideoPlayer::EnableCaptions(uint mode)
     1430void NuppelVideoPlayer::EnableCaptions(uint mode, bool osd_msg)
    14301431{
    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)
    14501435    {
    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));
    14581436
    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        }
    14661472
    1467     msg += " " + QObject::tr("On");
     1473        msg += " " + QObject::tr("On");
    14681474
    1469     textDisplayMode = mode;
    1470     if (osd)
    14711475        osd->SetSettingsText(msg, 3 /* seconds until message timeout */);
    1472 
     1476    }
    14731477}
    14741478
    14751479void NuppelVideoPlayer::EnableTeletext(void)
     
    15521556    return textDisplayMode;
    15531557}
    15541558
    1555 void NuppelVideoPlayer::SetCaptionsEnabled(bool enable)
     1559void NuppelVideoPlayer::SetCaptionsEnabled(bool enable, bool showOsd)
    15561560{
    15571561    uint origMode = textDisplayMode;
    15581562
    15591563    if (!enable)
    15601564    {
    1561         DisableCaptions(origMode);
     1565        DisableCaptions(origMode, showOsd);
     1566        m_wantSubtitles = false;
    15621567        return;
    15631568    }
     1569    m_wantSubtitles = true;
    15641570   
    15651571    // figure out which text type to enable..
    15661572    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    }
    15691578    else if (decoder->GetTrackCount(kTrackTypeCC708))
    1570         EnableCaptions(kDisplayCC708);
     1579        EnableCaptions(kDisplayCC708, showOsd);
    15711580    else if (decoder->GetTrackCount(kTrackTypeTeletextCaptions))
    1572         EnableCaptions(kDisplayTeletextCaptions);
     1581        EnableCaptions(kDisplayTeletextCaptions, showOsd);
    15731582    else if (vbimode == VBIMode::PAL_TT)
    1574         EnableCaptions(kDisplayNUVTeletextCaptions);
     1583        EnableCaptions(kDisplayNUVTeletextCaptions, showOsd);
    15751584    else if (vbimode == VBIMode::NTSC_CC)
    15761585    {
    15771586        if (decoder->GetTrackCount(kTrackTypeCC608))
    1578             EnableCaptions(kDisplayCC608);
     1587            EnableCaptions(kDisplayCC608, showOsd);
    15791588        else
    15801589            captions_found = false;
    15811590    }
    15821591    else
    15831592        captions_found = false;
    15841593
    1585     if (!captions_found && osd)
     1594    if (!captions_found && osd && showOsd)
    15861595    {
    15871596        QString msg = QObject::tr(
    15881597            "No captions", "CC/Teletext/Subtitle text not available");
     
    58515860    subtitleLock.unlock();
    58525861}
    58535862
     5863/** \fn NuppelVideoPlayer::SubtitleTracksChanged()
     5864 *  \brief Used to notify of subtitle track changes.
     5865 */
     5866void 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
    58545877/** \fn NuppelVideoPlayer::SetDecoder(DecoderBase*)
    58555878 *  \brief Sets the stream decoder, deleting any existing recorder.
    58565879 */
  • libs/libmythtv/NuppelVideoPlayer.h

    old new  
    277277    void AddTextData(unsigned char *buffer, int len,
    278278                     long long timecode, char type);
    279279    void AddSubtitle(const AVSubtitle& subtitle);
     280    void SubtitleTracksChanged();
    280281
    281282    // Closed caption and teletext stuff
    282283    uint GetCaptionMode(void) const { return textDisplayMode; }
    283284    void ResetCaptions(uint mode_override = 0);
    284285    void DisableCaptions(uint mode, bool osd_msg = true);
    285     void EnableCaptions(uint mode);
     286    void EnableCaptions(uint mode, bool osd_msg = true);
    286287    bool ToggleCaptions(void);
    287288    bool ToggleCaptions(uint mode);
    288     void SetCaptionsEnabled(bool);
     289    void SetCaptionsEnabled(bool, bool showOsd = true);
    289290
    290291    // Teletext Menu and non-NUV teletext decoder
    291292    void EnableTeletext(void);
     
    608609    long long osdSubtitlesExpireAt;
    609610    MythDeque<AVSubtitle> nonDisplayedSubtitles;
    610611
     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
    611618    CC708Service CC708services[64];
    612619    QString    osdfontname;
    613620    QString    osdccfontname;
  • libs/libmythtv/avformatdecoder.cpp

    old new  
    11791179    map<int,uint> lang_sub_cnt;
    11801180    map<int,uint> lang_aud_cnt;
    11811181
     1182    bool subtitleTracksFound = false;
    11821183    for (int i = 0; i < ic->nb_streams; i++)
    11831184    {
    11841185        AVCodecContext *enc = ic->streams[i]->codec;
     
    12891290            }
    12901291            case CODEC_TYPE_SUBTITLE:
    12911292            {
     1293                subtitleTracksFound = true;
    12921294                bitrate += enc->bit_rate;
    12931295                VERBOSE(VB_PLAYBACK, LOC + QString("subtitle codec (%1)")
    12941296                        .arg(codec_type_string(enc->codec_type)));
     
    14321434                }
    14331435            }
    14341436        }
    1435     }
     1437    } 
    14361438
    14371439    // Select a new track at the next opportunity.
    14381440    ResetTracks();
    14391441
     1442    if (subtitleTracksFound && GetNVP() != NULL)
     1443        GetNVP()->SubtitleTracksChanged();
     1444
    14401445    // We have to do this here to avoid the NVP getting stuck
    14411446    // waiting on audio.
    14421447    if (GetNVP()->HasAudioIn() && tracks[kTrackTypeAudio].empty())
  • libs/libmythtv/decoderbase.cpp

    old new  
    819819{
    820820    QMutexLocker locker(&avcodeclock);
    821821
     822    if (type == kTrackTypeSubtitle && GetNVP() != NULL)
     823        GetNVP()->SubtitleTracksChanged();
     824
    822825    for (uint i = 0; i < tracks[type].size(); i++)
    823826        if (info.stream_id == tracks[type][i].stream_id)
    824827            return false;
    825828
    826829    tracks[type].push_back(info);
     830       
    827831    return true;
    828832}
    829833
    830834/** \fn DecoderBase::AutoSelectTrack(uint)
    831835 *  \brief Select best track.
    832836 *
    833  *   If case there's only one track available, always choose it.
     837 *   In case there's only one track available, always choose it.
    834838 *
    835839 *   If there is a user selected track we try to find it.
    836840 *
  • libs/libmythtv/decoderbase.h

    old new  
    136136
    137137    virtual bool SetAudioByComponentTag(int) { return false; }
    138138    virtual bool SetVideoByComponentTag(int) { return false; }
     139    virtual int  AutoSelectTrack(uint type);
    139140
    140141  protected:
    141     virtual int  AutoSelectTrack(uint type);
    142142    inline  void AutoSelectTracks(void);
    143143    inline  void ResetTracks(void);
     144    void AnnounceTrackTypeChange(uint type);
    144145
    145146    void FileChanged(void);
    146147
     
    245246
    246247inline void DecoderBase::ResetTracks(void)
    247248{
    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    }   
    250258}
    251259
    252260#endif