Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 375d67e

Browse files
peak3dRadostan Riedel
authored andcommitted
[AML] v4l2_qbuf / vsync / freerun_mode_3 / DI pts_us64 fix
1 parent 1cc2d39 commit 375d67e

File tree

4 files changed

+70
-14
lines changed

4 files changed

+70
-14
lines changed

drivers/amlogic/amports/ptsserv.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ int calculation_stream_delayed_ms(u8 type, u32 *latestbitrate,
231231
outtime = timestamp_pcrscr_get();
232232
if (outtime == 0 || outtime == 0xffffffff)
233233
outtime = pTable->last_checkout_pts;
234-
timestampe_delayed = (pTable->last_checkin_pts - outtime) / 90;
234+
if (pTable->last_checkin_pts > outtime)
235+
timestampe_delayed = (pTable->last_checkin_pts - outtime) / 90;
236+
235237
pTable->last_pts_delay_ms = timestampe_delayed;
236238
if ((timestampe_delayed < 10
237239
|| abs(pTable->last_pts_delay_ms - timestampe_delayed) > 3000)
@@ -253,6 +255,7 @@ int calculation_stream_delayed_ms(u8 type, u32 *latestbitrate,
253255
} else
254256
/* #endif */
255257
diff2 = stbuf_level(get_buf_by_type(type));
258+
256259
/* #if MESON_CPU_TYPE >= MESON_CPU_TYPE_MESON8 */
257260
if (has_hevc_vdec()) {
258261
if (pTable->hevc) {
@@ -270,7 +273,7 @@ int calculation_stream_delayed_ms(u8 type, u32 *latestbitrate,
270273
if (diff2 > stbuf_space(get_buf_by_type(type)))
271274
diff = diff2;
272275
}
273-
delay_ms = diff * 1000 / (1 + pTable->last_avg_bitrate / 8);
276+
delay_ms = (diff * 1000) / (int)(1 + pTable->last_avg_bitrate / 8);
274277

275278
if (timestampe_delayed < 10
276279
|| (abs(timestampe_delayed - delay_ms) > 3 * 1000
@@ -888,6 +891,7 @@ static int pts_lookup_offset_inline_locked(u8 type, u32 offset, u32 *val,
888891
* use first checkin pts instead */
889892
if (!pTable->first_lookup_ok) {
890893
*val = pTable->first_checkin_pts;
894+
*uS64 = div64_u64((u64)pTable->first_checkin_pts * 100, 9);
891895
pTable->first_lookup_ok = 1;
892896
pTable->first_lookup_is_fail = 1;
893897

drivers/amlogic/amports/video.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3637,6 +3637,8 @@ static irqreturn_t vsync_isr(int irq, void *dev_id)
36373637
}
36383638
if (omx_secret_mode == true) {
36393639
u32 system_time = timestamp_pcrscr_get();
3640+
video_notify_flag |= VIDEO_NOTIFY_TRICK_WAIT;
3641+
atomic_set(&trickmode_framedone, 1);
36403642
int diff = system_time - omx_pts;
36413643
if ((diff - omx_pts_interval_upper) > 0
36423644
|| (diff - omx_pts_interval_lower) < 0) {

drivers/amlogic/deinterlace/deinterlace.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,6 +1912,7 @@ struct di_post_stru_s {
19121912
bool toggle_flag;
19131913
bool vscale_skip_flag;
19141914
uint start_pts;
1915+
u64 start_pts_us64;
19151916
int buf_type;
19161917
int de_post_process_done;
19171918
int post_de_busy;
@@ -6247,6 +6248,7 @@ static void vscale_skip_disable_post(struct di_buf_s *di_buf, vframe_t *disp_vf)
62476248
disp_vf->height = di_buf_i->vframe->height;
62486249
disp_vf->duration = di_buf_i->vframe->duration;
62496250
disp_vf->pts = di_buf_i->vframe->pts;
6251+
disp_vf->pts_us64 = di_buf_i->vframe->pts_us64;
62506252
disp_vf->flag = di_buf_i->vframe->flag;
62516253
disp_vf->canvas0Addr = di_post_idx[di_post_stru.canvas_id][0];
62526254
disp_vf->canvas1Addr = di_post_idx[di_post_stru.canvas_id][0];
@@ -7343,6 +7345,7 @@ void drop_frame(int check_drop, int throw_flag, struct di_buf_s *di_buf)
73437345
di_lock_irqfiq_save(irq_flag2, fiq_flag);
73447346
if ((frame_count == 0) && check_drop)
73457347
di_post_stru.start_pts = di_buf->vframe->pts;
7348+
di_post_stru.start_pts_us64 = di_buf->vframe->pts_us64;
73467349
if ((check_drop && (frame_count < start_frame_drop_count))
73477350
|| throw_flag) {
73487351
drop_flag = 1;
@@ -7351,6 +7354,7 @@ void drop_frame(int check_drop, int throw_flag, struct di_buf_s *di_buf)
73517354
if ((di_post_stru.start_pts)
73527355
&& (di_buf->vframe->pts == 0))
73537356
di_buf->vframe->pts = di_post_stru.start_pts;
7357+
di_buf->vframe->pts_us64 = di_post_stru.start_pts_us64;
73547358
di_post_stru.start_pts = 0;
73557359
}
73567360
for (i = 0; i < 3; i++) {

drivers/amlogic/video_dev/amlvideo.c

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@ AMLVIDEO_MINOR_VERSION, AMLVIDEO_RELEASE)
6767

6868
#define AMLVIDEO_POOL_SIZE 16
6969
static struct vfq_s q_ready;
70+
static struct vfq_s q_omx;
7071
/*extern bool omx_secret_mode;*/
7172
static u8 first_frame;
7273
static u64 last_pts_us64;
74+
static u32 omx_freerun_index = 0;
7375

7476
#define DUR2PTS(x) ((x) - ((x) >> 4))
7577
#define DUR2PTS_RM(x) ((x) & 0xf)
@@ -149,9 +151,11 @@ static struct vivi_fmt formats[] = {
149151
};
150152

151153
struct vframe_s *amlvideo_pool_ready[AMLVIDEO_POOL_SIZE + 1];
154+
struct vframe_s *amlvideo_pool_omx[AMLVIDEO_POOL_SIZE + 1];
152155
/* ------------------------------------------------------------------
153156
* provider operations
154157
*-----------------------------------------------------------------*/
158+
155159
static struct vframe_s *amlvideo_vf_peek(void *op_arg)
156160
{
157161
return vfq_peek(&q_ready);
@@ -187,10 +191,11 @@ static int amlvideo_vf_states(struct vframe_states *states, void *op_arg)
187191
{
188192
/* unsigned long flags; */
189193
/* spin_lock_irqsave(&lock, flags); */
194+
int avail_count = vfq_level(&q_ready) + vfq_level(&q_omx);
190195
states->vf_pool_size = AMLVIDEO_POOL_SIZE;
191196
states->buf_recycle_num = 0;
192-
states->buf_free_num = AMLVIDEO_POOL_SIZE - vfq_level(&q_ready);
193-
states->buf_avail_num = vfq_level(&q_ready);
197+
states->buf_free_num = AMLVIDEO_POOL_SIZE - avail_count;
198+
states->buf_avail_num = avail_count;
194199
/* spin_unlock_irqrestore(&lock, flags); */
195200
return 0;
196201
}
@@ -329,6 +334,8 @@ static int video_receiver_event_fun(int type, void *data, void *private_data)
329334
omx_secret_mode = true;
330335
vfq_init(&q_ready, AMLVIDEO_POOL_SIZE + 1,
331336
&amlvideo_pool_ready[0]);
337+
vfq_init(&q_omx, AMLVIDEO_POOL_SIZE + 1,
338+
&amlvideo_pool_omx[0]);
332339
vf_provider_init(&amlvideo_vf_prov, PROVIDER_NAME,
333340
&amlvideo_vf_provider, NULL);
334341
vf_reg_provider(&amlvideo_vf_prov);
@@ -577,8 +584,34 @@ static int vidioc_querybuf(struct file *file, void *priv, struct v4l2_buffer *p)
577584
static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
578585
{
579586
int ret = 0;
587+
u32 index;
580588
if (omx_secret_mode == true)
589+
{
590+
if (freerun_mode == 3)
591+
{
592+
struct vframe_s *vf;
593+
while ((vf = vfq_peek(&q_omx)))
594+
{
595+
index = (u32)vf->pts_us64;
596+
if (p->index > index)
597+
{
598+
vf_put(vfq_pop(&q_omx), RECEIVER_NAME);
599+
printk("vidioc_qbuf skip: index:%u:%u\n", p->index, index);
600+
continue;
601+
}
602+
else if (p->index == index)
603+
{
604+
vf = (vfq_pop(&q_omx));
605+
if (p->flags & V4L2_BUF_FLAG_DONE)
606+
vf_put(vf, RECEIVER_NAME);
607+
else
608+
vfq_push(&q_ready, vf);
609+
}
610+
break;
611+
}
612+
}
581613
return ret;
614+
}
582615

583616
if (ppmgrvf) {
584617
vf_put(ppmgrvf, RECEIVER_NAME);
@@ -653,8 +686,11 @@ static int freerun_dqbuf(struct v4l2_buffer *p)
653686
return -EAGAIN;
654687
}
655688
if (omx_secret_mode == true) {
656-
vfq_push(&q_ready, ppmgrvf);
657-
p->index = 0;
689+
690+
//printk("%s, %s, %d %x %llx\n", __FILE__, __FUNCTION__, __LINE__, ppmgrvf->pts, ppmgrvf->pts_us64);
691+
692+
if (!ppmgrvf->pts_us64)
693+
ppmgrvf->pts_us64 = ((u64)ppmgrvf->pts * 100) / 9;
658694

659695
if (ppmgrvf->pts_us64) {
660696
first_frame = 1;
@@ -672,11 +708,21 @@ static int freerun_dqbuf(struct v4l2_buffer *p)
672708
p->timecode.type = ppmgrvf->width;
673709
p->timecode.flags = ppmgrvf->height;
674710

675-
vf_notify_receiver(
676-
PROVIDER_NAME,
677-
VFRAME_EVENT_PROVIDER_VFRAME_READY,
678-
NULL);
679-
711+
if (freerun_mode != 3)
712+
{
713+
p->index = 0;
714+
vfq_push(&q_ready, ppmgrvf);
715+
vf_notify_receiver(
716+
PROVIDER_NAME,
717+
VFRAME_EVENT_PROVIDER_VFRAME_READY,
718+
NULL);
719+
}
720+
else
721+
{
722+
p->index = omx_freerun_index;
723+
ppmgrvf->pts_us64 = omx_freerun_index++;
724+
vfq_push(&q_omx, ppmgrvf);
725+
}
680726
return ret;
681727
}
682728
if (ppmgrvf->pts != 0) {
@@ -686,8 +732,8 @@ static int freerun_dqbuf(struct v4l2_buffer *p)
686732
ppmgrvf->pts = timestamp_vpts_get();
687733
}
688734

689-
if (!ppmgrvf->pts)
690-
ppmgrvf->pts_us64 = ppmgrvf->pts * 100 / 9;
735+
if (!ppmgrvf->pts_us64)
736+
ppmgrvf->pts_us64 = ((u64)ppmgrvf->pts * 100) / 9;
691737

692738
if (unregFlag || startFlag) {
693739
if (ppmgrvf->pts == 0)
@@ -804,7 +850,7 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
804850
{
805851
int ret = 0;
806852

807-
if (freerun_mode == 1) {
853+
if (freerun_mode == 1 || freerun_mode == 3) {
808854
/* pr_err("amlvideo dqbuf called freerun_mode=1\n"); */
809855
ret = freerun_dqbuf(p);
810856
} else if (freerun_mode == 2) {

0 commit comments

Comments
 (0)