int record(char ** buffer) { pthread_t t; ThreadValues threadValues; int ret; long startTime; /* We open the pi serial port */ threadValues.p = SerialLib_open("/dev/ttyAMA0"); /* The serial port of the raspberry pi */ if(threadValues.p<0) { return -1; } threadValues.frame = newFrame(0x01,0,NULL); threadValues.status=1; /* Creation of the thread for the communication */ ret = pthread_create(&t, NULL,fn_process, &threadValues); startTime = time(NULL); if(!ret) { while(1) { if(0 == threadValues.status) { /* We extract the most relevent part of the string */ int lenght = threadValues.frame->lenght * 8; unsigned char * extraction = extract((unsigned char *)threadValues.frame->content, (int * )&lenght); if(NULL == extraction || 1 == lenght) { freeFrame(threadValues.frame); close(threadValues.p); return -1; } *buffer = hexToString(extraction,lenght); free(extraction); printf("'%s'\n",*buffer); fflush(stdout); //freeFrame(threadValues.frame); close(threadValues.p); return 0; } } pthread_cancel(t); freeFrame(threadValues.frame); close(threadValues.p); return -1; } freeFrame(threadValues.frame); close(threadValues.p); return -1; }
/** \brief Completes writing the stream, closes it, release resources. **/ bool QVideoEncoder::close() { if(!isOk()) return false; av_write_trailer(pFormatCtx); // close_video avcodec_close(pVideoStream->codec); freeFrame(); freeOutputBuf(); /* free the streams */ for(unsigned i = 0; i < pFormatCtx->nb_streams; i++) { av_freep(&pFormatCtx->streams[i]->codec); av_freep(&pFormatCtx->streams[i]); } // Close file avio_close(pFormatCtx->pb); // Free the stream av_free(pFormatCtx); initVars(); return true; }
/** * Handles initialisation of the free pages using the memory map provided by the mboot header. */ void mapFreePages(struct multiboot* mboot_ptr) { uint32_t i = mboot_ptr->mmap_addr; uint32_t freeCounter = 0; while (i < mboot_ptr->mmap_addr + mboot_ptr->mmap_length) { mmap_entry_t *me = (mmap_entry_t*) i; // Does this entry specify usable RAM? if (me->type == 1) { uint32_t j; // For every page in this entry, add to the free page stack. for (j = me->base_addr_low; j < me->base_addr_low + me->length_low; j += 0x1000) { freeFrame(j); freeCounter++; } } //The multiboot specification is strange in this respect - the size member //does not include "size" itself in its calculations, so we must add sizeof //a 32bit int i += me->size + sizeof(uint32_t); } DEBUG_PRINT("Debug Message: Map Free Pages finished with 0x%x pages of free memory (PAGE SIZE: 0x%x)\n", freeCounter, PAGE_SIZE); }
int main(int argc, char ** argv) { pthread_t t; ThreadValues threadValues; int ret; char * string; long startTime; /* We open the pi serial port */ threadValues.p = SerialLib_open("/dev/ttyAMA0"); /* The serial port of the raspberry pi */ if(threadValues.p<0) { return -1; } threadValues.frame = newFrame(0x01,0,NULL); threadValues.status=1; /* Creation of the thread for the communication */ ret = pthread_create(&t, NULL,fn_process, &threadValues); startTime = time(NULL); if(!ret) { while((time(NULL) - startTime) < 3) { if(0 == threadValues.status) { /* We extract the most relevent part of the string */ int lenght = threadValues.frame->lenght ; string = hexToString(threadValues.frame->content,lenght); printf("%s",string); free(string); freeFrame(threadValues.frame); close(threadValues.p); return 0; } } pthread_cancel(t); freeFrame(threadValues.frame); close(threadValues.p); return -1; } freeFrame(threadValues.frame); close(threadValues.p); return -1; }
bool QVideoEncoder::close() { if (!m_isOpen) { return false; } // delayed frames? while (true) { AVPacket pkt = { 0 }; av_init_packet(&pkt); int got_packet = 0; int ret = avcodec_encode_video2(m_ff->codecContext, &pkt, 0, &got_packet); if (ret < 0 || !got_packet) { break; } write_frame(m_ff, &pkt); av_packet_unref(&pkt); } av_write_trailer(m_ff->formatContext); // close the codec avcodec_close(m_ff->videoStream->codec); // free the streams and other data freeFrame(); for(unsigned i = 0; i < m_ff->formatContext->nb_streams; i++) { av_freep(&m_ff->formatContext->streams[i]->codec); av_freep(&m_ff->formatContext->streams[i]); } // close the file avio_close(m_ff->formatContext->pb); // free the stream av_free(m_ff->formatContext); m_isOpen = false; return true; }
int main(int argc, char ** argv) { pthread_t t; ThreadValues threadValues; int ret; int try; char * string; long startTime; /* acquiring the semaphore */ while(!access(SEMAPHORE, F_OK)) { usleep(50000); } FILE *fp = fopen(SEMAPHORE, "ab+"); /* We open the pi serial port */ threadValues.p = SerialLib_open("/dev/ttyAMA0"); /* The serial port of the raspberry pi */ if(threadValues.p<0) { fclose(fp); unlink(SEMAPHORE); return -1; } threadValues.frame = newFrame(0x01,0,NULL); threadValues.status=1; /* Creation of the thread for the communication */ ret = pthread_create(&t, NULL,fn_process, &threadValues); startTime = time(NULL); if(!ret) { do { if(0 == threadValues.status) { /* We extract the most relevent part of the string */ unlink(SEMAPHORE); int lenght = threadValues.frame->lenght * 8; unsigned char * extraction = extractTrueFrame((unsigned char *)threadValues.frame->content, (int * )&lenght); if(NULL == extraction || 1 == lenght) { freeFrame(threadValues.frame); close(threadValues.p); fclose(fp); return -1; } string = hexToString(extraction,lenght); free(extraction); printf("%s",string); free(string); freeFrame(threadValues.frame); close(threadValues.p); fclose(fp); return 0; }while((time(NULL) - startTime) < 50); } pthread_cancel(t); freeFrame(threadValues.frame); close(threadValues.p); fclose(fp); unlink(SEMAPHORE); return -1; } freeFrame(threadValues.frame); close(threadValues.p); fclose(fp); unlink(SEMAPHORE); return -1; }
void dataInputHandler1(struct WorkerBuf* pWBuf, uint8_t* data) { int sock; int rvl; int i; int len; uint32_t flag; uint8_t chanId; struct DataHeader *pHeader; struct FrameBuf *frame; int total_len = FVL_SRIO_DMA_BUFSIZE/FVL_SRIO_CTL_SUBBUF_NUM; printf("Calling dataInputHandler: total length: %d \n",total_len); if(0) { char strbuf[32]; snprintf(strbuf, 32, "cpu-%02d recv", pWBuf->cpu); fvl_hex_dump(strbuf, data, 128); } LTRACE(); if(pWBuf->line_length != 0) { char *dest; dest = pWBuf->last_line.data; dest += pWBuf->line_length; memcpy(dest, data, pWBuf->line_restlen); LTRACE(); pHeader = (void*) pWBuf->last_line.data; flag = ntohl(pHeader->flag); if(DATA_HEADER_FLAG != flag) { printf("Data last line error! Flag = %x\n", flag); } frame = saveLine(pWBuf, pHeader); if(frame == NULL) { printf("Save last line failed\n"); } LTRACE(); data += pWBuf->line_restlen; total_len -= pWBuf->line_restlen; pWBuf->line_length = 0; pWBuf->line_restlen = 0; } i = 0; while(total_len > 0) { pHeader = (void*) data; chanId = pHeader->chanId; len = GETLEN_BY_CHANID(chanId); //LTRACE(); flag = ntohl(pHeader->flag); if(DATA_HEADER_FLAG != flag) { printf("Data #%d error! Flag = %x\n", i, flag); continue; } //LTRACE(); frame = saveLine(pWBuf, pHeader); if(frame == NULL) { printf("Save line #%d failed\n", pHeader->lineId); } //else { // printf("Save line #%d success\n", pHeader->lineId); // } data += len; total_len -= len; if((total_len != 0) && (total_len < len)) { LTRACE(); // fvl_hex_dump("Copylast", data, 128); pWBuf->line_length = total_len; pWBuf->line_restlen = len - total_len; printf("copy to %p, from %p, size %d\n", pWBuf->last_line.data, data, total_len); memcpy(pWBuf->last_line.data, data, total_len); pHeader = (void*) pWBuf->last_line.data; flag = ntohl(pHeader->flag); if(DATA_HEADER_FLAG != flag) { printf("Copy data last line error! Flag = %x\n", flag); } break; } i++; } LTRACE(); do{ LTRACE(); frame = getFullFrame(pWBuf); if(frame == NULL) { break; } LTRACE(); chanId = pHeader->chanId; sock = getSocket(chanId); LTRACE(); for(i = 0; i < 256; i++) { struct DataLine *line; line = &frame->lines[i]; pHeader = (void*) line->header; chanId = pHeader->chanId; len = GETLEN_BY_CHANID(chanId); // send buffer here rvl = fvl_tcp_send(sock, (void*)line->data, len); if(rvl < 0) { printf("Send failed!\n"); } } printf("send frame #%d done\n", pHeader->frameId); freeFrame(frame); } while(1); return; }
void freePage(int number){ pageTable[number] = 0; freeFrame(number); }
int main(int argc, char *argv[]){ if (argc != 1) { printf("USAGE: ./copyFrameTestCUDA\n"); printf(" only works if blobDetection works\n"); return 1; } const char *filename = "frames/diff/frame_1.jpg"; frame_t *frame = (frame_t *)malloc(sizeof(struct frame_s)); if (readImageFrame(frame, filename) == 1) { printf("Unable to read frame at [%s]\n", filename); return 1; } if (blobDetection(frame) == 1) { printf("Unable to detect blobs\n"); return 1; } printf("Copying frame\n"); frame_t *res = copyFrame(frame); if (res == NULL) { printf("Unable to copy frame\n"); return 1; } printf("----Checking all values in frame are the same----\n"); printf("Checking image data is correct\n"); int numBoxes = frame->numBoxes; int i; pixel_t p, pOrig; for (i = 0; i < res->image->width*res->image->height; i++) { p = res->image->data[i]; pOrig = frame->image->data[i]; if ((p.L != pOrig.L) || (p.A != pOrig.A) || (p.B != pOrig.B) || (p.S != pOrig.S) || (p.label != pOrig.label)){ printf("Pixel[%d] not valid\n", i); return 1; } } printf("Checking box data is correct\n"); if (frame->arBoxes == NULL) { printf("No boxes found in array\n"); if (res->arBoxes != NULL) { printf("Boxes not initialized correctly\n"); return 1; } } else { printf("Boxes found in array\n"); box_t *pFbox = frame->arBoxes; box_t *pRbox = res->arBoxes; if (frame->numBoxes != res->numBoxes) { printf("Boxes are not equal in number\n"); return 1; } for (i = 0; i < frame->numBoxes; i++) { box_t *box = &pFbox[i]; box_t *rbox = &pRbox[i]; if (box->startx != rbox->startx) { printf("box %d startx not initialized correctly\n", i); //return 1; } if (box->starty != rbox->starty) { printf("box %d starty not initialized correctly\n", i); //return 1; } if (box->centroid_x != rbox->centroid_x) { printf("box %d centroid_x not initialized correctly (original, copied) -> (%d, %d)\n", i, box->centroid_x, rbox->centroid_x); //return 1; } if (box->centroid_y != rbox->centroid_y) { printf("box %d centroid_y not initialized correctly\n", i); ///return 1; } if (box->center_x != rbox->center_x) { printf("box %d center_x not initialized correctly\n", i); //return 1; } if (box->center_y != rbox->center_y) { printf("box %d center_y not initialized correctly\n", i); //return 1; } if (box->height != rbox->height) { printf("box %d height not initialized correctly\n", i); //return 1; } if (box->width != rbox->width) { printf("box %d width not initialized correctly\n", i); //return 1; } if (box->dir != rbox->dir) { printf("box %d dir not initialized correctly\n", i); //return 1; } if (box->tag != rbox->tag) { printf("box %d tag not initialized correctly\n", i); //return 1; } if (box->isValid != rbox->isValid) { printf("box %d isValid not initialized correctly\n", i); //return 1; } } } printf("Box and Image data are correct\n"); printf("----Freeing frame----\n"); if (freeFrame(frame) == 1) { printf("Unable to free frame\n"); return 1; } printf("Checking if new frame exists after free\n"); if (res == NULL) { printf("Frame disappeared after free\n"); return 1; } printf("Checking if boxes exist after free\n"); box_t *rArBox = res->arBoxes; if ((res->numBoxes == 0) && (rArBox != NULL)) { printf("Box copy failure after free\n"); return 1; } else if (rArBox == NULL) { printf("Box copy failure - res is empty\n"); return 1; } else if (numBoxes != res->numBoxes) { printf("Box copy failure - not same num boxes after free\n"); return 1; } else { int i; box_t Bbox; for (i = 0; i < res->numBoxes; i++) { Bbox = rArBox[i]; } printf("Frames copied correctly\n"); } printf("----Freeing copy frame----\n"); if (freeFrame(res) == 1) { printf("Unable to free frame\n"); return 1; } return 0; }
int main(int argc, char *argv[]){ if (argc < 3) { printf("USAGE: ./fullTest <first_image_filename> <second_image_filename>\n"); return 1; } double startTime = CycleTimer::currentSeconds(); double deltaTime; char *filename1 = argv[1]; char *filename2 = argv[2]; frame_t *frame1 = (frame_t *) malloc(sizeof(struct frame_s)); frame_t *frame2 = (frame_t *) malloc(sizeof(struct frame_s)); frame_t *res1 = (frame_t *) malloc(sizeof(struct frame_s)); frame_t *res2 = (frame_t *) malloc(sizeof(struct frame_s)); frame_t *res3 = (frame_t *) malloc(sizeof(struct frame_s)); frame_t *res4 = (frame_t *) malloc(sizeof(struct frame_s)); readImageFrame(frame1, filename1); readImageFrame(frame2, filename2); res1 = copyFrame(frame1); res2 = copyFrame(frame1); res3 = copyFrame(frame2); res4 = copyFrame(frame2); deltaTime = CycleTimer::currentSeconds() - startTime; printf("CopyFrame finished, elapsed time = %f seconds\n", deltaTime); frameToJPG(frame1, "full1.jpg"); frameToJPG(frame2, "full2.jpg"); startTime = CycleTimer::currentSeconds(); if (frameSubtraction(frame1, frame2, res1) != 0) { printf("Error in frame subtraction\n"); } deltaTime = CycleTimer::currentSeconds() - startTime; printf("FrameSubtraction finished, time = %f seconds\n", deltaTime); frameToJPG(res1, "full3.jpg"); startTime = CycleTimer::currentSeconds(); if (thresholdImage(res1, res2) != 0) { printf("Error in thresholdImage\n"); } deltaTime = CycleTimer::currentSeconds() - startTime; printf("thresholdImage finished, time = %f seconds\n", deltaTime); frameToJPG(res2, "full4.jpg"); startTime = CycleTimer::currentSeconds(); if (blobDetection(res2) != 0) { printf("Error in blob detection\n"); } deltaTime = CycleTimer::currentSeconds() - startTime; printf("BlobDetection Finished, time = %f seconds\n", deltaTime); // res2 = copyFrame(res1); if (drawBoxOnImage(res2, res3) != 0) { printf("Error in draw box on image\n"); exit(1); } printf("Writing frame\n"); frameToJPG(res3, "full5.jpg"); printf("Write to frame complete, please check file = full5.jpg\n"); startTime = CycleTimer::currentSeconds(); // merge boxes if (mergeBoxes(res2) != 0) { printf("Error in mergeBoxes\n"); exit(1); } deltaTime = CycleTimer::currentSeconds() - startTime; printf("mergeBoxes Finished, time = %f seconds\n", deltaTime); if (drawBoxOnImage(res2, res4) != 0) { printf("Error in draw box on image\n"); exit(1); } printf("Writing frame\n"); frameToJPG(res4, "full6.jpg"); printf("Write to frame complete, please check file = full6.jpg\n"); printf("Freeing frames\n"); int err = freeFrame(frame1); err += freeFrame(frame2); err += freeFrame(res1); err += freeFrame(res2); err += freeFrame(res3); err += freeFrame(res4); if (err != 0) { printf("Unable to free frame\n"); return 1; } return 0; }