Skip to content

Commit 6e93137

Browse files
Mike IselyMauro Carvalho Chehab
authored andcommitted
V4L/DVB: pvrusb2: Enforce a 300msec stabilization interval during stream strart
Martin Dauskardt <martin.dauskardt@gmx.de> has determined that the encoder has a much better chance of starting cleanly if we deliberately hold off starting it util the video digitizer has had a chance to run for at least 300msec first. These changes implement an enforced 300msec wait in the state machine that orchestrates streaming start / stop. Signed-off-by: Mike Isely <isely@pobox.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
1 parent 7cae112 commit 6e93137

3 files changed

Lines changed: 49 additions & 5 deletions

File tree

‎drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,9 @@ struct pvr2_hdw {
233233
int state_encoder_waitok; /* Encoder pre-wait done */
234234
int state_encoder_runok; /* Encoder has run for >= .25 sec */
235235
int state_decoder_run; /* Decoder is running */
236+
int state_decoder_ready; /* Decoder is stabilized & streamable */
236237
int state_usbstream_run; /* FX2 is streaming */
237-
int state_decoder_quiescent; /* Decoder idle for > 50msec */
238+
int state_decoder_quiescent; /* Decoder idle for minimal interval */
238239
int state_pipeline_config; /* Pipeline is configured */
239240
int state_pipeline_req; /* Somebody wants to stream */
240241
int state_pipeline_pause; /* Pipeline must be paused */
@@ -255,9 +256,16 @@ struct pvr2_hdw {
255256
void (*state_func)(void *);
256257
void *state_data;
257258

258-
/* Timer for measuring decoder settling time */
259+
/* Timer for measuring required decoder settling time before we're
260+
allowed to fire it up again. */
259261
struct timer_list quiescent_timer;
260262

263+
/* Timer for measuring decoder stabilization time, which is the
264+
amount of time we need to let the decoder run before we can
265+
trust its output (otherwise the encoder might see garbage and
266+
then fail to start correctly). */
267+
struct timer_list decoder_stabilization_timer;
268+
261269
/* Timer for measuring encoder pre-wait time */
262270
struct timer_list encoder_wait_timer;
263271

‎drivers/media/video/pvrusb2/pvrusb2-hdw.c‎

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
before we are allowed to start it running. */
4949
#define TIME_MSEC_DECODER_WAIT 50
5050

51+
/* This defines a minimum interval that the decoder must be allowed to run
52+
before we can safely begin using its streaming output. */
53+
#define TIME_MSEC_DECODER_STABILIZATION_WAIT 300
54+
5155
/* This defines a minimum interval that the encoder must remain quiet
5256
before we are allowed to configure it. I had this originally set to
5357
50msec, but Martin Dauskardt <martin.dauskardt@gmx.de> reports that
@@ -334,6 +338,7 @@ static int pvr2_hdw_get_eeprom_addr(struct pvr2_hdw *hdw);
334338
static void pvr2_hdw_internal_find_stdenum(struct pvr2_hdw *hdw);
335339
static void pvr2_hdw_internal_set_std_avail(struct pvr2_hdw *hdw);
336340
static void pvr2_hdw_quiescent_timeout(unsigned long);
341+
static void pvr2_hdw_decoder_stabilization_timeout(unsigned long);
337342
static void pvr2_hdw_encoder_wait_timeout(unsigned long);
338343
static void pvr2_hdw_encoder_run_timeout(unsigned long);
339344
static int pvr2_issue_simple_cmd(struct pvr2_hdw *,u32);
@@ -2462,6 +2467,11 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
24622467
hdw->quiescent_timer.data = (unsigned long)hdw;
24632468
hdw->quiescent_timer.function = pvr2_hdw_quiescent_timeout;
24642469

2470+
init_timer(&hdw->decoder_stabilization_timer);
2471+
hdw->decoder_stabilization_timer.data = (unsigned long)hdw;
2472+
hdw->decoder_stabilization_timer.function =
2473+
pvr2_hdw_decoder_stabilization_timeout;
2474+
24652475
init_timer(&hdw->encoder_wait_timer);
24662476
hdw->encoder_wait_timer.data = (unsigned long)hdw;
24672477
hdw->encoder_wait_timer.function = pvr2_hdw_encoder_wait_timeout;
@@ -2675,6 +2685,7 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
26752685
fail:
26762686
if (hdw) {
26772687
del_timer_sync(&hdw->quiescent_timer);
2688+
del_timer_sync(&hdw->decoder_stabilization_timer);
26782689
del_timer_sync(&hdw->encoder_run_timer);
26792690
del_timer_sync(&hdw->encoder_wait_timer);
26802691
if (hdw->workqueue) {
@@ -2742,6 +2753,7 @@ void pvr2_hdw_destroy(struct pvr2_hdw *hdw)
27422753
hdw->workqueue = NULL;
27432754
}
27442755
del_timer_sync(&hdw->quiescent_timer);
2756+
del_timer_sync(&hdw->decoder_stabilization_timer);
27452757
del_timer_sync(&hdw->encoder_run_timer);
27462758
del_timer_sync(&hdw->encoder_wait_timer);
27472759
if (hdw->fw_buffer) {
@@ -4453,7 +4465,7 @@ static int state_check_enable_encoder_run(struct pvr2_hdw *hdw)
44534465

44544466
switch (hdw->pathway_state) {
44554467
case PVR2_PATHWAY_ANALOG:
4456-
if (hdw->state_decoder_run) {
4468+
if (hdw->state_decoder_run && hdw->state_decoder_ready) {
44574469
/* In analog mode, if the decoder is running, then
44584470
run the encoder. */
44594471
return !0;
@@ -4520,6 +4532,17 @@ static void pvr2_hdw_quiescent_timeout(unsigned long data)
45204532
}
45214533

45224534

4535+
/* Timeout function for decoder stabilization timer. */
4536+
static void pvr2_hdw_decoder_stabilization_timeout(unsigned long data)
4537+
{
4538+
struct pvr2_hdw *hdw = (struct pvr2_hdw *)data;
4539+
hdw->state_decoder_ready = !0;
4540+
trace_stbit("state_decoder_ready", hdw->state_decoder_ready);
4541+
hdw->state_stale = !0;
4542+
queue_work(hdw->workqueue, &hdw->workpoll);
4543+
}
4544+
4545+
45234546
/* Timeout function for encoder wait timer. */
45244547
static void pvr2_hdw_encoder_wait_timeout(unsigned long data)
45254548
{
@@ -4558,8 +4581,13 @@ static int state_eval_decoder_run(struct pvr2_hdw *hdw)
45584581
}
45594582
hdw->state_decoder_quiescent = 0;
45604583
hdw->state_decoder_run = 0;
4561-
/* paranoia - solve race if timer just completed */
4584+
/* paranoia - solve race if timer(s) just completed */
45624585
del_timer_sync(&hdw->quiescent_timer);
4586+
/* Kill the stabilization timer, in case we're killing the
4587+
encoder before the previous stabilization interval has
4588+
been properly timed. */
4589+
del_timer_sync(&hdw->decoder_stabilization_timer);
4590+
hdw->state_decoder_ready = 0;
45634591
} else {
45644592
if (!hdw->state_decoder_quiescent) {
45654593
if (!timer_pending(&hdw->quiescent_timer)) {
@@ -4597,10 +4625,16 @@ static int state_eval_decoder_run(struct pvr2_hdw *hdw)
45974625
if (hdw->flag_decoder_missed) return 0;
45984626
if (pvr2_decoder_enable(hdw,!0) < 0) return 0;
45994627
hdw->state_decoder_quiescent = 0;
4628+
hdw->state_decoder_ready = 0;
46004629
hdw->state_decoder_run = !0;
4630+
hdw->decoder_stabilization_timer.expires =
4631+
jiffies +
4632+
(HZ * TIME_MSEC_DECODER_STABILIZATION_WAIT / 1000);
4633+
add_timer(&hdw->decoder_stabilization_timer);
46014634
}
46024635
trace_stbit("state_decoder_quiescent",hdw->state_decoder_quiescent);
46034636
trace_stbit("state_decoder_run",hdw->state_decoder_run);
4637+
trace_stbit("state_decoder_ready", hdw->state_decoder_ready);
46044638
return !0;
46054639
}
46064640

@@ -4798,7 +4832,8 @@ static unsigned int pvr2_hdw_report_unlocked(struct pvr2_hdw *hdw,int which,
47984832
buf,acnt,
47994833
"worker:%s%s%s%s%s%s%s",
48004834
(hdw->state_decoder_run ?
4801-
" <decode:run>" :
4835+
(hdw->state_decoder_ready ?
4836+
"<decode:run>" : " <decode:start>") :
48024837
(hdw->state_decoder_quiescent ?
48034838
"" : " <decode:stop>")),
48044839
(hdw->state_decoder_quiescent ?

‎drivers/media/video/pvrusb2/pvrusb2-hdw.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ struct pvr2_hdw_debug_info {
306306
int state_encoder_ok;
307307
int state_encoder_run;
308308
int state_decoder_run;
309+
int state_decoder_ready;
309310
int state_usbstream_run;
310311
int state_decoder_quiescent;
311312
int state_pipeline_config;

0 commit comments

Comments
 (0)