Twitch SDK (Internal)
rtmpcontext.h
Go to the documentation of this file.
1 /********************************************************************************************
2 * Twitch Broadcasting SDK
3 *
4 * This software is supplied under the terms of a license agreement with Twitch Interactive, Inc. and
5 * may not be copied or used except in accordance with the terms of that agreement
6 * Copyright (c) 2012-2016 Twitch Interactive, Inc.
7 *********************************************************************************************/
8 
9 #pragma once
10 
11 #include "twitchsdk/core/socket.h"
13 
14 namespace ttv
15 {
16  namespace broadcast
17  {
18  struct RtmpContext;
19  class StreamStats;
20  }
21 }
22 
23 
25 // Context for RTMP operations.
26 //
27 // Making this a struct and not a class because it's usage is encapsulated
28 // by designed. Nothing has access to this except for the states themselves
30 
32 {
33 public:
34  enum class State
35  {
36  Invalid = -1,
37  Idle,
38  Initialize,
39  Handshake,
40  Connect,
42  Publish,
43  SendVideo,
44  Shutdown,
45  Error,
46 
47  Count
48  };
49 
50 public:
51  RtmpContext(std::shared_ptr<StreamStats> streamStats);
52 
53  std::string mURL;
54  std::string mHostName;
55  std::string mApplication;
56  uint32_t mPort;
57  std::string mStreamName;
58 
59  static const uint32_t kDesiredOutgoingChunkSize = 4096;
62  uint mWindowAckSize; // TODO: Should we also ack?
64 
65  size_t mChunkSpace; // How much more space do we have in the current chunk until a new header is needed
66 
68  double mStreamId;
69 
72 
74 
75  std::shared_ptr<StreamStats> mStreamStats;
76 
77  void SetNextState(State nextState);
78 
80  {
81  OnStateChange();
83  ttv::trace::Message("rtmp", TTV_ML_INFO, "Setting current state to %d", mCurrentState);
84  }
85 
86  State GetCurrentState() const { return mCurrentState; }
87  State GetNextState() const { return mNextState; }
88 
89 private:
92 
93  void OnStateChange();
94 };
Definition: tracingtypes.h:17
uint mIncomingChunkSize
Definition: rtmpcontext.h:60
void SetCurrentStateToNext()
Definition: rtmpcontext.h:79
std::string mApplication
Definition: rtmpcontext.h:55
State GetNextState() const
Definition: rtmpcontext.h:87
Definition: rtmpcontext.h:31
std::string mStreamName
Definition: rtmpcontext.h:57
JSON (JavaScript Object Notation).
Definition: adsapi.h:16
TTV_ErrorCode mLastError
Definition: rtmpcontext.h:70
double mTransactionId
Definition: rtmpcontext.h:67
Definition: socket.h:477
State mNextState
Definition: rtmpcontext.h:91
size_t mChunkSpace
Definition: rtmpcontext.h:65
void Message(const char *component, const TTV_MessageLevel messageLevel, const char *format,...)
uint32_t mPort
Definition: rtmpcontext.h:56
double mStreamId
Definition: rtmpcontext.h:68
State
Definition: rtmpcontext.h:34
BufferedSocket mSocket
Definition: rtmpcontext.h:71
uint32_t TTV_ErrorCode
Definition: errortypes.h:30
std::string mURL
Definition: rtmpcontext.h:53
unsigned int uint
Definition: coretypes.h:18
std::shared_ptr< StreamStats > mStreamStats
Definition: rtmpcontext.h:75
RtmpContext(std::shared_ptr< StreamStats > streamStats)
std::string mHostName
Definition: rtmpcontext.h:54
void SetNextState(State nextState)
uint mIncomingPeerBW
Definition: rtmpcontext.h:63
static const uint32_t kDesiredOutgoingChunkSize
Definition: rtmpcontext.h:59
uint mOutgoingChunkSize
Definition: rtmpcontext.h:61
AMF0Encoder mAmfEncoder
Definition: rtmpcontext.h:73
uint mWindowAckSize
Definition: rtmpcontext.h:62
Definition: amf0encoder.h:26
State mCurrentState
Definition: rtmpcontext.h:90
State GetCurrentState() const
Definition: rtmpcontext.h:86