Ticket #7252: mythtv_decoder_reorder_pts.diff

File mythtv_decoder_reorder_pts.diff, 8.4 KB (added by tralph11@…, 15 years ago)

FFmpeg reordered_opaque support

  • libs/libmythtv/avformatdecoder.cpp

     
    21402140
    21412141    pic->age = 256 * 256 * 256 * 64;
    21422142
     2143    pic->reordered_opaque= c->reordered_opaque;
     2144
    21432145    return 1;
    21442146}
    21452147
     
    22862288    render->state |= FF_VDPAU_STATE_USED_FOR_REFERENCE;
    22872289#endif
    22882290
     2291    pic->reordered_opaque= c->reordered_opaque;
     2292
    22892293    return 0;
    22902294}
    22912295
     
    38543858                    }
    38553859
    38563860                    AVCodecContext *context = curstream->codec;
    3857                     AVFrame mpa_pic;
    3858                     bzero(&mpa_pic, sizeof(AVFrame));
     3861                    AVFrame *mpa_pic= avcodec_alloc_frame();
    38593862
    38603863                    int gotpicture = 0;
    38613864
     
    38683871                            // HACK
    38693872                            while (!gotpicture && count < 5)
    38703873                            {
    3871                                 ret = d->DecodeMPEG2Video(context, &mpa_pic,
     3874                                ret = d->DecodeMPEG2Video(context, mpa_pic,
    38723875                                                  &gotpicture, ptr, len);
    38733876                                count++;
    38743877                            }
    38753878                        }
    38763879                        else
    38773880                        {
    3878                             ret = d->DecodeMPEG2Video(context, &mpa_pic,
     3881                            ret = d->DecodeMPEG2Video(context, mpa_pic,
    38793882                                                &gotpicture, ptr, len);
    38803883                        }
    38813884                    }
    38823885                    else
    38833886                    {
    3884                         ret = avcodec_decode_video(context, &mpa_pic,
     3887                        curstream->codec->reordered_opaque= pkt->pts;
     3888                        ret = avcodec_decode_video(context, mpa_pic,
    38853889                                                   &gotpicture, ptr, len);
    38863890                        // Reparse it to not drop the DVD still frame
    38873891                        if (decodeStillFrame)
    3888                             ret = avcodec_decode_video(context, &mpa_pic,
     3892                            ret = avcodec_decode_video(context, mpa_pic,
    38893893                                                        &gotpicture, ptr, len);
    38903894                    }
    38913895                    avcodeclock.unlock();
     
    39063910                    }
    39073911
    39083912                    // Decode ATSC captions
    3909                     for (uint i = 0; i < (uint)mpa_pic.atsc_cc_len;
    3910                          i += ((mpa_pic.atsc_cc_buf[i] & 0x1f) * 3) + 2)
     3913                    for (uint i = 0; i < (uint)mpa_pic->atsc_cc_len;
     3914                         i += ((mpa_pic->atsc_cc_buf[i] & 0x1f) * 3) + 2)
    39113915                    {
    3912                         DecodeDTVCC(mpa_pic.atsc_cc_buf + i);
     3916                        DecodeDTVCC(mpa_pic->atsc_cc_buf + i);
    39133917                    }
    39143918
    39153919                    // Decode DVB captions from MPEG user data
    3916                     if (mpa_pic.dvb_cc_len > 0)
     3920                    if (mpa_pic->dvb_cc_len > 0)
    39173921                    {
    39183922                        unsigned long long utc = lastccptsu;
    39193923
    3920                         for (uint i = 0; i < (uint)mpa_pic.dvb_cc_len; i += 2)
     3924                        for (uint i = 0; i < (uint)mpa_pic->dvb_cc_len; i += 2)
    39213925                        {
    3922                             uint8_t cc_lo = mpa_pic.dvb_cc_buf[i];
    3923                             uint8_t cc_hi = mpa_pic.dvb_cc_buf[i+1];
     3926                            uint8_t cc_lo = mpa_pic->dvb_cc_buf[i];
     3927                            uint8_t cc_hi = mpa_pic->dvb_cc_buf[i+1];
    39243928
    39253929                            uint16_t cc_dt = (cc_hi << 8) | cc_lo;
    39263930
     
    39333937                        lastccptsu = utc;
    39343938                    }
    39353939
    3936                     VideoFrame *picframe = (VideoFrame *)(mpa_pic.opaque);
     3940                    VideoFrame *picframe = (VideoFrame *)(mpa_pic->opaque);
    39373941
    39383942                    if (!directrendering)
    39393943                    {
     
    39523956
    39533957                        myth_sws_img_convert(
    39543958                            &tmppicture, PIX_FMT_YUV420P,
    3955                                     (AVPicture *)&mpa_pic,
     3959                                    (AVPicture *)mpa_pic,
    39563960                                    context->pix_fmt,
    39573961                                    context->width,
    39583962                                    context->height);
     
    39613965                        {
    39623966                            // Set the frame flags, but then discard it
    39633967                            // since we are not using it for display.
    3964                             xf->interlaced_frame = mpa_pic.interlaced_frame;
    3965                             xf->top_field_first = mpa_pic.top_field_first;
     3968                            xf->interlaced_frame = mpa_pic->interlaced_frame;
     3969                            xf->top_field_first = mpa_pic->top_field_first;
    39663970                            xf->frameNumber = framesPlayed;
    39673971                            GetNVP()->DiscardVideoFrame(xf);
    39683972                        }
    39693973                    }
    39703974
     3975                    int decoder_reorder_pts = 1;
     3976                    if(   (decoder_reorder_pts || pkt->dts == AV_NOPTS_VALUE)
     3977                       && mpa_pic->reordered_opaque != AV_NOPTS_VALUE) {
     3978                        pts= (long long)mpa_pic->reordered_opaque;
     3979                    }
     3980                    else if(pkt->dts != (int64_t)AV_NOPTS_VALUE) {
     3981                        pts= (long long)pkt->dts;
     3982                    }
     3983                    else {
     3984                        pts= 0;
     3985                    }
     3986                    pts = (long long)(av_q2d(curstream->time_base) * pts * 1000);
     3987
    39713988                    long long temppts = pts;
    39723989
    39733990                    // Validate the video pts against the last pts. If it's
     
    39803997                        temppts = lastvpts;
    39813998                        temppts += (long long)(1000 * av_q2d(context->time_base));
    39823999                        // MPEG2 frames can be repeated, update pts accordingly
    3983                         temppts += (long long)(mpa_pic.repeat_pict * 500
     4000                        temppts += (long long)(mpa_pic->repeat_pict * 500
    39844001                                      * av_q2d(curstream->codec->time_base));
    39854002                    }
    39864003
     
    39904007                            .arg(lastvpts));
    39914008
    39924009/* XXX: Broken.
    3993                     if (mpa_pic.qscale_table != NULL && mpa_pic.qstride > 0 &&
     4010                    if (mpa_pic->qscale_table != NULL && mpa_pic->qstride > 0 &&
    39944011                        context->height == picframe->height)
    39954012                    {
    3996                         int tblsize = mpa_pic.qstride *
     4013                        int tblsize = mpa_pic->qstride *
    39974014                                      ((picframe->height + 15) / 16);
    39984015
    3999                         if (picframe->qstride != mpa_pic.qstride ||
     4016                        if (picframe->qstride != mpa_pic->qstride ||
    40004017                            picframe->qscale_table == NULL)
    40014018                        {
    4002                             picframe->qstride = mpa_pic.qstride;
     4019                            picframe->qstride = mpa_pic->qstride;
    40034020                            if (picframe->qscale_table)
    40044021                                delete [] picframe->qscale_table;
    40054022                            picframe->qscale_table = new unsigned char[tblsize];
    40064023                        }
    40074024
    4008                         memcpy(picframe->qscale_table, mpa_pic.qscale_table,
     4025                        memcpy(picframe->qscale_table, mpa_pic->qscale_table,
    40094026                               tblsize);
    40104027                    }
    40114028*/
    40124029
    4013                     picframe->interlaced_frame = mpa_pic.interlaced_frame;
    4014                     picframe->top_field_first = mpa_pic.top_field_first;
    4015                     picframe->repeat_pict = mpa_pic.repeat_pict;
     4030                    picframe->interlaced_frame = mpa_pic->interlaced_frame;
     4031                    picframe->top_field_first = mpa_pic->top_field_first;
     4032                    picframe->repeat_pict = mpa_pic->repeat_pict;
    40164033
    40174034                    picframe->frameNumber = framesPlayed;
    40184035                    GetNVP()->ReleaseNextVideoFrame(picframe, temppts);
    4019                     if (d->HasMPEG2Dec() && mpa_pic.data[3])
    4020                         context->release_buffer(context, &mpa_pic);
     4036                    if (d->HasMPEG2Dec() && mpa_pic->data[3])
     4037                        context->release_buffer(context, mpa_pic);
    40214038
    40224039                    decoded_video_frame = picframe;
    40234040                    gotvideo = 1;