From 576da56ad211834887b23ff2c917675fbe5b03d1 Mon Sep 17 00:00:00 2001
From: Richard <peper03@yahoo.com>
Date: Wed, 13 Mar 2013 18:16:53 +0100
Subject: [PATCH] Respect the start and end times of menu highlights to avoid
showing the menu highlight too soon/for too long.
---
mythtv/libs/libmythtv/DVD/dvdringbuffer.cpp | 13 ++++++++-----
mythtv/libs/libmythtv/DVD/dvdringbuffer.h | 4 ++--
mythtv/libs/libmythtv/DVD/mythdvdplayer.cpp | 26 ++++++++++++++++++++++++--
mythtv/libs/libmythtv/avformatdecoder.cpp | 9 +++++----
4 files changed, 39 insertions(+), 13 deletions(-)
diff --git a/mythtv/libs/libmythtv/DVD/dvdringbuffer.cpp b/mythtv/libs/libmythtv/DVD/dvdringbuffer.cpp
index 2932cd8..a7ef500 100644
a
|
b
|
void DVDRingBuffer::ActivateButton(void) |
1240 | 1240 | |
1241 | 1241 | /** \brief get SPU pkt from dvd menu subtitle stream |
1242 | 1242 | */ |
1243 | | void DVDRingBuffer::GetMenuSPUPkt(uint8_t *buf, int buf_size, int stream_id) |
| 1243 | void DVDRingBuffer::GetMenuSPUPkt(uint8_t *buf, int buf_size, |
| 1244 | int stream_id, uint32_t startTime) |
1244 | 1245 | { |
1245 | 1246 | if (buf_size < 4) |
1246 | 1247 | return; |
… |
… |
void DVDRingBuffer::GetMenuSPUPkt(uint8_t *buf, int buf_size, int stream_id) |
1266 | 1267 | { |
1267 | 1268 | int32_t gotbutton; |
1268 | 1269 | m_buttonExists = DecodeSubtitles(&m_dvdMenuButton, &gotbutton, |
1269 | | m_menuSpuPkt, m_menuBuflength); |
| 1270 | m_menuSpuPkt, m_menuBuflength, startTime); |
1270 | 1271 | } |
1271 | 1272 | } |
1272 | 1273 | |
… |
… |
QRect DVDRingBuffer::GetButtonCoords(void) |
1311 | 1312 | * code obtained from ffmpeg project |
1312 | 1313 | */ |
1313 | 1314 | bool DVDRingBuffer::DecodeSubtitles(AVSubtitle *sub, int *gotSubtitles, |
1314 | | const uint8_t *spu_pkt, int buf_size) |
| 1315 | const uint8_t *spu_pkt, int buf_size, uint32_t startTime) |
1315 | 1316 | { |
1316 | 1317 | #define GETBE16(p) (((p)[0] << 8) | (p)[1]) |
1317 | 1318 | |
… |
… |
bool DVDRingBuffer::DecodeSubtitles(AVSubtitle *sub, int *gotSubtitles, |
1349 | 1350 | { |
1350 | 1351 | case 0x00: |
1351 | 1352 | force_subtitle_display = true; |
| 1353 | sub->start_display_time = startTime; |
| 1354 | sub->end_display_time = 0xFFFFFFFF; |
1352 | 1355 | break; |
1353 | 1356 | case 0x01: |
1354 | | sub->start_display_time = (date << 10) / 90; |
| 1357 | sub->start_display_time = ((date << 10) / 90) + startTime; |
1355 | 1358 | break; |
1356 | 1359 | case 0x02: |
1357 | | sub->end_display_time = (date << 10) / 90; |
| 1360 | sub->end_display_time = ((date << 10) / 90) + startTime; |
1358 | 1361 | break; |
1359 | 1362 | case 0x03: |
1360 | 1363 | { |
diff --git a/mythtv/libs/libmythtv/DVD/dvdringbuffer.h b/mythtv/libs/libmythtv/DVD/dvdringbuffer.h
index 1c089fe..0e3247f 100644
a
|
b
|
class MTV_PUBLIC DVDRingBuffer : public RingBuffer |
77 | 77 | bool AudioStreamsChanged(void) const { return m_audioStreamsChanged; } |
78 | 78 | bool IsWaiting(void) const { return m_dvdWaiting; } |
79 | 79 | int NumPartsInTitle(void) const { return m_titleParts; } |
80 | | void GetMenuSPUPkt(uint8_t *buf, int len, int stream_id); |
| 80 | void GetMenuSPUPkt(uint8_t *buf, int len, int stream_id, uint32_t startTime); |
81 | 81 | int64_t GetTimeDiff(void) const { return m_timeDiff; } |
82 | 82 | |
83 | 83 | // Public menu/button stuff |
… |
… |
class MTV_PUBLIC DVDRingBuffer : public RingBuffer |
91 | 91 | // Subtitles |
92 | 92 | uint GetSubtitleLanguage(int key); |
93 | 93 | bool DecodeSubtitles(AVSubtitle * sub, int * gotSubtitles, |
94 | | const uint8_t * buf, int buf_size); |
| 94 | const uint8_t * buf, int buf_size, uint32_t startTime); |
95 | 95 | |
96 | 96 | uint GetAudioLanguage(int id); |
97 | 97 | int GetAudioTrackNum(uint key); |
diff --git a/mythtv/libs/libmythtv/DVD/mythdvdplayer.cpp b/mythtv/libs/libmythtv/DVD/mythdvdplayer.cpp
index 3f79e4b..2faf2dd 100644
a
|
b
|
void MythDVDPlayer::DisplayDVDButton(void) |
518 | 518 | AVSubtitle *dvdSubtitle = player_ctx->buffer->DVD()->GetMenuSubtitle(buttonversion); |
519 | 519 | bool numbuttons = player_ctx->buffer->DVD()->NumMenuButtons(); |
520 | 520 | |
| 521 | bool expired = false; |
| 522 | |
| 523 | VideoFrame *currentFrame = videoOutput ? videoOutput->GetLastShownFrame() : NULL; |
| 524 | |
| 525 | if (!currentFrame) |
| 526 | { |
| 527 | player_ctx->buffer->DVD()->ReleaseMenuButton(); |
| 528 | return; |
| 529 | } |
| 530 | |
| 531 | if (dvdSubtitle && |
| 532 | (dvdSubtitle->end_display_time < currentFrame->timecode)) |
| 533 | { |
| 534 | expired = true; |
| 535 | } |
| 536 | |
521 | 537 | // nothing to do |
522 | | if (buttonversion == ((uint)m_buttonVersion)) |
| 538 | if (!expired && (buttonversion == ((uint)m_buttonVersion))) |
523 | 539 | { |
524 | 540 | player_ctx->buffer->DVD()->ReleaseMenuButton(); |
525 | 541 | return; |
526 | 542 | } |
527 | 543 | |
528 | 544 | // clear any buttons |
529 | | if (!numbuttons || !dvdSubtitle || (buttonversion == 0)) |
| 545 | if (!numbuttons || !dvdSubtitle || (buttonversion == 0) || expired) |
530 | 546 | { |
531 | 547 | SetCaptionsEnabled(false, false); |
532 | 548 | osdLock.lock(); |
… |
… |
void MythDVDPlayer::DisplayDVDButton(void) |
538 | 554 | return; |
539 | 555 | } |
540 | 556 | |
| 557 | if (currentFrame->timecode && (dvdSubtitle->start_display_time > currentFrame->timecode)) |
| 558 | { |
| 559 | player_ctx->buffer->DVD()->ReleaseMenuButton(); |
| 560 | return; |
| 561 | } |
| 562 | |
541 | 563 | m_buttonVersion = buttonversion; |
542 | 564 | QRect buttonPos = player_ctx->buffer->DVD()->GetButtonCoords(); |
543 | 565 | osdLock.lock(); |
diff --git a/mythtv/libs/libmythtv/avformatdecoder.cpp b/mythtv/libs/libmythtv/avformatdecoder.cpp
index 7a1716b..cb55ac9 100644
a
|
b
|
bool AvFormatDecoder::ProcessSubtitlePacket(AVStream *curstream, AVPacket *pkt) |
3696 | 3696 | if (ringBuffer->DVD()->NumMenuButtons() > 0) |
3697 | 3697 | { |
3698 | 3698 | ringBuffer->DVD()->GetMenuSPUPkt(pkt->data, pkt->size, |
3699 | | curstream->id); |
| 3699 | curstream->id, pts); |
3700 | 3700 | } |
3701 | 3701 | else |
3702 | 3702 | { |
… |
… |
bool AvFormatDecoder::ProcessSubtitlePacket(AVStream *curstream, AVPacket *pkt) |
3704 | 3704 | { |
3705 | 3705 | QMutexLocker locker(avcodeclock); |
3706 | 3706 | ringBuffer->DVD()->DecodeSubtitles(&subtitle, &gotSubtitles, |
3707 | | pkt->data, pkt->size); |
| 3707 | pkt->data, pkt->size, pts); |
3708 | 3708 | } |
3709 | 3709 | } |
3710 | 3710 | } |
… |
… |
bool AvFormatDecoder::ProcessSubtitlePacket(AVStream *curstream, AVPacket *pkt) |
3713 | 3713 | QMutexLocker locker(avcodeclock); |
3714 | 3714 | avcodec_decode_subtitle2(curstream->codec, &subtitle, &gotSubtitles, |
3715 | 3715 | pkt); |
| 3716 | |
| 3717 | subtitle.start_display_time += pts; |
| 3718 | subtitle.end_display_time += pts; |
3716 | 3719 | } |
3717 | 3720 | |
3718 | 3721 | if (gotSubtitles) |
3719 | 3722 | { |
3720 | 3723 | if (isForcedTrack) |
3721 | 3724 | subtitle.forced = true; |
3722 | | subtitle.start_display_time += pts; |
3723 | | subtitle.end_display_time += pts; |
3724 | 3725 | LOG(VB_PLAYBACK | VB_TIMESTAMP, LOG_INFO, LOC + |
3725 | 3726 | QString("subtl timecode %1 %2 %3 %4") |
3726 | 3727 | .arg(pkt->pts).arg(pkt->dts) |