Ticket #7892: t7892_avchapter_support_v2.diff

File t7892_avchapter_support_v2.diff, 10.9 KB (added by taylor.ralph@…, 14 years ago)

clean up code and change previous chapter delay from 1.0 to 2.0 seconds

  • libs/libmythtv/NuppelVideoPlayer.cpp

     
    163163      transcoding(false),
    164164      hasFullPositionMap(false),    limitKeyRepeat(false),
    165165      errorMsg(QString::null),      errorType(kError_None),
     166      // Chapter stuff
     167      jumpchapter(0),
    166168      // Bookmark stuff
    167169      bookmarkseek(0),
    168170      // Seek
     
    31633165}
    31643166
    31653167
     3168void NuppelVideoPlayer::JumpChapter(int direction)
     3169{
     3170    if (jumpchapter == 0)
     3171        jumpchapter = direction;
     3172}
     3173
    31663174void NuppelVideoPlayer::SkipCommercials(int direction)
    31673175{
    31683176    if (skipcommercials == 0)
     
    34913499    }
    34923500
    34933501    rewindtime = fftime = 0;
     3502    jumpchapter = 0;
    34943503    skipcommercials = 0;
    34953504
    34963505    if (bookmarkseek > 30)
     
    36973706                RefreshPauseFrame();
    36983707                need_change_dvd_track = 0;
    36993708            }
     3709            else if (jumpchapter != 0)
     3710            {
     3711                DoJumpChapter(jumpchapter);
     3712                RefreshPauseFrame();
     3713                jumpchapter = 0;
     3714            }
    37003715            else if (player_ctx->tvchain && player_ctx->tvchain->NeedsToJump())
    37013716            {
    37023717                JumpToProgram();
     
    37593774            need_change_dvd_track = 0;
    37603775        }
    37613776
     3777        if (jumpchapter != 0)
     3778        {
     3779            QMutexLocker locker(&internalPauseLock);
     3780
     3781            PauseVideo(true);
     3782            DoJumpChapter(jumpchapter);
     3783            UnpauseVideo(true);
     3784
     3785            jumpchapter = 0;
     3786        }
     3787
    37623788        if (skipcommercials != 0 && ffrew_skip == 1)
    37633789        {
    37643790            QMutexLocker locker(&internalPauseLock);
     
    65396565    }
    65406566}
    65416567
     6568int NuppelVideoPlayer::GetNumChapters()
     6569{
     6570    return GetDecoder()->GetNumChapters();
     6571}
     6572
     6573bool NuppelVideoPlayer::DoJumpChapter(int direction)
     6574{
     6575  int desiredFrame = 0;
     6576
     6577  if (direction == -1)
     6578  {
     6579      desiredFrame = GetDecoder()->GetPrevChapter(framesPlayed);
     6580  }
     6581  else
     6582  {
     6583      desiredFrame = GetDecoder()->GetNextChapter(framesPlayed);
     6584  }
     6585
     6586  if (paused && !editmode)
     6587      GetDecoder()->setExactSeeks(true);
     6588  if (direction == -1)
     6589      GetDecoder()->DoRewind(desiredFrame);
     6590  else
     6591      GetDecoder()->DoFastForward(desiredFrame);
     6592  GetDecoder()->setExactSeeks(exactseeks);
     6593
     6594  // Note: The video output will be reset by what the the decoder
     6595  //       does, so we only need to reset the audio, subtitles, etc.
     6596  ClearAfterSeek(false);
     6597
     6598  lastSkipTime = time(NULL);
     6599  return true;
     6600}
     6601
    65426602bool NuppelVideoPlayer::DoSkipCommercials(int direction)
    65436603{
    65446604    if (!hascommbreaktable)
  • libs/libmythtv/decoderbase.h

     
    7878    virtual bool GetFrame(int onlyvideo) = 0;
    7979    NuppelVideoPlayer *GetNVP() { return m_parent; }
    8080
     81    virtual int GetNumChapters(void) { return 0; }
     82    virtual int GetNextChapter(int framesPlayed) { return framesPlayed; }
     83    virtual int GetPrevChapter(int framesPlayed) { return framesPlayed; }
    8184    virtual bool DoRewind(long long desiredFrame, bool doflush = true);
    8285    virtual bool DoFastForward(long long desiredFrame, bool doflush = true);
    8386
  • libs/libmythtv/avformatdecoder.cpp

     
    580580    return  ((lsb - base_ts)&mask);
    581581}
    582582
     583int AvFormatDecoder::GetNumChapters()
     584{
     585  return ic->nb_chapters;
     586}
     587
     588int AvFormatDecoder::GetPrevChapter(int framesPlayed)
     589{
     590    int framenum = 0;
     591    int prevframenum = framesPlayed;
     592    int prevchapter = 0;
     593    for (unsigned int i=0; i < ic->nb_chapters; i++)
     594    {
     595        int num = ic->chapters[i]->time_base.num;
     596        int den = ic->chapters[i]->time_base.den;
     597        int64_t start = ic->chapters[i]->start;
     598        double total_secs = (double)((long double)start * (long double)num / (long double)den);
     599        framenum = (int)(total_secs * fps);
     600        if (framenum > (framesPlayed - (int)(2.0 * fps)))
     601        {
     602            VERBOSE(VB_PLAYBACK, LOC +
     603                    QString("GetPrevChapter(selected chapter %1 framenum %2)")
     604                            .arg(prevchapter).arg(prevframenum));
     605            return prevframenum;
     606        }
     607        prevframenum = framenum;
     608        prevchapter = i;
     609    }
     610    return framenum;
     611}
     612
     613int AvFormatDecoder::GetNextChapter(int framesPlayed)
     614{
     615    int framenum = 0;
     616    for (unsigned int i=0; i < ic->nb_chapters; i++)
     617    {
     618        int num = ic->chapters[i]->time_base.num;
     619        int den = ic->chapters[i]->time_base.den;
     620        int64_t start = ic->chapters[i]->start;
     621        double total_secs = (double)((long double)start * (long double)num / (long double)den);
     622        framenum = (int)(total_secs * fps);
     623        if (framenum > framesPlayed)
     624        {
     625            VERBOSE(VB_IMPORTANT, LOC +
     626                    QString("GetNextChapter(selected chapter %1 framenum %2)")
     627                            .arg(i).arg(framenum));
     628            return framenum;
     629        }
     630    }
     631    return framesPlayed;
     632}
     633
    583634bool AvFormatDecoder::DoRewind(long long desiredFrame, bool discardFrames)
    584635{
    585636    VERBOSE(VB_PLAYBACK, LOC + "DoRewind("
     
    11001151            QString("Successfully opened decoder for file: "
    11011152                    "\"%1\". novideo(%2)").arg(filename).arg(novideo));
    11021153
     1154    // Print AVChapter information
     1155    for (unsigned int i=0; i < ic->nb_chapters; i++)
     1156    {
     1157        int num = ic->chapters[i]->time_base.num;
     1158        int den = ic->chapters[i]->time_base.den;
     1159        int64_t start = ic->chapters[i]->start;
     1160        double total_secs = (double)((long double)start * (long double)num / (long double)den);
     1161        int hours = (int)total_secs / 60 / 60;
     1162        int minutes = ((int)total_secs / 60) - (hours * 60);
     1163        double secs = total_secs - (double)(hours * 60 * 60 + minutes * 60);
     1164        VERBOSE(VB_PLAYBACK, LOC + QString("Chapter %1 found @ [%2:%3:%4]")
     1165                .arg(QString().sprintf("%02d", i))
     1166                .arg(QString().sprintf("%02d", hours))
     1167                .arg(QString().sprintf("%02d", minutes))
     1168                .arg(QString().sprintf("%06.3f", secs)));
     1169    }
     1170
    11031171    // Return true if recording has position map
    11041172    return recordingHasPositionMap;
    11051173}
  • libs/libmythtv/tv_play.h

     
    442442    float StopFFRew(PlayerContext*);
    443443    void ChangeFFRew(PlayerContext*, int direction);
    444444    void SetFFRew(PlayerContext*, int index);
     445    int GetNumChapters(PlayerContext*);
     446    void DoJumpChapter(PlayerContext*, int direction);
    445447    void DoSkipCommercials(PlayerContext*, int direction);
    446448    void StartProgramEditMode(PlayerContext*);
    447449
  • libs/libmythtv/NuppelVideoPlayer.h

     
    265265    bool RebuildSeekTable(bool showPercentage = true, StatusCallback cb = NULL,
    266266                          void* cbData = NULL);
    267267
     268    // Chapter stuff
     269    void JumpChapter(int direction);
     270
    268271    // Commercial stuff
    269272    void SkipCommercials(int direction);
    270273    int FlagCommercials(bool showPercentage, bool fullSpeed,
     
    409412    void CheckTVChain();
    410413    void FileChangedCallback();
    411414
     415    // Chapter public stuff
     416    int GetNumChapters();
     417
    412418    // DVD public stuff
    413419    void ChangeDVDTrack(bool ffw);
    414420    void ActivateDVDButton(void);
     
    485491    void JumpToNetFrame(long long net) { JumpToFrame(framesPlayed + net); }
    486492    void RefreshPauseFrame(void);
    487493
     494    // Private chapter stuff
     495    bool DoJumpChapter(int direction);
     496
    488497    // Private commercial skipping
    489498    void SkipCommercialsByBlanks(void);
    490499    bool DoSkipCommercials(int direction);
     
    595604    mutable QString  errorMsg;   ///< Reason why NVP exited with a error
    596605    mutable int errorType;
    597606
     607    // Chapter stuff
     608    int jumpchapter;
     609
    598610    // Bookmark stuff
    599611    long long bookmarkseek;
    600612
  • libs/libmythtv/tv_play.cpp

     
    43084308    {
    43094309        if (isDVD)
    43104310            DVDJumpBack(ctx);
     4311        else if (GetNumChapters(ctx) > 0)
     4312            DoJumpChapter(ctx, -1);
    43114313        else
    43124314            DoSeek(ctx, -ctx->jumptime * 60, tr("Jump Back"));
    43134315    }
     
    43154317    {
    43164318        if (isDVD)
    43174319            DVDJumpForward(ctx);
     4320        else if (GetNumChapters(ctx) > 0)
     4321            DoJumpChapter(ctx, 1);
    43184322        else
    43194323            DoSeek(ctx, ctx->jumptime * 60, tr("Jump Ahead"));
    43204324    }
     
    61986202    ctx->UnlockPlayingInfo(__FILE__, __LINE__);
    61996203}
    62006204
     6205int TV::GetNumChapters(PlayerContext *ctx)
     6206{
     6207    int num_chapters;
     6208    ctx->LockDeleteNVP(__FILE__, __LINE__);
     6209    if (ctx->nvp)
     6210        num_chapters = ctx->nvp->GetNumChapters();
     6211    ctx->UnlockDeleteNVP(__FILE__, __LINE__);
     6212
     6213    return num_chapters;
     6214}
     6215
     6216void TV::DoJumpChapter(PlayerContext *ctx, int direction)
     6217{
     6218    NormalSpeed(ctx);
     6219    StopFFRew(ctx);
     6220
     6221    ctx->LockDeleteNVP(__FILE__, __LINE__);
     6222    bool muted = MuteChannelChange(ctx);
     6223    ctx->UnlockDeleteNVP(__FILE__, __LINE__);
     6224
     6225    struct StatusPosInfo posInfo;
     6226    ctx->CalcNVPSliderPosition(posInfo);
     6227
     6228    bool slidertype = false;
     6229
     6230    OSD *osd = GetOSDLock(ctx);
     6231    if (osd)
     6232    {
     6233        posInfo.desc = tr("Searching...");
     6234        if (direction < 0)
     6235            osd->ShowStatus(posInfo, slidertype, tr("Previous Chapter"), 6);
     6236        else
     6237            osd->ShowStatus(posInfo, slidertype, tr("Next Chapter"), 6);
     6238        SetUpdateOSDPosition(true);
     6239    }
     6240    ReturnOSDLock(ctx, osd);
     6241
     6242    ctx->LockDeleteNVP(__FILE__, __LINE__);
     6243    if (ctx->nvp)
     6244        ctx->nvp->JumpChapter(direction);
     6245    ctx->UnlockDeleteNVP(__FILE__, __LINE__);
     6246
     6247    if (muted)
     6248        SetMuteTimer(ctx, kMuteTimeout);
     6249}
     6250
    62016251void TV::DoSkipCommercials(PlayerContext *ctx, int direction)
    62026252{
    62036253    NormalSpeed(ctx);
  • libs/libmythtv/avformatdecoder.h

     
    131131
    132132    int ScanStreams(bool novideo);
    133133
     134    virtual int GetNumChapters();
     135    virtual int GetPrevChapter(int framesPlayed);
     136    virtual int GetNextChapter(int framesPlayed);
    134137    virtual bool DoRewind(long long desiredFrame, bool doflush = true);
    135138    virtual bool DoFastForward(long long desiredFrame, bool doflush = true);
    136139