4343#include <string.h> // for strcmp, strlen
4444
4545#include "compat/usleep.h" // for usleep
46+ #include "debug.h" // for MSG
4647#include "lib_common.h" // for REGISTER_MODULE, library_class
4748#include "tv.h" // for time_ns_t
4849#include "types.h" // for tile, video_desc, video_frame
5758
5859#define MAGIC to_fourcc('v', 'p', 't', '3')
5960#define MOD_NAME "[temporal_3d] "
61+ #define TIMEOUT "20ms"
6062
6163struct state_temporal_3d {
6264 uint32_t magic ;
6365 struct video_frame * in ;
6466 time_ns_t first_tile_time ;
67+ bool disable_timing ; ///< issue the second eye right after the first
6568};
6669
70+ static void temporal_3d_done (void * state );
71+
6772static bool
6873temporal_3d_get_property (void * state , int property , void * val , size_t * len )
6974{
@@ -78,23 +83,45 @@ temporal_3d_get_property(void *state, int property, void *val, size_t *len)
7883 return false;
7984}
8085
86+ static void
87+ usage ()
88+ {
89+ color_printf (
90+ TBOLD ("temporal_3d" ) " postprocessor interleaves left and "
91+ "right eye temporarily into a single stream "
92+ "with double FPS.\n\n" );
93+ color_printf (
94+ "Usage:\n\t" TBOLD (TRED ("-p temporal_3d" ) "[:nodelay]" ) "\n\n" );
95+ printf ("Parameters:\n" );
96+ printf (
97+ "\tnodelay - disable timing, pass right eye right after first\n" );
98+ printf ("\t (may help performance)\n" );
99+ }
100+
81101static void *
82102temporal_3d_init (const char * config )
83103{
84104 if (strcmp (config , "help" ) == 0 ) {
85- color_printf (TBOLD (
86- "temporal_3d" ) " postprocessor interleaves left and "
87- "right eye temporarily into a single stream "
88- "with double FPS.\n\n" );
89- color_printf ("Usage:\n\t" TBOLD (TRED ("-p temporal_3d" )) "\n\n" );
90- }
91- if (strlen (config ) > 0 ) {
92- printf ("3d-interlaced takes no parameters.\n" );
105+ usage ();
93106 return NULL ;
94107 }
95-
96108 struct state_temporal_3d * s = calloc (1 , sizeof * s );
97109 s -> magic = MAGIC ;
110+ if (strcmp (config , "nodelay" ) == 0 ) {
111+ s -> disable_timing = true;
112+ if (get_commandline_param ("decoder-drop-policy" ) == NULL ) {
113+ MSG (NOTICE ,
114+ "nodelay option used, setting drop policy to %s "
115+ "timeout.\n" ,
116+ TIMEOUT );
117+ set_commandline_param ("decoder-drop-policy" , TIMEOUT );
118+ }
119+ } else {
120+ MSG (ERROR , "Unknown option: %s!\n" , config );
121+ temporal_3d_done (s );
122+ return NULL ;
123+ }
124+
98125 return s ;
99126}
100127
@@ -146,12 +173,12 @@ temporal_3d_postprocess(void *state, struct video_frame *in,
146173 }
147174
148175 // delay the other tile for correct timing
149- if (in == NULL ) {
176+ if (! s -> disable_timing && in == NULL ) {
150177 time_ns_t t1 = get_time_in_ns ();
151178 long long since_first_tile_us =
152179 NS_TO_US (t1 - s -> first_tile_time );
153180 long long sleep_us =
154- US_IN_SEC / s -> in -> fps - since_first_tile_us ;
181+ ( US_IN_SEC / s -> in -> fps ) - ( double ) since_first_tile_us ;
155182 if (sleep_us > 0 ) {
156183 usleep (sleep_us );
157184 }
0 commit comments