BroadcastController .java

net.minecraft.client.stream.BroadcastController (class): members: setRecordingDeviceVolume, setPlaybackDeviceVolume, setBroadcastListener, audioParamaters.

net.minecraft.client.streamclass1,219 linesclient40.2 KB

API Surface (63)

void requestAuthTokenCallback(ErrorCode p_requestAuthTokenCallback_1_, AuthToken p_requestAuthTokenCallback_2_)
void loginCallback(ErrorCode p_loginCallback_1_, ChannelInfo p_loginCallback_2_)
void getIngestServersCallback(ErrorCode p_getIngestServersCallback_1_, IngestList p_getIngestServersCallback_2_)
void getUserInfoCallback(ErrorCode p_getUserInfoCallback_1_, UserInfo p_getUserInfoCallback_2_)
void getStreamInfoCallback(ErrorCode p_getStreamInfoCallback_1_, StreamInfo p_getStreamInfoCallback_2_)
void getArchivingStateCallback(ErrorCode p_getArchivingStateCallback_1_, ArchivingState p_getArchivingStateCallback_2_)
void runCommercialCallback(ErrorCode p_runCommercialCallback_1_)
void setStreamInfoCallback(ErrorCode p_setStreamInfoCallback_1_)
void getGameNameListCallback(ErrorCode p_getGameNameListCallback_1_, GameInfoList p_getGameNameListCallback_2_)
void bufferUnlockCallback(long p_bufferUnlockCallback_1_)
void startCallback(ErrorCode p_startCallback_1_)
void stopCallback(ErrorCode p_stopCallback_1_)
void sendActionMetaDataCallback(ErrorCode p_sendActionMetaDataCallback_1_)
void sendStartSpanMetaDataCallback(ErrorCode p_sendStartSpanMetaDataCallback_1_)
void sendEndSpanMetaDataCallback(ErrorCode p_sendEndSpanMetaDataCallback_1_)
void statCallback(StatType p_statCallback_1_, long p_statCallback_2_)
void setBroadcastListener(BroadcastController.BroadcastListener broadcastListenerIn)
boolean func_152858_b()
void func_152842_a(String p_152842_1_)
StreamInfo getStreamInfo()
ChannelInfo getChannelInfo()
boolean isBroadcasting()
boolean isReadyToBroadcast()
boolean isIngestTesting()
boolean isBroadcastPaused()
boolean func_152849_q()
IngestServer getIngestServer()
void setIngestServer(IngestServer ingestServerSet)
IngestList getIngestList()
void setRecordingDeviceVolume(float volume)
void setPlaybackDeviceVolume(float volume)
IngestServerTester isReady()
long getStreamTime()
boolean func_152848_y()
ErrorCode getErrorCode()
PixelFormat getPixelFormat()
boolean func_152817_A()
boolean func_152851_B()
void statCallback()
boolean func_152818_a(String p_152818_1_, AuthToken p_152818_2_)
boolean func_152845_C()
boolean func_152828_a(String p_152828_1_, String p_152828_2_, String p_152828_3_)
boolean requestCommercial()
VideoParams func_152834_a(int maxKbps, int p_152834_2_, float p_152834_3_, float p_152834_4_)
boolean func_152836_a(VideoParams p_152836_1_)
boolean stopBroadcasting()
boolean func_152847_F()
boolean func_152854_G()
boolean func_152840_a(String p_152840_1_, long p_152840_2_, String p_152840_4_, String p_152840_5_)
long func_177946_b(String p_177946_1_, long p_177946_2_, String p_177946_4_, String p_177946_5_)
boolean func_177947_a(String p_177947_1_, long p_177947_2_, long p_177947_4_, String p_177947_6_, String p_177947_7_)
void func_152827_a(BroadcastController.BroadcastState p_152827_1_)
void func_152821_H()
void func_152835_I()
IngestServerTester func_152838_J()
boolean func_152823_L()
void func_152831_M()
FrameBuffer func_152822_N()
void captureFramebuffer(FrameBuffer p_152846_1_)
ErrorCode submitStreamFrame(FrameBuffer frame)
boolean func_152853_a(ErrorCode p_152853_1_)
void logError(String error)
void logWarning(String warning)

Fields & Constants (33)

logger
field_152862_C
field_152865_a
field_152866_b
lastError
broadcastListener
field_152868_d
field_152869_e
field_152870_f
field_152871_g
streamCore
theStream
field_152874_j
field_152875_k
field_152876_l
field_152877_m
field_152878_n
broadcastState
field_152880_p
videoParamaters
audioParamaters
ingestList
ingestServ
authenticationToken
channelInfo
userInfo

…and 7 more (see full source).

String literals (14)

"java.library.path"
"Auth token must be valid"
"Username must be valid"
"Error in SendStartSpanMetaData\n"
"Error while allocating frame buffer"
"Out of free buffers, this should never happen"
"Trying to submit a frame to Twitch"
"Broadcast State"
"Last reported errors"
"Buffer"
"Free buffer count"
"Capture buffer count"
"<Error> "
"<Warning> "

Code Graph: Dependencies (5)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

