2 * Copyright (C) 2016 Christian Browet
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
9 #include "JNIXBMCVideoView.h"
11 #include "CompileInfo.h"
12 #include "utils/StringUtils.h"
13 #include "utils/log.h"
19 #include <androidjni/Context.h>
20 #include <androidjni/jutils-details.hpp>
24 static std::string s_className
= std::string(CCompileInfo::GetClass()) + "/XBMCVideoView";
26 void CJNIXBMCVideoView::RegisterNatives(JNIEnv
* env
)
28 jclass cClass
= env
->FindClass(s_className
.c_str());
31 JNINativeMethod methods
[] =
33 {"_surfaceChanged", "(Landroid/view/SurfaceHolder;III)V", (void*)&CJNIXBMCVideoView::_surfaceChanged
},
34 {"_surfaceCreated", "(Landroid/view/SurfaceHolder;)V", (void*)&CJNIXBMCVideoView::_surfaceCreated
},
35 {"_surfaceDestroyed", "(Landroid/view/SurfaceHolder;)V", (void*)&CJNIXBMCVideoView::_surfaceDestroyed
}
38 env
->RegisterNatives(cClass
, methods
, sizeof(methods
)/sizeof(methods
[0]));
42 CJNIXBMCVideoView::CJNIXBMCVideoView(const jni::jhobject
&object
)
47 CJNIXBMCVideoView
* CJNIXBMCVideoView::createVideoView(CJNISurfaceHolderCallback
* callback
)
49 std::string signature
= "()L" + s_className
+ ";";
51 CJNIXBMCVideoView
* pvw
= new CJNIXBMCVideoView(call_static_method
<jhobject
>(xbmc_jnienv(), CJNIContext::getClassLoader().loadClass(GetDotClassName(s_className
)),
52 "createVideoView", signature
.c_str()));
55 CLog::Log(LOGERROR
, "Cannot instantiate VideoView!!");
60 add_instance(pvw
->get_raw(), pvw
);
61 pvw
->m_callback
= callback
;
63 pvw
->m_surfaceCreated
.Set();
69 void CJNIXBMCVideoView::_surfaceChanged(JNIEnv
*env
, jobject thiz
, jobject holder
, jint format
, jint width
, jint height
)
73 CJNIXBMCVideoView
*inst
= find_instance(thiz
);
75 inst
->surfaceChanged(CJNISurfaceHolder(jhobject::fromJNI(holder
)), format
, width
, height
);
78 void CJNIXBMCVideoView::_surfaceCreated(JNIEnv
* env
, jobject thiz
, jobject holder
)
82 CJNIXBMCVideoView
*inst
= find_instance(thiz
);
84 inst
->surfaceCreated(CJNISurfaceHolder(jhobject::fromJNI(holder
)));
87 void CJNIXBMCVideoView::_surfaceDestroyed(JNIEnv
* env
, jobject thiz
, jobject holder
)
91 CJNIXBMCVideoView
*inst
= find_instance(thiz
);
93 inst
->surfaceDestroyed(CJNISurfaceHolder(jhobject::fromJNI(holder
)));
96 void CJNIXBMCVideoView::surfaceChanged(CJNISurfaceHolder holder
, int format
, int width
, int height
)
99 m_callback
->surfaceChanged(holder
, format
, width
, height
);
102 void CJNIXBMCVideoView::surfaceCreated(CJNISurfaceHolder holder
)
105 m_callback
->surfaceCreated(holder
);
106 m_surfaceCreated
.Set();
109 void CJNIXBMCVideoView::surfaceDestroyed(CJNISurfaceHolder holder
)
111 m_surfaceCreated
.Reset();
113 m_callback
->surfaceDestroyed(holder
);
116 bool CJNIXBMCVideoView::waitForSurface(unsigned int millis
)
118 return m_surfaceCreated
.Wait(std::chrono::milliseconds(millis
));
121 void CJNIXBMCVideoView::add()
123 call_method
<void>(m_object
,
127 void CJNIXBMCVideoView::release()
129 remove_instance(this);
130 call_method
<void>(m_object
,
134 CJNISurface
CJNIXBMCVideoView::getSurface()
136 return call_method
<jhobject
>(m_object
,
137 "getSurface", "()Landroid/view/Surface;");
140 const CRect
& CJNIXBMCVideoView::getSurfaceRect()
142 return m_surfaceRect
;
145 void CJNIXBMCVideoView::setSurfaceRect(const CRect
& rect
)
147 call_method
<void>(m_object
,
148 "setSurfaceRect", "(IIII)V", int(rect
.x1
), int(rect
.y1
), int(rect
.x2
), int(rect
.y2
));
149 m_surfaceRect
= rect
;
152 bool CJNIXBMCVideoView::isCreated() const
154 return get_field
<jboolean
>(m_object
, "mIsCreated");