| 1 | package net.minecraft.client.stream;
|
| 2 |
|
| 3 | import com.google.common.base.Strings;
|
| 4 | import com.google.common.collect.Maps;
|
| 5 | import com.google.gson.JsonObject;
|
| 6 | import com.google.gson.JsonParser;
|
| 7 | import com.mojang.authlib.properties.Property;
|
| 8 | import java.io.IOException;
|
| 9 | import java.net.URL;
|
| 10 | import java.net.URLEncoder;
|
| 11 | import java.util.Map;
|
| 12 | import java.util.Set;
|
| 13 | import net.minecraft.client.Minecraft;
|
| 14 | import net.minecraft.client.gui.stream.GuiTwitchUserMode;
|
| 15 | import net.minecraft.client.renderer.GlStateManager;
|
| 16 | import net.minecraft.client.renderer.OpenGlHelper;
|
| 17 | import net.minecraft.client.renderer.Tessellator;
|
| 18 | import net.minecraft.client.renderer.WorldRenderer;
|
| 19 | import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
| 20 | import net.minecraft.client.settings.GameSettings;
|
| 21 | import net.minecraft.client.shader.Framebuffer;
|
| 22 | import net.minecraft.event.ClickEvent;
|
| 23 | import net.minecraft.event.HoverEvent;
|
| 24 | import net.minecraft.util.ChatComponentText;
|
| 25 | import net.minecraft.util.ChatComponentTranslation;
|
| 26 | import net.minecraft.util.EnumChatFormatting;
|
| 27 | import net.minecraft.util.HttpUtil;
|
| 28 | import net.minecraft.util.IChatComponent;
|
| 29 | import net.minecraft.util.JsonUtils;
|
| 30 | import net.minecraft.util.MathHelper;
|
| 31 | import net.minecraft.util.Util;
|
| 32 | import org.apache.logging.log4j.LogManager;
|
| 33 | import org.apache.logging.log4j.Logger;
|
| 34 | import org.apache.logging.log4j.Marker;
|
| 35 | import org.apache.logging.log4j.MarkerManager;
|
| 36 | import org.lwjgl.opengl.GL11;
|
| 37 | import tv.twitch.AuthToken;
|
| 38 | import tv.twitch.ErrorCode;
|
| 39 | import tv.twitch.broadcast.EncodingCpuUsage;
|
| 40 | import tv.twitch.broadcast.FrameBuffer;
|
| 41 | import tv.twitch.broadcast.GameInfo;
|
| 42 | import tv.twitch.broadcast.IngestList;
|
| 43 | import tv.twitch.broadcast.IngestServer;
|
| 44 | import tv.twitch.broadcast.StreamInfo;
|
| 45 | import tv.twitch.broadcast.VideoParams;
|
| 46 | import tv.twitch.chat.ChatRawMessage;
|
| 47 | import tv.twitch.chat.ChatTokenizedMessage;
|
| 48 | import tv.twitch.chat.ChatUserInfo;
|
| 49 | import tv.twitch.chat.ChatUserMode;
|
| 50 | import tv.twitch.chat.ChatUserSubscription;
|
| 51 |
|
| 52 | public class TwitchStream implements BroadcastController.BroadcastListener, ChatController.ChatListener, IngestServerTester.IngestTestListener, IStream
|
| 53 | {
|
| 54 | private static final Logger LOGGER = LogManager.getLogger();
|
| 55 | public static final Marker STREAM_MARKER = MarkerManager.getMarker("STREAM");
|
| 56 | private final BroadcastController broadcastController;
|
| 57 | private final ChatController chatController;
|
| 58 | private String field_176029_e;
|
| 59 |
|
| 60 | /** the minecraft instance */
|
| 61 | private final Minecraft mc;
|
| 62 | private final IChatComponent twitchComponent = new ChatComponentText("Twitch");
|
| 63 | private final Map<String, ChatUserInfo> field_152955_g = Maps.<String, ChatUserInfo>newHashMap();
|
| 64 | private Framebuffer framebuffer;
|
| 65 | private boolean field_152957_i;
|
| 66 |
|
| 67 | /** stream's target fps */
|
| 68 | private int targetFPS = 30;
|
| 69 | private long field_152959_k = 0L;
|
| 70 | private boolean field_152960_l = false;
|
| 71 | private boolean loggedIn;
|
| 72 | private boolean field_152962_n;
|
| 73 | private boolean field_152963_o;
|
| 74 | private IStream.AuthFailureReason authFailureReason = IStream.AuthFailureReason.ERROR;
|
| 75 | private static boolean field_152965_q;
|
| 76 |
|
| 77 | public TwitchStream(Minecraft mcIn, final Property streamProperty)
|
| 78 | {
|
| 79 | this.mc = mcIn;
|
| 80 | this.broadcastController = new BroadcastController();
|
| 81 | this.chatController = new ChatController();
|
| 82 | this.broadcastController.setBroadcastListener(this);
|
| 83 | this.chatController.func_152990_a(this);
|
| 84 | this.broadcastController.func_152842_a("nmt37qblda36pvonovdkbopzfzw3wlq");
|
| 85 | this.chatController.func_152984_a("nmt37qblda36pvonovdkbopzfzw3wlq");
|
| 86 | this.twitchComponent.getChatStyle().setColor(EnumChatFormatting.DARK_PURPLE);
|
| 87 |
|
| 88 | if (streamProperty != null && !Strings.isNullOrEmpty(streamProperty.getValue()) && OpenGlHelper.framebufferSupported)
|
| 89 | {
|
| 90 | Thread thread = new Thread("Twitch authenticator")
|
| 91 | {
|
| 92 | public void run()
|
| 93 | {
|
| 94 | try
|
| 95 | {
|
| 96 | URL url = new URL("https://api.twitch.tv/kraken?oauth_token=" + URLEncoder.encode(streamProperty.getValue(), "UTF-8"));
|
| 97 | String s = HttpUtil.get(url);
|
| 98 | JsonObject jsonobject = JsonUtils.getJsonObject((new JsonParser()).parse(s), "Response");
|
| 99 | JsonObject jsonobject1 = JsonUtils.getJsonObject(jsonobject, "token");
|
| 100 |
|
| 101 | if (JsonUtils.getBoolean(jsonobject1, "valid"))
|
| 102 | {
|
| 103 | String s1 = JsonUtils.getString(jsonobject1, "user_name");
|
| 104 | TwitchStream.LOGGER.debug(TwitchStream.STREAM_MARKER, "Authenticated with twitch; username is {}", new Object[] {s1});
|
| 105 | AuthToken authtoken = new AuthToken();
|
| 106 | authtoken.data = streamProperty.getValue();
|
| 107 | TwitchStream.this.broadcastController.func_152818_a(s1, authtoken);
|
| 108 | TwitchStream.this.chatController.func_152998_c(s1);
|
| 109 | TwitchStream.this.chatController.func_152994_a(authtoken);
|
| 110 | Runtime.getRuntime().addShutdownHook(new Thread("Twitch shutdown hook")
|
| 111 | {
|
| 112 | public void run()
|
| 113 | {
|
| 114 | TwitchStream.this.shutdownStream();
|
| 115 | }
|
| 116 | });
|
| 117 | TwitchStream.this.broadcastController.func_152817_A();
|
| 118 | TwitchStream.this.chatController.func_175984_n();
|
| 119 | }
|
| 120 | else
|
| 121 | {
|
| 122 | TwitchStream.this.authFailureReason = IStream.AuthFailureReason.INVALID_TOKEN;
|
| 123 | TwitchStream.LOGGER.error(TwitchStream.STREAM_MARKER, "Given twitch access token is invalid");
|
| 124 | }
|
| 125 | }
|
| 126 | catch (IOException ioexception)
|
| 127 | {
|
| 128 | TwitchStream.this.authFailureReason = IStream.AuthFailureReason.ERROR;
|
| 129 | TwitchStream.LOGGER.error(TwitchStream.STREAM_MARKER, (String)"Could not authenticate with twitch", (Throwable)ioexception);
|
| 130 | }
|
| 131 | }
|
| 132 | };
|
| 133 | thread.setDaemon(true);
|
| 134 | thread.start();
|
| 135 | }
|
| 136 | }
|
| 137 |
|
| 138 | /**
|
| 139 | * Shuts down a steam
|
| 140 | */
|
| 141 | public void shutdownStream()
|
| 142 | {
|
| 143 | LOGGER.debug(STREAM_MARKER, "Shutdown streaming");
|
| 144 | this.broadcastController.statCallback();
|
| 145 | this.chatController.func_175988_p();
|
| 146 | }
|
| 147 |
|
| 148 | public void func_152935_j()
|
| 149 | {
|
| 150 | int i = this.mc.gameSettings.streamChatEnabled;
|
| 151 | boolean flag = this.field_176029_e != null && this.chatController.func_175990_d(this.field_176029_e);
|
| 152 | boolean flag1 = this.chatController.func_153000_j() == ChatController.ChatState.Initialized && (this.field_176029_e == null || this.chatController.func_175989_e(this.field_176029_e) == ChatController.EnumChannelState.Disconnected);
|
| 153 |
|
| 154 | if (i == 2)
|
| 155 | {
|
| 156 | if (flag)
|
| 157 | {
|
| 158 | LOGGER.debug(STREAM_MARKER, "Disconnecting from twitch chat per user options");
|
| 159 | this.chatController.func_175991_l(this.field_176029_e);
|
| 160 | }
|
| 161 | }
|
| 162 | else if (i == 1)
|
| 163 | {
|
| 164 | if (flag1 && this.broadcastController.func_152849_q())
|
| 165 | {
|
| 166 | LOGGER.debug(STREAM_MARKER, "Connecting to twitch chat per user options");
|
| 167 | this.func_152942_I();
|
| 168 | }
|
| 169 | }
|
| 170 | else if (i == 0)
|
| 171 | {
|
| 172 | if (flag && !this.isBroadcasting())
|
| 173 | {
|
| 174 | LOGGER.debug(STREAM_MARKER, "Disconnecting from twitch chat as user is no longer streaming");
|
| 175 | this.chatController.func_175991_l(this.field_176029_e);
|
| 176 | }
|
| 177 | else if (flag1 && this.isBroadcasting())
|
| 178 | {
|
| 179 | LOGGER.debug(STREAM_MARKER, "Connecting to twitch chat as user is streaming");
|
| 180 | this.func_152942_I();
|
| 181 | }
|
| 182 | }
|
| 183 |
|
| 184 | this.broadcastController.func_152821_H();
|
| 185 | this.chatController.func_152997_n();
|
| 186 | }
|
| 187 |
|
| 188 | protected void func_152942_I()
|
| 189 | {
|
| 190 | ChatController.ChatState chatcontroller$chatstate = this.chatController.func_153000_j();
|
| 191 | String s = this.broadcastController.getChannelInfo().name;
|
| 192 | this.field_176029_e = s;
|
| 193 |
|
| 194 | if (chatcontroller$chatstate != ChatController.ChatState.Initialized)
|
| 195 | {
|
| 196 | LOGGER.warn("Invalid twitch chat state {}", new Object[] {chatcontroller$chatstate});
|
| 197 | }
|
| 198 | else if (this.chatController.func_175989_e(this.field_176029_e) == ChatController.EnumChannelState.Disconnected)
|
| 199 | {
|
| 200 | this.chatController.func_152986_d(s);
|
| 201 | }
|
| 202 | else
|
| 203 | {
|
| 204 | LOGGER.warn("Invalid twitch chat state {}", new Object[] {chatcontroller$chatstate});
|
| 205 | }
|
| 206 | }
|
| 207 |
|
| 208 | public void func_152922_k()
|
| 209 | {
|
| 210 | if (this.broadcastController.isBroadcasting() && !this.broadcastController.isBroadcastPaused())
|
| 211 | {
|
| 212 | long i = System.nanoTime();
|
| 213 | long j = (long)(1000000000 / this.targetFPS);
|
| 214 | long k = i - this.field_152959_k;
|
| 215 | boolean flag = k >= j;
|
| 216 |
|
| 217 | if (flag)
|
| 218 | {
|
| 219 | FrameBuffer framebuffer = this.broadcastController.func_152822_N();
|
| 220 | Framebuffer framebuffer1 = this.mc.getFramebuffer();
|
| 221 | this.framebuffer.bindFramebuffer(true);
|
| 222 | GlStateManager.matrixMode(5889);
|
| 223 | GlStateManager.pushMatrix();
|
| 224 | GlStateManager.loadIdentity();
|
| 225 | GlStateManager.ortho(0.0D, (double)this.framebuffer.framebufferWidth, (double)this.framebuffer.framebufferHeight, 0.0D, 1000.0D, 3000.0D);
|
| 226 | GlStateManager.matrixMode(5888);
|
| 227 | GlStateManager.pushMatrix();
|
| 228 | GlStateManager.loadIdentity();
|
| 229 | GlStateManager.translate(0.0F, 0.0F, -2000.0F);
|
| 230 | GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
| 231 | GlStateManager.viewport(0, 0, this.framebuffer.framebufferWidth, this.framebuffer.framebufferHeight);
|
| 232 | GlStateManager.enableTexture2D();
|
| 233 | GlStateManager.disableAlpha();
|
| 234 | GlStateManager.disableBlend();
|
| 235 | float f = (float)this.framebuffer.framebufferWidth;
|
| 236 | float f1 = (float)this.framebuffer.framebufferHeight;
|
| 237 | float f2 = (float)framebuffer1.framebufferWidth / (float)framebuffer1.framebufferTextureWidth;
|
| 238 | float f3 = (float)framebuffer1.framebufferHeight / (float)framebuffer1.framebufferTextureHeight;
|
| 239 | framebuffer1.bindFramebufferTexture();
|
| 240 | GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, 9729.0F);
|
| 241 | GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, 9729.0F);
|
| 242 | Tessellator tessellator = Tessellator.getInstance();
|
| 243 | WorldRenderer worldrenderer = tessellator.getWorldRenderer();
|
| 244 | worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);
|
| 245 | worldrenderer.pos(0.0D, (double)f1, 0.0D).tex(0.0D, (double)f3).endVertex();
|
| 246 | worldrenderer.pos((double)f, (double)f1, 0.0D).tex((double)f2, (double)f3).endVertex();
|
| 247 | worldrenderer.pos((double)f, 0.0D, 0.0D).tex((double)f2, 0.0D).endVertex();
|
| 248 | worldrenderer.pos(0.0D, 0.0D, 0.0D).tex(0.0D, 0.0D).endVertex();
|
| 249 | tessellator.draw();
|
| 250 | framebuffer1.unbindFramebufferTexture();
|
| 251 | GlStateManager.popMatrix();
|
| 252 | GlStateManager.matrixMode(5889);
|
| 253 | GlStateManager.popMatrix();
|
| 254 | GlStateManager.matrixMode(5888);
|
| 255 | this.broadcastController.captureFramebuffer(framebuffer);
|
| 256 | this.framebuffer.unbindFramebuffer();
|
| 257 | this.broadcastController.submitStreamFrame(framebuffer);
|
| 258 | this.field_152959_k = i;
|
| 259 | }
|
| 260 | }
|
| 261 | }
|
| 262 |
|
| 263 | public boolean func_152936_l()
|
| 264 | {
|
| 265 | return this.broadcastController.func_152849_q();
|
| 266 | }
|
| 267 |
|
| 268 | public boolean isReadyToBroadcast()
|
| 269 | {
|
| 270 | return this.broadcastController.isReadyToBroadcast();
|
| 271 | }
|
| 272 |
|
| 273 | public boolean isBroadcasting()
|
| 274 | {
|
| 275 | return this.broadcastController.isBroadcasting();
|
| 276 | }
|
| 277 |
|
| 278 | public void func_152911_a(Metadata p_152911_1_, long p_152911_2_)
|
| 279 | {
|
| 280 | if (this.isBroadcasting() && this.field_152957_i)
|
| 281 | {
|
| 282 | long i = this.broadcastController.getStreamTime();
|
| 283 |
|
| 284 | if (!this.broadcastController.func_152840_a(p_152911_1_.func_152810_c(), i + p_152911_2_, p_152911_1_.func_152809_a(), p_152911_1_.func_152806_b()))
|
| 285 | {
|
| 286 | LOGGER.warn(STREAM_MARKER, "Couldn\'t send stream metadata action at {}: {}", new Object[] {Long.valueOf(i + p_152911_2_), p_152911_1_});
|
| 287 | }
|
| 288 | else
|
| 289 | {
|
| 290 | LOGGER.debug(STREAM_MARKER, "Sent stream metadata action at {}: {}", new Object[] {Long.valueOf(i + p_152911_2_), p_152911_1_});
|
| 291 | }
|
| 292 | }
|
| 293 | }
|
| 294 |
|
| 295 | public void func_176026_a(Metadata p_176026_1_, long p_176026_2_, long p_176026_4_)
|
| 296 | {
|
| 297 | if (this.isBroadcasting() && this.field_152957_i)
|
| 298 | {
|
| 299 | long i = this.broadcastController.getStreamTime();
|
| 300 | String s = p_176026_1_.func_152809_a();
|
| 301 | String s1 = p_176026_1_.func_152806_b();
|
| 302 | long j = this.broadcastController.func_177946_b(p_176026_1_.func_152810_c(), i + p_176026_2_, s, s1);
|
| 303 |
|
| 304 | if (j < 0L)
|
| 305 | {
|
| 306 | LOGGER.warn(STREAM_MARKER, "Could not send stream metadata sequence from {} to {}: {}", new Object[] {Long.valueOf(i + p_176026_2_), Long.valueOf(i + p_176026_4_), p_176026_1_});
|
| 307 | }
|
| 308 | else if (this.broadcastController.func_177947_a(p_176026_1_.func_152810_c(), i + p_176026_4_, j, s, s1))
|
| 309 | {
|
| 310 | LOGGER.debug(STREAM_MARKER, "Sent stream metadata sequence from {} to {}: {}", new Object[] {Long.valueOf(i + p_176026_2_), Long.valueOf(i + p_176026_4_), p_176026_1_});
|
| 311 | }
|
| 312 | else
|
| 313 | {
|
| 314 | LOGGER.warn(STREAM_MARKER, "Half-sent stream metadata sequence from {} to {}: {}", new Object[] {Long.valueOf(i + p_176026_2_), Long.valueOf(i + p_176026_4_), p_176026_1_});
|
| 315 | }
|
| 316 | }
|
| 317 | }
|
| 318 |
|
| 319 | public boolean isPaused()
|
| 320 | {
|
| 321 | return this.broadcastController.isBroadcastPaused();
|
| 322 | }
|
| 323 |
|
| 324 | public void requestCommercial()
|
| 325 | {
|
| 326 | if (this.broadcastController.requestCommercial())
|
| 327 | {
|
| 328 | LOGGER.debug(STREAM_MARKER, "Requested commercial from Twitch");
|
| 329 | }
|
| 330 | else
|
| 331 | {
|
| 332 | LOGGER.warn(STREAM_MARKER, "Could not request commercial from Twitch");
|
| 333 | }
|
| 334 | }
|
| 335 |
|
| 336 | /**
|
| 337 | * pauses a stream
|
| 338 | */
|
| 339 | public void pause()
|
| 340 | {
|
| 341 | this.broadcastController.func_152847_F();
|
| 342 | this.field_152962_n = true;
|
| 343 | this.updateStreamVolume();
|
| 344 | }
|
| 345 |
|
| 346 | /**
|
| 347 | * unpauses a stream
|
| 348 | */
|
| 349 | public void unpause()
|
| 350 | {
|
| 351 | this.broadcastController.func_152854_G();
|
| 352 | this.field_152962_n = false;
|
| 353 | this.updateStreamVolume();
|
| 354 | }
|
| 355 |
|
| 356 | public void updateStreamVolume()
|
| 357 | {
|
| 358 | if (this.isBroadcasting())
|
| 359 | {
|
| 360 | float f = this.mc.gameSettings.streamGameVolume;
|
| 361 | boolean flag = this.field_152962_n || f <= 0.0F;
|
| 362 | this.broadcastController.setPlaybackDeviceVolume(flag ? 0.0F : f);
|
| 363 | this.broadcastController.setRecordingDeviceVolume(this.func_152929_G() ? 0.0F : this.mc.gameSettings.streamMicVolume);
|
| 364 | }
|
| 365 | }
|
| 366 |
|
| 367 | public void func_152930_t()
|
| 368 | {
|
| 369 | GameSettings gamesettings = this.mc.gameSettings;
|
| 370 | VideoParams videoparams = this.broadcastController.func_152834_a(formatStreamKbps(gamesettings.streamKbps), formatStreamFps(gamesettings.streamFps), formatStreamBps(gamesettings.streamBytesPerPixel), (float)this.mc.displayWidth / (float)this.mc.displayHeight);
|
| 371 |
|
| 372 | switch (gamesettings.streamCompression)
|
| 373 | {
|
| 374 | case 0:
|
| 375 | videoparams.encodingCpuUsage = EncodingCpuUsage.TTV_ECU_LOW;
|
| 376 | break;
|
| 377 |
|
| 378 | case 1:
|
| 379 | videoparams.encodingCpuUsage = EncodingCpuUsage.TTV_ECU_MEDIUM;
|
| 380 | break;
|
| 381 |
|
| 382 | case 2:
|
| 383 | videoparams.encodingCpuUsage = EncodingCpuUsage.TTV_ECU_HIGH;
|
| 384 | }
|
| 385 |
|
| 386 | if (this.framebuffer == null)
|
| 387 | {
|
| 388 | this.framebuffer = new Framebuffer(videoparams.outputWidth, videoparams.outputHeight, false);
|
| 389 | }
|
| 390 | else
|
| 391 | {
|
| 392 | this.framebuffer.createBindFramebuffer(videoparams.outputWidth, videoparams.outputHeight);
|
| 393 | }
|
| 394 |
|
| 395 | if (gamesettings.streamPreferredServer != null && gamesettings.streamPreferredServer.length() > 0)
|
| 396 | {
|
| 397 | for (IngestServer ingestserver : this.func_152925_v())
|
| 398 | {
|
| 399 | if (ingestserver.serverUrl.equals(gamesettings.streamPreferredServer))
|
| 400 | {
|
| 401 | this.broadcastController.setIngestServer(ingestserver);
|
| 402 | break;
|
| 403 | }
|
| 404 | }
|
| 405 | }
|
| 406 |
|
| 407 | this.targetFPS = videoparams.targetFps;
|
| 408 | this.field_152957_i = gamesettings.streamSendMetadata;
|
| 409 | this.broadcastController.func_152836_a(videoparams);
|
| 410 | LOGGER.info(STREAM_MARKER, "Streaming at {}/{} at {} kbps to {}", new Object[] {Integer.valueOf(videoparams.outputWidth), Integer.valueOf(videoparams.outputHeight), Integer.valueOf(videoparams.maxKbps), this.broadcastController.getIngestServer().serverUrl});
|
| 411 | this.broadcastController.func_152828_a((String)null, "Minecraft", (String)null);
|
| 412 | }
|
| 413 |
|
| 414 | public void stopBroadcasting()
|
| 415 | {
|
| 416 | if (this.broadcastController.stopBroadcasting())
|
| 417 | {
|
| 418 | LOGGER.info(STREAM_MARKER, "Stopped streaming to Twitch");
|
| 419 | }
|
| 420 | else
|
| 421 | {
|
| 422 | LOGGER.warn(STREAM_MARKER, "Could not stop streaming to Twitch");
|
| 423 | }
|
| 424 | }
|
| 425 |
|
| 426 | public void func_152900_a(ErrorCode p_152900_1_, AuthToken p_152900_2_)
|
| 427 | {
|
| 428 | }
|
| 429 |
|
| 430 | public void func_152897_a(ErrorCode p_152897_1_)
|
| 431 | {
|
| 432 | if (ErrorCode.succeeded(p_152897_1_))
|
| 433 | {
|
| 434 | LOGGER.debug(STREAM_MARKER, "Login attempt successful");
|
| 435 | this.loggedIn = true;
|
| 436 | }
|
| 437 | else
|
| 438 | {
|
| 439 | LOGGER.warn(STREAM_MARKER, "Login attempt unsuccessful: {} (error code {})", new Object[] {ErrorCode.getString(p_152897_1_), Integer.valueOf(p_152897_1_.getValue())});
|
| 440 | this.loggedIn = false;
|
| 441 | }
|
| 442 | }
|
| 443 |
|
| 444 | public void func_152898_a(ErrorCode p_152898_1_, GameInfo[] p_152898_2_)
|
| 445 | {
|
| 446 | }
|
| 447 |
|
| 448 | public void func_152891_a(BroadcastController.BroadcastState p_152891_1_)
|
| 449 | {
|
| 450 | LOGGER.debug(STREAM_MARKER, "Broadcast state changed to {}", new Object[] {p_152891_1_});
|
| 451 |
|
| 452 | if (p_152891_1_ == BroadcastController.BroadcastState.Initialized)
|
| 453 | {
|
| 454 | this.broadcastController.func_152827_a(BroadcastController.BroadcastState.Authenticated);
|
| 455 | }
|
| 456 | }
|
| 457 |
|
| 458 | public void func_152895_a()
|
| 459 | {
|
| 460 | LOGGER.info(STREAM_MARKER, "Logged out of twitch");
|
| 461 | }
|
| 462 |
|
| 463 | public void func_152894_a(StreamInfo p_152894_1_)
|
| 464 | {
|
| 465 | LOGGER.debug(STREAM_MARKER, "Stream info updated; {} viewers on stream ID {}", new Object[] {Integer.valueOf(p_152894_1_.viewers), Long.valueOf(p_152894_1_.streamId)});
|
| 466 | }
|
| 467 |
|
| 468 | public void func_152896_a(IngestList p_152896_1_)
|
| 469 | {
|
| 470 | }
|
| 471 |
|
| 472 | public void func_152893_b(ErrorCode p_152893_1_)
|
| 473 | {
|
| 474 | LOGGER.warn(STREAM_MARKER, "Issue submitting frame: {} (Error code {})", new Object[] {ErrorCode.getString(p_152893_1_), Integer.valueOf(p_152893_1_.getValue())});
|
| 475 | this.mc.ingameGUI.getChatGUI().printChatMessageWithOptionalDeletion(new ChatComponentText("Issue streaming frame: " + p_152893_1_ + " (" + ErrorCode.getString(p_152893_1_) + ")"), 2);
|
| 476 | }
|
| 477 |
|
| 478 | public void func_152899_b()
|
| 479 | {
|
| 480 | this.updateStreamVolume();
|
| 481 | LOGGER.info(STREAM_MARKER, "Broadcast to Twitch has started");
|
| 482 | }
|
| 483 |
|
| 484 | public void func_152901_c()
|
| 485 | {
|
| 486 | LOGGER.info(STREAM_MARKER, "Broadcast to Twitch has stopped");
|
| 487 | }
|
| 488 |
|
| 489 | public void func_152892_c(ErrorCode p_152892_1_)
|
| 490 | {
|
| 491 | if (p_152892_1_ == ErrorCode.TTV_EC_SOUNDFLOWER_NOT_INSTALLED)
|
| 492 | {
|
| 493 | IChatComponent ichatcomponent = new ChatComponentTranslation("stream.unavailable.soundflower.chat.link", new Object[0]);
|
| 494 | ichatcomponent.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://help.mojang.com/customer/portal/articles/1374877-configuring-soundflower-for-streaming-on-apple-computers"));
|
| 495 | ichatcomponent.getChatStyle().setUnderlined(Boolean.valueOf(true));
|
| 496 | IChatComponent ichatcomponent1 = new ChatComponentTranslation("stream.unavailable.soundflower.chat", new Object[] {ichatcomponent});
|
| 497 | ichatcomponent1.getChatStyle().setColor(EnumChatFormatting.DARK_RED);
|
| 498 | this.mc.ingameGUI.getChatGUI().printChatMessage(ichatcomponent1);
|
| 499 | }
|
| 500 | else
|
| 501 | {
|
| 502 | IChatComponent ichatcomponent2 = new ChatComponentTranslation("stream.unavailable.unknown.chat", new Object[] {ErrorCode.getString(p_152892_1_)});
|
| 503 | ichatcomponent2.getChatStyle().setColor(EnumChatFormatting.DARK_RED);
|
| 504 | this.mc.ingameGUI.getChatGUI().printChatMessage(ichatcomponent2);
|
| 505 | }
|
| 506 | }
|
| 507 |
|
| 508 | public void func_152907_a(IngestServerTester p_152907_1_, IngestServerTester.IngestTestState p_152907_2_)
|
| 509 | {
|
| 510 | LOGGER.debug(STREAM_MARKER, "Ingest test state changed to {}", new Object[] {p_152907_2_});
|
| 511 |
|
| 512 | if (p_152907_2_ == IngestServerTester.IngestTestState.Finished)
|
| 513 | {
|
| 514 | this.field_152960_l = true;
|
| 515 | }
|
| 516 | }
|
| 517 |
|
| 518 | public static int formatStreamFps(float p_152948_0_)
|
| 519 | {
|
| 520 | return MathHelper.floor_float(10.0F + p_152948_0_ * 50.0F);
|
| 521 | }
|
| 522 |
|
| 523 | public static int formatStreamKbps(float p_152946_0_)
|
| 524 | {
|
| 525 | return MathHelper.floor_float(230.0F + p_152946_0_ * 3270.0F);
|
| 526 | }
|
| 527 |
|
| 528 | public static float formatStreamBps(float p_152947_0_)
|
| 529 | {
|
| 530 | return 0.1F + p_152947_0_ * 0.1F;
|
| 531 | }
|
| 532 |
|
| 533 | public IngestServer[] func_152925_v()
|
| 534 | {
|
| 535 | return this.broadcastController.getIngestList().getServers();
|
| 536 | }
|
| 537 |
|
| 538 | public void func_152909_x()
|
| 539 | {
|
| 540 | IngestServerTester ingestservertester = this.broadcastController.func_152838_J();
|
| 541 |
|
| 542 | if (ingestservertester != null)
|
| 543 | {
|
| 544 | ingestservertester.func_153042_a(this);
|
| 545 | }
|
| 546 | }
|
| 547 |
|
| 548 | public IngestServerTester func_152932_y()
|
| 549 | {
|
| 550 | return this.broadcastController.isReady();
|
| 551 | }
|
| 552 |
|
| 553 | public boolean func_152908_z()
|
| 554 | {
|
| 555 | return this.broadcastController.isIngestTesting();
|
| 556 | }
|
| 557 |
|
| 558 | public int func_152920_A()
|
| 559 | {
|
| 560 | return this.isBroadcasting() ? this.broadcastController.getStreamInfo().viewers : 0;
|
| 561 | }
|
| 562 |
|
| 563 | public void func_176023_d(ErrorCode p_176023_1_)
|
| 564 | {
|
| 565 | if (ErrorCode.failed(p_176023_1_))
|
| 566 | {
|
| 567 | LOGGER.error(STREAM_MARKER, "Chat failed to initialize");
|
| 568 | }
|
| 569 | }
|
| 570 |
|
| 571 | public void func_176022_e(ErrorCode p_176022_1_)
|
| 572 | {
|
| 573 | if (ErrorCode.failed(p_176022_1_))
|
| 574 | {
|
| 575 | LOGGER.error(STREAM_MARKER, "Chat failed to shutdown");
|
| 576 | }
|
| 577 | }
|
| 578 |
|
| 579 | public void func_176017_a(ChatController.ChatState p_176017_1_)
|
| 580 | {
|
| 581 | }
|
| 582 |
|
| 583 | public void func_180605_a(String p_180605_1_, ChatRawMessage[] p_180605_2_)
|
| 584 | {
|
| 585 | for (ChatRawMessage chatrawmessage : p_180605_2_)
|
| 586 | {
|
| 587 | this.func_176027_a(chatrawmessage.userName, chatrawmessage);
|
| 588 |
|
| 589 | if (this.func_176028_a(chatrawmessage.modes, chatrawmessage.subscriptions, this.mc.gameSettings.streamChatUserFilter))
|
| 590 | {
|
| 591 | IChatComponent ichatcomponent = new ChatComponentText(chatrawmessage.userName);
|
| 592 | IChatComponent ichatcomponent1 = new ChatComponentTranslation("chat.stream." + (chatrawmessage.action ? "emote" : "text"), new Object[] {this.twitchComponent, ichatcomponent, EnumChatFormatting.getTextWithoutFormattingCodes(chatrawmessage.message)});
|
| 593 |
|
| 594 | if (chatrawmessage.action)
|
| 595 | {
|
| 596 | ichatcomponent1.getChatStyle().setItalic(Boolean.valueOf(true));
|
| 597 | }
|
| 598 |
|
| 599 | IChatComponent ichatcomponent2 = new ChatComponentText("");
|
| 600 | ichatcomponent2.appendSibling(new ChatComponentTranslation("stream.userinfo.chatTooltip", new Object[0]));
|
| 601 |
|
| 602 | for (IChatComponent ichatcomponent3 : GuiTwitchUserMode.func_152328_a(chatrawmessage.modes, chatrawmessage.subscriptions, (IStream)null))
|
| 603 | {
|
| 604 | ichatcomponent2.appendText("\n");
|
| 605 | ichatcomponent2.appendSibling(ichatcomponent3);
|
| 606 | }
|
| 607 |
|
| 608 | ichatcomponent.getChatStyle().setChatHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, ichatcomponent2));
|
| 609 | ichatcomponent.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.TWITCH_USER_INFO, chatrawmessage.userName));
|
| 610 | this.mc.ingameGUI.getChatGUI().printChatMessage(ichatcomponent1);
|
| 611 | }
|
| 612 | }
|
| 613 | }
|
| 614 |
|
| 615 | public void func_176025_a(String p_176025_1_, ChatTokenizedMessage[] p_176025_2_)
|
| 616 | {
|
| 617 | }
|
| 618 |
|
| 619 | private void func_176027_a(String p_176027_1_, ChatRawMessage p_176027_2_)
|
| 620 | {
|
| 621 | ChatUserInfo chatuserinfo = (ChatUserInfo)this.field_152955_g.get(p_176027_1_);
|
| 622 |
|
| 623 | if (chatuserinfo == null)
|
| 624 | {
|
| 625 | chatuserinfo = new ChatUserInfo();
|
| 626 | chatuserinfo.displayName = p_176027_1_;
|
| 627 | this.field_152955_g.put(p_176027_1_, chatuserinfo);
|
| 628 | }
|
| 629 |
|
| 630 | chatuserinfo.subscriptions = p_176027_2_.subscriptions;
|
| 631 | chatuserinfo.modes = p_176027_2_.modes;
|
| 632 | chatuserinfo.nameColorARGB = p_176027_2_.nameColorARGB;
|
| 633 | }
|
| 634 |
|
| 635 | private boolean func_176028_a(Set<ChatUserMode> p_176028_1_, Set<ChatUserSubscription> p_176028_2_, int p_176028_3_)
|
| 636 | {
|
| 637 | return p_176028_1_.contains(ChatUserMode.TTV_CHAT_USERMODE_BANNED) ? false : (p_176028_1_.contains(ChatUserMode.TTV_CHAT_USERMODE_ADMINSTRATOR) ? true : (p_176028_1_.contains(ChatUserMode.TTV_CHAT_USERMODE_MODERATOR) ? true : (p_176028_1_.contains(ChatUserMode.TTV_CHAT_USERMODE_STAFF) ? true : (p_176028_3_ == 0 ? true : (p_176028_3_ == 1 ? p_176028_2_.contains(ChatUserSubscription.TTV_CHAT_USERSUB_SUBSCRIBER) : false)))));
|
| 638 | }
|
| 639 |
|
| 640 | public void func_176018_a(String p_176018_1_, ChatUserInfo[] p_176018_2_, ChatUserInfo[] p_176018_3_, ChatUserInfo[] p_176018_4_)
|
| 641 | {
|
| 642 | for (ChatUserInfo chatuserinfo : p_176018_3_)
|
| 643 | {
|
| 644 | this.field_152955_g.remove(chatuserinfo.displayName);
|
| 645 | }
|
| 646 |
|
| 647 | for (ChatUserInfo chatuserinfo1 : p_176018_4_)
|
| 648 | {
|
| 649 | this.field_152955_g.put(chatuserinfo1.displayName, chatuserinfo1);
|
| 650 | }
|
| 651 |
|
| 652 | for (ChatUserInfo chatuserinfo2 : p_176018_2_)
|
| 653 | {
|
| 654 | this.field_152955_g.put(chatuserinfo2.displayName, chatuserinfo2);
|
| 655 | }
|
| 656 | }
|
| 657 |
|
| 658 | public void func_180606_a(String p_180606_1_)
|
| 659 | {
|
| 660 | LOGGER.debug(STREAM_MARKER, "Chat connected");
|
| 661 | }
|
| 662 |
|
| 663 | public void func_180607_b(String p_180607_1_)
|
| 664 | {
|
| 665 | LOGGER.debug(STREAM_MARKER, "Chat disconnected");
|
| 666 | this.field_152955_g.clear();
|
| 667 | }
|
| 668 |
|
| 669 | public void func_176019_a(String p_176019_1_, String p_176019_2_)
|
| 670 | {
|
| 671 | }
|
| 672 |
|
| 673 | public void func_176021_d()
|
| 674 | {
|
| 675 | }
|
| 676 |
|
| 677 | public void func_176024_e()
|
| 678 | {
|
| 679 | }
|
| 680 |
|
| 681 | public void func_176016_c(String p_176016_1_)
|
| 682 | {
|
| 683 | }
|
| 684 |
|
| 685 | public void func_176020_d(String p_176020_1_)
|
| 686 | {
|
| 687 | }
|
| 688 |
|
| 689 | public boolean func_152927_B()
|
| 690 | {
|
| 691 | return this.field_176029_e != null && this.field_176029_e.equals(this.broadcastController.getChannelInfo().name);
|
| 692 | }
|
| 693 |
|
| 694 | public String func_152921_C()
|
| 695 | {
|
| 696 | return this.field_176029_e;
|
| 697 | }
|
| 698 |
|
| 699 | public ChatUserInfo func_152926_a(String p_152926_1_)
|
| 700 | {
|
| 701 | return (ChatUserInfo)this.field_152955_g.get(p_152926_1_);
|
| 702 | }
|
| 703 |
|
| 704 | public void func_152917_b(String p_152917_1_)
|
| 705 | {
|
| 706 | this.chatController.func_175986_a(this.field_176029_e, p_152917_1_);
|
| 707 | }
|
| 708 |
|
| 709 | public boolean func_152928_D()
|
| 710 | {
|
| 711 | return field_152965_q && this.broadcastController.func_152858_b();
|
| 712 | }
|
| 713 |
|
| 714 | public ErrorCode func_152912_E()
|
| 715 | {
|
| 716 | return !field_152965_q ? ErrorCode.TTV_EC_OS_TOO_OLD : this.broadcastController.getErrorCode();
|
| 717 | }
|
| 718 |
|
| 719 | public boolean func_152913_F()
|
| 720 | {
|
| 721 | return this.loggedIn;
|
| 722 | }
|
| 723 |
|
| 724 | /**
|
| 725 | * mutes or unmutes the microphone based on the boolean parameter passed into the method
|
| 726 | */
|
| 727 | public void muteMicrophone(boolean p_152910_1_)
|
| 728 | {
|
| 729 | this.field_152963_o = p_152910_1_;
|
| 730 | this.updateStreamVolume();
|
| 731 | }
|
| 732 |
|
| 733 | public boolean func_152929_G()
|
| 734 | {
|
| 735 | boolean flag = this.mc.gameSettings.streamMicToggleBehavior == 1;
|
| 736 | return this.field_152962_n || this.mc.gameSettings.streamMicVolume <= 0.0F || flag != this.field_152963_o;
|
| 737 | }
|
| 738 |
|
| 739 | public IStream.AuthFailureReason func_152918_H()
|
| 740 | {
|
| 741 | return this.authFailureReason;
|
| 742 | }
|
| 743 |
|
| 744 | static
|
| 745 | {
|
| 746 | try
|
| 747 | {
|
| 748 | if (Util.getOSType() == Util.EnumOS.WINDOWS)
|
| 749 | {
|
| 750 | System.loadLibrary("avutil-ttv-51");
|
| 751 | System.loadLibrary("swresample-ttv-0");
|
| 752 | System.loadLibrary("libmp3lame-ttv");
|
| 753 |
|
| 754 | if (System.getProperty("os.arch").contains("64"))
|
| 755 | {
|
| 756 | System.loadLibrary("libmfxsw64");
|
| 757 | }
|
| 758 | else
|
| 759 | {
|
| 760 | System.loadLibrary("libmfxsw32");
|
| 761 | }
|
| 762 | }
|
| 763 |
|
| 764 | field_152965_q = true;
|
| 765 | }
|
| 766 | catch (Throwable var1)
|
| 767 | {
|
| 768 | field_152965_q = false;
|
| 769 | }
|
| 770 | }
|
| 771 | }
|
| 772 |
|