| 1 | package net.minecraft.client.stream;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import java.util.List;
|
| 5 | import tv.twitch.AuthToken;
|
| 6 | import tv.twitch.ErrorCode;
|
| 7 | import tv.twitch.broadcast.ArchivingState;
|
| 8 | import tv.twitch.broadcast.AudioParams;
|
| 9 | import tv.twitch.broadcast.ChannelInfo;
|
| 10 | import tv.twitch.broadcast.EncodingCpuUsage;
|
| 11 | import tv.twitch.broadcast.FrameBuffer;
|
| 12 | import tv.twitch.broadcast.GameInfoList;
|
| 13 | import tv.twitch.broadcast.IStatCallbacks;
|
| 14 | import tv.twitch.broadcast.IStreamCallbacks;
|
| 15 | import tv.twitch.broadcast.IngestList;
|
| 16 | import tv.twitch.broadcast.IngestServer;
|
| 17 | import tv.twitch.broadcast.PixelFormat;
|
| 18 | import tv.twitch.broadcast.RTMPState;
|
| 19 | import tv.twitch.broadcast.StartFlags;
|
| 20 | import tv.twitch.broadcast.StatType;
|
| 21 | import tv.twitch.broadcast.Stream;
|
| 22 | import tv.twitch.broadcast.StreamInfo;
|
| 23 | import tv.twitch.broadcast.UserInfo;
|
| 24 | import tv.twitch.broadcast.VideoParams;
|
| 25 |
|
| 26 | public class IngestServerTester
|
| 27 | {
|
| 28 | protected IngestServerTester.IngestTestListener field_153044_b = null;
|
| 29 | protected Stream field_153045_c = null;
|
| 30 | protected IngestList field_153046_d = null;
|
| 31 | protected IngestServerTester.IngestTestState field_153047_e = IngestServerTester.IngestTestState.Uninitalized;
|
| 32 | protected long field_153048_f = 8000L;
|
| 33 | protected long field_153049_g = 2000L;
|
| 34 | protected long field_153050_h = 0L;
|
| 35 | protected RTMPState field_153051_i = RTMPState.Invalid;
|
| 36 | protected VideoParams field_153052_j = null;
|
| 37 | protected AudioParams audioParameters = null;
|
| 38 | protected long field_153054_l = 0L;
|
| 39 | protected List<FrameBuffer> field_153055_m = null;
|
| 40 | protected boolean field_153056_n = false;
|
| 41 | protected IStreamCallbacks field_153057_o = null;
|
| 42 | protected IStatCallbacks field_153058_p = null;
|
| 43 | protected IngestServer field_153059_q = null;
|
| 44 | protected boolean field_153060_r = false;
|
| 45 | protected boolean field_153061_s = false;
|
| 46 | protected int field_153062_t = -1;
|
| 47 | protected int field_153063_u = 0;
|
| 48 | protected long field_153064_v = 0L;
|
| 49 | protected float field_153065_w = 0.0F;
|
| 50 | protected float field_153066_x = 0.0F;
|
| 51 | protected boolean field_176009_x = false;
|
| 52 | protected boolean field_176008_y = false;
|
| 53 | protected boolean field_176007_z = false;
|
| 54 | protected IStreamCallbacks field_176005_A = new IStreamCallbacks()
|
| 55 | {
|
| 56 | public void requestAuthTokenCallback(ErrorCode p_requestAuthTokenCallback_1_, AuthToken p_requestAuthTokenCallback_2_)
|
| 57 | {
|
| 58 | }
|
| 59 | public void loginCallback(ErrorCode p_loginCallback_1_, ChannelInfo p_loginCallback_2_)
|
| 60 | {
|
| 61 | }
|
| 62 | public void getIngestServersCallback(ErrorCode p_getIngestServersCallback_1_, IngestList p_getIngestServersCallback_2_)
|
| 63 | {
|
| 64 | }
|
| 65 | public void getUserInfoCallback(ErrorCode p_getUserInfoCallback_1_, UserInfo p_getUserInfoCallback_2_)
|
| 66 | {
|
| 67 | }
|
| 68 | public void getStreamInfoCallback(ErrorCode p_getStreamInfoCallback_1_, StreamInfo p_getStreamInfoCallback_2_)
|
| 69 | {
|
| 70 | }
|
| 71 | public void getArchivingStateCallback(ErrorCode p_getArchivingStateCallback_1_, ArchivingState p_getArchivingStateCallback_2_)
|
| 72 | {
|
| 73 | }
|
| 74 | public void runCommercialCallback(ErrorCode p_runCommercialCallback_1_)
|
| 75 | {
|
| 76 | }
|
| 77 | public void setStreamInfoCallback(ErrorCode p_setStreamInfoCallback_1_)
|
| 78 | {
|
| 79 | }
|
| 80 | public void getGameNameListCallback(ErrorCode p_getGameNameListCallback_1_, GameInfoList p_getGameNameListCallback_2_)
|
| 81 | {
|
| 82 | }
|
| 83 | public void bufferUnlockCallback(long p_bufferUnlockCallback_1_)
|
| 84 | {
|
| 85 | }
|
| 86 | public void startCallback(ErrorCode p_startCallback_1_)
|
| 87 | {
|
| 88 | IngestServerTester.this.field_176008_y = false;
|
| 89 |
|
| 90 | if (ErrorCode.succeeded(p_startCallback_1_))
|
| 91 | {
|
| 92 | IngestServerTester.this.field_176009_x = true;
|
| 93 | IngestServerTester.this.field_153054_l = System.currentTimeMillis();
|
| 94 | IngestServerTester.this.func_153034_a(IngestServerTester.IngestTestState.ConnectingToServer);
|
| 95 | }
|
| 96 | else
|
| 97 | {
|
| 98 | IngestServerTester.this.field_153056_n = false;
|
| 99 | IngestServerTester.this.func_153034_a(IngestServerTester.IngestTestState.DoneTestingServer);
|
| 100 | }
|
| 101 | }
|
| 102 | public void stopCallback(ErrorCode p_stopCallback_1_)
|
| 103 | {
|
| 104 | if (ErrorCode.failed(p_stopCallback_1_))
|
| 105 | {
|
| 106 | System.out.println("IngestTester.stopCallback failed to stop - " + IngestServerTester.this.field_153059_q.serverName + ": " + p_stopCallback_1_.toString());
|
| 107 | }
|
| 108 |
|
| 109 | IngestServerTester.this.field_176007_z = false;
|
| 110 | IngestServerTester.this.field_176009_x = false;
|
| 111 | IngestServerTester.this.func_153034_a(IngestServerTester.IngestTestState.DoneTestingServer);
|
| 112 | IngestServerTester.this.field_153059_q = null;
|
| 113 |
|
| 114 | if (IngestServerTester.this.field_153060_r)
|
| 115 | {
|
| 116 | IngestServerTester.this.func_153034_a(IngestServerTester.IngestTestState.Cancelling);
|
| 117 | }
|
| 118 | }
|
| 119 | public void sendActionMetaDataCallback(ErrorCode p_sendActionMetaDataCallback_1_)
|
| 120 | {
|
| 121 | }
|
| 122 | public void sendStartSpanMetaDataCallback(ErrorCode p_sendStartSpanMetaDataCallback_1_)
|
| 123 | {
|
| 124 | }
|
| 125 | public void sendEndSpanMetaDataCallback(ErrorCode p_sendEndSpanMetaDataCallback_1_)
|
| 126 | {
|
| 127 | }
|
| 128 | };
|
| 129 | protected IStatCallbacks field_176006_B = new IStatCallbacks()
|
| 130 | {
|
| 131 | public void statCallback(StatType p_statCallback_1_, long p_statCallback_2_)
|
| 132 | {
|
| 133 | switch (p_statCallback_1_)
|
| 134 | {
|
| 135 | case TTV_ST_RTMPSTATE:
|
| 136 | IngestServerTester.this.field_153051_i = RTMPState.lookupValue((int)p_statCallback_2_);
|
| 137 | break;
|
| 138 |
|
| 139 | case TTV_ST_RTMPDATASENT:
|
| 140 | IngestServerTester.this.field_153050_h = p_statCallback_2_;
|
| 141 | }
|
| 142 | }
|
| 143 | };
|
| 144 |
|
| 145 | public void func_153042_a(IngestServerTester.IngestTestListener p_153042_1_)
|
| 146 | {
|
| 147 | this.field_153044_b = p_153042_1_;
|
| 148 | }
|
| 149 |
|
| 150 | public IngestServer func_153040_c()
|
| 151 | {
|
| 152 | return this.field_153059_q;
|
| 153 | }
|
| 154 |
|
| 155 | public int func_153028_p()
|
| 156 | {
|
| 157 | return this.field_153062_t;
|
| 158 | }
|
| 159 |
|
| 160 | public boolean func_153032_e()
|
| 161 | {
|
| 162 | return this.field_153047_e == IngestServerTester.IngestTestState.Finished || this.field_153047_e == IngestServerTester.IngestTestState.Cancelled || this.field_153047_e == IngestServerTester.IngestTestState.Failed;
|
| 163 | }
|
| 164 |
|
| 165 | public float func_153030_h()
|
| 166 | {
|
| 167 | return this.field_153066_x;
|
| 168 | }
|
| 169 |
|
| 170 | public IngestServerTester(Stream p_i1019_1_, IngestList p_i1019_2_)
|
| 171 | {
|
| 172 | this.field_153045_c = p_i1019_1_;
|
| 173 | this.field_153046_d = p_i1019_2_;
|
| 174 | }
|
| 175 |
|
| 176 | public void func_176004_j()
|
| 177 | {
|
| 178 | if (this.field_153047_e == IngestServerTester.IngestTestState.Uninitalized)
|
| 179 | {
|
| 180 | this.field_153062_t = 0;
|
| 181 | this.field_153060_r = false;
|
| 182 | this.field_153061_s = false;
|
| 183 | this.field_176009_x = false;
|
| 184 | this.field_176008_y = false;
|
| 185 | this.field_176007_z = false;
|
| 186 | this.field_153058_p = this.field_153045_c.getStatCallbacks();
|
| 187 | this.field_153045_c.setStatCallbacks(this.field_176006_B);
|
| 188 | this.field_153057_o = this.field_153045_c.getStreamCallbacks();
|
| 189 | this.field_153045_c.setStreamCallbacks(this.field_176005_A);
|
| 190 | this.field_153052_j = new VideoParams();
|
| 191 | this.field_153052_j.targetFps = 60;
|
| 192 | this.field_153052_j.maxKbps = 3500;
|
| 193 | this.field_153052_j.outputWidth = 1280;
|
| 194 | this.field_153052_j.outputHeight = 720;
|
| 195 | this.field_153052_j.pixelFormat = PixelFormat.TTV_PF_BGRA;
|
| 196 | this.field_153052_j.encodingCpuUsage = EncodingCpuUsage.TTV_ECU_HIGH;
|
| 197 | this.field_153052_j.disableAdaptiveBitrate = true;
|
| 198 | this.field_153052_j.verticalFlip = false;
|
| 199 | this.field_153045_c.getDefaultParams(this.field_153052_j);
|
| 200 | this.audioParameters = new AudioParams();
|
| 201 | this.audioParameters.audioEnabled = false;
|
| 202 | this.audioParameters.enableMicCapture = false;
|
| 203 | this.audioParameters.enablePlaybackCapture = false;
|
| 204 | this.audioParameters.enablePassthroughAudio = false;
|
| 205 | this.field_153055_m = Lists.<FrameBuffer>newArrayList();
|
| 206 | int i = 3;
|
| 207 |
|
| 208 | for (int j = 0; j < i; ++j)
|
| 209 | {
|
| 210 | FrameBuffer framebuffer = this.field_153045_c.allocateFrameBuffer(this.field_153052_j.outputWidth * this.field_153052_j.outputHeight * 4);
|
| 211 |
|
| 212 | if (!framebuffer.getIsValid())
|
| 213 | {
|
| 214 | this.func_153031_o();
|
| 215 | this.func_153034_a(IngestServerTester.IngestTestState.Failed);
|
| 216 | return;
|
| 217 | }
|
| 218 |
|
| 219 | this.field_153055_m.add(framebuffer);
|
| 220 | this.field_153045_c.randomizeFrameBuffer(framebuffer);
|
| 221 | }
|
| 222 |
|
| 223 | this.func_153034_a(IngestServerTester.IngestTestState.Starting);
|
| 224 | this.field_153054_l = System.currentTimeMillis();
|
| 225 | }
|
| 226 | }
|
| 227 |
|
| 228 | @SuppressWarnings("incomplete-switch")
|
| 229 | public void func_153041_j()
|
| 230 | {
|
| 231 | if (!this.func_153032_e() && this.field_153047_e != IngestServerTester.IngestTestState.Uninitalized)
|
| 232 | {
|
| 233 | if (!this.field_176008_y && !this.field_176007_z)
|
| 234 | {
|
| 235 | switch (this.field_153047_e)
|
| 236 | {
|
| 237 | case Starting:
|
| 238 | case DoneTestingServer:
|
| 239 | if (this.field_153059_q != null)
|
| 240 | {
|
| 241 | if (this.field_153061_s || !this.field_153056_n)
|
| 242 | {
|
| 243 | this.field_153059_q.bitrateKbps = 0.0F;
|
| 244 | }
|
| 245 |
|
| 246 | this.func_153035_b(this.field_153059_q);
|
| 247 | }
|
| 248 | else
|
| 249 | {
|
| 250 | this.field_153054_l = 0L;
|
| 251 | this.field_153061_s = false;
|
| 252 | this.field_153056_n = true;
|
| 253 |
|
| 254 | if (this.field_153047_e != IngestServerTester.IngestTestState.Starting)
|
| 255 | {
|
| 256 | ++this.field_153062_t;
|
| 257 | }
|
| 258 |
|
| 259 | if (this.field_153062_t < this.field_153046_d.getServers().length)
|
| 260 | {
|
| 261 | this.field_153059_q = this.field_153046_d.getServers()[this.field_153062_t];
|
| 262 | this.func_153036_a(this.field_153059_q);
|
| 263 | }
|
| 264 | else
|
| 265 | {
|
| 266 | this.func_153034_a(IngestServerTester.IngestTestState.Finished);
|
| 267 | }
|
| 268 | }
|
| 269 |
|
| 270 | break;
|
| 271 |
|
| 272 | case ConnectingToServer:
|
| 273 | case TestingServer:
|
| 274 | this.func_153029_c(this.field_153059_q);
|
| 275 | break;
|
| 276 |
|
| 277 | case Cancelling:
|
| 278 | this.func_153034_a(IngestServerTester.IngestTestState.Cancelled);
|
| 279 | }
|
| 280 |
|
| 281 | this.func_153038_n();
|
| 282 |
|
| 283 | if (this.field_153047_e == IngestServerTester.IngestTestState.Cancelled || this.field_153047_e == IngestServerTester.IngestTestState.Finished)
|
| 284 | {
|
| 285 | this.func_153031_o();
|
| 286 | }
|
| 287 | }
|
| 288 | }
|
| 289 | }
|
| 290 |
|
| 291 | public void func_153039_l()
|
| 292 | {
|
| 293 | if (!this.func_153032_e() && !this.field_153060_r)
|
| 294 | {
|
| 295 | this.field_153060_r = true;
|
| 296 |
|
| 297 | if (this.field_153059_q != null)
|
| 298 | {
|
| 299 | this.field_153059_q.bitrateKbps = 0.0F;
|
| 300 | }
|
| 301 | }
|
| 302 | }
|
| 303 |
|
| 304 | protected boolean func_153036_a(IngestServer p_153036_1_)
|
| 305 | {
|
| 306 | this.field_153056_n = true;
|
| 307 | this.field_153050_h = 0L;
|
| 308 | this.field_153051_i = RTMPState.Idle;
|
| 309 | this.field_153059_q = p_153036_1_;
|
| 310 | this.field_176008_y = true;
|
| 311 | this.func_153034_a(IngestServerTester.IngestTestState.ConnectingToServer);
|
| 312 | ErrorCode errorcode = this.field_153045_c.start(this.field_153052_j, this.audioParameters, p_153036_1_, StartFlags.TTV_Start_BandwidthTest, true);
|
| 313 |
|
| 314 | if (ErrorCode.failed(errorcode))
|
| 315 | {
|
| 316 | this.field_176008_y = false;
|
| 317 | this.field_153056_n = false;
|
| 318 | this.func_153034_a(IngestServerTester.IngestTestState.DoneTestingServer);
|
| 319 | return false;
|
| 320 | }
|
| 321 | else
|
| 322 | {
|
| 323 | this.field_153064_v = this.field_153050_h;
|
| 324 | p_153036_1_.bitrateKbps = 0.0F;
|
| 325 | this.field_153063_u = 0;
|
| 326 | return true;
|
| 327 | }
|
| 328 | }
|
| 329 |
|
| 330 | protected void func_153035_b(IngestServer p_153035_1_)
|
| 331 | {
|
| 332 | if (this.field_176008_y)
|
| 333 | {
|
| 334 | this.field_153061_s = true;
|
| 335 | }
|
| 336 | else if (this.field_176009_x)
|
| 337 | {
|
| 338 | this.field_176007_z = true;
|
| 339 | ErrorCode errorcode = this.field_153045_c.stop(true);
|
| 340 |
|
| 341 | if (ErrorCode.failed(errorcode))
|
| 342 | {
|
| 343 | this.field_176005_A.stopCallback(ErrorCode.TTV_EC_SUCCESS);
|
| 344 | System.out.println("Stop failed: " + errorcode.toString());
|
| 345 | }
|
| 346 |
|
| 347 | this.field_153045_c.pollStats();
|
| 348 | }
|
| 349 | else
|
| 350 | {
|
| 351 | this.field_176005_A.stopCallback(ErrorCode.TTV_EC_SUCCESS);
|
| 352 | }
|
| 353 | }
|
| 354 |
|
| 355 | protected long func_153037_m()
|
| 356 | {
|
| 357 | return System.currentTimeMillis() - this.field_153054_l;
|
| 358 | }
|
| 359 |
|
| 360 | protected void func_153038_n()
|
| 361 | {
|
| 362 | float f = (float)this.func_153037_m();
|
| 363 |
|
| 364 | switch (this.field_153047_e)
|
| 365 | {
|
| 366 | case Starting:
|
| 367 | case ConnectingToServer:
|
| 368 | case Uninitalized:
|
| 369 | case Finished:
|
| 370 | case Cancelled:
|
| 371 | case Failed:
|
| 372 | this.field_153066_x = 0.0F;
|
| 373 | break;
|
| 374 |
|
| 375 | case DoneTestingServer:
|
| 376 | this.field_153066_x = 1.0F;
|
| 377 | break;
|
| 378 |
|
| 379 | case TestingServer:
|
| 380 | case Cancelling:
|
| 381 | default:
|
| 382 | this.field_153066_x = f / (float)this.field_153048_f;
|
| 383 | }
|
| 384 |
|
| 385 | switch (this.field_153047_e)
|
| 386 | {
|
| 387 | case Finished:
|
| 388 | case Cancelled:
|
| 389 | case Failed:
|
| 390 | this.field_153065_w = 1.0F;
|
| 391 | break;
|
| 392 |
|
| 393 | default:
|
| 394 | this.field_153065_w = (float)this.field_153062_t / (float)this.field_153046_d.getServers().length;
|
| 395 | this.field_153065_w += this.field_153066_x / (float)this.field_153046_d.getServers().length;
|
| 396 | }
|
| 397 | }
|
| 398 |
|
| 399 | protected boolean func_153029_c(IngestServer p_153029_1_)
|
| 400 | {
|
| 401 | if (!this.field_153061_s && !this.field_153060_r && this.func_153037_m() < this.field_153048_f)
|
| 402 | {
|
| 403 | if (!this.field_176008_y && !this.field_176007_z)
|
| 404 | {
|
| 405 | ErrorCode errorcode = this.field_153045_c.submitVideoFrame((FrameBuffer)this.field_153055_m.get(this.field_153063_u));
|
| 406 |
|
| 407 | if (ErrorCode.failed(errorcode))
|
| 408 | {
|
| 409 | this.field_153056_n = false;
|
| 410 | this.func_153034_a(IngestServerTester.IngestTestState.DoneTestingServer);
|
| 411 | return false;
|
| 412 | }
|
| 413 | else
|
| 414 | {
|
| 415 | this.field_153063_u = (this.field_153063_u + 1) % this.field_153055_m.size();
|
| 416 | this.field_153045_c.pollStats();
|
| 417 |
|
| 418 | if (this.field_153051_i == RTMPState.SendVideo)
|
| 419 | {
|
| 420 | this.func_153034_a(IngestServerTester.IngestTestState.TestingServer);
|
| 421 | long i = this.func_153037_m();
|
| 422 |
|
| 423 | if (i > 0L && this.field_153050_h > this.field_153064_v)
|
| 424 | {
|
| 425 | p_153029_1_.bitrateKbps = (float)(this.field_153050_h * 8L) / (float)this.func_153037_m();
|
| 426 | this.field_153064_v = this.field_153050_h;
|
| 427 | }
|
| 428 | }
|
| 429 |
|
| 430 | return true;
|
| 431 | }
|
| 432 | }
|
| 433 | else
|
| 434 | {
|
| 435 | return true;
|
| 436 | }
|
| 437 | }
|
| 438 | else
|
| 439 | {
|
| 440 | this.func_153034_a(IngestServerTester.IngestTestState.DoneTestingServer);
|
| 441 | return true;
|
| 442 | }
|
| 443 | }
|
| 444 |
|
| 445 | protected void func_153031_o()
|
| 446 | {
|
| 447 | this.field_153059_q = null;
|
| 448 |
|
| 449 | if (this.field_153055_m != null)
|
| 450 | {
|
| 451 | for (int i = 0; i < this.field_153055_m.size(); ++i)
|
| 452 | {
|
| 453 | ((FrameBuffer)this.field_153055_m.get(i)).free();
|
| 454 | }
|
| 455 |
|
| 456 | this.field_153055_m = null;
|
| 457 | }
|
| 458 |
|
| 459 | if (this.field_153045_c.getStatCallbacks() == this.field_176006_B)
|
| 460 | {
|
| 461 | this.field_153045_c.setStatCallbacks(this.field_153058_p);
|
| 462 | this.field_153058_p = null;
|
| 463 | }
|
| 464 |
|
| 465 | if (this.field_153045_c.getStreamCallbacks() == this.field_176005_A)
|
| 466 | {
|
| 467 | this.field_153045_c.setStreamCallbacks(this.field_153057_o);
|
| 468 | this.field_153057_o = null;
|
| 469 | }
|
| 470 | }
|
| 471 |
|
| 472 | protected void func_153034_a(IngestServerTester.IngestTestState p_153034_1_)
|
| 473 | {
|
| 474 | if (p_153034_1_ != this.field_153047_e)
|
| 475 | {
|
| 476 | this.field_153047_e = p_153034_1_;
|
| 477 |
|
| 478 | if (this.field_153044_b != null)
|
| 479 | {
|
| 480 | this.field_153044_b.func_152907_a(this, p_153034_1_);
|
| 481 | }
|
| 482 | }
|
| 483 | }
|
| 484 |
|
| 485 | public interface IngestTestListener
|
| 486 | {
|
| 487 | void func_152907_a(IngestServerTester p_152907_1_, IngestServerTester.IngestTestState p_152907_2_);
|
| 488 | }
|
| 489 |
|
| 490 | public static enum IngestTestState
|
| 491 | {
|
| 492 | Uninitalized,
|
| 493 | Starting,
|
| 494 | ConnectingToServer,
|
| 495 | TestingServer,
|
| 496 | DoneTestingServer,
|
| 497 | Finished,
|
| 498 | Cancelling,
|
| 499 | Cancelled,
|
| 500 | Failed;
|
| 501 | }
|
| 502 | }
|
| 503 |
|