|
@@ -91,11 +91,11 @@ static int av_decode(struct DecoderContext *pContext, AVPacket *pPacket, enum AV
|
|
(av_q2d(pContext->avformatContext->streams[pContext->st_index[type]]->time_base)));
|
|
(av_q2d(pContext->avformatContext->streams[pContext->st_index[type]]->time_base)));
|
|
|
|
|
|
|
|
|
|
- int64_t offset = 0;
|
|
|
|
- if (pContext->offset != AV_NOPTS_VALUE) {
|
|
|
|
- offset += pContext->offset / 1000;
|
|
|
|
- pts -= offset;
|
|
|
|
- }
|
|
|
|
|
|
+// int64_t offset = 0;
|
|
|
|
+// if (pContext->offset != AV_NOPTS_VALUE) {
|
|
|
|
+// offset += pContext->offset / 1000;
|
|
|
|
+// pts -= offset;
|
|
|
|
+// }
|
|
|
|
|
|
if (pContext->end_time > 0 && pts > pContext->end_time && type == AVMEDIA_TYPE_VIDEO) {
|
|
if (pContext->end_time > 0 && pts > pContext->end_time && type == AVMEDIA_TYPE_VIDEO) {
|
|
av_frame_free(&out_frame);
|
|
av_frame_free(&out_frame);
|
|
@@ -277,14 +277,34 @@ long initDecoder(const char *url, int force_Iframe, DisableMediaType disableMedi
|
|
return ret == 0 ? (long) dctx : ret;
|
|
return ret == 0 ? (long) dctx : ret;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+static int is_realtime(AVFormatContext *s) {
|
|
|
|
+ if (!strcmp(s->iformat->name, "rtp")
|
|
|
|
+ || !strcmp(s->iformat->name, "rtsp")
|
|
|
|
+ || !strcmp(s->iformat->name, "sdp")
|
|
|
|
+ || !strcmp(s->iformat->name, "hls")
|
|
|
|
+ )
|
|
|
|
+ return 1;
|
|
|
|
+
|
|
|
|
+ if (s->pb && (!strncmp(s->url, "rtp:", 4)
|
|
|
|
+ || !strncmp(s->url, "udp:", 4)
|
|
|
|
+ )
|
|
|
|
+ )
|
|
|
|
+ return 1;
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
void seekToMs(DecoderContext *dctx, int64_t offset) {
|
|
void seekToMs(DecoderContext *dctx, int64_t offset) {
|
|
int64_t timestamp = dctx->start_time * 1000;
|
|
int64_t timestamp = dctx->start_time * 1000;
|
|
if (offset != AV_NOPTS_VALUE)
|
|
if (offset != AV_NOPTS_VALUE)
|
|
timestamp += offset;
|
|
timestamp += offset;
|
|
if (timestamp > 0) {
|
|
if (timestamp > 0) {
|
|
avformat_flush(dctx->avformatContext);
|
|
avformat_flush(dctx->avformatContext);
|
|
- int ret = avformat_seek_file(dctx->avformatContext, -1, INT64_MIN, timestamp,
|
|
|
|
- timestamp,
|
|
|
|
|
|
+
|
|
|
|
+ int re = is_realtime(dctx->avformatContext);
|
|
|
|
+ int64_t tartget_pos = re ? MAX(0, timestamp - 10000000) : timestamp;
|
|
|
|
+
|
|
|
|
+ int ret = avformat_seek_file(dctx->avformatContext, -1, INT64_MIN, tartget_pos,
|
|
|
|
+ tartget_pos,
|
|
AVSEEK_FLAG_BACKWARD);
|
|
AVSEEK_FLAG_BACKWARD);
|
|
if (ret >= 0) {
|
|
if (ret >= 0) {
|
|
if (dctx->videoCodecContext)
|
|
if (dctx->videoCodecContext)
|