Ticket #7252: mythtv_decoder_reorder_pts_v3.diff
File mythtv_decoder_reorder_pts_v3.diff, 8.9 KB (added by , 15 years ago) |
---|
-
libs/libmythtv/avformatdecoder.cpp
65 65 66 66 static const int max_video_queue_size = 180; 67 67 68 static const int decoder_reorder_pts = 1; 69 68 70 static int cc608_parity(uint8_t byte); 69 71 static int cc608_good_parity(const int *parity_table, uint16_t data); 70 72 static void cc608_build_parity_table(int *parity_table); … … 2144 2146 2145 2147 pic->age = 256 * 256 * 256 * 64; 2146 2148 2149 pic->reordered_opaque = c->reordered_opaque; 2150 2147 2151 return 1; 2148 2152 } 2149 2153 … … 2290 2294 render->state |= FF_VDPAU_STATE_USED_FOR_REFERENCE; 2291 2295 #endif 2292 2296 2297 pic->reordered_opaque = c->reordered_opaque; 2298 2293 2299 return 0; 2294 2300 } 2295 2301 … … 3860 3866 } 3861 3867 3862 3868 AVCodecContext *context = curstream->codec; 3863 AVFrame mpa_pic; 3864 bzero(&mpa_pic, sizeof(AVFrame)); 3869 AVFrame *mpa_pic= avcodec_alloc_frame(); 3865 3870 3866 3871 int gotpicture = 0; 3867 3872 … … 3874 3879 // HACK 3875 3880 while (!gotpicture && count < 5) 3876 3881 { 3877 ret = d->DecodeMPEG2Video(context, &mpa_pic,3882 ret = d->DecodeMPEG2Video(context, mpa_pic, 3878 3883 &gotpicture, ptr, len); 3879 3884 count++; 3880 3885 } 3881 3886 } 3882 3887 else 3883 3888 { 3884 ret = d->DecodeMPEG2Video(context, &mpa_pic,3889 ret = d->DecodeMPEG2Video(context, mpa_pic, 3885 3890 &gotpicture, ptr, len); 3886 3891 } 3887 3892 } 3888 3893 else 3889 3894 { 3890 ret = avcodec_decode_video(context, &mpa_pic, 3895 curstream->codec->reordered_opaque = pkt->pts; 3896 ret = avcodec_decode_video(context, mpa_pic, 3891 3897 &gotpicture, ptr, len); 3892 3898 // Reparse it to not drop the DVD still frame 3893 3899 if (decodeStillFrame) 3894 ret = avcodec_decode_video(context, &mpa_pic,3900 ret = avcodec_decode_video(context, mpa_pic, 3895 3901 &gotpicture, ptr, len); 3896 3902 } 3897 3903 avcodeclock.unlock(); … … 3912 3918 } 3913 3919 3914 3920 // Decode ATSC captions 3915 for (uint i = 0; i < (uint)mpa_pic .atsc_cc_len;3916 i += ((mpa_pic .atsc_cc_buf[i] & 0x1f) * 3) + 2)3921 for (uint i = 0; i < (uint)mpa_pic->atsc_cc_len; 3922 i += ((mpa_pic->atsc_cc_buf[i] & 0x1f) * 3) + 2) 3917 3923 { 3918 DecodeDTVCC(mpa_pic .atsc_cc_buf + i);3924 DecodeDTVCC(mpa_pic->atsc_cc_buf + i); 3919 3925 } 3920 3926 3921 3927 // Decode DVB captions from MPEG user data 3922 if (mpa_pic .dvb_cc_len > 0)3928 if (mpa_pic->dvb_cc_len > 0) 3923 3929 { 3924 3930 unsigned long long utc = lastccptsu; 3925 3931 3926 for (uint i = 0; i < (uint)mpa_pic .dvb_cc_len; i += 2)3932 for (uint i = 0; i < (uint)mpa_pic->dvb_cc_len; i += 2) 3927 3933 { 3928 uint8_t cc_lo = mpa_pic .dvb_cc_buf[i];3929 uint8_t cc_hi = mpa_pic .dvb_cc_buf[i+1];3934 uint8_t cc_lo = mpa_pic->dvb_cc_buf[i]; 3935 uint8_t cc_hi = mpa_pic->dvb_cc_buf[i+1]; 3930 3936 3931 3937 uint16_t cc_dt = (cc_hi << 8) | cc_lo; 3932 3938 … … 3939 3945 lastccptsu = utc; 3940 3946 } 3941 3947 3942 VideoFrame *picframe = (VideoFrame *)(mpa_pic .opaque);3948 VideoFrame *picframe = (VideoFrame *)(mpa_pic->opaque); 3943 3949 3944 3950 if (!directrendering) 3945 3951 { … … 3958 3964 3959 3965 myth_sws_img_convert( 3960 3966 &tmppicture, PIX_FMT_YUV420P, 3961 (AVPicture *) &mpa_pic,3967 (AVPicture *)mpa_pic, 3962 3968 context->pix_fmt, 3963 3969 context->width, 3964 3970 context->height); … … 3967 3973 { 3968 3974 // Set the frame flags, but then discard it 3969 3975 // since we are not using it for display. 3970 xf->interlaced_frame = mpa_pic .interlaced_frame;3971 xf->top_field_first = mpa_pic .top_field_first;3976 xf->interlaced_frame = mpa_pic->interlaced_frame; 3977 xf->top_field_first = mpa_pic->top_field_first; 3972 3978 xf->frameNumber = framesPlayed; 3973 3979 GetNVP()->DiscardVideoFrame(xf); 3974 3980 } 3975 3981 } 3976 3982 3983 if ((decoder_reorder_pts || pkt->dts == AV_NOPTS_VALUE) && 3984 mpa_pic->reordered_opaque != AV_NOPTS_VALUE) 3985 { 3986 pts = (long long)mpa_pic->reordered_opaque; 3987 } 3988 else if (pkt->dts != AV_NOPTS_VALUE) 3989 { 3990 pts = (long long)pkt->dts; 3991 } 3992 else 3993 { 3994 pts = 0; 3995 } 3996 pts = (long long)(av_q2d(curstream->time_base) * pts * 1000); 3997 3977 3998 long long temppts = pts; 3978 3999 3979 4000 // Validate the video pts against the last pts. If it's … … 3986 4007 temppts = lastvpts; 3987 4008 temppts += (long long)(1000 * av_q2d(context->time_base)); 3988 4009 // MPEG2 frames can be repeated, update pts accordingly 3989 temppts += (long long)(mpa_pic .repeat_pict * 5004010 temppts += (long long)(mpa_pic->repeat_pict * 500 3990 4011 * av_q2d(curstream->codec->time_base)); 3991 4012 } 3992 4013 … … 3996 4017 .arg(lastvpts)); 3997 4018 3998 4019 /* XXX: Broken. 3999 if (mpa_pic .qscale_table != NULL && mpa_pic.qstride > 0 &&4020 if (mpa_pic->qscale_table != NULL && mpa_pic->qstride > 0 && 4000 4021 context->height == picframe->height) 4001 4022 { 4002 int tblsize = mpa_pic .qstride *4023 int tblsize = mpa_pic->qstride * 4003 4024 ((picframe->height + 15) / 16); 4004 4025 4005 if (picframe->qstride != mpa_pic .qstride ||4026 if (picframe->qstride != mpa_pic->qstride || 4006 4027 picframe->qscale_table == NULL) 4007 4028 { 4008 picframe->qstride = mpa_pic .qstride;4029 picframe->qstride = mpa_pic->qstride; 4009 4030 if (picframe->qscale_table) 4010 4031 delete [] picframe->qscale_table; 4011 4032 picframe->qscale_table = new unsigned char[tblsize]; 4012 4033 } 4013 4034 4014 memcpy(picframe->qscale_table, mpa_pic .qscale_table,4035 memcpy(picframe->qscale_table, mpa_pic->qscale_table, 4015 4036 tblsize); 4016 4037 } 4017 4038 */ 4018 4039 4019 picframe->interlaced_frame = mpa_pic .interlaced_frame;4020 picframe->top_field_first = mpa_pic .top_field_first;4021 picframe->repeat_pict = mpa_pic .repeat_pict;4040 picframe->interlaced_frame = mpa_pic->interlaced_frame; 4041 picframe->top_field_first = mpa_pic->top_field_first; 4042 picframe->repeat_pict = mpa_pic->repeat_pict; 4022 4043 4023 4044 picframe->frameNumber = framesPlayed; 4024 4045 GetNVP()->ReleaseNextVideoFrame(picframe, temppts); 4025 if (d->HasMPEG2Dec() && mpa_pic .data[3])4026 context->release_buffer(context, &mpa_pic);4046 if (d->HasMPEG2Dec() && mpa_pic->data[3]) 4047 context->release_buffer(context, mpa_pic); 4027 4048 4028 4049 decoded_video_frame = picframe; 4029 4050 gotvideo = 1; 4030 4051 framesPlayed++; 4031 4052 4032 4053 lastvpts = temppts; 4054 4055 if (mpa_pic) 4056 av_free(mpa_pic); 4057 4033 4058 break; 4034 4059 } 4035 4060 case CODEC_TYPE_SUBTITLE: