bool Configuration::getAudioGrade(MediaElement::AudioGrade& audioGrade) const{ bool exist = false; int value = toN(optionsToValue.get(AUDIO_GRADE_VALUE_OPT, exist), int()); MediaElement::AudioGrade::Type gradeType = (MediaElement::AudioGrade::Type)toN(optionsToValue.get(AUDIO_GRADE_VALUE_OPT, exist), int()); audioGrade = MediaElement::AudioGrade(value, gradeType); return exist; }
double ConvertParser::toSecondTime(const std::string& time){ std::string::size_type pos; std::string tmpTime = time; double secondTime = 0; while((pos = tmpTime.find(":"))!= std::string::npos){ std::string sub = tmpTime.substr(0, pos); secondTime = secondTime*60 + toN(sub, int()); tmpTime = tmpTime.substr(pos+1); } secondTime = secondTime*60 + toN(tmpTime, int()); return secondTime; }
bool Configuration::getVideoFFpreset(MediaElement::FFpreset& ffpreset) const{ bool exist = true; int type = toN(optionsToValue.get(VIDEO_FFPRESET_TYPE_OPT, exist), int()); if(!exist){ return false; } MediaElement::FFpreset::FFType fftype = (MediaElement::FFpreset::FFType)type; if(fftype == MediaElement::FFpreset::DISABLE_FFTYPE){ ffpreset = MediaElement::FFpreset(std::string(), std::string(), fftype); return true; } std::string path = optionsToValue.get(VIDEO_FFPRESET_PATH_OPT, exist); if(!exist){ return false; } Path ffFilePath(path); std::string prefix = optionsToValue.get(VIDEO_FFPRESET_PREFIX_OPT, exist); if(!exist){ return false; } ffpreset = MediaElement::FFpreset(ffFilePath, prefix, fftype); return true; }
bool Configuration::getVideoResolution(MediaElement::Resolution& resolution) const{ bool exist; int x = toN(optionsToValue.get(VIDEO_RESOLUTION_X_OPT, exist), int()); if(x == -1){ return true; } if(!exist){ return false; } int y = toN(optionsToValue.get(VIDEO_RESOLUTION_Y_OPT, exist), int()); std::string name = optionsToValue.get(VIDEO_RESOLUTION_NAME_OPT, exist); std::string aspect = optionsToValue.get(VIDEO_RESOLUTION_ASP_OPT, exist); resolution = MediaElement::Resolution(name, MediaElement::AspectRatio::createFromString(aspect), x, y); return true; }
bool Configuration::getVideoBitrate(MediaElement::Bitrate& videoBitrate) const{ bool exist; int bitrate = toN(optionsToValue.get(VIDEO_BITRATE_OPT, exist), int()); if(!exist){ return false; } int bitrateMin = toN(optionsToValue.get(VIDEO_BITRATE_MIN_OPT, exist), int()); if(!exist){ bitrateMin = -1; } int bitrateMax = toN(optionsToValue.get(VIDEO_BITRATE_MAX_OPT, exist), int()); if(!exist){ bitrateMax = -1; } int buffer = toN(optionsToValue.get(VIDEO_BUFFER_OPT, exist), int()); if(!exist){ buffer = -1; } videoBitrate = MediaElement::Bitrate(bitrate, buffer, bitrateMin, bitrateMax); return true; }
bool Configuration::getAudioChannel(MediaElement::Channel& audioChannel) const{ bool exist = false; int numOfChannel = toN(optionsToValue.get(AUDIO_CHANNEL_VALUE_OPT, exist), int()); if(!exist){ return false; } if(numOfChannel < 0){ return true; } std::string name = optionsToValue.get(AUDIO_CHANNEL_NAME_OPT, exist); if(!exist){ return false; } audioChannel = MediaElement::Channel(name, numOfChannel); return true; }
int main(int argc, char** argv) { printf("(UDP) File Transfer Server\n"); printf("Anthony Phelps, aphelps\n"); char* port; port = malloc(sizeof(char*)*5); //Argument parsing if(argc > 1) { strcpy(port, argv[1]); } else { strcpy(port, "54323"); } struct addrinfo hints, *res; memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_DGRAM; hints.ai_flags = AI_PASSIVE; //Get network info about the server int addrStats = getaddrinfo(NULL, port, &hints, &res); if(addrStats < 0) { perror("[ERROR] Could not get address info"); exit(-1); } //create socket int sockFd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); if(sockFd < 1) { perror("[ERROR] Could not create socket"); exit(-1); } //Bind to port int binRes = bind(sockFd, res->ai_addr, res->ai_addrlen); if(binRes < 0) { perror("[ERROR] Failed to bind to port"); exit(-1); } int curTrans = -1; int curUIN = -1; int totalBytes = -1; int bad = 0; int lastgood = 0; Packet * packs = malloc(sizeof(Packet)*5); int packSize = 5; int packC = 0; int save = 0; //Loop forever because is a server while(1) { struct sockaddr_in remaddr; socklen_t addrlen = sizeof(remaddr); Packet response; response.header = packs[packC].header; //Receive initial data from client printf("[INFO] Waiting for new packet...\n"); int recvB = recvfrom(sockFd, &packs[packC], sizeof(Packet), 0, (struct sockaddr *)&remaddr, &addrlen); if(recvB <= 0) { perror("[ERROR] Could not correctly receive bytes"); exit(-1); } toH(&(packs[packC].header)); if(calcChecksum(&packs[packC], sizeof(Packet)) == 0) { printf("[INFO] Packet received: %i.\n", packs[packC].header.sequenceNumber); lastgood = packs[packC].header.sequenceNumber; totalBytes -= packs[packC].header.nbytes; bad = 0; } else { printf("[INFO] Bad Packets.\n"); bad = 1; } if((curTrans == -1 || curUIN == -1) && bad == 0 && packs[packC].header.sequenceNumber == 1) { printf("[INFO] Packet for new file received.\n"); curTrans = packs[packC].header.transactionNumber; curUIN = packs[packC].header.UIN; totalBytes = packs[packC].header.nTotalBytes-packs[packC].header.nbytes; save = packs[packC].header.saveFile; packC = 0; if(packC >= packSize) { packSize *= 2; packs = realloc(packs, sizeof(Packet)*packSize); } } else if(bad == 0 && curTrans != packs[packC].header.transactionNumber && curUIN != packs[packC].header.UIN) { printf("[WARN] Received packet from different transaction.\n"); } else if(bad == 0 && curTrans == packs[packC].header.transactionNumber && curUIN == packs[packC].header.UIN) { packC += 1; if(packC >= packSize) { packSize *= 2; packs = realloc(packs, sizeof(Packet)*packSize); } } //Setup response packet response.header.ackNumber = lastgood; response.header.garbleChance = packs[packC].header.garbleChance; response.header.packetType = 2; response.header.checksum = 0; response.header.checksum = calcChecksum(&response, sizeof(Packet)); //Send response to client toN(&(response.header)); int sentb = sendto(sockFd, &response, sizeof(Packet), 0, (struct sockaddr *) &remaddr, addrlen); if(sentb < 0) { perror("[ERROR] Failed to send response packet"); exit(1); } if(totalBytes <= 0) { //Write contents to file if(save == 1) { printf("[INFO] Writing data to file.\n"); int file = open(packs[0].header.filename, O_WRONLY | O_CREAT); if(file == -1) { perror("[ERROR] Couldn't create file descriptor"); exit(1); } int i; for(i = 0; i < packC; i++) { write(file, packs[i].data, packs[i].header.nbytes); } close(file); } totalBytes = -1; curTrans = -1; curUIN = -1; } } //Close and free unneeded stuff (Not really ever possible to run this though because the loop is infintie) close(sockFd); freeaddrinfo(res); return 0; }
int VideoStream::priority() const{ int resx = toN(content.get(VideoStream::RESX), int()); int resy = toN(content.get(VideoStream::RESY), int()); return resx*resx + resy*resy; //compare slant // return resx*resy; //compare content }
bool Configuration::getAudioSamplerate(MediaElement::Samplerate& audioSamplerate) const{ bool exist = false; int samplerate = toN(optionsToValue.get(AUDIO_SAMPLERATE_OPT, exist), int()); audioSamplerate = MediaElement::Samplerate(samplerate); return exist; }
bool Configuration::getAudioMode(int& row) const{ bool exist = false; row = toN(optionsToValue.get(AUDIO_MODE_OPT, exist), int()); return exist; }
bool Configuration::getVideoFramerate(MediaElement::Framerate& framerate) const{ bool exist; double frame = toN(optionsToValue.get(VIDEO_FRAMERATE_OPT, exist), double()); framerate = MediaElement::Framerate(frame); return exist; }
bool Configuration::getVideoMode(int& row) const{ //todo object bool exist; row = toN(optionsToValue.get(VIDEO_MODE_OPT, exist),int()); return exist; }