- proper pts for packets. leaving it blank leaves it up for guessing, but the guess doesn't take seeking into account, causing weirdness. - clamp to 0 when seeking to negative ts. libopenmpt docs are unclear on this but not doing this causes an immediate EOF when seeking backwards to the beginning in mpv. - only set song duration and packet pts when they are non-negative and in int64 range. NaNs count as out of range. this isn't a fix for any specific issue but might be helpful still, and shouldn't break anything.
Unified · Split
| @@ -148,7 +148,8 @@ static int read_header_openmpt(AVFormatContext *s) · 147 unmodified lines | ||
| 148 | 148 | if (!st) |
| 149 | 149 | return AVERROR(ENOMEM); |
| 150 | 150 | avpriv_set_pts_info(st, 64, 1, AV_TIME_BASE); |
| 151 | − st->duration = llrint(openmpt->duration*AV_TIME_BASE); | |
| 151 | + if (openmpt->duration >= 0 && openmpt->duration < ((double)INT64_MAX + 1) / AV_TIME_BASE) | |
| 152 | + st->duration = llrint(openmpt->duration*AV_TIME_BASE); | |
| 152 | 153 | |
| 153 | 154 | st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; |
| 154 | 155 | st->codecpar->codec_id = AV_NE(AV_CODEC_ID_PCM_F32BE, AV_CODEC_ID_PCM_F32LE); |
| @@ -171,6 +172,8 @@ static int read_packet_openmpt(AVFormatContext *s, AVPacket *pkt) · 16 unmodified lines | ||
| 171 | 172 | if ((ret = av_new_packet(pkt, AUDIO_PKT_SIZE)) < 0) |
| 172 | 173 | return ret; |
| 173 | 174 | |
| 175 | + double pos = openmpt_module_get_position_seconds(openmpt->module); | |
| 176 | + | |
| 174 | 177 | switch (openmpt->ch_layout.nb_channels) { |
| 175 | 178 | case 1: |
| 176 | 179 | ret = openmpt_module_read_float_mono(openmpt->module, openmpt->sample_rate, |
| @@ -196,6 +199,9 @@ static int read_packet_openmpt(AVFormatContext *s, AVPacket *pkt) · 19 unmodified lines | ||
| 196 | 199 | |
| 197 | 200 | pkt->size = ret * (openmpt->ch_layout.nb_channels * 4); |
| 198 | 201 | |
| 202 | + if (pos >= 0 && pos < ((double)INT64_MAX + 1) / AV_TIME_BASE) | |
| 203 | + pkt->pts = llrint(pos * AV_TIME_BASE); | |
| 204 | + | |
| 199 | 205 | return 0; |
| 200 | 206 | } |
| 201 | 207 | |
| @@ -212,6 +218,8 @@ static int read_close_openmpt(AVFormatContext *s) · 10 unmodified lines | ||
| 212 | 218 | static int read_seek_openmpt(AVFormatContext *s, int stream_idx, int64_t ts, int flags) |
| 213 | 219 | { |
| 214 | 220 | OpenMPTContext *openmpt = s->priv_data; |
| 221 | + if (ts < 0) | |
| 222 | + ts = 0; | |
| 215 | 223 | openmpt_module_set_position_seconds(openmpt->module, (double)ts/AV_TIME_BASE); |
| 216 | 224 | return 0; |
| 217 | 225 | } |