-
Notifications
You must be signed in to change notification settings - Fork 35
/
SubscribeTest.java
215 lines (182 loc) · 8.26 KB
/
SubscribeTest.java
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
//
// Copyright © 2015 Infrared5, Inc. All rights reserved.
//
// The accompanying code comprising examples for use solely in conjunction with Red5 Pro (the "Example Code")
// is licensed to you by Infrared5 Inc. in consideration of your agreement to the following
// license terms and conditions. Access, use, modification, or redistribution of the accompanying
// code constitutes your acceptance of the following license terms and conditions.
//
// Permission is hereby granted, free of charge, to you to use the Example Code and associated documentation
// files (collectively, the "Software") without restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The Software shall be used solely in conjunction with Red5 Pro. Red5 Pro is licensed under a separate end
// user license agreement (the "EULA"), which must be executed with Infrared5, Inc.
// An example of the EULA can be found on our website at: https://account.red5pro.com/assets/LICENSE.txt.
//
// The above copyright notice and this license shall be included in all copies or portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
// NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL INFRARED5, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
package red5pro.org.testandroidproject.tests.SubscribeTest;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import com.red5pro.streaming.R5Connection;
import com.red5pro.streaming.R5Stream;
import com.red5pro.streaming.R5StreamFormat;
import com.red5pro.streaming.R5StreamProtocol;
import com.red5pro.streaming.config.R5Configuration;
import com.red5pro.streaming.event.R5ConnectionEvent;
import com.red5pro.streaming.event.R5ConnectionListener;
import com.red5pro.streaming.event.R5FrameListener;
import com.red5pro.streaming.media.R5AudioController;
import com.red5pro.streaming.view.R5VideoView;
import red5pro.org.testandroidproject.R;
import red5pro.org.testandroidproject.TestDetailFragment;
import red5pro.org.testandroidproject.tests.SubscribeNoViewTest.SubscribeNoViewTest;
import red5pro.org.testandroidproject.tests.TestContent;
/**
* Created by davidHeimann on 2/9/16.
*/
public class SubscribeTest extends TestDetailFragment implements R5ConnectionListener {
protected R5VideoView display;
protected R5Stream subscribe;
protected void showToast (String message) {
final CharSequence text = message;
final Context context = getContext();
final int duration = Toast.LENGTH_SHORT;
if (getActivity() == null || context == null) {
return;
}
try {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
});
} catch (Exception e) {
// Most likely have moved away from activity back to main listing on Event.CLOSE.
e.printStackTrace();
}
}
@Override
public void onConnectionEvent(R5ConnectionEvent event) {
Log.d("Subscriber", ":onConnectionEvent " + event.name());
String msg = event.message;
showToast(msg == null ? event.name() : msg);
if (event.name() == R5ConnectionEvent.LICENSE_ERROR.name()) {
Handler h = new Handler(Looper.getMainLooper());
h.post(new Runnable() {
@Override
public void run() {
AlertDialog alertDialog = new AlertDialog.Builder(SubscribeTest.this.getActivity()).create();
alertDialog.setTitle("Error");
alertDialog.setMessage("License is Invalid");
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL,"OK",
new DialogInterface.OnClickListener()
{
public void onClick (DialogInterface dialog,int which){
dialog.dismiss();
}
}
);
alertDialog.show();
}
});
}
else if (event.name() == R5ConnectionEvent.START_STREAMING.name()){
// subscribe.setFrameListener(new R5FrameListener() {
// @Override
// public void onFrameReceived(Object o, R5StreamFormat r5StreamFormat, int w, int h) {
// int format = r5StreamFormat.value(); // 2 - YUV_PLANAR
// if (r5StreamFormat.equals(R5StreamFormat.YUV_PLANAR)) {
// byte[][] yuv_frames = (byte[][]) o; // Cast and access data in 3 planes as byte array. (byte[3][])
// }
// }
// });
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.subscribe_test, container, false);
//find the view and attach the stream
display = (R5VideoView) view.findViewById(R.id.videoView);
Subscribe();
//
// ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
// NetworkInfo info = cm.getActiveNetworkInfo();
return view;
}
public void Subscribe(){
//Create the configuration from the tests.xml
R5Configuration config = new R5Configuration(R5StreamProtocol.RTSP,
TestContent.GetPropertyString("host"),
TestContent.GetPropertyInt("port"),
TestContent.GetPropertyString("context"),
TestContent.GetPropertyFloat("subscribe_buffer_time"));
config.setLicenseKey(TestContent.GetPropertyString("license_key"));
config.setBundleID(getActivity().getPackageName());
String params = TestContent.getConnectionParams();
if (params != null) {
config.setParameters(params);
}
R5Connection connection = new R5Connection(config);
//setup a new stream using the connection
subscribe = new R5Stream(connection);
//Some devices can't handle rapid reuse of the audio controller, and will crash
//Recreation of the controller assures that the example will always be stable
subscribe.audioController = new R5AudioController();
subscribe.audioController.sampleRate = TestContent.GetPropertyInt("sample_rate");
subscribe.client = this;
subscribe.setListener(this);
//show all logging
subscribe.setLogLevel(R5Stream.LOG_LEVEL_DEBUG);
//display.setZOrderOnTop(true);
display.attachStream(subscribe);
display.showDebugView(TestContent.GetPropertyBool("debug_view"));
subscribe.play(TestContent.GetPropertyString("stream1"), TestContent.GetPropertyBool("hwAccel_on"));
}
public void onMetaData(String metadata) {
Log.d("SubscribeTest", "Metadata receieved: " + metadata);
String[] props = metadata.split(";");
// for (String s : props) {
// String[] kv = s.split("=");
// if (kv[0].equalsIgnoreCase("orientation")) {
// updateOrientation(Integer.parseInt(kv[1]));
// }
// }
}
public void onStreamSend(String msg){
Log.d("SubscribeTest", "GOT MSG");
}
@Override
public void onStop() {
if (display != null) {
display.attachStream(null);
}
if(subscribe != null) {
subscribe.stop();
subscribe = null;
}
super.onStop();
}
}