1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
/*
* Copyright (C) 2016 Christian Browet
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "JNIXBMCVideoView.h"
#include "CompileInfo.h"
#include "utils/StringUtils.h"
#include "utils/log.h"
#include <algorithm>
#include <cassert>
#include <list>
#include <androidjni/Context.h>
#include <androidjni/jutils-details.hpp>
using namespace jni;
static std::string s_className = std::string(CCompileInfo::GetClass()) + "/XBMCVideoView";
void CJNIXBMCVideoView::RegisterNatives(JNIEnv* env)
{
jclass cClass = env->FindClass(s_className.c_str());
if(cClass)
{
JNINativeMethod methods[] =
{
{"_surfaceChanged", "(Landroid/view/SurfaceHolder;III)V", (void*)&CJNIXBMCVideoView::_surfaceChanged},
{"_surfaceCreated", "(Landroid/view/SurfaceHolder;)V", (void*)&CJNIXBMCVideoView::_surfaceCreated},
{"_surfaceDestroyed", "(Landroid/view/SurfaceHolder;)V", (void*)&CJNIXBMCVideoView::_surfaceDestroyed}
};
env->RegisterNatives(cClass, methods, sizeof(methods)/sizeof(methods[0]));
}
}
CJNIXBMCVideoView::CJNIXBMCVideoView(const jni::jhobject &object)
: CJNIBase(object)
{
}
CJNIXBMCVideoView* CJNIXBMCVideoView::createVideoView(CJNISurfaceHolderCallback* callback)
{
std::string signature = "()L" + s_className + ";";
CJNIXBMCVideoView* pvw = new CJNIXBMCVideoView(call_static_method<jhobject>(xbmc_jnienv(), CJNIContext::getClassLoader().loadClass(GetDotClassName(s_className)),
"createVideoView", signature.c_str()));
if (!*pvw)
{
CLog::Log(LOGERROR, "Cannot instantiate VideoView!!");
delete pvw;
return nullptr;
}
add_instance(pvw->get_raw(), pvw);
pvw->m_callback = callback;
if (pvw->isCreated())
pvw->m_surfaceCreated.Set();
pvw->add();
return pvw;
}
void CJNIXBMCVideoView::_surfaceChanged(JNIEnv *env, jobject thiz, jobject holder, jint format, jint width, jint height )
{
(void)env;
CJNIXBMCVideoView *inst = find_instance(thiz);
if (inst)
inst->surfaceChanged(CJNISurfaceHolder(jhobject::fromJNI(holder)), format, width, height);
}
void CJNIXBMCVideoView::_surfaceCreated(JNIEnv* env, jobject thiz, jobject holder)
{
(void)env;
CJNIXBMCVideoView *inst = find_instance(thiz);
if (inst)
inst->surfaceCreated(CJNISurfaceHolder(jhobject::fromJNI(holder)));
}
void CJNIXBMCVideoView::_surfaceDestroyed(JNIEnv* env, jobject thiz, jobject holder)
{
(void)env;
CJNIXBMCVideoView *inst = find_instance(thiz);
if (inst)
inst->surfaceDestroyed(CJNISurfaceHolder(jhobject::fromJNI(holder)));
}
void CJNIXBMCVideoView::surfaceChanged(CJNISurfaceHolder holder, int format, int width, int height)
{
if (m_callback)
m_callback->surfaceChanged(holder, format, width, height);
}
void CJNIXBMCVideoView::surfaceCreated(CJNISurfaceHolder holder)
{
if (m_callback)
m_callback->surfaceCreated(holder);
m_surfaceCreated.Set();
}
void CJNIXBMCVideoView::surfaceDestroyed(CJNISurfaceHolder holder)
{
m_surfaceCreated.Reset();
if (m_callback)
m_callback->surfaceDestroyed(holder);
}
bool CJNIXBMCVideoView::waitForSurface(unsigned int millis)
{
return m_surfaceCreated.WaitMSec(millis);
}
void CJNIXBMCVideoView::add()
{
call_method<void>(m_object,
"add", "()V");
}
void CJNIXBMCVideoView::release()
{
remove_instance(this);
call_method<void>(m_object,
"release", "()V");
}
CJNISurface CJNIXBMCVideoView::getSurface()
{
return call_method<jhobject>(m_object,
"getSurface", "()Landroid/view/Surface;");
}
const CRect& CJNIXBMCVideoView::getSurfaceRect()
{
return m_surfaceRect;
}
void CJNIXBMCVideoView::setSurfaceRect(const CRect& rect)
{
call_method<void>(m_object,
"setSurfaceRect", "(IIII)V", int(rect.x1), int(rect.y1), int(rect.x2), int(rect.y2));
m_surfaceRect = rect;
}
bool CJNIXBMCVideoView::isCreated() const
{
return get_field<jboolean>(m_object, "mIsCreated");
}
|