void resolveCB(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char *fullname, const char *hosttarget, uint16_t port, uint16_t txtLen, const char *txtRecord, void *context) { player_sd_dev_t* sddev = (player_sd_dev_t*)context; const char* value; uint8_t value_len; char* colon; char buf[PLAYER_SD_TXT_MAXLEN]; // Handle resolution result if(errorCode == kDNSServiceErr_NoError) { // Fill in the address info memset(sddev->hostname,0,sizeof(sddev->hostname)); strncpy(sddev->hostname,hosttarget,sizeof(sddev->hostname)-1); sddev->robot = port; if(!(value = (const char*)TXTRecordGetValuePtr(txtLen, txtRecord, PLAYER_SD_DEVICE_TXTNAME, &value_len))) { PLAYER_ERROR1("Failed to find TXT info for service %s\n", sddev->name); sddev->addr_fail = 1; return; } if(!(colon = strchr(value,':')) || ((colon-value) <= 0) || ((value_len - (colon-value+1)) <= 0)) { PLAYER_ERROR2("Failed to parse TXT info \"%s\" for service %s\n", value, sddev->name); sddev->addr_fail = 1; return; } memset(buf,0,sizeof(buf)); strncpy(buf,value,(colon-value)); sddev->interf = str_to_interf(buf); memset(buf,0,sizeof(buf)); strncpy(buf,colon+1,(value_len-(colon-value+1))); sddev->index = atoi(buf); sddev->addr_valid = 1; } else { // Something went wrong. sddev->addr_fail = 1; } }
//////////////////////////////////////////////////////////////////////////////// // Check that we have some data in the message. bool LocalBB::CheckHeader(player_msghdr * hdr) { if (hdr->size <= 0) { PLAYER_ERROR2("request is wrong length (%d <= %d); ignoring", hdr->size, 0); return false; } return true; }
/** * Apply setting according to field value read from config or request; * changed are: this->fieldType * @param sfield one of values mentioned in config for "field" setting * @return 0 on success */ int CameraV4L2::selectField(const char *sfield){ int i; for(i=0; fieldy[i].name; i++) if (strcasecmp(sfield, fieldy[i].name) == 0) break; if (fieldy[i].name){ this->fieldType = fieldy[i].fieldType; } else { PLAYER_ERROR2("Field type %s is not supported", sfield, __FILE__); return -1; } return 0; }
/** * Apply setting according to mode value from config or request; * changed are: this->data.format, this->depth, this->v4l2_type_id * @param sformat one of values mentioned in config for "mode" setting * @return 0 on success */ int CameraV4L2::selectFormat(const char *sformat){ int i; for(i=0; formaty[i].name; i++) if (strcasecmp(sformat, formaty[i].name) == 0) break; if (formaty[i].name){ this->data.format = formaty[i].player_type_id; this->depth = formaty[i].bits; this->v4l2_type_id = formaty[i].v4l2_type_id; } else { PLAYER_ERROR2("image pallete %s is not supported (add it yourself to formaty struct in %s)", sformat, __FILE__); return -1; } return 0; }
/** * Apply setting according to snorm value read from config or request; * changed are: this->norm, this->width, this->height * @param snorm one of values mentioned in config for "norm" setting * @return 0 on success */ int CameraV4L2::selectNorm(const char *snorm){ int i=0; for(i=0; normy[i].name; i++) if (strcasecmp(snorm, normy[i].name) == 0) break; if (normy[i].name){ this->norm = normy[i].id; this->width = normy[i].width; this->height = normy[i].height; } else { PLAYER_ERROR2("norm: %s is not supported (add it yourself to normy struct in %s)", snorm, __FILE__); return -1; } return 0; }
/** @brief Update the device data (the data going back to the client). */ void CameraV4L2::WriteData() { size_t image_size, size; unsigned char * ptr1, * ptr2; struct my_buffer *v4lBuffer = getFrameBuffer(fg); if (v4lBuffer==NULL) exit(1); ptr1 = (unsigned char *)v4lBuffer->start; ptr2 = this->data.image; // Compute size of image image_size = this->width * this->height * this->depth / 8; // Set the image properties this->data.width = htons(this->width); this->data.height = htons(this->height); this->data.bpp = this->depth; this->data.compression = PLAYER_CAMERA_COMPRESS_RAW; this->data.image_size = htonl(image_size); if (image_size > sizeof(this->data.image)){ PLAYER_ERROR2("image_size <= sizeof(this->data.image) failed: %d > %d", image_size, sizeof(this->data.image)); } assert(image_size <= sizeof(this->data.image)); if (image_size > (size_t) v4lBuffer->length){ PLAYER_WARN("Frame size is smaller then expected"); image_size = (size_t) v4lBuffer->length; } //assert(image_size <= (size_t) v4lBuffer->length); if (!flip_rb) { memcpy(ptr2, ptr1, image_size); } else { int imgSize = ((this->width) * (this->height)); int i; switch (v4l2_type_id) { case V4L2_PIX_FMT_RGB24: case V4L2_PIX_FMT_BGR24: for (i = 0; i < imgSize; i++) { ptr2[0] = ptr1[2]; ptr2[1] = ptr1[1]; ptr2[2] = ptr1[0]; ptr1 += 3; ptr2 += 3; } break; case V4L2_PIX_FMT_RGB32: case V4L2_PIX_FMT_BGR32: for (i = 0; i < imgSize; i++) { ptr2[0] = ptr1[2]; ptr2[1] = ptr1[1]; ptr2[2] = ptr1[0]; ptr2[3] = ptr1[3]; ptr1 += 4; ptr2 += 4; } break; default: memcpy(ptr2, ptr1, image_size); } } // Copy data to server size = sizeof(this->data) - sizeof(this->data.image) + image_size; struct timeval timestamp; timestamp.tv_sec = this->tsec; timestamp.tv_usec = this->tusec; PutData((void*) &this->data, size, ×tamp); giveBackFrameBuffer(fg, v4lBuffer); return; }