Ticket #7252: mythtv_decoder_reorder_pts.diff
File mythtv_decoder_reorder_pts.diff, 8.4 KB (added by , 15 years ago) |
---|
-
libs/libmythtv/avformatdecoder.cpp
2140 2140 2141 2141 pic->age = 256 * 256 * 256 * 64; 2142 2142 2143 pic->reordered_opaque= c->reordered_opaque; 2144 2143 2145 return 1; 2144 2146 } 2145 2147 … … 2286 2288 render->state |= FF_VDPAU_STATE_USED_FOR_REFERENCE; 2287 2289 #endif 2288 2290 2291 pic->reordered_opaque= c->reordered_opaque; 2292 2289 2293 return 0; 2290 2294 } 2291 2295 … … 3854 3858 } 3855 3859 3856 3860 AVCodecContext *context = curstream->codec; 3857 AVFrame mpa_pic; 3858 bzero(&mpa_pic, sizeof(AVFrame)); 3861 AVFrame *mpa_pic= avcodec_alloc_frame(); 3859 3862 3860 3863 int gotpicture = 0; 3861 3864 … … 3868 3871 // HACK 3869 3872 while (!gotpicture && count < 5) 3870 3873 { 3871 ret = d->DecodeMPEG2Video(context, &mpa_pic,3874 ret = d->DecodeMPEG2Video(context, mpa_pic, 3872 3875 &gotpicture, ptr, len); 3873 3876 count++; 3874 3877 } 3875 3878 } 3876 3879 else 3877 3880 { 3878 ret = d->DecodeMPEG2Video(context, &mpa_pic,3881 ret = d->DecodeMPEG2Video(context, mpa_pic, 3879 3882 &gotpicture, ptr, len); 3880 3883 } 3881 3884 } 3882 3885 else 3883 3886 { 3884 ret = avcodec_decode_video(context, &mpa_pic, 3887 curstream->codec->reordered_opaque= pkt->pts; 3888 ret = avcodec_decode_video(context, mpa_pic, 3885 3889 &gotpicture, ptr, len); 3886 3890 // Reparse it to not drop the DVD still frame 3887 3891 if (decodeStillFrame) 3888 ret = avcodec_decode_video(context, &mpa_pic,3892 ret = avcodec_decode_video(context, mpa_pic, 3889 3893 &gotpicture, ptr, len); 3890 3894 } 3891 3895 avcodeclock.unlock(); … … 3906 3910 } 3907 3911 3908 3912 // 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) 3911 3915 { 3912 DecodeDTVCC(mpa_pic .atsc_cc_buf + i);3916 DecodeDTVCC(mpa_pic->atsc_cc_buf + i); 3913 3917 } 3914 3918 3915 3919 // Decode DVB captions from MPEG user data 3916 if (mpa_pic .dvb_cc_len > 0)3920 if (mpa_pic->dvb_cc_len > 0) 3917 3921 { 3918 3922 unsigned long long utc = lastccptsu; 3919 3923 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) 3921 3925 { 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]; 3924 3928 3925 3929 uint16_t cc_dt = (cc_hi << 8) | cc_lo; 3926 3930 … … 3933 3937 lastccptsu = utc; 3934 3938 } 3935 3939 3936 VideoFrame *picframe = (VideoFrame *)(mpa_pic .opaque);3940 VideoFrame *picframe = (VideoFrame *)(mpa_pic->opaque); 3937 3941 3938 3942 if (!directrendering) 3939 3943 { … … 3952 3956 3953 3957 myth_sws_img_convert( 3954 3958 &tmppicture, PIX_FMT_YUV420P, 3955 (AVPicture *) &mpa_pic,3959 (AVPicture *)mpa_pic, 3956 3960 context->pix_fmt, 3957 3961 context->width, 3958 3962 context->height); … … 3961 3965 { 3962 3966 // Set the frame flags, but then discard it 3963 3967 // 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; 3966 3970 xf->frameNumber = framesPlayed; 3967 3971 GetNVP()->DiscardVideoFrame(xf); 3968 3972 } 3969 3973 } 3970 3974 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 3971 3988 long long temppts = pts; 3972 3989 3973 3990 // Validate the video pts against the last pts. If it's … … 3980 3997 temppts = lastvpts; 3981 3998 temppts += (long long)(1000 * av_q2d(context->time_base)); 3982 3999 // MPEG2 frames can be repeated, update pts accordingly 3983 temppts += (long long)(mpa_pic .repeat_pict * 5004000 temppts += (long long)(mpa_pic->repeat_pict * 500 3984 4001 * av_q2d(curstream->codec->time_base)); 3985 4002 } 3986 4003 … … 3990 4007 .arg(lastvpts)); 3991 4008 3992 4009 /* XXX: Broken. 3993 if (mpa_pic .qscale_table != NULL && mpa_pic.qstride > 0 &&4010 if (mpa_pic->qscale_table != NULL && mpa_pic->qstride > 0 && 3994 4011 context->height == picframe->height) 3995 4012 { 3996 int tblsize = mpa_pic .qstride *4013 int tblsize = mpa_pic->qstride * 3997 4014 ((picframe->height + 15) / 16); 3998 4015 3999 if (picframe->qstride != mpa_pic .qstride ||4016 if (picframe->qstride != mpa_pic->qstride || 4000 4017 picframe->qscale_table == NULL) 4001 4018 { 4002 picframe->qstride = mpa_pic .qstride;4019 picframe->qstride = mpa_pic->qstride; 4003 4020 if (picframe->qscale_table) 4004 4021 delete [] picframe->qscale_table; 4005 4022 picframe->qscale_table = new unsigned char[tblsize]; 4006 4023 } 4007 4024 4008 memcpy(picframe->qscale_table, mpa_pic .qscale_table,4025 memcpy(picframe->qscale_table, mpa_pic->qscale_table, 4009 4026 tblsize); 4010 4027 } 4011 4028 */ 4012 4029 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; 4016 4033 4017 4034 picframe->frameNumber = framesPlayed; 4018 4035 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); 4021 4038 4022 4039 decoded_video_frame = picframe; 4023 4040 gotvideo = 1;