Commit 52e2e90f authored by Thomas Guillem's avatar Thomas Guillem

Revert "android: rework AWindowHandler interface"

This reverts commit 159a6f1e.
This is finally not needed by a future patch, and it's less obvious.
parent f4cb3f99
......@@ -85,7 +85,6 @@ struct decoder_sys_t
struct
{
AWindowHandler *p_awh;
jobject jsurface;
int i_pixel_format, i_stride, i_slice_height, i_width, i_height;
uint32_t i_nal_length_size;
size_t i_h264_profile;
......@@ -394,23 +393,8 @@ static int StartMediaCodec(decoder_t *p_dec)
}
if (!p_sys->u.video.p_awh && var_InheritBool(p_dec, CFG_PREFIX "dr"))
{
p_sys->u.video.p_awh = AWindowHandler_new(VLC_OBJECT(p_dec));
if (p_sys->u.video.p_awh)
{
p_sys->u.video.jsurface = AWindowHandler_getSurface(
p_sys->u.video.p_awh,
AWindow_Video);
if (!p_sys->u.video.jsurface)
{
AWindowHandler_destroy(p_sys->u.video.p_awh);
p_sys->u.video.p_awh = NULL;
}
}
}
args.video.p_awh = p_sys->u.video.p_awh;
args.video.jsurface = p_sys->u.video.jsurface;
}
else
{
......@@ -447,8 +431,10 @@ static void StopMediaCodec(decoder_t *p_dec)
p_sys->api->stop(p_sys->api);
if (p_dec->fmt_in.i_cat == VIDEO_ES && p_sys->u.video.p_awh)
AWindowHandler_releaseSurface(p_sys->u.video.p_awh,
p_sys->u.video.jsurface);
{
AWindowHandler_releaseANativeWindow(p_sys->u.video.p_awh, AWindow_Video);
AWindowHandler_releaseSurface(p_sys->u.video.p_awh, AWindow_Video);
}
}
/*****************************************************************************
......
......@@ -78,7 +78,6 @@ union mc_api_args
struct
{
AWindowHandler *p_awh;
jobject jsurface;
int i_width;
int i_height;
int i_angle;
......
......@@ -482,6 +482,7 @@ static int Start(mc_api *api, const char *psz_name, const char *psz_mime,
jobject jinput_buffers = NULL;
jobject joutput_buffers = NULL;
jobject jbuffer_info = NULL;
jobject jsurface = NULL;
GET_ENV();
......@@ -511,7 +512,10 @@ static int Start(mc_api *api, const char *psz_name, const char *psz_mime,
jmime,
p_args->video.i_width,
p_args->video.i_height);
b_direct_rendering = !!p_args->video.jsurface;
if (p_args->video.p_awh)
jsurface = AWindowHandler_getSurface(p_args->video.p_awh,
AWindow_Video);
b_direct_rendering = !!jsurface;
/* There is no way to rotate the video using direct rendering (and
* using a SurfaceView) before API 21 (Lollipop). Therefore, we
......@@ -541,7 +545,7 @@ static int Start(mc_api *api, const char *psz_name, const char *psz_mime,
{
// Configure MediaCodec with the Android surface.
(*env)->CallVoidMethod(env, p_sys->codec, jfields.configure,
jformat, p_args->video.jsurface, NULL, 0);
jformat, jsurface, NULL, 0);
if (CHECK_EXCEPTION())
{
msg_Warn(api->p_obj, "Exception occurred in MediaCodec.configure "
......
......@@ -326,7 +326,7 @@ static int Start(mc_api *api, const char *psz_name, const char *psz_mime,
syms.AMediaFormat.setInt32(p_sys->p_format, "rotation-degrees", p_args->video.i_angle);
if (p_args->video.p_awh)
p_anw = AWindowHandler_getANativeWindow(p_args->video.p_awh,
p_args->video.jsurface);
AWindow_Video);
}
else
{
......
......@@ -2016,7 +2016,6 @@ static void HwBuffer_ChangeState( decoder_t *p_dec, OmxPort *p_port,
static void HwBuffer_Init( decoder_t *p_dec, OmxPort *p_port )
{
VLC_UNUSED( p_dec );
jobject jsurface;
ANativeWindow *p_anw;
OMX_ERRORTYPE omx_error;
......@@ -2054,14 +2053,8 @@ static void HwBuffer_Init( decoder_t *p_dec, OmxPort *p_port )
msg_Warn( p_dec, "AWindowHandler_getANativeWindowPrivAPI failed" );
goto error;
}
jsurface = AWindowHandler_getSurface( p_port->p_hwbuf->p_awh,
AWindow_Video );
if( !jsurface )
{
msg_Warn( p_dec, "AWindowHandler_getSurface failed" );
goto error;
}
p_anw = AWindowHandler_getANativeWindow( p_port->p_hwbuf->p_awh, jsurface );
p_anw = AWindowHandler_getANativeWindow( p_port->p_hwbuf->p_awh,
AWindow_Video );
if( !p_anw )
{
msg_Warn( p_dec, "AWindowHandler_getVideoANativeWindow failed" );
......
......@@ -89,8 +89,9 @@ struct android_window
unsigned int i_pic_count;
unsigned int i_min_undequeued;
bool b_use_priv;
bool b_opaque;
jobject jsurface; /* NULL if opaque */
enum AWindow_ID id;
ANativeWindow *p_handle;
native_window_priv *p_handle_priv;
};
......@@ -306,7 +307,7 @@ static void AndroidWindow_DisconnectSurface(vout_display_sys_t *sys,
p_window->p_handle_priv = NULL;
}
if (p_window->p_handle) {
AWindowHandler_releaseANativeWindow(sys->p_awh, p_window->p_handle);
AWindowHandler_releaseANativeWindow(sys->p_awh, p_window->id);
p_window->p_handle = NULL;
}
}
......@@ -314,9 +315,9 @@ static void AndroidWindow_DisconnectSurface(vout_display_sys_t *sys,
static int AndroidWindow_ConnectSurface(vout_display_sys_t *sys,
android_window *p_window)
{
if (!p_window->p_handle && p_window->jsurface) {
if (!p_window->p_handle && !p_window->b_opaque) {
p_window->p_handle = AWindowHandler_getANativeWindow(sys->p_awh,
p_window->jsurface);
p_window->id);
if (!p_window->p_handle)
return -1;
}
......@@ -331,13 +332,14 @@ static android_window *AndroidWindow_New(vout_display_t *vd,
{
vout_display_sys_t *sys = vd->sys;
android_window *p_window = NULL;
const bool b_opaque = p_fmt->i_chroma == VLC_CODEC_ANDROID_OPAQUE;
p_window = calloc(1, sizeof(android_window));
if (!p_window)
goto error;
if (!b_opaque) {
p_window->id = id;
p_window->b_opaque = p_fmt->i_chroma == VLC_CODEC_ANDROID_OPAQUE;
if (!p_window->b_opaque) {
p_window->b_use_priv = sys->anwp && b_use_priv;
p_window->i_android_hal = ChromaToAndroidHal(p_fmt->i_chroma);
......@@ -365,14 +367,6 @@ static android_window *AndroidWindow_New(vout_display_t *vd,
video_format_ApplyRotation(&p_window->fmt, p_fmt);
p_window->i_pic_count = 1;
if (!b_opaque) {
p_window->jsurface = AWindowHandler_getSurface(sys->p_awh, id);
if (!p_window->jsurface)
{
msg_Err(vd, "AWindowHandler_getSurface failed");
goto error;
}
}
if (AndroidWindow_ConnectSurface(sys, p_window) != 0)
{
if (id == AWindow_Video)
......@@ -390,8 +384,6 @@ static void AndroidWindow_Destroy(vout_display_t *vd,
android_window *p_window)
{
AndroidWindow_DisconnectSurface(vd->sys, p_window);
if (p_window->jsurface)
AWindowHandler_releaseSurface(vd->sys->p_awh, p_window->jsurface);
free(p_window);
}
......@@ -472,7 +464,7 @@ static int AndroidWindow_ConfigureJavaSurface(vout_display_sys_t *sys,
* don't need to call it (ie, after ics). if this call succeed, you need to
* get a new surface handle. That's why AndroidWindow_DisconnectSurface is
* called here. */
if (AWindowHandler_setBuffersGeometry(sys->p_awh, p_window->jsurface,
if (AWindowHandler_setBuffersGeometry(sys->p_awh, p_window->id,
p_window->fmt.i_width,
p_window->fmt.i_height,
p_window->i_android_hal) == VLC_SUCCESS)
......@@ -512,7 +504,7 @@ static int AndroidWindow_Setup(vout_display_sys_t *sys,
if (i_pic_count != 0)
p_window->i_pic_count = i_pic_count;
if (p_window->jsurface) {
if (!p_window->b_opaque) {
int align_pixels;
picture_t *p_pic = PictureAlloc(sys, &p_window->fmt);
......@@ -694,10 +686,10 @@ static int Open(vlc_object_t *p_this)
goto error;
/* use software rotation if we don't use private anw */
if (sys->p_window->jsurface && !sys->p_window->b_use_priv)
if (!sys->p_window->b_opaque && !sys->p_window->b_use_priv)
video_format_ApplyRotation(&vd->fmt, &vd->fmt);
msg_Dbg(vd, "using %s", !sys->p_window->jsurface ? "opaque" :
msg_Dbg(vd, "using %s", sys->p_window->b_opaque ? "opaque" :
(sys->p_window->b_use_priv ? "ANWP" : "ANW"));
video_format_ApplyRotation(&sub_fmt, &vd->fmt);
......@@ -822,7 +814,7 @@ static picture_pool_t *PoolAlloc(vout_display_t *vd, unsigned requested_count)
picture_t *p_pic = PictureAlloc(sys, &sys->p_window->fmt);
if (!p_pic)
goto error;
if (sys->p_window->jsurface) {
if (!sys->p_window->b_opaque) {
p_pic->p_sys->pf_lock_pic = DefaultLockPicture;
p_pic->p_sys->pf_unlock_pic = DefaultUnlockPicture;
}
......@@ -1056,7 +1048,7 @@ static int Control(vout_display_t *vd, int query, va_list args)
return VLC_SUCCESS;
case VOUT_DISPLAY_RESET_PICTURES:
{
if (!sys->p_window->jsurface)
if (sys->p_window->b_opaque)
return VLC_EGENERIC;
msg_Dbg(vd, "resetting pictures");
......
......@@ -510,21 +510,31 @@ AWindowHandler_new(vlc_object_t *p_obj)
return p_awh;
}
static void
AWindowHandler_releaseSurfaceEnv(AWindowHandler *p_awh, JNIEnv *p_env,
enum AWindow_ID id)
{
if (p_awh->views[id].jsurface)
{
(*p_env)->DeleteGlobalRef(p_env, p_awh->views[id].jsurface);
p_awh->views[id].jsurface = NULL;
}
}
void
AWindowHandler_destroy(AWindowHandler *p_awh)
{
JNIEnv *p_env = AWindowHandler_getEnv(p_awh);
AWindowHandler_releaseANativeWindow(p_awh, AWindow_Video);
AWindowHandler_releaseANativeWindow(p_awh, AWindow_Subtitles);
if (p_env)
{
if (p_awh->event.b_registered)
JNI_CALL(CallBooleanMethod, setCallback, (jlong)0LL);
if (p_awh->views[AWindow_Video].jsurface)
AWindowHandler_releaseSurface(p_awh,
p_awh->views[AWindow_Video].jsurface);
if (p_awh->views[AWindow_Subtitles].jsurface)
AWindowHandler_releaseSurface(p_awh,
p_awh->views[AWindow_Subtitles].jsurface);
AWindowHandler_releaseSurfaceEnv(p_awh, p_env, AWindow_Video);
AWindowHandler_releaseSurfaceEnv(p_awh, p_env, AWindow_Subtitles);
(*p_env)->DeleteGlobalRef(p_env, p_awh->jobj);
}
......@@ -551,40 +561,6 @@ AWindowHandler_getANativeWindowPrivAPI(AWindowHandler *p_awh)
return &p_awh->anwpriv_api;
}
static enum AWindow_ID
AWindowHandler_getIdFromSurface(AWindowHandler *p_awh, jobject jsurface)
{
enum AWindow_ID id = AWindow_Max;
if (jsurface)
{
if (p_awh->views[AWindow_Video].jsurface == jsurface)
id = AWindow_Video;
else if (p_awh->views[AWindow_Subtitles].jsurface == jsurface)
id = AWindow_Subtitles;
}
assert(id != AWindow_Max);
return id;
}
static enum AWindow_ID
AWindowHandler_getIdFromANW(AWindowHandler *p_awh, ANativeWindow *p_anw)
{
enum AWindow_ID id = AWindow_Max;
if (p_anw)
{
if (p_awh->views[AWindow_Video].p_anw == p_anw)
id = AWindow_Video;
else if (p_awh->views[AWindow_Subtitles].p_anw == p_anw)
id = AWindow_Subtitles;
}
assert(id != AWindow_Max);
return id;
}
jobject
AWindowHandler_getSurface(AWindowHandler *p_awh, enum AWindow_ID id)
{
......@@ -613,37 +589,22 @@ AWindowHandler_getSurface(AWindowHandler *p_awh, enum AWindow_ID id)
}
void
AWindowHandler_releaseSurface(AWindowHandler *p_awh, jobject jsurface)
AWindowHandler_releaseSurface(AWindowHandler *p_awh, enum AWindow_ID id)
{
assert(id < AWindow_Max);
JNIEnv *p_env = AWindowHandler_getEnv(p_awh);
if (p_env)
{
enum AWindow_ID id = AWindowHandler_getIdFromSurface(p_awh, jsurface);
if (id != AWindow_Max)
{
if (p_awh->views[id].p_anw)
{
p_awh->pf_winRelease(p_awh->views[id].p_anw);
p_awh->views[id].p_anw = NULL;
}
if (p_awh->views[id].jsurface)
{
(*p_env)->DeleteGlobalRef(p_env, p_awh->views[id].jsurface);
p_awh->views[id].jsurface = NULL;
}
}
}
AWindowHandler_releaseSurfaceEnv(p_awh, p_env, id);
}
ANativeWindow *
AWindowHandler_getANativeWindow(AWindowHandler *p_awh, jobject jsurface)
AWindowHandler_getANativeWindow(AWindowHandler *p_awh, enum AWindow_ID id)
{
assert(id < AWindow_Max);
jobject jsurf;
JNIEnv *p_env;
enum AWindow_ID id = AWindowHandler_getIdFromSurface(p_awh, jsurface);
if (id == AWindow_Max)
return NULL;
if (p_awh->views[id].p_anw)
return p_awh->views[id].p_anw;
......@@ -652,16 +613,20 @@ AWindowHandler_getANativeWindow(AWindowHandler *p_awh, jobject jsurface)
if (!p_env)
return NULL;
p_awh->views[id].p_anw = p_awh->pf_winFromSurface(p_env, jsurface);
jsurf = AWindowHandler_getSurface(p_awh, id);
if (!jsurf)
return NULL;
p_awh->views[id].p_anw = p_awh->pf_winFromSurface(p_env, jsurf);
return p_awh->views[id].p_anw;
}
void AWindowHandler_releaseANativeWindow(AWindowHandler *p_awh,
ANativeWindow *p_anw)
enum AWindow_ID id)
{
enum AWindow_ID id = AWindowHandler_getIdFromANW(p_awh, p_anw);
assert(id < AWindow_Max);
if (id != AWindow_Max)
if (p_awh->views[id].p_anw)
{
p_awh->pf_winRelease(p_awh->views[id].p_anw);
p_awh->views[id].p_anw = NULL;
......@@ -761,16 +726,21 @@ AWindowHandler_getWindowSize(AWindowHandler *p_awh,
}
int
AWindowHandler_setBuffersGeometry(AWindowHandler *p_awh, jobject jsurface,
AWindowHandler_setBuffersGeometry(AWindowHandler *p_awh, enum AWindow_ID id,
int i_width, int i_height, int i_format)
{
jobject jsurf;
JNIEnv *p_env = AWindowHandler_getEnv(p_awh);
if (!p_env)
return VLC_EGENERIC;
return JNI_CALL(CallBooleanMethod, setBuffersGeometry, jsurface,
i_width, i_height, i_format) ? VLC_SUCCESS
: VLC_EGENERIC;
jsurf = AWindowHandler_getSurface(p_awh, id);
if (!jsurf)
return VLC_EGENERIC;
return JNI_CALL(CallBooleanMethod, setBuffersGeometry,
jsurf, i_width, i_height, i_format) ? VLC_SUCCESS
: VLC_EGENERIC;
}
int
......
......@@ -143,25 +143,24 @@ bool AWindowHandler_getWindowSize(AWindowHandler *p_awh,
* AWindowHandler_destroy.
*/
jobject AWindowHandler_getSurface(AWindowHandler *p_awh, enum AWindow_ID id);
void AWindowHandler_releaseSurface(AWindowHandler *p_awh, jobject jsurface);
void AWindowHandler_releaseSurface(AWindowHandler *p_awh, enum AWindow_ID id);
/**
* This function returns the Video or the Subtitles ANativeWindow attached to
* the Android Surface. It can be released with
* AWindowHandler_releaseANativeWindow, AWindowHandler_releaseSurface or by
* AWindowHandler_destroy.
* AWindowHandler_releaseANativeWindow or by AWindowHandler_destroy.
*/
ANativeWindow *AWindowHandler_getANativeWindow(AWindowHandler *p_awh,
jobject jsurface);
enum AWindow_ID id);
void AWindowHandler_releaseANativeWindow(AWindowHandler *p_awh,
ANativeWindow *panw);
enum AWindow_ID id);
/**
* This function is a fix up of ANativeWindow_setBuffersGeometry that doesn't
* work before Android ICS. It configures the Surface from the Android
* MainThread via a SurfaceHolder. It returns VLC_SUCCESS if the Surface was
* configured (it returns VLC_EGENERIC after Android ICS).
*/
int AWindowHandler_setBuffersGeometry(AWindowHandler *p_awh, jobject jsurface,
int AWindowHandler_setBuffersGeometry(AWindowHandler *p_awh, enum AWindow_ID id,
int i_width, int i_height, int i_format);
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment