Skip to content

Commit

Permalink
Bitrate now changes depending on the input of other players
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel committed May 23, 2017
1 parent 2a998eb commit 0ce2c9e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
27 changes: 16 additions & 11 deletions samples/DirectxIFR/DXIFRShim/Common/NvIFREncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ std::atomic_bool isThreadStarted[MAX_PLAYERS] = { false, false, false, false };
std::atomic_bool isThreadComplete[MAX_PLAYERS] = { false, false, false, false }; // to ensure that AVCodecContext is fully set up by the thread before it is properly applied
AVCodecContext *codecContextArray[MAX_PLAYERS] = {}; // to store the new AVCodecContext created by the thread
setupAVCodecStruct st[MAX_PLAYERS];
const int bandwidthPerPlayer = 1500000;
const int bandwidthPerPlayer = 2000000;
int totalBandwidthAvailable = 0;
int sumWeight = 0;
int playerInputArray[MAX_PLAYERS] = { 0 };
Expand Down Expand Up @@ -774,20 +774,25 @@ void NvIFREncoder::EncoderThreadProc(int index)
}
ResetEvent(gpuEvent[index]);

if (playerInputArray[index] == 3) { // shooting
targetBitrate = 5000000;
}
else if (playerInputArray[index] == 2) { // mouse movement or any other keyboard key
targetBitrate = 2500000;
}
else if (playerInputArray[index] == 1) { // no input
targetBitrate = 500000;
}
// Adaptive bitrate - independent of other players
//if (playerInputArray[index] == 3) { // shooting
// targetBitrate = 5000000;
//}
//else if (playerInputArray[index] == 2) { // mouse movement or any other keyboard key
// targetBitrate = 2500000;
//}
//else if (playerInputArray[index] == 1) { // no input
// targetBitrate = 500000;
//}

// Adaptive bitrate - depends on other players
float weight = (float)playerInputArray[index] / (float)sumWeight;
targetBitrate = (int)(weight * totalBandwidthAvailable);

if (targetBitrate != currentBitrate)
{
NvIFREncoderLogFile.open("NvIFREncoderLogFile.txt", std::ios::app);
NvIFREncoderLogFile << "Changing bitrate to = " << targetBitrate << ". Current bitrate = " << currentBitrate << "\n";
NvIFREncoderLogFile << "Player " << index << " changing bitrate to = " << targetBitrate << ". Current bitrate = " << currentBitrate << "\n";
NvIFREncoderLogFile.close();
nvEncoder.EncodeFrameLoop(bufferArray[index], true, index, targetBitrate);
currentBitrate = targetBitrate;
Expand Down
2 changes: 1 addition & 1 deletion samples/DirectxIFR/DXIFRShim/DXGI/NvEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ void CNvEncoder::EncodeFrameLoop(uint8_t *buffer, bool isReconfiguringBitrate, i
{
printf("bitrate changed!\n");
NvEncoderLogFile.open("NvEncoderLogFile.txt", std::ios::app);
NvEncoderLogFile << "Bitrate changed to " << targetBitrate << "\n";
NvEncoderLogFile << "Player " << index << " bitrate changed to " << targetBitrate << "\n";
NvEncoderLogFile.close();
}
else
Expand Down

0 comments on commit 0ce2c9e

Please sign in to comment.