From 6fa0d949f5db94e21410e0a44a4821e86ae5a306 Mon Sep 17 00:00:00 2001
From: Richard <peper03@yahoo.com>
Date: Mon, 11 Mar 2013 14:47:42 +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 9f8ab82..2ff0d29 100644
|
a
|
b
|
void DVDRingBuffer::ActivateButton(void)
|
| 1172 | 1172 | |
| 1173 | 1173 | /** \brief get SPU pkt from dvd menu subtitle stream |
| 1174 | 1174 | */ |
| 1175 | | void DVDRingBuffer::GetMenuSPUPkt(uint8_t *buf, int buf_size, int stream_id) |
| | 1175 | void DVDRingBuffer::GetMenuSPUPkt(uint8_t *buf, int buf_size, |
| | 1176 | int stream_id, uint32_t startTime) |
| 1176 | 1177 | { |
| 1177 | 1178 | if (buf_size < 4) |
| 1178 | 1179 | return; |
| … |
… |
void DVDRingBuffer::GetMenuSPUPkt(uint8_t *buf, int buf_size, int stream_id)
|
| 1198 | 1199 | { |
| 1199 | 1200 | int32_t gotbutton; |
| 1200 | 1201 | m_buttonExists = DecodeSubtitles(&m_dvdMenuButton, &gotbutton, |
| 1201 | | m_menuSpuPkt, m_menuBuflength); |
| | 1202 | m_menuSpuPkt, m_menuBuflength, startTime); |
| 1202 | 1203 | } |
| 1203 | 1204 | } |
| 1204 | 1205 | |
| … |
… |
QRect DVDRingBuffer::GetButtonCoords(void)
|
| 1243 | 1244 | * code obtained from ffmpeg project |
| 1244 | 1245 | */ |
| 1245 | 1246 | bool DVDRingBuffer::DecodeSubtitles(AVSubtitle *sub, int *gotSubtitles, |
| 1246 | | const uint8_t *spu_pkt, int buf_size) |
| | 1247 | const uint8_t *spu_pkt, int buf_size, uint32_t startTime) |
| 1247 | 1248 | { |
| 1248 | 1249 | #define GETBE16(p) (((p)[0] << 8) | (p)[1]) |
| 1249 | 1250 | |
| … |
… |
bool DVDRingBuffer::DecodeSubtitles(AVSubtitle *sub, int *gotSubtitles,
|
| 1281 | 1282 | { |
| 1282 | 1283 | case 0x00: |
| 1283 | 1284 | force_subtitle_display = true; |
| | 1285 | sub->start_display_time = startTime; |
| | 1286 | sub->end_display_time = 0xFFFFFFFF; |
| 1284 | 1287 | break; |
| 1285 | 1288 | case 0x01: |
| 1286 | | sub->start_display_time = (date << 10) / 90; |
| | 1289 | sub->start_display_time = ((date << 10) / 90) + startTime; |
| 1287 | 1290 | break; |
| 1288 | 1291 | case 0x02: |
| 1289 | | sub->end_display_time = (date << 10) / 90; |
| | 1292 | sub->end_display_time = ((date << 10) / 90) + startTime; |
| 1290 | 1293 | break; |
| 1291 | 1294 | case 0x03: |
| 1292 | 1295 | { |
diff --git a/mythtv/libs/libmythtv/DVD/dvdringbuffer.h b/mythtv/libs/libmythtv/DVD/dvdringbuffer.h
index 3a31c1b..3f85a3e 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 | |
| 82 | 82 | // Public menu/button stuff |
| 83 | 83 | AVSubtitle *GetMenuSubtitle(uint &version); |
| … |
… |
class MTV_PUBLIC DVDRingBuffer : public RingBuffer
|
| 90 | 90 | // Subtitles |
| 91 | 91 | uint GetSubtitleLanguage(int key); |
| 92 | 92 | bool DecodeSubtitles(AVSubtitle * sub, int * gotSubtitles, |
| 93 | | const uint8_t * buf, int buf_size); |
| | 93 | const uint8_t * buf, int buf_size, uint32_t startTime); |
| 94 | 94 | |
| 95 | 95 | uint GetAudioLanguage(int id); |
| 96 | 96 | 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 452c679..975f54e 100644
|
a
|
b
|
bool AvFormatDecoder::ProcessSubtitlePacket(AVStream *curstream, AVPacket *pkt)
|
| 3686 | 3686 | if (ringBuffer->DVD()->NumMenuButtons() > 0) |
| 3687 | 3687 | { |
| 3688 | 3688 | ringBuffer->DVD()->GetMenuSPUPkt(pkt->data, pkt->size, |
| 3689 | | curstream->id); |
| | 3689 | curstream->id, pts); |
| 3690 | 3690 | } |
| 3691 | 3691 | else |
| 3692 | 3692 | { |
| … |
… |
bool AvFormatDecoder::ProcessSubtitlePacket(AVStream *curstream, AVPacket *pkt)
|
| 3694 | 3694 | { |
| 3695 | 3695 | QMutexLocker locker(avcodeclock); |
| 3696 | 3696 | ringBuffer->DVD()->DecodeSubtitles(&subtitle, &gotSubtitles, |
| 3697 | | pkt->data, pkt->size); |
| | 3697 | pkt->data, pkt->size, pts); |
| 3698 | 3698 | } |
| 3699 | 3699 | } |
| 3700 | 3700 | } |
| … |
… |
bool AvFormatDecoder::ProcessSubtitlePacket(AVStream *curstream, AVPacket *pkt)
|
| 3703 | 3703 | QMutexLocker locker(avcodeclock); |
| 3704 | 3704 | avcodec_decode_subtitle2(curstream->codec, &subtitle, &gotSubtitles, |
| 3705 | 3705 | pkt); |
| | 3706 | |
| | 3707 | subtitle.start_display_time += pts; |
| | 3708 | subtitle.end_display_time += pts; |
| 3706 | 3709 | } |
| 3707 | 3710 | |
| 3708 | 3711 | if (gotSubtitles) |
| 3709 | 3712 | { |
| 3710 | 3713 | if (isForcedTrack) |
| 3711 | 3714 | subtitle.forced = true; |
| 3712 | | subtitle.start_display_time += pts; |
| 3713 | | subtitle.end_display_time += pts; |
| 3714 | 3715 | LOG(VB_PLAYBACK | VB_TIMESTAMP, LOG_INFO, LOC + |
| 3715 | 3716 | QString("subtl timecode %1 %2 %3 %4") |
| 3716 | 3717 | .arg(pkt->pts).arg(pkt->dts) |