MCPcopy Create free account
hub / github.com/MayaPosch/NymphCast / session_data

Function session_data

src/server/NymphCastServer.cpp:929–1036  ·  view source on GitHub ↗

Client sends a chunk of track data. Returns: OK (0), ERROR (1). int session_data(string buffer, boolean done)

Source from the content-addressed store, hash-verified

927// Returns: OK (0), ERROR (1).
928// int session_data(string buffer, boolean done)
929NymphMessage* session_data(int session, NymphMessage* msg, void* data) {
930 NymphMessage* returnMsg = msg->getReplyMessage();
931
932 // Get iterator to the session instance for the client.
933 std::map<int, CastClient>::iterator it;
934 it = clients.find(session);
935 if (it == clients.end()) {
936 returnMsg->setResultValue(new NymphType((uint8_t) 1));
937 msg->discard();
938 return returnMsg;
939 }
940
941 // Safely write the data for this session to the buffer.
942 NymphType* mediaData = msg->parameters()[0];
943 bool done = msg->parameters()[1]->getBool();
944
945 // Update EOF status.
946 DataBuffer::setEof(done);
947
948 // Write string into buffer.
949 DataBuffer::write(mediaData->getChar(), mediaData->string_length());
950
951 // If passing the message through to slave remotes, add the timestamp to the message.
952 // This timestamp is the current time plus the largest master-slave latency times 2.
953 int64_t then = 0;
954 if (serverMode == NCS_MODE_MASTER) {
955 Poco::Timestamp ts;
956 int64_t now = (int64_t) ts.epochMicroseconds();
957 //then = now + (slaveLatencyMax * 2);
958
959 // Timing: Multiply the max slave latency by the number of slaves. After sending this delay
960 // to the first slave (minus half its recorded latency),
961 // subtract the time it took to send to this slave from the
962 // first delay, then send this new delay to the second slave, and so on.
963 int64_t countdown = slaveLatencyMax * slave_remotes.size();
964
965 for (int i = 0; i < slave_remotes.size(); ++i) {
966 NymphCastSlaveRemote& rm = slave_remotes[i];
967 //then = slaveLatencyMax - rm.delay;
968 then = countdown - (rm.delay / 2);
969
970 int64_t send = (int64_t) ts.epochMicroseconds();
971
972 // Prepare data vector.
973 NymphType* media = new NymphType((char*) mediaData->getChar(), mediaData->string_length());
974 NymphType* doneBool = new NymphType(done);
975 std::vector<NymphType*> values;
976 values.push_back(media);
977 values.push_back(doneBool);
978 values.push_back(new NymphType(then));
979
980 std::string result;
981 NymphType* returnValue = 0;
982 if (!NymphRemoteServer::callMethod(rm.handle, "receiveDataMaster", values, returnValue, result)) {
983 // TODO:
984 }
985
986 delete returnValue;

Callers

nothing calls this directly

Calls 7

push_backMethod · 0.80
sendGlobalStatusUpdateFunction · 0.70
findMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
playbackActiveMethod · 0.45
playTrackMethod · 0.45

Tested by

no test coverage detected