From 6dec07e785db93ea9d2702b660b885d678dc87e4 Mon Sep 17 00:00:00 2001 From: august black Date: Wed, 28 Jul 2010 09:14:17 +0000 Subject: adding the readanysf~ again svn path=/trunk/externals/august/readanysf~/; revision=13732 --- src/FifoVideoFrames.cpp | 120 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 src/FifoVideoFrames.cpp (limited to 'src/FifoVideoFrames.cpp') diff --git a/src/FifoVideoFrames.cpp b/src/FifoVideoFrames.cpp new file mode 100644 index 0000000..29975dc --- /dev/null +++ b/src/FifoVideoFrames.cpp @@ -0,0 +1,120 @@ +#include "FifoVideoFrames.h" + +FifoVideoFrames::FifoVideoFrames(int s, gavl_video_format_t * f) { + size = s ; + start = 0 ; + end = 0 ; + count = 0; + format = new gavl_video_format_t; + gavl_video_format_copy(format, f); + fifoPtr = new gavl_video_frame_t * [size] ; + for(int i=0; i < size; i++) { + fifoPtr[i] = gavl_video_frame_create( format ); + } + pthread_mutex_init (&mut, 0); +} + +FifoVideoFrames::~FifoVideoFrames() { + //printf("deleting fifo \n"); + for(int i=0; i < size; i++) { + gavl_video_frame_destroy( fifoPtr[i] ); + } + delete format; + delete[] fifoPtr; + pthread_mutex_destroy (&mut); + //printf("deleted fifo \n"); +} + +// empty the fifo of any content +void FifoVideoFrames::Flush() { + pthread_mutex_lock (&mut); + start = 0 ; + end = 0 ; + count = 0; + //printf("FifoVideoFrames::flushed size=%d\n", count); + pthread_mutex_unlock (&mut); +} + +// push an element onto the FifoVideoFrames +bool FifoVideoFrames::Append( gavl_video_frame_t * source) { + bool ret = false; + //Dump("Appending a frame "); + pthread_mutex_lock (&mut); + if ( count < size ) { // if there is room for one more + gavl_video_frame_copy(format, fifoPtr[end], source) ; + fifoPtr[end]->timestamp = source->timestamp; + fifoPtr[end]->duration = source->duration; + if (++end >= size) + end = 0; + count++; + ret = true; + } // no room in fifo, return false + pthread_mutex_unlock (&mut); + //Dump("Appended a frame "); + return ret; +} +// remove an element off the front FifoVideoFrames +bool FifoVideoFrames::Get( ) { + bool ret = false; + pthread_mutex_lock (&mut); + if ( count > 0 ) { // if there any items in the fifo + if ( ++start >= size ) + start = 0; + count--; + ret = true; + } + pthread_mutex_unlock (&mut); + //Dump("Got a frame "); + return ret; +} + +// get an element off the FifoVideoFrames +bool FifoVideoFrames::Get( gavl_video_frame_t * dest) { + bool ret = false; + //Dump("Getting a frame "); + pthread_mutex_lock (&mut); + if ( count > 0 ) { // if there any items in the fifo + gavl_video_frame_copy(format, dest, fifoPtr[start]) ; + dest->timestamp = fifoPtr[start]->timestamp; + dest->duration = fifoPtr[start]->duration; + if ( ++start >= size ) + start = 0; + count--; + ret = true; + } + pthread_mutex_unlock (&mut); + //Dump("Got a frame "); + return ret; +} +/* +void FifoVideoFrames::Dump( char * c) { + int i,j = 0; + pthread_mutex_lock (&mut); + printf("%s -----------------------\n", c); + for( i=0;i= size) + // j = j -size; + j=i; + if ( j == start) + textcolor(BRIGHT, GREEN, BLACK); + if (j == end) + textcolor(BRIGHT, RED, BLACK); + if (j == end && j == start) + textcolor(BRIGHT, YELLOW, BLACK); + printf("[%d]=%ld ", j, fifoPtr[j]->timestamp); + textcolor(RESET, BLACK, WHITE); + } + printf("\n"); + printf("start=%02d, end=%02d, count=%02d\n", start,end,count); + printf("-----------------------\n"); + pthread_mutex_unlock (&mut); +} +*/ +bool FifoVideoFrames::FreeSpace() { bool ret; pthread_mutex_lock(&mut); ret = (count < size);pthread_mutex_unlock (&mut); return ret;} +bool FifoVideoFrames::isEmpty() { bool c; pthread_mutex_lock(&mut); c = (count == 0) ; pthread_mutex_unlock (&mut); return c; } +bool FifoVideoFrames::isFull() { bool c; pthread_mutex_lock(&mut); c = (count == size ); pthread_mutex_unlock (&mut); return c; } +gavl_video_format_t * FifoVideoFrames::getFormat() { return format; }; +float FifoVideoFrames::getSizePercentage() { float ret; pthread_mutex_lock(&mut);ret = count / (float) size; pthread_mutex_unlock (&mut); return ret;}; +int FifoVideoFrames::getSize() { int ret; pthread_mutex_lock(&mut);ret = count; pthread_mutex_unlock (&mut); return ret;}; + -- cgit v1.2.1