x264_t *h;
x264_param_t param;
- int i_buffer;
- uint8_t *p_buffer;
-
mtime_t i_interpolated_dts;
char *psz_stat_name;
};
+#ifdef PTW32_STATIC_LIB
+static vlc_mutex_t pthread_win32_mutex = VLC_STATIC_MUTEX;
+static int pthread_win32_count = 0;
+#endif
+
/*****************************************************************************
* Open: probe the encoder
*****************************************************************************/
return VLC_ENOMEM;
p_sys->i_interpolated_dts = 0;
p_sys->psz_stat_name = NULL;
- p_sys->p_buffer = NULL;
x264_param_default( &p_sys->param );
p_sys->param.i_width = p_enc->fmt_in.video.i_width;
p_sys->param.analyse.b_transform_8x8 = var_GetBool( p_enc,
SOUT_CFG_PREFIX "8x8dct" );
- if( p_enc->fmt_in.video.i_aspect > 0 )
+ if( p_enc->fmt_in.video.i_sar_num > 0 &&
+ p_enc->fmt_in.video.i_sar_den > 0 )
{
- int64_t i_num, i_den;
unsigned int i_dst_num, i_dst_den;
-
- i_num = p_enc->fmt_in.video.i_aspect *
- (int64_t)p_enc->fmt_in.video.i_height;
- i_den = VOUT_ASPECT_FACTOR * p_enc->fmt_in.video.i_width;
- vlc_ureduce( &i_dst_num, &i_dst_den, i_num, i_den, 0 );
-
+ vlc_ureduce( &i_dst_num, &i_dst_den,
+ p_enc->fmt_in.video.i_sar_num,
+ p_enc->fmt_in.video.i_sar_den, 0 );
p_sys->param.vui.i_sar_width = i_dst_num;
p_sys->param.vui.i_sar_height = i_dst_den;
}
but only once for the whole application. Since pthreadw32
doesn't keep a refcount, do it ourselves. */
#ifdef PTW32_STATIC_LIB
- vlc_value_t lock, count;
-
- var_Create( p_enc->p_libvlc, "pthread_win32_mutex", VLC_VAR_MUTEX );
- var_Get( p_enc->p_libvlc, "pthread_win32_mutex", &lock );
- vlc_mutex_lock( lock.p_address );
+ vlc_mutex_lock( &pthread_win32_mutex );
- var_Create( p_enc->p_libvlc, "pthread_win32_count", VLC_VAR_INTEGER );
- var_Get( p_enc->p_libvlc, "pthread_win32_count", &count );
-
- if( count.i_int == 0 )
+ if( pthread_win32_count == 0 )
{
msg_Dbg( p_enc, "initializing pthread-win32" );
if( !pthread_win32_process_attach_np() || !pthread_win32_thread_attach_np() )
{
msg_Warn( p_enc, "pthread Win32 Initialization failed" );
- vlc_mutex_unlock( lock.p_address );
+ vlc_mutex_unlock( &pthread_win32_mutex );
return VLC_EGENERIC;
}
}
- count.i_int++;
- var_Set( p_enc->p_libvlc, "pthread_win32_count", count );
- vlc_mutex_unlock( lock.p_address );
-
+ pthread_win32_count++;
+ vlc_mutex_unlock( &pthread_win32_mutex );
#endif
/* Set lookahead value to lower than default,
return VLC_EGENERIC;
}
- /* alloc mem */
- p_sys->i_buffer = 4 * p_enc->fmt_in.video.i_width *
- p_enc->fmt_in.video.i_height + 1000;
- p_sys->p_buffer = malloc( p_sys->i_buffer );
- if( !p_sys->p_buffer )
- {
- Close( VLC_OBJECT(p_enc) );
- return VLC_ENOMEM;
- }
-
/* get the globals headers */
p_enc->fmt_out.i_extra = 0;
p_enc->fmt_out.p_extra = NULL;
Close( VLC_OBJECT(p_enc) );
return VLC_ENOMEM;
}
- void *p_tmp = p_enc->fmt_out.p_extra;
+ uint8_t *p_tmp = p_enc->fmt_out.p_extra;
for( i = 0; i < i_nal; i++ )
{
memcpy( p_tmp, nal[i].p_payload, nal[i].i_payload );
if( !i_nal ) return NULL;
+
+ /* Get size of block we need */
for( i = 0, i_out = 0; i < i_nal; i++ )
- {
- memcpy( p_sys->p_buffer + i_out, nal[i].p_payload, nal[i].i_payload );
i_out += nal[i].i_payload;
- }
p_block = block_New( p_enc, i_out );
if( !p_block ) return NULL;
- memcpy( p_block->p_buffer, p_sys->p_buffer, i_out );
+
+ /* copy encoded data directly to block */
+ for( i = 0, i_out = 0; i < i_nal; i++ )
+ {
+ memcpy( p_block->p_buffer + i_out, nal[i].p_payload, nal[i].i_payload );
+ i_out += nal[i].i_payload;
+ }
if( pic.i_type == X264_TYPE_IDR || pic.i_type == X264_TYPE_I )
p_block->i_flags |= BLOCK_FLAG_TYPE_I;
}
else
{
+#if 1 /* XXX: remove me when 0 is a valid timestamp (see #3135) */
if( p_sys->i_interpolated_dts )
{
p_block->i_dts = p_sys->i_interpolated_dts;
/* Let's put something sensible */
p_block->i_dts = p_block->i_pts;
}
-
+#else
+ p_block->i_dts = p_sys->i_interpolated_dts;
+#endif
p_sys->i_interpolated_dts += p_block->i_length;
}
}
x264_encoder_close( p_sys->h );
#ifdef PTW32_STATIC_LIB
- vlc_value_t lock, count;
+ vlc_mutex_lock( &pthread_win32_mutex );
+ pthread_win32_count--;
- var_Get( p_enc->p_libvlc, "pthread_win32_mutex", &lock );
- vlc_mutex_lock( lock.p_address );
-
- var_Get( p_enc->p_libvlc, "pthread_win32_count", &count );
- count.i_int--;
- var_Set( p_enc->p_libvlc, "pthread_win32_count", count );
-
- if( count.i_int == 0 )
+ if( pthread_win32_count == 0 )
{
pthread_win32_thread_detach_np();
pthread_win32_process_detach_np();
msg_Dbg( p_enc, "pthread-win32 deinitialized" );
}
- vlc_mutex_unlock( lock.p_address );
+
+ vlc_mutex_unlock( &pthread_win32_mutex );
#endif
- free( p_sys->p_buffer );
free( p_sys );
}