[Windows] Remove redundant DirectSound error codes
[xbmc.git] / xbmc / platform / android / activity / JNIXBMCVideoView.cpp
blob2f9ab34decaf52d12a0ba5e89415649dd1eae169
1 /*
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.
7 */
9 #include "JNIXBMCVideoView.h"
11 #include "CompileInfo.h"
12 #include "utils/StringUtils.h"
13 #include "utils/log.h"
15 #include <algorithm>
16 #include <cassert>
17 #include <list>
19 #include <androidjni/Context.h>
20 #include <androidjni/jutils-details.hpp>
22 using namespace jni;
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());
29 if(cClass)
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)
43 : CJNIBase(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()));
53 if (!*pvw)
55 CLog::Log(LOGERROR, "Cannot instantiate VideoView!!");
56 delete pvw;
57 return nullptr;
60 add_instance(pvw->get_raw(), pvw);
61 pvw->m_callback = callback;
62 if (pvw->isCreated())
63 pvw->m_surfaceCreated.Set();
64 pvw->add();
66 return pvw;
69 void CJNIXBMCVideoView::_surfaceChanged(JNIEnv *env, jobject thiz, jobject holder, jint format, jint width, jint height )
71 (void)env;
73 CJNIXBMCVideoView *inst = find_instance(thiz);
74 if (inst)
75 inst->surfaceChanged(CJNISurfaceHolder(jhobject::fromJNI(holder)), format, width, height);
78 void CJNIXBMCVideoView::_surfaceCreated(JNIEnv* env, jobject thiz, jobject holder)
80 (void)env;
82 CJNIXBMCVideoView *inst = find_instance(thiz);
83 if (inst)
84 inst->surfaceCreated(CJNISurfaceHolder(jhobject::fromJNI(holder)));
87 void CJNIXBMCVideoView::_surfaceDestroyed(JNIEnv* env, jobject thiz, jobject holder)
89 (void)env;
91 CJNIXBMCVideoView *inst = find_instance(thiz);
92 if (inst)
93 inst->surfaceDestroyed(CJNISurfaceHolder(jhobject::fromJNI(holder)));
96 void CJNIXBMCVideoView::surfaceChanged(CJNISurfaceHolder holder, int format, int width, int height)
98 if (m_callback)
99 m_callback->surfaceChanged(holder, format, width, height);
102 void CJNIXBMCVideoView::surfaceCreated(CJNISurfaceHolder holder)
104 if (m_callback)
105 m_callback->surfaceCreated(holder);
106 m_surfaceCreated.Set();
109 void CJNIXBMCVideoView::surfaceDestroyed(CJNISurfaceHolder holder)
111 m_surfaceCreated.Reset();
112 if (m_callback)
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,
124 "add", "()V");
127 void CJNIXBMCVideoView::release()
129 remove_instance(this);
130 call_method<void>(m_object,
131 "release", "()V");
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");