|
@@ -89,11 +89,19 @@ static int av_decode(struct DecoderContext *pContext, AVPacket *pPacket, enum AV
|
|
|
else
|
|
|
pts = out_frame->pts * (1000 *
|
|
|
(av_q2d(pContext->avformatContext->streams[pContext->st_index[type]]->time_base)));
|
|
|
- if (pContext->end_time > 0 && pts > pContext->end_time && type == AVMEDIA_TYPE_VIDEO){
|
|
|
+
|
|
|
+
|
|
|
+ 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) {
|
|
|
av_frame_free(&out_frame);
|
|
|
return -4;
|
|
|
}
|
|
|
- if (pContext->end_time > 0 && pts > pContext->end_time && type == AVMEDIA_TYPE_AUDIO){
|
|
|
+ if (pContext->end_time > 0 && pts > pContext->end_time && type == AVMEDIA_TYPE_AUDIO) {
|
|
|
av_frame_free(&out_frame);
|
|
|
return 0;
|
|
|
}
|
|
@@ -265,18 +273,18 @@ long initDecoder(const char *url, int force_Iframe, DisableMediaType disableMedi
|
|
|
dctx->video_queue = new BlockQueue<AVFrame *>(dctx->fps);
|
|
|
}
|
|
|
|
|
|
- seekToMs(dctx);
|
|
|
+ seekToMs(dctx, dctx->offset);
|
|
|
return ret == 0 ? (long) dctx : ret;
|
|
|
}
|
|
|
|
|
|
-void seekToMs(DecoderContext *dctx) {
|
|
|
+void seekToMs(DecoderContext *dctx, int64_t offset) {
|
|
|
int64_t timestamp = dctx->start_time * 1000;
|
|
|
- if (dctx->offset != AV_NOPTS_VALUE)
|
|
|
- timestamp += dctx->offset;
|
|
|
+ if (offset != AV_NOPTS_VALUE)
|
|
|
+ timestamp += offset;
|
|
|
if (timestamp > 0) {
|
|
|
avformat_flush(dctx->avformatContext);
|
|
|
int ret = avformat_seek_file(dctx->avformatContext, -1, INT64_MIN, timestamp,
|
|
|
- INT64_MAX,
|
|
|
+ timestamp,
|
|
|
AVSEEK_FLAG_BACKWARD);
|
|
|
if (ret >= 0) {
|
|
|
if (dctx->videoCodecContext)
|
|
@@ -358,7 +366,7 @@ void *av_read_decode_thread(void *pVoid) {
|
|
|
ctx->decode_frame_ms = 0;
|
|
|
if (cur_item->startTimeMs > 0) {
|
|
|
ctx->start_time = cur_item->startTimeMs;
|
|
|
- seekToMs(ctx);
|
|
|
+ seekToMs(ctx, ctx->offset);
|
|
|
}
|
|
|
if (cur_item->endTimeMs > 0)
|
|
|
ctx->end_time = cur_item->endTimeMs;
|