Skip to content

Commit 8765676

Browse files
authored
Merge pull request #43 from mpeg5/dev-DTSfromPTS
update DTS
2 parents 7c80ae2 + bcae922 commit 8765676

File tree

6 files changed

+62
-8
lines changed

6 files changed

+62
-8
lines changed

app/xeve_app.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@
4444
#ifdef _WIN32
4545
#define y4m_struct_stat struct _stati64
4646
#define y4m_fstat _fstati64
47+
48+
#if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
49+
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
50+
#endif
51+
4752
#else
4853
#define y4m_struct_stat struct stat
4954
#define y4m_fstat fstat
@@ -1325,7 +1330,7 @@ int main(int argc, const char **argv)
13251330
}
13261331

13271332
/* store reconstructed image to list */
1328-
ilist_t = imgb_list_put(ilist_rec, imgb_rec, imgb_rec->ts[0]);
1333+
ilist_t = imgb_list_put(ilist_rec, imgb_rec, imgb_rec->ts[XEVE_TS_PTS]);
13291334
if(ilist_t == NULL)
13301335
{
13311336
logerr("cannot put reconstructed image to list\n");

app/xeve_app_util.h

+3
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,9 @@ static void imgb_cpy(XEVE_IMGB * dst, XEVE_IMGB * src)
464464
dst->y[i] = src->y[i];
465465
dst->w[i] = src->w[i];
466466
dst->h[i] = src->h[i];
467+
}
468+
for (i = 0; i < XEVE_TS_NUM; i++)
469+
{
467470
dst->ts[i] = src->ts[i];
468471
}
469472
}

inc/xeve.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ extern "C"
175175
* type and macro for media time
176176
*****************************************************************************/
177177
typedef long long XEVE_MTIME; /* in 100-nanosec unit */
178+
#define XEVE_TS_PTS 0
179+
#define XEVE_TS_DTS 1
180+
#define XEVE_TS_NUM 2
178181

179182
/*****************************************************************************
180183
* profiles
@@ -241,7 +244,7 @@ struct _XEVE_IMGB
241244
void * a[XEVE_IMGB_MAX_PLANE];
242245

243246
/* time-stamps */
244-
XEVE_MTIME ts[4];
247+
XEVE_MTIME ts[XEVE_TS_NUM];
245248

246249
int ndata[4]; /* arbitrary data, if needs */
247250
void * pdata[4]; /* arbitrary adedress if needs */
@@ -292,7 +295,7 @@ typedef struct _XEVE_BITB
292295
/* arbitrary address, if needs */
293296
void * pdata[4];
294297
/* time-stamps */
295-
XEVE_MTIME ts[4];
298+
XEVE_MTIME ts[XEVE_TS_NUM];
296299

297300
} XEVE_BITB;
298301

src_base/xeve_enc.c

+34-5
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,21 @@ int xeve_push_frm(XEVE_CTX * ctx, XEVE_IMGB * img)
683683
xeve_mset(pico->sinfo.transfer_cost, 0, sizeof(u16) * ctx->fcst.f_blk);
684684
xeve_picbuf_expand(spic, spic->pad_l, spic->pad_c, ctx->sps.chroma_format_idc);
685685
}
686+
687+
if (ctx->ts.frame_delay > 0)
688+
{
689+
if (ctx->pic_icnt == 0)
690+
{
691+
ctx->ts.frame_first_pts = pic->imgb->ts[XEVE_TS_PTS];
692+
}
693+
else if (ctx->pic_icnt == ctx->ts.frame_delay)
694+
{
695+
ctx->ts.frame_dealy_time = ctx->ts.frame_first_pts - pic->imgb->ts[XEVE_TS_PTS];
696+
}
697+
}
698+
699+
ctx->ts.frame_ts[ctx->pic_icnt % XEVE_MAX_INBUF_CNT] = pic->imgb->ts[XEVE_TS_PTS];
700+
686701
return XEVE_OK;
687702
}
688703

@@ -1265,15 +1280,27 @@ int xeve_pic_finish(XEVE_CTX *ctx, XEVE_BITB *bitb, XEVE_STAT *stat)
12651280
}
12661281
}
12671282

