Skip to content

Commit 326d49c

Browse files
maki-rxrzdwbuiten
authored andcommitted
Fix handling of case here the first GOP is open
Signed-off-by: Derek Buitenhuis <[email protected]>
1 parent 0a785b9 commit 326d49c

File tree

2 files changed

+48
-20
lines changed

2 files changed

+48
-20
lines changed

README

-3
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ Parameters:
5252
Known Limitations & Bugs
5353
------------------------
5454

55-
* Has decode / frame-accuracy issues on files that start with leading B frames.
56-
These are very easy to detect given the flags in the D2V file, but I am
57-
unsure how to handle this using libavcodec, or if it is even possible.
5855
* Only works with D2V files created by DGIndex (version flag 16).
5956
* Not all the IDCT algorithms in DGDecode are in libavcodec, so I've tried to
6057
map them as best I could. See idct_algo_conv in d2v.hpp for more info.

core/decode.cpp

+48-17
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ int decodeframe(int frame_num, d2vcontext *ctx, decodecontext *dctx, AVFrame *ou
257257
gop g;
258258
unsigned int i;
259259
int o, j, av_ret, offset;
260-
bool next;
260+
bool next = true;
261261

262262
/* Get our frame and the GOP its in. */
263263
f = ctx->frames[frame_num];
@@ -277,26 +277,57 @@ int decodeframe(int frame_num, d2vcontext *ctx, decodecontext *dctx, AVFrame *ou
277277
* from the previous GOP (one at most is needed), and adjust
278278
* out offset accordingly.
279279
*/
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;
283283

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];
285317

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)
291318
t = ctx->frames[--n];
292319

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++;
294328

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+
}
300331
}
301332

302333
/*
@@ -305,7 +336,7 @@ int decodeframe(int frame_num, d2vcontext *ctx, decodecontext *dctx, AVFrame *ou
305336
* the same, or also linear. If so, we can decode
306337
* linearly.
307338
*/
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;
309340

310341
/* Skip GOP initialization if we're decoding linearly. */
311342
if (!next) {

0 commit comments

Comments
 (0)