void MoonlightInstance::NvHTTPInit(int32_t callbackId, pp::VarArray args) { std::string _cert = args.Get(0).AsString(); std::string _key = args.Get(1).AsString(); std::string _uniqueId = args.Get(2).AsString(); LoadCert(_cert.c_str(), _key.c_str()); g_UniqueId = strdup(_uniqueId.c_str()); pp::VarDictionary ret; ret.Set("callbackId", pp::Var(callbackId)); ret.Set("type", pp::Var("resolve")); ret.Set("ret", pp::Var("")); PostMessage(ret); }
void MoonlightInstance::HandleStartStream(int32_t callbackId, pp::VarArray args) { std::string host = args.Get(0).AsString(); std::string width = args.Get(1).AsString(); std::string height = args.Get(2).AsString(); std::string fps = args.Get(3).AsString(); std::string bitrate = args.Get(4).AsString(); std::string rikey = args.Get(5).AsString(); std::string rikeyid = args.Get(6).AsString(); std::string appversion = args.Get(7).AsString(); pp::Var response("Setting stream width to: " + width); PostMessage(response); response = ("Setting stream height to: " + height); PostMessage(response); response = ("Setting stream fps to: " + fps); PostMessage(response); response = ("Setting stream host to: " + host); PostMessage(response); response = ("Setting stream bitrate to: " + bitrate); PostMessage(response); response = ("Setting rikey to: " + rikey); PostMessage(response); response = ("Setting rikeyid to: " + rikeyid); PostMessage(response); response = ("Setting appversion to: " + appversion); PostMessage(response); // Populate the stream configuration LiInitializeStreamConfiguration(&m_StreamConfig); m_StreamConfig.width = stoi(width); m_StreamConfig.height = stoi(height); m_StreamConfig.fps = stoi(fps); m_StreamConfig.bitrate = stoi(bitrate); // kilobits per second m_StreamConfig.streamingRemotely = 0; m_StreamConfig.audioConfiguration = AUDIO_CONFIGURATION_STEREO; // The overhead of receiving a packet is much higher in NaCl because we must // pass through various layers of abstraction on each recv() call. We're using a // higher than normal default video packet size here to reduce CPU cycles wasted // receiving packets. The possible cost is greater network losses. m_StreamConfig.packetSize = 1392; // Load the rikey and rikeyid into the stream configuration hexStringToBytes(rikey.c_str(), m_StreamConfig.remoteInputAesKey); int rikeyiv = htonl(stoi(rikeyid)); memcpy(m_StreamConfig.remoteInputAesIv, &rikeyiv, sizeof(rikeyiv)); // Store the parameters from the start message m_Host = host; m_AppVersion = appversion; // Initialize the rendering surface before starting the connection if (InitializeRenderingSurface(m_StreamConfig.width, m_StreamConfig.height)) { // Start the worker thread to establish the connection pthread_create(&m_ConnectionThread, NULL, MoonlightInstance::ConnectionThreadFunc, this); } else { // Failed to initialize renderer OnConnectionStopped(0); } pp::VarDictionary ret; ret.Set("callbackId", pp::Var(callbackId)); ret.Set("type", pp::Var("resolve")); ret.Set("ret", pp::VarDictionary()); PostMessage(ret); }