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

Function session_start

src/server/NymphCastServer.cpp:708–804  ·  view source on GitHub ↗

Client starts a session. Return value: OK (0), ERROR (1). int session_start(struct fileInfo)

Source from the content-addressed store, hash-verified

706// Return value: OK (0), ERROR (1).
707// int session_start(struct fileInfo)
708NymphMessage* session_start(int session, NymphMessage* msg, void* data) {
709 NymphMessage* returnMsg = msg->getReplyMessage();
710
711 // Set up a new session instance for the client.
712 std::map<int, CastClient>::iterator it;
713 it = clients.find(session);
714 if (it == clients.end()) {
715 returnMsg->setResultValue(new NymphType((uint8_t) 1));
716 msg->discard();
717
718 return returnMsg;
719 }
720
721 // Obtain the filesize from the client, which we use with the buffer management.
722 NymphType* fileInfo = msg->parameters()[0];
723 NymphType* num = 0;
724 if (!fileInfo->getStructValue("filesize", num)) {
725 NYMPH_LOG_FATAL("Didn't find entry 'filesize'. Aborting...");
726 returnMsg->setResultValue(new NymphType((uint8_t) 1));
727 msg->discard();
728
729 return returnMsg;
730 }
731
732 it->second.filesize = num->getUint32();
733
734 // Check whether we're already playing or not. If we continue here, this will forcefully
735 // end current playback.
736 // FIXME: => this likely happens due to a status update glitch. Fix by sending back status update
737 // along with error?
738 if (ffplay.playbackActive()) {
739 NYMPH_LOG_ERROR("Trying to start a new session with session already active. Abort.");
740 returnMsg->setResultValue(new NymphType((uint8_t) 1));
741 msg->discard();
742
743 return returnMsg;
744 }
745
746 // If the AV thread is currently running, we wait until it's quit.
747 //if (avThread.joinable()) { avThread.join(); } // FIXME: C++11 version
748 /* if (avThread.isRunning()) {
749 std::cout << "AV thread active: waiting for join..." << std::endl;
750 bool ret = avThread.tryJoin(100);
751 if (!ret) {
752 // Player thread is still running, meaning we cannot proceed. Error out.
753 std::cerr << "Joining failed: aborting new session..." << std::endl;
754 returnMsg->setResultValue(new NymphType((uint8_t) 1));
755 msg->discard();
756
757 return returnMsg;
758 }
759 } */
760
761 NYMPH_LOG_INFORMATION("Starting new session for file with size: " +
762 Poco::NumberFormatter::format(it->second.filesize));
763
764 DataBuffer::setFileSize(it->second.filesize);
765 DataBuffer::setSessionHandle(session);

Callers

nothing calls this directly

Calls 4

formatFunction · 0.85
findMethod · 0.45
endMethod · 0.45
playbackActiveMethod · 0.45

Tested by

no test coverage detected