BroadcastController.java1219 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.stream;
2
3
import com.google.common.collect.Lists;
4
import java.util.Arrays;
5
import java.util.List;
6
import net.minecraft.crash.CrashReport;
7
import net.minecraft.crash.CrashReportCategory;
8
import net.minecraft.util.ReportedException;
9
import net.minecraft.util.ThreadSafeBoundList;
10
import org.apache.logging.log4j.LogManager;
11
import org.apache.logging.log4j.Logger;
12
import tv.twitch.AuthToken;
13
import tv.twitch.Core;
14
import tv.twitch.ErrorCode;
15
import tv.twitch.MessageLevel;
16
import tv.twitch.StandardCoreAPI;
17
import tv.twitch.broadcast.ArchivingState;
18
import tv.twitch.broadcast.AudioDeviceType;
19
import tv.twitch.broadcast.AudioParams;
20
import tv.twitch.broadcast.ChannelInfo;
21
import tv.twitch.broadcast.DesktopStreamAPI;
22
import tv.twitch.broadcast.EncodingCpuUsage;
23
import tv.twitch.broadcast.FrameBuffer;
24
import tv.twitch.broadcast.GameInfo;
25
import tv.twitch.broadcast.GameInfoList;
26
import tv.twitch.broadcast.IStatCallbacks;
27
import tv.twitch.broadcast.IStreamCallbacks;
28
import tv.twitch.broadcast.IngestList;
29
import tv.twitch.broadcast.IngestServer;
30
import tv.twitch.broadcast.PixelFormat;
31
import tv.twitch.broadcast.StartFlags;
32
import tv.twitch.broadcast.StatType;
33
import tv.twitch.broadcast.Stream;
34
import tv.twitch.broadcast.StreamInfo;
35
import tv.twitch.broadcast.StreamInfoForSetting;
36
import tv.twitch.broadcast.UserInfo;
37
import tv.twitch.broadcast.VideoParams;
38
39
public class BroadcastController
40
{
41
    private static final Logger logger = LogManager.getLogger();
42
    protected final int field_152865_a = 30;
43
    protected final int field_152866_b = 3;
44
    private static final ThreadSafeBoundList<String> field_152862_C = new ThreadSafeBoundList(String.class, 50);
45
46
    /** The last error that ocurred */
47
    private String lastError = null;
48
    protected BroadcastController.BroadcastListener broadcastListener = null;
49
    protected String field_152868_d = "";
50
    protected String field_152869_e = "";
51
    protected String field_152870_f = "";
52
    protected boolean field_152871_g = true;
53
54
    /** The stream's core */
55
    protected Core streamCore = null;
56
57
    /** The Stream's instance */
58
    protected Stream theStream = null;
59
    protected List<FrameBuffer> field_152874_j = Lists.<FrameBuffer>newArrayList();
60
    protected List<FrameBuffer> field_152875_k = Lists.<FrameBuffer>newArrayList();
61
    protected boolean field_152876_l = false;
62
    protected boolean field_152877_m = false;
63
    protected boolean field_152878_n = false;
64
    protected BroadcastController.BroadcastState broadcastState = BroadcastController.BroadcastState.Uninitialized;
65
    protected String field_152880_p = null;
66
    protected VideoParams videoParamaters = null;
67
    protected AudioParams audioParamaters = null;
68
    protected IngestList ingestList = new IngestList(new IngestServer[0]);
69
70
    /** The IngestServer's instance */
71
    protected IngestServer ingestServ = null;
72
    protected AuthToken authenticationToken = new AuthToken();
73
    protected ChannelInfo channelInfo = new ChannelInfo();
74
    protected UserInfo userInfo = new UserInfo();
75
    protected StreamInfo streamInfo = new StreamInfo();
76
77
    /** The current archiving state */
78
    protected ArchivingState archivingState = new ArchivingState();
79
    protected long field_152890_z = 0L;
80
81
    /** Instance of the IngestServerTester */
82
    protected IngestServerTester ingestServTester = null;
83
    private ErrorCode errorCode;
84
85
    /** The stream callback instance */
86
    protected IStreamCallbacks streamCallback = new IStreamCallbacks()
87
    {
88
        public void requestAuthTokenCallback(ErrorCode p_requestAuthTokenCallback_1_, AuthToken p_requestAuthTokenCallback_2_)
89
        {
90
            if (ErrorCode.succeeded(p_requestAuthTokenCallback_1_))
91
            {
92
                BroadcastController.this.authenticationToken = p_requestAuthTokenCallback_2_;
93
                BroadcastController.this.func_152827_a(BroadcastController.BroadcastState.Authenticated);
94
            }
95
            else
96
            {
97
                BroadcastController.this.authenticationToken.data = "";
98
                BroadcastController.this.func_152827_a(BroadcastController.BroadcastState.Initialized);
99
                String s = ErrorCode.getString(p_requestAuthTokenCallback_1_);
100
                BroadcastController.this.logError(String.format("RequestAuthTokenDoneCallback got failure: %s", new Object[] {s}));
101
            }
102
103
            try
104
            {
105
                if (BroadcastController.this.broadcastListener != null)
106
                {
107
                    BroadcastController.this.broadcastListener.func_152900_a(p_requestAuthTokenCallback_1_, p_requestAuthTokenCallback_2_);
108
                }
109
            }
110
            catch (Exception exception)
111
            {
112
                BroadcastController.this.logError(exception.toString());
113
            }
114
        }
115
        public void loginCallback(ErrorCode p_loginCallback_1_, ChannelInfo p_loginCallback_2_)
116
        {
117
            if (ErrorCode.succeeded(p_loginCallback_1_))
118
            {
119
                BroadcastController.this.channelInfo = p_loginCallback_2_;
120
                BroadcastController.this.func_152827_a(BroadcastController.BroadcastState.LoggedIn);
121
                BroadcastController.this.field_152877_m = true;
122
            }
123
            else
124
            {
125
                BroadcastController.this.func_152827_a(BroadcastController.BroadcastState.Initialized);
126
                BroadcastController.this.field_152877_m = false;
127
                String s = ErrorCode.getString(p_loginCallback_1_);
128
                BroadcastController.this.logError(String.format("LoginCallback got failure: %s", new Object[] {s}));
129
            }
130
131
            try
132
            {
133
                if (BroadcastController.this.broadcastListener != null)
134
                {
135
                    BroadcastController.this.broadcastListener.func_152897_a(p_loginCallback_1_);
136
                }
137
            }
138
            catch (Exception exception)
139
            {
140
                BroadcastController.this.logError(exception.toString());
141
            }
142
        }
143
        public void getIngestServersCallback(ErrorCode p_getIngestServersCallback_1_, IngestList p_getIngestServersCallback_2_)
144
        {
145
            if (ErrorCode.succeeded(p_getIngestServersCallback_1_))
146
            {
147
                BroadcastController.this.ingestList = p_getIngestServersCallback_2_;
148
                BroadcastController.this.ingestServ = BroadcastController.this.ingestList.getDefaultServer();
149
                BroadcastController.this.func_152827_a(BroadcastController.BroadcastState.ReceivedIngestServers);
150
151
                try
152
                {
153
                    if (BroadcastController.this.broadcastListener != null)
154
                    {
155
                        BroadcastController.this.broadcastListener.func_152896_a(p_getIngestServersCallback_2_);
156
                    }
157
                }
158
                catch (Exception exception)
159
                {
160
                    BroadcastController.this.logError(exception.toString());
161
                }
162
            }
163
            else
164
            {
165
                String s = ErrorCode.getString(p_getIngestServersCallback_1_);
166
                BroadcastController.this.logError(String.format("IngestListCallback got failure: %s", new Object[] {s}));
167
                BroadcastController.this.func_152827_a(BroadcastController.BroadcastState.LoggingIn);
168
            }
169
        }
170
        public void getUserInfoCallback(ErrorCode p_getUserInfoCallback_1_, UserInfo p_getUserInfoCallback_2_)
171
        {
172
            BroadcastController.this.userInfo = p_getUserInfoCallback_2_;
173
174
            if (ErrorCode.failed(p_getUserInfoCallback_1_))
175
            {
176
                String s = ErrorCode.getString(p_getUserInfoCallback_1_);
177
                BroadcastController.this.logError(String.format("UserInfoDoneCallback got failure: %s", new Object[] {s}));
178
            }
179
        }
180
        public void getStreamInfoCallback(ErrorCode p_getStreamInfoCallback_1_, StreamInfo p_getStreamInfoCallback_2_)
181
        {
182
            if (ErrorCode.succeeded(p_getStreamInfoCallback_1_))
183
            {
184
                BroadcastController.this.streamInfo = p_getStreamInfoCallback_2_;
185
186
                try
187
                {
188
                    if (BroadcastController.this.broadcastListener != null)
189
                    {
190
                        BroadcastController.this.broadcastListener.func_152894_a(p_getStreamInfoCallback_2_);
191
                    }
192
                }
193
                catch (Exception exception)
194
                {
195
                    BroadcastController.this.logError(exception.toString());
196
                }
197
            }
198
            else
199
            {
200
                String s = ErrorCode.getString(p_getStreamInfoCallback_1_);
201
                BroadcastController.this.logWarning(String.format("StreamInfoDoneCallback got failure: %s", new Object[] {s}));
202
            }
203
        }
204
        public void getArchivingStateCallback(ErrorCode p_getArchivingStateCallback_1_, ArchivingState p_getArchivingStateCallback_2_)
205
        {
206
            BroadcastController.this.archivingState = p_getArchivingStateCallback_2_;
207
208
            if (ErrorCode.failed(p_getArchivingStateCallback_1_))
209
            {
210
                ;
211
            }
212
        }
213
        public void runCommercialCallback(ErrorCode p_runCommercialCallback_1_)
214
        {
215
            if (ErrorCode.failed(p_runCommercialCallback_1_))
216
            {
217
                String s = ErrorCode.getString(p_runCommercialCallback_1_);
218
                BroadcastController.this.logWarning(String.format("RunCommercialCallback got failure: %s", new Object[] {s}));
219
            }
220
        }
221
        public void setStreamInfoCallback(ErrorCode p_setStreamInfoCallback_1_)
222
        {
223
            if (ErrorCode.failed(p_setStreamInfoCallback_1_))
224
            {
225
                String s = ErrorCode.getString(p_setStreamInfoCallback_1_);
226
                BroadcastController.this.logWarning(String.format("SetStreamInfoCallback got failure: %s", new Object[] {s}));
227
            }
228
        }
229
        public void getGameNameListCallback(ErrorCode p_getGameNameListCallback_1_, GameInfoList p_getGameNameListCallback_2_)
230
        {
231
            if (ErrorCode.failed(p_getGameNameListCallback_1_))
232
            {
233
                String s = ErrorCode.getString(p_getGameNameListCallback_1_);
234
                BroadcastController.this.logError(String.format("GameNameListCallback got failure: %s", new Object[] {s}));
235
            }
236
237
            try
238
            {
239
                if (BroadcastController.this.broadcastListener != null)
240
                {
241
                    BroadcastController.this.broadcastListener.func_152898_a(p_getGameNameListCallback_1_, p_getGameNameListCallback_2_ == null ? new GameInfo[0] : p_getGameNameListCallback_2_.list);
242
                }
243
            }
244
            catch (Exception exception)
245
            {
246
                BroadcastController.this.logError(exception.toString());
247
            }
248
        }
249
        public void bufferUnlockCallback(long p_bufferUnlockCallback_1_)
250
        {
251
            FrameBuffer framebuffer = FrameBuffer.lookupBuffer(p_bufferUnlockCallback_1_);
252
            BroadcastController.this.field_152875_k.add(framebuffer);
253
        }
254
        public void startCallback(ErrorCode p_startCallback_1_)
255
        {
256
            if (ErrorCode.succeeded(p_startCallback_1_))
257
            {
258
                try
259
                {
260
                    if (BroadcastController.this.broadcastListener != null)
261
                    {
262
                        BroadcastController.this.broadcastListener.func_152899_b();
263
                    }
264
                }
265
                catch (Exception exception1)
266
                {
267
                    BroadcastController.this.logError(exception1.toString());
268
                }
269
270
                BroadcastController.this.func_152827_a(BroadcastController.BroadcastState.Broadcasting);
271
            }
272
            else
273
            {
274
                BroadcastController.this.videoParamaters = null;
275
                BroadcastController.this.audioParamaters = null;
276
                BroadcastController.this.func_152827_a(BroadcastController.BroadcastState.ReadyToBroadcast);
277
278
                try
279
                {
280
                    if (BroadcastController.this.broadcastListener != null)
281
                    {
282
                        BroadcastController.this.broadcastListener.func_152892_c(p_startCallback_1_);
283
                    }
284
                }
285
                catch (Exception exception)
286
                {
287
                    BroadcastController.this.logError(exception.toString());
288
                }
289
290
                String s = ErrorCode.getString(p_startCallback_1_);
291
                BroadcastController.this.logError(String.format("startCallback got failure: %s", new Object[] {s}));
292
            }
293
        }
294
        public void stopCallback(ErrorCode p_stopCallback_1_)
295
        {
296
            if (ErrorCode.succeeded(p_stopCallback_1_))
297
            {
298
                BroadcastController.this.videoParamaters = null;
299
                BroadcastController.this.audioParamaters = null;
300
                BroadcastController.this.func_152831_M();
301
302
                try
303
                {
304
                    if (BroadcastController.this.broadcastListener != null)
305
                    {
306
                        BroadcastController.this.broadcastListener.func_152901_c();
307
                    }
308
                }
309
                catch (Exception exception)
310
                {
311
                    BroadcastController.this.logError(exception.toString());
312
                }
313
314
                if (BroadcastController.this.field_152877_m)
315
                {
316
                    BroadcastController.this.func_152827_a(BroadcastController.BroadcastState.ReadyToBroadcast);
317
                }
318
                else
319
                {
320
                    BroadcastController.this.func_152827_a(BroadcastController.BroadcastState.Initialized);
321
                }
322
            }
323
            else
324
            {
325
                BroadcastController.this.func_152827_a(BroadcastController.BroadcastState.ReadyToBroadcast);
326
                String s = ErrorCode.getString(p_stopCallback_1_);
327
                BroadcastController.this.logError(String.format("stopCallback got failure: %s", new Object[] {s}));
328
            }
329
        }
330
        public void sendActionMetaDataCallback(ErrorCode p_sendActionMetaDataCallback_1_)
331
        {
332
            if (ErrorCode.failed(p_sendActionMetaDataCallback_1_))
333
            {
334
                String s = ErrorCode.getString(p_sendActionMetaDataCallback_1_);
335
                BroadcastController.this.logError(String.format("sendActionMetaDataCallback got failure: %s", new Object[] {s}));
336
            }
337
        }
338
        public void sendStartSpanMetaDataCallback(ErrorCode p_sendStartSpanMetaDataCallback_1_)
339
        {
340
            if (ErrorCode.failed(p_sendStartSpanMetaDataCallback_1_))
341
            {
342
                String s = ErrorCode.getString(p_sendStartSpanMetaDataCallback_1_);
343
                BroadcastController.this.logError(String.format("sendStartSpanMetaDataCallback got failure: %s", new Object[] {s}));
344
            }
345
        }
346
        public void sendEndSpanMetaDataCallback(ErrorCode p_sendEndSpanMetaDataCallback_1_)
347
        {
348
            if (ErrorCode.failed(p_sendEndSpanMetaDataCallback_1_))
349
            {
350
                String s = ErrorCode.getString(p_sendEndSpanMetaDataCallback_1_);
351
                BroadcastController.this.logError(String.format("sendEndSpanMetaDataCallback got failure: %s", new Object[] {s}));
352
            }
353
        }
354
    };
355
    protected IStatCallbacks field_177949_C = new IStatCallbacks()
356
    {
357
        public void statCallback(StatType p_statCallback_1_, long p_statCallback_2_)
358
        {
359
        }
360
    };
361
362
    /**
363
     * Set a new BroadcastListener
364
     *  
365
     * @param broadcastListenerIn The BroadcastListener to set
366
     */
367
    public void setBroadcastListener(BroadcastController.BroadcastListener broadcastListenerIn)
368
    {
369
        this.broadcastListener = broadcastListenerIn;
370
    }
371
372
    public boolean func_152858_b()
373
    {
374
        return this.field_152876_l;
375
    }
376
377
    public void func_152842_a(String p_152842_1_)
378
    {
379
        this.field_152868_d = p_152842_1_;
380
    }
381
382
    public StreamInfo getStreamInfo()
383
    {
384
        return this.streamInfo;
385
    }
386
387
    public ChannelInfo getChannelInfo()
388
    {
389
        return this.channelInfo;
390
    }
391
392
    public boolean isBroadcasting()
393
    {
394
        return this.broadcastState == BroadcastController.BroadcastState.Broadcasting || this.broadcastState == BroadcastController.BroadcastState.Paused;
395
    }
396
397
    public boolean isReadyToBroadcast()
398
    {
399
        return this.broadcastState == BroadcastController.BroadcastState.ReadyToBroadcast;
400
    }
401
402
    public boolean isIngestTesting()
403
    {
404
        return this.broadcastState == BroadcastController.BroadcastState.IngestTesting;
405
    }
406
407
    public boolean isBroadcastPaused()
408
    {
409
        return this.broadcastState == BroadcastController.BroadcastState.Paused;
410
    }
411
412
    public boolean func_152849_q()
413
    {
414
        return this.field_152877_m;
415
    }
416
417
    /**
418
     * Return the IngestServer's instance
419
     */
420
    public IngestServer getIngestServer()
421
    {
422
        return this.ingestServ;
423
    }
424
425
    /**
426
     * Set a new IngestServer
427
     *  
428
     * @param ingestServerSet The new IngestServer
429
     */
430
    public void setIngestServer(IngestServer ingestServerSet)
431
    {
432
        this.ingestServ = ingestServerSet;
433
    }
434
435
    /**
436
     * Return the IngestList
437
     */
438
    public IngestList getIngestList()
439
    {
440
        return this.ingestList;
441
    }
442
443
    public void setRecordingDeviceVolume(float volume)
444
    {
445
        this.theStream.setVolume(AudioDeviceType.TTV_RECORDER_DEVICE, volume);
446
    }
447
448
    public void setPlaybackDeviceVolume(float volume)
449
    {
450
        this.theStream.setVolume(AudioDeviceType.TTV_PLAYBACK_DEVICE, volume);
451
    }
452
453
    public IngestServerTester isReady()
454
    {
455
        return this.ingestServTester;
456
    }
457
458
    /**
459
     * Return the stream time
460
     */
461
    public long getStreamTime()
462
    {
463
        return this.theStream.getStreamTime();
464
    }
465
466
    protected boolean func_152848_y()
467
    {
468
        return true;
469
    }
470
471
    public ErrorCode getErrorCode()
472
    {
473
        return this.errorCode;
474
    }
475
476
    public BroadcastController()
477
    {
478
        this.streamCore = Core.getInstance();
479
480
        if (Core.getInstance() == null)
481
        {
482
            this.streamCore = new Core(new StandardCoreAPI());
483
        }
484
485
        this.theStream = new Stream(new DesktopStreamAPI());
486
    }
487
488
    /**
489
     * Return the PixelFormat
490
     */
491
    protected PixelFormat getPixelFormat()
492
    {
493
        return PixelFormat.TTV_PF_RGBA;
494
    }
495
496
    public boolean func_152817_A()
497
    {
498
        if (this.field_152876_l)
499
        {
500
            return false;
501
        }
502
        else
503
        {
504
            this.theStream.setStreamCallbacks(this.streamCallback);
505
            ErrorCode errorcode = this.streamCore.initialize(this.field_152868_d, System.getProperty("java.library.path"));
506
507
            if (!this.func_152853_a(errorcode))
508
            {
509
                this.theStream.setStreamCallbacks((IStreamCallbacks)null);
510
                this.errorCode = errorcode;
511
                return false;
512
            }
513
            else
514
            {
515
                errorcode = this.streamCore.setTraceLevel(MessageLevel.TTV_ML_ERROR);
516
517
                if (!this.func_152853_a(errorcode))
518
                {
519
                    this.theStream.setStreamCallbacks((IStreamCallbacks)null);
520
                    this.streamCore.shutdown();
521
                    this.errorCode = errorcode;
522
                    return false;
523
                }
524
                else if (ErrorCode.succeeded(errorcode))
525
                {
526
                    this.field_152876_l = true;
527
                    this.func_152827_a(BroadcastController.BroadcastState.Initialized);
528
                    return true;
529
                }
530
                else
531
                {
532
                    this.errorCode = errorcode;
533
                    this.streamCore.shutdown();
534
                    return false;
535
                }
536
            }
537
        }
538
    }
539
540
    public boolean func_152851_B()
541
    {
542
        if (!this.field_152876_l)
543
        {
544
            return true;
545
        }
546
        else if (this.isIngestTesting())
547
        {
548
            return false;
549
        }
550
        else
551
        {
552
            this.field_152878_n = true;
553
            this.func_152845_C();
554
            this.theStream.setStreamCallbacks((IStreamCallbacks)null);
555
            this.theStream.setStatCallbacks((IStatCallbacks)null);
556
            ErrorCode errorcode = this.streamCore.shutdown();
557
            this.func_152853_a(errorcode);
558
            this.field_152876_l = false;
559
            this.field_152878_n = false;
560
            this.func_152827_a(BroadcastController.BroadcastState.Uninitialized);
561
            return true;
562
        }
563
    }
564
565
    public void statCallback()
566
    {
567
        if (this.broadcastState != BroadcastController.BroadcastState.Uninitialized)
568
        {
569
            if (this.ingestServTester != null)
570
            {
571
                this.ingestServTester.func_153039_l();
572
            }
573
574
            for (; this.ingestServTester != null; this.func_152821_H())
575
            {
576
                try
577
                {
578
                    Thread.sleep(200L);
579
                }
580
                catch (Exception exception)
581
                {
582
                    this.logError(exception.toString());
583
                }
584
            }
585
586
            this.func_152851_B();
587
        }
588
    }
589
590
    public boolean func_152818_a(String p_152818_1_, AuthToken p_152818_2_)
591
    {
592
        if (this.isIngestTesting())
593
        {
594
            return false;
595
        }
596
        else
597
        {
598
            this.func_152845_C();
599
600
            if (p_152818_1_ != null && !p_152818_1_.isEmpty())
601
            {
602
                if (p_152818_2_ != null && p_152818_2_.data != null && !p_152818_2_.data.isEmpty())
603
                {
604
                    this.field_152880_p = p_152818_1_;
605
                    this.authenticationToken = p_152818_2_;
606
607
                    if (this.func_152858_b())
608
                    {
609
                        this.func_152827_a(BroadcastController.BroadcastState.Authenticated);
610
                    }
611
612
                    return true;
613
                }
614
                else
615
                {
616
                    this.logError("Auth token must be valid");
617
                    return false;
618
                }
619
            }
620
            else
621
            {
622
                this.logError("Username must be valid");
623
                return false;
624
            }
625
        }
626
    }
627
628
    public boolean func_152845_C()
629
    {
630
        if (this.isIngestTesting())
631
        {
632
            return false;
633
        }
634
        else
635
        {
636
            if (this.isBroadcasting())
637
            {
638
                this.theStream.stop(false);
639
            }
640
641
            this.field_152880_p = "";
642
            this.authenticationToken = new AuthToken();
643
644
            if (!this.field_152877_m)
645
            {
646
                return false;
647
            }
648
            else
649
            {
650
                this.field_152877_m = false;
651
652
                if (!this.field_152878_n)
653
                {
654
                    try
655
                    {
656
                        if (this.broadcastListener != null)
657
                        {
658
                            this.broadcastListener.func_152895_a();
659
                        }
660
                    }
661
                    catch (Exception exception)
662
                    {
663
                        this.logError(exception.toString());
664
                    }
665
                }
666
667
                this.func_152827_a(BroadcastController.BroadcastState.Initialized);
668
                return true;
669
            }
670
        }
671
    }
672
673
    public boolean func_152828_a(String p_152828_1_, String p_152828_2_, String p_152828_3_)
674
    {
675
        if (!this.field_152877_m)
676
        {
677
            return false;
678
        }
679
        else
680
        {
681
            if (p_152828_1_ == null || p_152828_1_.equals(""))
682
            {
683
                p_152828_1_ = this.field_152880_p;
684
            }
685
686
            if (p_152828_2_ == null)
687
            {
688
                p_152828_2_ = "";
689
            }
690
691
            if (p_152828_3_ == null)
692
            {
693
                p_152828_3_ = "";
694
            }
695
696
            StreamInfoForSetting streaminfoforsetting = new StreamInfoForSetting();
697
            streaminfoforsetting.streamTitle = p_152828_3_;
698
            streaminfoforsetting.gameName = p_152828_2_;
699
            ErrorCode errorcode = this.theStream.setStreamInfo(this.authenticationToken, p_152828_1_, streaminfoforsetting);
700
            this.func_152853_a(errorcode);
701
            return ErrorCode.succeeded(errorcode);
702
        }
703
    }
704
705
    public boolean requestCommercial()
706
    {
707
        if (!this.isBroadcasting())
708
        {
709
            return false;
710
        }
711
        else
712
        {
713
            ErrorCode errorcode = this.theStream.runCommercial(this.authenticationToken);
714
            this.func_152853_a(errorcode);
715
            return ErrorCode.succeeded(errorcode);
716
        }
717
    }
718
719
    public VideoParams func_152834_a(int maxKbps, int p_152834_2_, float p_152834_3_, float p_152834_4_)
720
    {
721
        int[] aint = this.theStream.getMaxResolution(maxKbps, p_152834_2_, p_152834_3_, p_152834_4_);
722
        VideoParams videoparams = new VideoParams();
723
        videoparams.maxKbps = maxKbps;
724
        videoparams.encodingCpuUsage = EncodingCpuUsage.TTV_ECU_HIGH;
725
        videoparams.pixelFormat = this.getPixelFormat();
726
        videoparams.targetFps = p_152834_2_;
727
        videoparams.outputWidth = aint[0];
728
        videoparams.outputHeight = aint[1];
729
        videoparams.disableAdaptiveBitrate = false;
730
        videoparams.verticalFlip = false;
731
        return videoparams;
732
    }
733
734
    public boolean func_152836_a(VideoParams p_152836_1_)
735
    {
736
        if (p_152836_1_ != null && this.isReadyToBroadcast())
737
        {
738
            this.videoParamaters = p_152836_1_.clone();
739
            this.audioParamaters = new AudioParams();
740
            this.audioParamaters.audioEnabled = this.field_152871_g && this.func_152848_y();
741
            this.audioParamaters.enableMicCapture = this.audioParamaters.audioEnabled;
742
            this.audioParamaters.enablePlaybackCapture = this.audioParamaters.audioEnabled;
743
            this.audioParamaters.enablePassthroughAudio = false;
744
745
            if (!this.func_152823_L())
746
            {
747
                this.videoParamaters = null;
748
                this.audioParamaters = null;
749
                return false;
750
            }
751
            else
752
            {
753
                ErrorCode errorcode = this.theStream.start(p_152836_1_, this.audioParamaters, this.ingestServ, StartFlags.None, true);
754
755
                if (ErrorCode.failed(errorcode))
756
                {
757
                    this.func_152831_M();
758
                    String s = ErrorCode.getString(errorcode);
759
                    this.logError(String.format("Error while starting to broadcast: %s", new Object[] {s}));
760
                    this.videoParamaters = null;
761
                    this.audioParamaters = null;
762
                    return false;
763
                }
764
                else
765
                {
766
                    this.func_152827_a(BroadcastController.BroadcastState.Starting);
767
                    return true;
768
                }
769
            }
770
        }
771
        else
772
        {
773
            return false;
774
        }
775
    }
776
777
    public boolean stopBroadcasting()
778
    {
779
        if (!this.isBroadcasting())
780
        {
781
            return false;
782
        }
783
        else
784
        {
785
            ErrorCode errorcode = this.theStream.stop(true);
786
787
            if (ErrorCode.failed(errorcode))
788
            {
789
                String s = ErrorCode.getString(errorcode);
790
                this.logError(String.format("Error while stopping the broadcast: %s", new Object[] {s}));
791
                return false;
792
            }
793
            else
794
            {
795
                this.func_152827_a(BroadcastController.BroadcastState.Stopping);
796
                return ErrorCode.succeeded(errorcode);
797
            }
798
        }
799
    }
800
801
    public boolean func_152847_F()
802
    {
803
        if (!this.isBroadcasting())
804
        {
805
            return false;
806
        }
807
        else
808
        {
809
            ErrorCode errorcode = this.theStream.pauseVideo();
810
811
            if (ErrorCode.failed(errorcode))
812
            {
813
                this.stopBroadcasting();
814
                String s = ErrorCode.getString(errorcode);
815
                this.logError(String.format("Error pausing stream: %s\n", new Object[] {s}));
816
            }
817
            else
818
            {
819
                this.func_152827_a(BroadcastController.BroadcastState.Paused);
820
            }
821
822
            return ErrorCode.succeeded(errorcode);
823
        }
824
    }
825
826
    public boolean func_152854_G()
827
    {
828
        if (!this.isBroadcastPaused())
829
        {
830
            return false;
831
        }
832
        else
833
        {
834
            this.func_152827_a(BroadcastController.BroadcastState.Broadcasting);
835
            return true;
836
        }
837
    }
838
839
    public boolean func_152840_a(String p_152840_1_, long p_152840_2_, String p_152840_4_, String p_152840_5_)
840
    {
841
        ErrorCode errorcode = this.theStream.sendActionMetaData(this.authenticationToken, p_152840_1_, p_152840_2_, p_152840_4_, p_152840_5_);
842
843
        if (ErrorCode.failed(errorcode))
844
        {
845
            String s = ErrorCode.getString(errorcode);
846
            this.logError(String.format("Error while sending meta data: %s\n", new Object[] {s}));
847
            return false;
848
        }
849
        else
850
        {
851
            return true;
852
        }
853
    }
854
855
    public long func_177946_b(String p_177946_1_, long p_177946_2_, String p_177946_4_, String p_177946_5_)
856
    {
857
        long i = this.theStream.sendStartSpanMetaData(this.authenticationToken, p_177946_1_, p_177946_2_, p_177946_4_, p_177946_5_);
858
859
        if (i == -1L)
860
        {
861
            this.logError(String.format("Error in SendStartSpanMetaData\n", new Object[0]));
862
        }
863
864
        return i;
865
    }
866
867
    public boolean func_177947_a(String p_177947_1_, long p_177947_2_, long p_177947_4_, String p_177947_6_, String p_177947_7_)
868
    {
869
        if (p_177947_4_ == -1L)
870
        {
871
            this.logError(String.format("Invalid sequence id: %d\n", new Object[] {Long.valueOf(p_177947_4_)}));
872
            return false;
873
        }
874
        else
875
        {
876
            ErrorCode errorcode = this.theStream.sendEndSpanMetaData(this.authenticationToken, p_177947_1_, p_177947_2_, p_177947_4_, p_177947_6_, p_177947_7_);
877
878
            if (ErrorCode.failed(errorcode))
879
            {
880
                String s = ErrorCode.getString(errorcode);
881
                this.logError(String.format("Error in SendStopSpanMetaData: %s\n", new Object[] {s}));
882
                return false;
883
            }
884
            else
885
            {
886
                return true;
887
            }
888
        }
889
    }
890
891
    protected void func_152827_a(BroadcastController.BroadcastState p_152827_1_)
892
    {
893
        if (p_152827_1_ != this.broadcastState)
894
        {
895
            this.broadcastState = p_152827_1_;
896
897
            try
898
            {
899
                if (this.broadcastListener != null)
900
                {
901
                    this.broadcastListener.func_152891_a(p_152827_1_);
902
                }
903
            }
904
            catch (Exception exception)
905
            {
906
                this.logError(exception.toString());
907
            }
908
        }
909
    }
910
911
    public void func_152821_H()
912
    {
913
        if (this.theStream != null && this.field_152876_l)
914
        {
915
            ErrorCode errorcode = this.theStream.pollTasks();
916
            this.func_152853_a(errorcode);
917
918
            if (this.isIngestTesting())
919
            {
920
                this.ingestServTester.func_153041_j();
921
922
                if (this.ingestServTester.func_153032_e())
923
                {
924
                    this.ingestServTester = null;
925
                    this.func_152827_a(BroadcastController.BroadcastState.ReadyToBroadcast);
926
                }
927
            }
928
929
            switch (this.broadcastState)
930
            {
931
                case Authenticated:
932
                    this.func_152827_a(BroadcastController.BroadcastState.LoggingIn);
933
                    errorcode = this.theStream.login(this.authenticationToken);
934
935
                    if (ErrorCode.failed(errorcode))
936
                    {
937
                        String s3 = ErrorCode.getString(errorcode);
938
                        this.logError(String.format("Error in TTV_Login: %s\n", new Object[] {s3}));
939
                    }
940
941
                    break;
942
943
                case LoggedIn:
944
                    this.func_152827_a(BroadcastController.BroadcastState.FindingIngestServer);
945
                    errorcode = this.theStream.getIngestServers(this.authenticationToken);
946
947
                    if (ErrorCode.failed(errorcode))
948
                    {
949
                        this.func_152827_a(BroadcastController.BroadcastState.LoggedIn);
950
                        String s2 = ErrorCode.getString(errorcode);
951
                        this.logError(String.format("Error in TTV_GetIngestServers: %s\n", new Object[] {s2}));
952
                    }
953
954
                    break;
955
956
                case ReceivedIngestServers:
957
                    this.func_152827_a(BroadcastController.BroadcastState.ReadyToBroadcast);
958
                    errorcode = this.theStream.getUserInfo(this.authenticationToken);
959
960
                    if (ErrorCode.failed(errorcode))
961
                    {
962
                        String s = ErrorCode.getString(errorcode);
963
                        this.logError(String.format("Error in TTV_GetUserInfo: %s\n", new Object[] {s}));
964
                    }
965
966
                    this.func_152835_I();
967
                    errorcode = this.theStream.getArchivingState(this.authenticationToken);
968
969
                    if (ErrorCode.failed(errorcode))
970
                    {
971
                        String s1 = ErrorCode.getString(errorcode);
972
                        this.logError(String.format("Error in TTV_GetArchivingState: %s\n", new Object[] {s1}));
973
                    }
974
975
                case Starting:
976
                case Stopping:
977
                case FindingIngestServer:
978
                case Authenticating:
979
                case Initialized:
980
                case Uninitialized:
981
                case IngestTesting:
982
                default:
983
                    break;
984
985
                case Paused:
986
                case Broadcasting:
987
                    this.func_152835_I();
988
            }
989
        }
990
    }
991
992
    protected void func_152835_I()
993
    {
994
        long i = System.nanoTime();
995
        long j = (i - this.field_152890_z) / 1000000000L;
996
997
        if (j >= 30L)
998
        {
999
            this.field_152890_z = i;
1000
            ErrorCode errorcode = this.theStream.getStreamInfo(this.authenticationToken, this.field_152880_p);
1001
1002
            if (ErrorCode.failed(errorcode))
1003
            {
1004
                String s = ErrorCode.getString(errorcode);
1005
                this.logError(String.format("Error in TTV_GetStreamInfo: %s", new Object[] {s}));
1006
            }
1007
        }
1008
    }
1009
1010
    public IngestServerTester func_152838_J()
1011
    {
1012
        if (this.isReadyToBroadcast() && this.ingestList != null)
1013
        {
1014
            if (this.isIngestTesting())
1015
            {
1016
                return null;
1017
            }
1018
            else
1019
            {
1020
                this.ingestServTester = new IngestServerTester(this.theStream, this.ingestList);
1021
                this.ingestServTester.func_176004_j();
1022
                this.func_152827_a(BroadcastController.BroadcastState.IngestTesting);
1023
                return this.ingestServTester;
1024
            }
1025
        }
1026
        else
1027
        {
1028
            return null;
1029
        }
1030
    }
1031
1032
    protected boolean func_152823_L()
1033
    {
1034
        for (int i = 0; i < 3; ++i)
1035
        {
1036
            FrameBuffer framebuffer = this.theStream.allocateFrameBuffer(this.videoParamaters.outputWidth * this.videoParamaters.outputHeight * 4);
1037
1038
            if (!framebuffer.getIsValid())
1039
            {
1040
                this.logError(String.format("Error while allocating frame buffer", new Object[0]));
1041
                return false;
1042
            }
1043
1044
            this.field_152874_j.add(framebuffer);
1045
            this.field_152875_k.add(framebuffer);
1046
        }
1047
1048
        return true;
1049
    }
1050
1051
    protected void func_152831_M()
1052
    {
1053
        for (int i = 0; i < this.field_152874_j.size(); ++i)
1054
        {
1055
            FrameBuffer framebuffer = (FrameBuffer)this.field_152874_j.get(i);
1056
            framebuffer.free();
1057
        }
1058
1059
        this.field_152875_k.clear();
1060
        this.field_152874_j.clear();
1061
    }
1062
1063
    public FrameBuffer func_152822_N()
1064
    {
1065
        if (this.field_152875_k.size() == 0)
1066
        {
1067
            this.logError(String.format("Out of free buffers, this should never happen", new Object[0]));
1068
            return null;
1069
        }
1070
        else
1071
        {
1072
            FrameBuffer framebuffer = (FrameBuffer)this.field_152875_k.get(this.field_152875_k.size() - 1);
1073
            this.field_152875_k.remove(this.field_152875_k.size() - 1);
1074
            return framebuffer;
1075
        }
1076
    }
1077
1078
    /**
1079
     * caputres the current framebuffer
1080
     */
1081
    public void captureFramebuffer(FrameBuffer p_152846_1_)
1082
    {
1083
        try
1084
        {
1085
            this.theStream.captureFrameBuffer_ReadPixels(p_152846_1_);
1086
        }
1087
        catch (Throwable throwable)
1088
        {
1089
            CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Trying to submit a frame to Twitch");
1090
            CrashReportCategory crashreportcategory = crashreport.makeCategory("Broadcast State");
1091
            crashreportcategory.addCrashSection("Last reported errors", Arrays.toString(field_152862_C.func_152756_c()));
1092
            crashreportcategory.addCrashSection("Buffer", p_152846_1_);
1093
            crashreportcategory.addCrashSection("Free buffer count", Integer.valueOf(this.field_152875_k.size()));
1094
            crashreportcategory.addCrashSection("Capture buffer count", Integer.valueOf(this.field_152874_j.size()));
1095
            throw new ReportedException(crashreport);
1096
        }
1097
    }
1098
1099
    /**
1100
     * passes the framebuffer on to the video stream
1101
     *  
1102
     * @param frame The FrameBuffer tu submit
1103
     */
1104
    public ErrorCode submitStreamFrame(FrameBuffer frame)
1105
    {
1106
        if (this.isBroadcastPaused())
1107
        {
1108
            this.func_152854_G();
1109
        }
1110
        else if (!this.isBroadcasting())
1111
        {
1112
            return ErrorCode.TTV_EC_STREAM_NOT_STARTED;
1113
        }
1114
1115
        ErrorCode errorcode = this.theStream.submitVideoFrame(frame);
1116
1117
        if (errorcode != ErrorCode.TTV_EC_SUCCESS)
1118
        {
1119
            String s = ErrorCode.getString(errorcode);
1120
1121
            if (ErrorCode.succeeded(errorcode))
1122
            {
1123
                this.logWarning(String.format("Warning in SubmitTexturePointer: %s\n", new Object[] {s}));
1124
            }
1125
            else
1126
            {
1127
                this.logError(String.format("Error in SubmitTexturePointer: %s\n", new Object[] {s}));
1128
                this.stopBroadcasting();
1129
            }
1130
1131
            if (this.broadcastListener != null)
1132
            {
1133
                this.broadcastListener.func_152893_b(errorcode);
1134
            }
1135
        }
1136
1137
        return errorcode;
1138
    }
1139
1140
    protected boolean func_152853_a(ErrorCode p_152853_1_)
1141
    {
1142
        if (ErrorCode.failed(p_152853_1_))
1143
        {
1144
            this.logError(ErrorCode.getString(p_152853_1_));
1145
            return false;
1146
        }
1147
        else
1148
        {
1149
            return true;
1150
        }
1151
    }
1152
1153
    /**
1154
     * Log an error
1155
     *  
1156
     * @param error The error to log
1157
     */
1158
    protected void logError(String error)
1159
    {
1160
        this.lastError = error;
1161
        field_152862_C.func_152757_a("<Error> " + error);
1162
        logger.error(TwitchStream.STREAM_MARKER, "[Broadcast controller] {}", new Object[] {error});
1163
    }
1164
1165
    /**
1166
     * Log an warning
1167
     *  
1168
     * @param warning The warning to log
1169
     */
1170
    protected void logWarning(String warning)
1171
    {
1172
        field_152862_C.func_152757_a("<Warning> " + warning);
1173
        logger.warn(TwitchStream.STREAM_MARKER, "[Broadcast controller] {}", new Object[] {warning});
1174
    }
1175
1176
    public interface BroadcastListener
1177
    {
1178
        void func_152900_a(ErrorCode p_152900_1_, AuthToken p_152900_2_);
1179
1180
        void func_152897_a(ErrorCode p_152897_1_);
1181
1182
        void func_152898_a(ErrorCode p_152898_1_, GameInfo[] p_152898_2_);
1183
1184
        void func_152891_a(BroadcastController.BroadcastState p_152891_1_);
1185
1186
        void func_152895_a();
1187
1188
        void func_152894_a(StreamInfo p_152894_1_);
1189
1190
        void func_152896_a(IngestList p_152896_1_);
1191
1192
        void func_152893_b(ErrorCode p_152893_1_);
1193
1194
        void func_152899_b();
1195
1196
        void func_152901_c();
1197
1198
        void func_152892_c(ErrorCode p_152892_1_);
1199
    }
1200
1201
    public static enum BroadcastState
1202
    {
1203
        Uninitialized,
1204
        Initialized,
1205
        Authenticating,
1206
        Authenticated,
1207
        LoggingIn,
1208
        LoggedIn,
1209
        FindingIngestServer,
1210
        ReceivedIngestServers,
1211
        ReadyToBroadcast,
1212
        Starting,
1213
        Broadcasting,
1214
        Stopping,
1215
        Paused,
1216
        IngestTesting;
1217
    }
1218
}
1219

Deobfuscated MCP 1.8.9 source of BroadcastController from Marcelektro/MavenMCP-1.8.9 (net/minecraft/client/stream/BroadcastController.java), stored verbatim.