@ -479,56 +479,9 @@ loopclean:
}
/*****************************************************************************
* Stop
* ConfigureDecoder
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static int Stop ( mc_api * api )
{
mc_api_sys * p_sys = api - > p_sys ;
JNIEnv * env ;
api - > b_direct_rendering = false ;
GET_ENV ( ) ;
if ( p_sys - > input_buffers )
{
( * env ) - > DeleteGlobalRef ( env , p_sys - > input_buffers ) ;
p_sys - > input_buffers = NULL ;
}
if ( p_sys - > output_buffers )
{
( * env ) - > DeleteGlobalRef ( env , p_sys - > output_buffers ) ;
p_sys - > output_buffers = NULL ;
}
if ( p_sys - > codec )
{
if ( api - > b_started )
{
( * env ) - > CallVoidMethod ( env , p_sys - > codec , jfields . stop ) ;
if ( CHECK_EXCEPTION ( ) )
msg_Err ( api - > p_obj , " Exception in MediaCodec.stop " ) ;
api - > b_started = false ;
}
( * env ) - > CallVoidMethod ( env , p_sys - > codec , jfields . release ) ;
if ( CHECK_EXCEPTION ( ) )
msg_Err ( api - > p_obj , " Exception in MediaCodec.release " ) ;
( * env ) - > DeleteGlobalRef ( env , p_sys - > codec ) ;
p_sys - > codec = NULL ;
}
if ( p_sys - > buffer_info )
{
( * env ) - > DeleteGlobalRef ( env , p_sys - > buffer_info ) ;
p_sys - > buffer_info = NULL ;
}
msg_Dbg ( api - > p_obj , " MediaCodec via JNI closed " ) ;
return 0 ;
}
/*****************************************************************************
* Start
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static int Start ( mc_api * api , union mc_api_args * p_args )
static int ConfigureDecoder ( mc_api * api , union mc_api_args * p_args )
{
mc_api_sys * p_sys = api - > p_sys ;
JNIEnv * env = NULL ;
@ -538,9 +491,6 @@ static int Start(mc_api *api, union mc_api_args *p_args)
jstring jcodec_name = NULL ;
jobject jcodec = NULL ;
jobject jformat = NULL ;
jobject jinput_buffers = NULL ;
jobject joutput_buffers = NULL ;
jobject jbuffer_info = NULL ;
jobject jsurface = NULL ;
assert ( api - > psz_mime & & api - > psz_name ) ;
@ -599,6 +549,7 @@ static int Start(mc_api *api, union mc_api_args *p_args)
p_args - > audio . i_sample_rate ,
p_args - > audio . i_channel_count ) ;
}
/* No limits for input size */
SET_INTEGER ( jformat , " max-input-size " , 0 ) ;
@ -613,6 +564,8 @@ static int Start(mc_api *api, union mc_api_args *p_args)
" with an output surface. " ) ;
goto error ;
}
api - > b_direct_rendering = b_direct_rendering ;
}
else
{
@ -623,7 +576,85 @@ static int Start(mc_api *api, union mc_api_args *p_args)
msg_Warn ( api - > p_obj , " Exception occurred in MediaCodec.configure " ) ;
goto error ;
}
api - > b_direct_rendering = false ;
}
i_ret = 0 ;
error :
if ( jmime )
( * env ) - > DeleteLocalRef ( env , jmime ) ;
if ( jcodec_name )
( * env ) - > DeleteLocalRef ( env , jcodec_name ) ;
if ( jcodec )
( * env ) - > DeleteLocalRef ( env , jcodec ) ;
if ( jformat )
( * env ) - > DeleteLocalRef ( env , jformat ) ;
return i_ret ;
}
/*****************************************************************************
* Stop
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static int Stop ( mc_api * api )
{
mc_api_sys * p_sys = api - > p_sys ;
JNIEnv * env ;
api - > b_direct_rendering = false ;
GET_ENV ( ) ;
if ( p_sys - > input_buffers )
{
( * env ) - > DeleteGlobalRef ( env , p_sys - > input_buffers ) ;
p_sys - > input_buffers = NULL ;
}
if ( p_sys - > output_buffers )
{
( * env ) - > DeleteGlobalRef ( env , p_sys - > output_buffers ) ;
p_sys - > output_buffers = NULL ;
}
if ( p_sys - > codec )
{
if ( api - > b_started )
{
( * env ) - > CallVoidMethod ( env , p_sys - > codec , jfields . stop ) ;
if ( CHECK_EXCEPTION ( ) )
msg_Err ( api - > p_obj , " Exception in MediaCodec.stop " ) ;
api - > b_started = false ;
}
( * env ) - > CallVoidMethod ( env , p_sys - > codec , jfields . release ) ;
if ( CHECK_EXCEPTION ( ) )
msg_Err ( api - > p_obj , " Exception in MediaCodec.release " ) ;
( * env ) - > DeleteGlobalRef ( env , p_sys - > codec ) ;
p_sys - > codec = NULL ;
}
if ( p_sys - > buffer_info )
{
( * env ) - > DeleteGlobalRef ( env , p_sys - > buffer_info ) ;
p_sys - > buffer_info = NULL ;
}
msg_Dbg ( api - > p_obj , " MediaCodec via JNI closed " ) ;
return 0 ;
}
/*****************************************************************************
* Start
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static int Start ( mc_api * api )
{
mc_api_sys * p_sys = api - > p_sys ;
JNIEnv * env = NULL ;
jobject jinput_buffers = NULL ;
jobject joutput_buffers = NULL ;
jobject jbuffer_info = NULL ;
GET_ENV ( ) ;
int i_ret = MC_API_ERROR ;
( * env ) - > CallVoidMethod ( env , p_sys - > codec , jfields . start ) ;
if ( CHECK_EXCEPTION ( ) )
@ -635,7 +666,6 @@ static int Start(mc_api *api, union mc_api_args *p_args)
if ( jfields . get_input_buffers & & jfields . get_output_buffers )
{
jinput_buffers = ( * env ) - > CallObjectMethod ( env , p_sys - > codec ,
jfields . get_input_buffers ) ;
if ( CHECK_EXCEPTION ( ) )
@ -658,19 +688,10 @@ static int Start(mc_api *api, union mc_api_args *p_args)
jfields . buffer_info_ctor ) ;
p_sys - > buffer_info = ( * env ) - > NewGlobalRef ( env , jbuffer_info ) ;
api - > b_direct_rendering = b_direct_rendering ;
i_ret = 0 ;
msg_Dbg ( api - > p_obj , " MediaCodec via JNI opened " ) ;
error :
if ( jmime )
( * env ) - > DeleteLocalRef ( env , jmime ) ;
if ( jcodec_name )
( * env ) - > DeleteLocalRef ( env , jcodec_name ) ;
if ( jcodec )
( * env ) - > DeleteLocalRef ( env , jcodec ) ;
if ( jformat )
( * env ) - > DeleteLocalRef ( env , jformat ) ;
if ( jinput_buffers )
( * env ) - > DeleteLocalRef ( env , jinput_buffers ) ;
if ( joutput_buffers )
@ -1022,6 +1043,7 @@ int MediaCodecJni_Init(mc_api *api)
api - > clean = Clean ;
api - > prepare = Prepare ;
api - > configure_decoder = ConfigureDecoder ;
api - > start = Start ;
api - > stop = Stop ;
api - > flush = Flush ;