@@ -257,7 +257,7 @@ int decodeframe(int frame_num, d2vcontext *ctx, decodecontext *dctx, AVFrame *ou
257
257
gop g;
258
258
unsigned int i;
259
259
int o, j, av_ret, offset;
260
- bool next;
260
+ bool next = true ;
261
261
262
262
/* Get our frame and the GOP its in. */
263
263
f = ctx->frames [frame_num];
@@ -277,26 +277,57 @@ int decodeframe(int frame_num, d2vcontext *ctx, decodecontext *dctx, AVFrame *ou
277
277
* from the previous GOP (one at most is needed), and adjust
278
278
* out offset accordingly.
279
279
*/
280
- if (!(g.info & GOP_FLAG_CLOSED) && (f. gop > 0 ) ) {
281
- int n = frame_num;
282
- frame t = ctx-> frames [n] ;
280
+ if (!(g.info & GOP_FLAG_CLOSED)) {
281
+ if (f. gop == 0 ) {
282
+ int n = 0 ;
283
283
284
- g = ctx->gops [f.gop - 1 ];
284
+ /*
285
+ * Adjust the offset by the number of frames
286
+ * that require of the previous GOP when the
287
+ * first GOP is open.
288
+ */
289
+ while (!(g.flags [n] & GOP_FLAG_PROGRESSIVE))
290
+ n++;
291
+
292
+ /*
293
+ * Only adjust the offset if it's feasible;
294
+ * that is, if it produces a positive offset.
295
+ */
296
+ offset = n > f.offset ? 0 : f.offset - n;
297
+
298
+ /*
299
+ * If the offset is 0, force decoding.
300
+ *
301
+ * FIXME: This method increases the number
302
+ * of frames to be decoded.
303
+ */
304
+ next = offset != 0 ;
305
+ } else {
306
+ int n = frame_num;
307
+ frame t = ctx->frames [n];
308
+
309
+ g = ctx->gops [f.gop - 1 ];
310
+
311
+ /*
312
+ * Find the offset of the last frame in the
313
+ * previous GOP and add it to our offset.
314
+ */
315
+ while (t.offset )
316
+ t = ctx->frames [--n];
285
317
286
- /*
287
- * Find the offset of the last frame in the
288
- * previous GOP and add it to our offset.
289
- */
290
- while (t.offset )
291
318
t = ctx->frames [--n];
292
319
293
- t = ctx->frames [--n];
320
+ /*
321
+ * Subtract number of frames that require the
322
+ * previous GOP.
323
+ */
324
+ n = 0 ;
325
+ if (!(g.info & GOP_FLAG_CLOSED))
326
+ while (!(g.flags [n] & GOP_FLAG_PROGRESSIVE))
327
+ n++;
294
328
295
- /*
296
- * Subtract one from the offset to compensate for
297
- * libavcodec delay, I think.
298
- */
299
- offset += t.offset - 1 ;
329
+ offset += t.offset + 1 - n;
330
+ }
300
331
}
301
332
302
333
/*
@@ -305,7 +336,7 @@ int decodeframe(int frame_num, d2vcontext *ctx, decodecontext *dctx, AVFrame *ou
305
336
* the same, or also linear. If so, we can decode
306
337
* linearly.
307
338
*/
308
- next = (dctx->last_gop == f.gop || dctx->last_gop == f.gop - 1 ) && dctx->last_frame == frame_num - 1 ;
339
+ next = next && (dctx->last_gop == f.gop || dctx->last_gop == f.gop - 1 ) && dctx->last_frame == frame_num - 1 ;
309
340
310
341
/* Skip GOP initialization if we're decoding linearly. */
311
342
if (!next) {
0 commit comments