1283+
imgb_c->ts[XEVE_TS_PTS] = bitb->ts[XEVE_TS_PTS] = imgb_o->ts[XEVE_TS_PTS];
1284+
if (ctx->ts.frame_delay > 0)
1285+
{
1286+
if (ctx->pic_cnt < ctx->ts.frame_delay)
1287+
{
1288+
imgb_c->ts[XEVE_TS_DTS] = bitb->ts[XEVE_TS_DTS] = ctx->ts.frame_ts[ctx->pic_cnt % XEVE_MAX_INBUF_CNT] + ctx->ts.frame_dealy_time;
1289+
}
1290+
else
1291+
{
1292+
imgb_c->ts[XEVE_TS_DTS] = bitb->ts[XEVE_TS_DTS] = ctx->ts.frame_ts[(ctx->pic_cnt - ctx->ts.frame_delay) % XEVE_MAX_INBUF_CNT];
1293+
}
1294+
}
1295+
else
1296+
{
1297+
imgb_c->ts[XEVE_TS_DTS] = bitb->ts[XEVE_TS_DTS] = ctx->ts.frame_ts[ctx->pic_cnt % XEVE_MAX_INBUF_CNT];
1298+
}
1299+
12681300
ctx->pic_cnt++; /* increase picture count */
12691301
ctx->param.f_ifrm = 0; /* clear force-IDR flag */
12701302
ctx->pico->is_used = 0;
12711303

1272-
imgb_c->ts[0] = bitb->ts[0] = imgb_o->ts[0];
1273-
imgb_c->ts[1] = bitb->ts[1] = imgb_o->ts[1];
1274-
imgb_c->ts[2] = bitb->ts[2] = imgb_o->ts[2];
1275-
imgb_c->ts[3] = bitb->ts[3] = imgb_o->ts[3];
1276-
12771304
if (ctx->param.rc_type != 0)
12781305
{
12791306
ctx->rcore->real_bits = (stat->write - stat->sei_size) << 3;
@@ -1757,6 +1784,8 @@ int xeve_ready(XEVE_CTX* ctx)
17571784
xeve_mset(ctx->sh_array, 0, sizeof(XEVE_SH) * ctx->ts_info.num_slice_in_pic);
17581785
ctx->sh = &ctx->sh_array[0];
17591786

1787+
ctx->ts.frame_delay = ctx->param.bframes > 0 ? 8 : 0;
1788+
17601789
return XEVE_OK;
17611790
ERR:
17621791
for (i = 0; i < (int)ctx->f_lcu; i++)

src_base/xeve_type.h

+11
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,15 @@ typedef struct _XEVE_TS_INFO
556556
int num_remaining_tiles_in_slice_minus1[XEVE_MAX_NUM_TILES >> 1];
557557
} XEVE_TS_INFO;
558558

559+
/* time stamp */
560+
typedef struct _XEVE_TIME_STAMP
561+
{
562+
int frame_delay;
563+
XEVE_MTIME frame_first_pts;
564+
XEVE_MTIME frame_dealy_time;
565+
XEVE_MTIME frame_ts[XEVE_MAX_INBUF_CNT];
566+
}XEVE_TIME_STAMP;
567+
559568
typedef struct _XEVE_CU_DATA
560569
{
561570
s8 split_mode[NUM_CU_DEPTH][NUM_BLOCK_SHAPE][MAX_CU_CNT_IN_LCU];
@@ -783,6 +792,8 @@ struct _XEVE_CTX
783792
XEVE_SH * sh_array;
784793
/* reference picture manager */
785794
XEVE_PM rpm;
795+
/* time stamp */
796+
XEVE_TIME_STAMP ts;
786797
/* quantization value of current encoding slice */
787798
u8 qp;
788799
/* encoding picture width */

src_base/xeve_util.c

+3
Original file line numberDiff line numberDiff line change
@@ -1856,6 +1856,9 @@ void xeve_imgb_cpy(XEVE_IMGB * dst, XEVE_IMGB * src)
18561856
dst->y[i] = src->y[i];
18571857
dst->w[i] = src->w[i];
18581858
dst->h[i] = src->h[i];
1859+
}
1860+
for (i = 0; i < XEVE_TS_NUM; i++)
1861+
{
18591862
dst->ts[i] = src->ts[i];
18601863
}
18611864
}

0 commit comments

Comments
 (0)