aboutsummaryrefslogtreecommitdiffstats
path: root/src/libdash/source/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'src/libdash/source/helpers')
-rw-r--r--src/libdash/source/helpers/Block.h59
-rw-r--r--src/libdash/source/helpers/BlockStream.cpp290
-rw-r--r--src/libdash/source/helpers/BlockStream.h55
-rw-r--r--src/libdash/source/helpers/Path.cpp118
-rw-r--r--src/libdash/source/helpers/Path.h33
-rw-r--r--src/libdash/source/helpers/String.cpp53
-rw-r--r--src/libdash/source/helpers/String.h31
-rw-r--r--src/libdash/source/helpers/SyncedBlockStream.cpp250
-rw-r--r--src/libdash/source/helpers/SyncedBlockStream.h57
-rw-r--r--src/libdash/source/helpers/Time.cpp33
-rw-r--r--src/libdash/source/helpers/Time.h35
11 files changed, 1014 insertions, 0 deletions
diff --git a/src/libdash/source/helpers/Block.h b/src/libdash/source/helpers/Block.h
new file mode 100644
index 00000000..c71462e8
--- /dev/null
+++ b/src/libdash/source/helpers/Block.h
@@ -0,0 +1,59 @@
+/*
+ * Block.h
+ *****************************************************************************
+ * Copyright (C) 2012, bitmovin Softwareentwicklung OG, All Rights Reserved
+ *
+ * Email: libdash-dev@vicky.bitmovin.net
+ *
+ * This source code and its use and distribution, is subject to the terms
+ * and conditions of the applicable license agreement.
+ *****************************************************************************/
+
+#ifndef __BLOCK_H__
+#define __BLOCK_H__
+
+#include "config.h"
+
+namespace dash
+{
+ namespace helpers
+ {
+ struct block_t
+ {
+ uint8_t *data;
+ size_t len;
+ float millisec;
+ size_t offset;
+ };
+
+ static inline block_t* AllocBlock (size_t len)
+ {
+ block_t *block = (block_t *)malloc(sizeof(block_t));
+ block->data = new uint8_t[len];
+ block->len = len;
+ block->millisec = 0;
+ block->offset = 0;
+ return block;
+ }
+ static inline void DeleteBlock (block_t *block)
+ {
+ if(block)
+ {
+ delete [] block->data;
+ free(block);
+ block = NULL;
+ }
+ }
+ static inline block_t* DuplicateBlock (block_t *block)
+ {
+ block_t *ret = AllocBlock(block->len);
+ ret->offset = block->offset;
+
+ memcpy(ret->data, block->data, ret->len);
+
+ return block;
+ }
+ }
+}
+
+#endif
diff --git a/src/libdash/source/helpers/BlockStream.cpp b/src/libdash/source/helpers/BlockStream.cpp
new file mode 100644
index 00000000..fd34f88e
--- /dev/null
+++ b/src/libdash/source/helpers/BlockStream.cpp
@@ -0,0 +1,290 @@
+/*
+ * BlockStream.cpp
+ *****************************************************************************
+ * Copyright (C) 2012, bitmovin Softwareentwicklung OG, All Rights Reserved
+ *
+ * Email: libdash-dev@vicky.bitmovin.net
+ *
+ * This source code and its use and distribution, is subject to the terms
+ * and conditions of the applicable license agreement.
+ *****************************************************************************/
+
+#include "BlockStream.h"
+#include <limits>
+
+using namespace dash::helpers;
+
+BlockStream::BlockStream () :
+ length (0)
+{
+}
+BlockStream::~BlockStream ()
+{
+ this->Clear();
+}
+
+void BlockStream::PopAndDeleteFront ()
+{
+ if(this->blockqueue.empty())
+ return;
+
+ this->length -= this->blockqueue.front()->len;
+ DeleteBlock(this->blockqueue.front());
+ this->blockqueue.pop_front();
+}
+void BlockStream::PushBack (block_t *block)
+{
+ this->length += block->len;
+ this->blockqueue.push_back(block);
+}
+void BlockStream::PushFront (block_t *block)
+{
+ this->length += block->len;
+ this->blockqueue.push_front(block);
+}
+const block_t* BlockStream::GetBytes (uint32_t len)
+{
+ /* Performance Intensive */
+ if(this->length < len)
+ return NULL;
+
+ block_t *block = AllocBlock(len);
+ this->BlockQueueGetBytes(block->data, block->len);
+
+ this->length -= len;
+
+ return block;
+}
+size_t BlockStream::GetBytes (uint8_t *data, size_t len)
+{
+ /* Performance Intensive */
+ if(len > this->length)
+ len = (size_t) this->length;
+
+ this->BlockQueueGetBytes(data, len);
+
+ this->length -= len;
+
+ return len;
+}
+size_t BlockStream::PeekBytes (uint8_t *data, size_t len)
+{
+ /* Performance Intensive */
+ if(len > this->length)
+ len = (size_t) this->length;
+
+ this->BlockQueuePeekBytes(data, len, 0);
+
+ return len;
+}
+size_t BlockStream::PeekBytes (uint8_t *data, size_t len, size_t offset)
+{
+ /* Performance Intensive */
+ if(len > this->length)
+ len = (size_t) this->length;
+
+ if (offset + len > this->length)
+ len = (size_t) (this->length - offset);
+
+ this->BlockQueuePeekBytes(data, len, offset);
+
+ return len;
+}
+uint64_t BlockStream::Length () const
+{
+ return this->length;
+}
+const block_t* BlockStream::GetFront ()
+{
+ if(this->blockqueue.empty())
+ return NULL;
+
+ const block_t* ret = this->blockqueue.front();
+ this->length -= ret->len;
+ this->blockqueue.pop_front();
+
+ return ret;
+}
+const block_t* BlockStream::Front () const
+{
+ if(this->blockqueue.empty())
+ return NULL;
+
+ return this->blockqueue.front();
+}
+bool BlockStream::BlockQueueGetBytes (uint8_t *data, uint32_t len)
+{
+ uint32_t pos = 0;
+
+ block_t *block = NULL;
+
+ while(pos < len)
+ {
+ block = this->blockqueue.front();
+ if((len - pos) < (block->len))
+ {
+ memcpy(data + pos, block->data, len - pos);
+
+ this->blockqueue.pop_front();
+
+ block_t* newfront = AllocBlock(block->len - (len - pos));
+ memcpy(newfront->data, block->data + (len - pos), newfront->len);
+
+ DeleteBlock(block);
+ this->blockqueue.push_front(newfront);
+
+ return true;
+ }
+ else
+ {
+ memcpy(data + pos, block->data, block->len);
+ pos += block->len;
+
+ DeleteBlock(block);
+ this->blockqueue.pop_front();
+ }
+ }
+
+ return false;
+}
+bool BlockStream::BlockQueuePeekBytes (uint8_t *data, uint32_t len, size_t offset)
+{
+ uint32_t pos = 0;
+ int cnt = 0;
+
+ const block_t *block = NULL;
+
+ while(pos < len)
+ {
+ block = this->blockqueue.at(cnt);
+ if((offset + len - pos) < (block->len))
+ {
+ memcpy(data + pos, block->data + offset, len - pos - offset);
+ return true;
+ }
+ else
+ {
+ memcpy(data + pos, block->data + offset, block->len - offset);
+ pos += block->len;
+ }
+
+ cnt++;
+ }
+
+ return false;
+}
+uint8_t BlockStream::ByteAt (uint64_t position) const
+{
+ if(position > this->length)
+ return -1;
+
+ uint64_t pos = 0;
+
+ for(size_t i = 0; i < this->blockqueue.size(); i++)
+ {
+ const block_t *block = this->blockqueue.at(i);
+
+ if(pos + block->len > position)
+ return block->data[position - pos];
+ else
+ pos += block->len;
+ }
+
+ return -1;
+}
+const block_t* BlockStream::ToBlock ()
+{
+ if(this->length > std::numeric_limits<size_t>::max())
+ return NULL;
+
+ return BlockStream::GetBytes((size_t)this->length);
+}
+void BlockStream::Clear ()
+{
+ while(!this->blockqueue.empty())
+ {
+ DeleteBlock(this->blockqueue.front());
+ this->blockqueue.pop_front();
+ }
+
+ this->length = 0;
+}
+void BlockStream::EraseFront (uint64_t len)
+{
+ if(len > this->length)
+ len = this->length;
+
+ uint64_t actLen = 0;
+
+ while(actLen < len)
+ {
+ if(this->blockqueue.size() == 0)
+ return;
+
+ block_t *front = this->blockqueue.front();
+
+ if((actLen + front->len) <= len)
+ {
+ this->length -= front->len;
+ actLen += front->len;
+
+ DeleteBlock(front);
+ this->blockqueue.pop_front();
+ }
+ else
+ {
+ uint32_t diff = (uint32_t) (len - actLen);
+ this->length -= diff;
+ actLen += diff;
+ block_t* newfront = AllocBlock(front->len - diff);
+
+ memcpy(newfront->data, front->data + diff, newfront->len);
+
+ DeleteBlock(front);
+ this->blockqueue.pop_front();
+ this->blockqueue.push_front(newfront);
+ }
+ }
+}
+BlockStream* BlockStream::GetBlocks (uint64_t len)
+{
+ if(len > this->length)
+ return NULL;
+
+ BlockStream *blocks = new BlockStream();
+
+ uint64_t actLen = 0;
+
+ while(actLen < len)
+ {
+ block_t *front = this->blockqueue.front();
+
+ if((actLen + front->len) <= len)
+ {
+ this->length -= front->len;
+ actLen += front->len;
+
+ blocks->PushBack(front);
+ this->blockqueue.pop_front();
+ }
+ else
+ {
+ uint32_t diff = (uint32_t) (len - actLen);
+ this->length -= diff;
+ actLen += diff;
+ block_t *block = AllocBlock(diff);
+ block_t* newfront = AllocBlock(front->len - diff);
+
+ memcpy(block->data, front->data, diff);
+ blocks->PushBack(block);
+
+ memcpy(newfront->data, front->data+ diff, newfront->len);
+
+ DeleteBlock(front);
+ this->blockqueue.pop_front();
+ this->blockqueue.push_front(newfront);
+ }
+ }
+
+ return blocks;
+}
diff --git a/src/libdash/source/helpers/BlockStream.h b/src/libdash/source/helpers/BlockStream.h
new file mode 100644
index 00000000..4b8b3fd5
--- /dev/null
+++ b/src/libdash/source/helpers/BlockStream.h
@@ -0,0 +1,55 @@
+/*
+ * BlockStream.h
+ *****************************************************************************
+ * Copyright (C) 2012, bitmovin Softwareentwicklung OG, All Rights Reserved
+ *
+ * Email: libdash-dev@vicky.bitmovin.net
+ *
+ * This source code and its use and distribution, is subject to the terms
+ * and conditions of the applicable license agreement.
+ *****************************************************************************/
+
+#ifndef __BLOCKSTREAM_H__
+#define __BLOCKSTREAM_H__
+
+#include "config.h"
+
+#include "Block.h"
+
+namespace dash
+{
+ namespace helpers
+ {
+ class BlockStream
+ {
+ public:
+ BlockStream ();
+ virtual ~BlockStream ();
+
+ virtual void PushBack (block_t *block);
+ virtual void PushFront (block_t *block);
+ virtual const block_t* GetBytes (uint32_t len);
+ virtual size_t GetBytes (uint8_t *data, size_t len);
+ virtual size_t PeekBytes (uint8_t *data, size_t len);
+ virtual size_t PeekBytes (uint8_t *data, size_t len, size_t offset);
+ virtual const block_t* GetFront ();
+ virtual const block_t* Front () const;
+ virtual uint64_t Length () const;
+ virtual uint8_t ByteAt (uint64_t position) const;
+ virtual const block_t* ToBlock ();
+ virtual void Clear ();
+ virtual void EraseFront (uint64_t len);
+ virtual BlockStream* GetBlocks (uint64_t len);
+ virtual void PopAndDeleteFront ();
+
+ protected:
+ uint64_t length;
+ std::deque<block_t *> blockqueue;
+
+ virtual bool BlockQueueGetBytes (uint8_t *data, uint32_t len);
+ virtual bool BlockQueuePeekBytes (uint8_t *data, uint32_t len, size_t offset);
+ };
+ }
+}
+
+#endif // __BLOCKSTREAM_H__ \ No newline at end of file
diff --git a/src/libdash/source/helpers/Path.cpp b/src/libdash/source/helpers/Path.cpp
new file mode 100644
index 00000000..301d9fa0
--- /dev/null
+++ b/src/libdash/source/helpers/Path.cpp
@@ -0,0 +1,118 @@
+/*
+ * Path.cpp
+ *****************************************************************************
+ * Copyright (C) 2012, bitmovin Softwareentwicklung OG, All Rights Reserved
+ *
+ * Email: libdash-dev@vicky.bitmovin.net
+ *
+ * This source code and its use and distribution, is subject to the terms
+ * and conditions of the applicable license agreement.
+ *****************************************************************************/
+
+#include "Path.h"
+
+using namespace dash::helpers;
+
+std::string Path::CombinePaths (const std::string &path1, const std::string &path2)
+{
+ if(path1 == "")
+ return path2;
+ if(path2 == "")
+ return path1;
+
+ char path1Last = path1.at(path1.size() - 1);
+ char path2First = path2.at(0);
+
+ if(path1Last == '/' && path2First == '/')
+ return path1 + path2.substr(1, path2.size());
+
+ if(path1Last != '/' && path2First != '/')
+ return path1 + "/" + path2;
+
+ return path1 + path2;
+}
+std::string Path::GetDirectoryPath (const std::string &path)
+{
+ int pos = path.find_last_of('/');
+
+ return path.substr(0, pos);
+}
+std::vector<std::string> Path::Split (const std::string &s, char delim)
+{
+ std::stringstream ss(s);
+ std::string item;
+ std::vector<std::string> ret;
+
+ while(std::getline(ss, item, delim))
+ ret.push_back(item);
+
+ return ret;
+}
+bool Path::GetHostPortAndPath (const std::string &url, std::string &host, size_t &port, std::string& path)
+{
+ std::string hostPort = "";
+ size_t found = 0;
+ size_t pathBegin = 0;
+
+ if (url.substr(0,7) == "http://" || url.substr(0,8) == "https://")
+ {
+ found = url.find("//");
+ pathBegin = url.find('/', found+2);
+ path = url.substr(pathBegin, std::string::npos);
+
+ hostPort = url.substr(found+2, pathBegin - (found+2));
+ found = hostPort.find(':');
+ if (found != std::string::npos)
+ {
+ port = strtoul(hostPort.substr(found+1, std::string::npos).c_str(), NULL, 10);
+ }
+ host = hostPort.substr(0, found);
+ return (host.size() > 0) && (path.size() > 0);
+ }
+ else if(url.substr(0,5) == "ndn:/")
+ {
+ found = url.find("/");
+ pathBegin = url.find('/', found+1);
+ path = url.substr(pathBegin, std::string::npos);
+
+ hostPort = url.substr(found+1, pathBegin - (found+1));
+ found = hostPort.find(':');
+ if (found != std::string::npos)
+ {
+ port = strtoul(hostPort.substr(found+1, std::string::npos).c_str(), NULL, 10);
+ }
+ host = hostPort.substr(0, found);
+ return (host.size() > 0) && (path.size() > 0);
+ }
+ else if(url.substr(0,6) == "ccnx:/")
+ {
+ found = url.find("/");
+ pathBegin = url.find('/', found+1);
+ path = url.substr(pathBegin, std::string::npos);
+
+ hostPort = url.substr(found+1, pathBegin - (found+1));
+ found = hostPort.find(':');
+ if (found != std::string::npos)
+ {
+ port = strtoul(hostPort.substr(found+1, std::string::npos).c_str(), NULL, 10);
+ }
+ host = hostPort.substr(0, found);
+ return (host.size() > 0) && (path.size() > 0);
+ }
+
+ return false;
+}
+bool Path::GetStartAndEndBytes (const std::string &byteRange, size_t &startByte, size_t &endByte)
+{
+ size_t found = 0;
+
+ found = byteRange.find('-');
+ if (found != std::string::npos && found < byteRange.size()-1 )
+ {
+ startByte = strtoul(byteRange.substr(0, found).c_str(), NULL, 10);
+ endByte = strtoul(byteRange.substr(found+1, std::string::npos).c_str(), NULL, 10);
+ return (startByte <= endByte);
+ }
+
+ return false;
+}
diff --git a/src/libdash/source/helpers/Path.h b/src/libdash/source/helpers/Path.h
new file mode 100644
index 00000000..1c791baa
--- /dev/null
+++ b/src/libdash/source/helpers/Path.h
@@ -0,0 +1,33 @@
+/*
+ * Path.h
+ *****************************************************************************
+ * Copyright (C) 2012, bitmovin Softwareentwicklung OG, All Rights Reserved
+ *
+ * Email: libdash-dev@vicky.bitmovin.net
+ *
+ * This source code and its use and distribution, is subject to the terms
+ * and conditions of the applicable license agreement.
+ *****************************************************************************/
+
+#ifndef PATH_H_
+#define PATH_H_
+
+#include "config.h"
+
+namespace dash
+{
+ namespace helpers
+ {
+ class Path
+ {
+ public:
+ static std::string CombinePaths (const std::string &path1, const std::string &path2);
+ static std::string GetDirectoryPath (const std::string &path);
+ static std::vector<std::string> Split (const std::string &s, char delim);
+ static bool GetHostPortAndPath (const std::string &url, std::string &host, size_t &port, std::string& path);
+ static bool GetStartAndEndBytes (const std::string &byteRange, size_t &startByte, size_t &endByte);
+ };
+ }
+}
+
+#endif /* PATH_H_ */ \ No newline at end of file
diff --git a/src/libdash/source/helpers/String.cpp b/src/libdash/source/helpers/String.cpp
new file mode 100644
index 00000000..53da5592
--- /dev/null
+++ b/src/libdash/source/helpers/String.cpp
@@ -0,0 +1,53 @@
+/*
+ * String.cpp
+ *****************************************************************************
+ * Copyright (C) 2012, bitmovin Softwareentwicklung OG, All Rights Reserved
+ *
+ * Email: libdash-dev@vicky.bitmovin.net
+ *
+ * This source code and its use and distribution, is subject to the terms
+ * and conditions of the applicable license agreement.
+ *****************************************************************************/
+
+#include "String.h"
+
+using namespace dash::helpers;
+
+void String::Split (const std::string &s, char delim, std::vector<std::string>& vector)
+{
+ std::stringstream ss(s);
+ std::string item;
+
+ while(std::getline(ss, item, delim))
+ vector.push_back(item);
+}
+void String::Split (const std::string &s, char delim, std::vector<uint32_t>& vector)
+{
+ size_t lengthOfString = s.length();
+ size_t pos = 0;
+ size_t i = 0;
+ uint32_t level = 0;
+
+ while (pos != std::string::npos)
+ {
+ pos = s.find(delim, i);
+
+ if (i < lengthOfString)
+ {
+ level = strtoul(s.substr(i, pos-i).c_str(), NULL, 10);
+ vector.push_back(level);
+ i = pos + 1;
+ }
+ }
+}
+bool String::ToBool (const std::string &s)
+{
+ if (s == "true" || s == "True" || s == "TRUE")
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+} \ No newline at end of file
diff --git a/src/libdash/source/helpers/String.h b/src/libdash/source/helpers/String.h
new file mode 100644
index 00000000..73ac6db8
--- /dev/null
+++ b/src/libdash/source/helpers/String.h
@@ -0,0 +1,31 @@
+/*
+ * String.h
+ *****************************************************************************
+ * Copyright (C) 2012, bitmovin Softwareentwicklung OG, All Rights Reserved
+ *
+ * Email: libdash-dev@vicky.bitmovin.net
+ *
+ * This source code and its use and distribution, is subject to the terms
+ * and conditions of the applicable license agreement.
+ *****************************************************************************/
+
+#ifndef STRING_H_
+#define STRING_H_
+
+#include "config.h"
+
+namespace dash
+{
+ namespace helpers
+ {
+ class String
+ {
+ public:
+ static void Split (const std::string &s, char delim, std::vector<std::string>& vector);
+ static void Split (const std::string &s, char delim, std::vector<uint32_t>& vector);
+ static bool ToBool (const std::string &s);
+ };
+ }
+}
+
+#endif /* STRING_H_ */ \ No newline at end of file
diff --git a/src/libdash/source/helpers/SyncedBlockStream.cpp b/src/libdash/source/helpers/SyncedBlockStream.cpp
new file mode 100644
index 00000000..84fa63cf
--- /dev/null
+++ b/src/libdash/source/helpers/SyncedBlockStream.cpp
@@ -0,0 +1,250 @@
+/*
+ * SyncedBlockStream.cpp
+ *****************************************************************************
+ * Copyright (C) 2012, bitmovin Softwareentwicklung OG, All Rights Reserved
+ *
+ * Email: libdash-dev@vicky.bitmovin.net
+ *
+ * This source code and its use and distribution, is subject to the terms
+ * and conditions of the applicable license agreement.
+ *****************************************************************************/
+
+#include "SyncedBlockStream.h"
+
+using namespace dash::helpers;
+
+SyncedBlockStream::SyncedBlockStream () :
+ eos (false)
+{
+ InitializeConditionVariable (&this->full);
+ InitializeCriticalSection (&this->monitorMutex);
+}
+SyncedBlockStream::~SyncedBlockStream ()
+{
+ DeleteConditionVariable(&this->full);
+ DeleteCriticalSection(&this->monitorMutex);
+}
+
+void SyncedBlockStream::PopAndDeleteFront ()
+{
+ EnterCriticalSection(&this->monitorMutex);
+
+ BlockStream::PopAndDeleteFront();
+
+ LeaveCriticalSection(&this->monitorMutex);
+}
+void SyncedBlockStream::PushBack (block_t *block)
+{
+ EnterCriticalSection(&this->monitorMutex);
+
+ BlockStream::PushBack(block);
+
+ WakeAllConditionVariable(&this->full);
+ LeaveCriticalSection(&this->monitorMutex);
+}
+void SyncedBlockStream::PushFront (block_t *block)
+{
+ EnterCriticalSection(&this->monitorMutex);
+
+ BlockStream::PushFront(block);
+
+ WakeAllConditionVariable(&this->full);
+ LeaveCriticalSection(&this->monitorMutex);
+}
+const block_t* SyncedBlockStream::GetBytes (uint32_t len)
+{
+ EnterCriticalSection(&this->monitorMutex);
+
+ while(this->length == 0 && !this->eos)
+ SleepConditionVariableCS(&this->full, &this->monitorMutex, INFINITE);
+
+ if(this->length == 0)
+ {
+ LeaveCriticalSection(&this->monitorMutex);
+ return NULL;
+ }
+
+ const block_t* block = BlockStream::GetBytes(len);
+ LeaveCriticalSection(&this->monitorMutex);
+
+ return block;
+}
+size_t SyncedBlockStream::GetBytes (uint8_t *data, size_t len)
+{
+ EnterCriticalSection(&this->monitorMutex);
+
+ while(this->length == 0 && !this->eos)
+ SleepConditionVariableCS(&this->full, &this->monitorMutex, INFINITE);
+
+ if(this->length == 0)
+ {
+ LeaveCriticalSection(&this->monitorMutex);
+ return 0;
+ }
+
+ size_t ret = BlockStream::GetBytes(data, len);
+ LeaveCriticalSection(&this->monitorMutex);
+
+ return ret;
+}
+size_t SyncedBlockStream::PeekBytes (uint8_t *data, size_t len)
+{
+ EnterCriticalSection(&this->monitorMutex);
+
+ while(this->length == 0 && !this->eos)
+ SleepConditionVariableCS(&this->full, &this->monitorMutex, INFINITE);
+
+ if(this->length == 0)
+ {
+ LeaveCriticalSection(&this->monitorMutex);
+ return 0;
+ }
+
+ size_t ret = BlockStream::PeekBytes(data, len);
+ LeaveCriticalSection(&this->monitorMutex);
+
+ return ret;
+}
+size_t SyncedBlockStream::PeekBytes (uint8_t *data, size_t len, size_t offset)
+{
+ EnterCriticalSection(&this->monitorMutex);
+
+ while((this->length == 0 || offset >= this->length) && !this->eos)
+ SleepConditionVariableCS(&this->full, &this->monitorMutex, INFINITE);
+
+ if(this->length == 0 || offset >= this->length)
+ {
+ LeaveCriticalSection(&this->monitorMutex);
+ return 0;
+ }
+
+ size_t ret = BlockStream::PeekBytes(data, len, offset);
+ LeaveCriticalSection(&this->monitorMutex);
+
+ return ret;
+}
+uint64_t SyncedBlockStream::Length () const
+{
+ EnterCriticalSection(&this->monitorMutex);
+
+ uint64_t len = BlockStream::Length();
+
+ LeaveCriticalSection(&this->monitorMutex);
+
+ return len;
+}
+const block_t* SyncedBlockStream::GetFront ()
+{
+ EnterCriticalSection(&this->monitorMutex);
+
+ while(this->length == 0 && !this->eos)
+ SleepConditionVariableCS(&this->full, &this->monitorMutex, INFINITE);
+
+ if(this->length == 0)
+ {
+ LeaveCriticalSection(&this->monitorMutex);
+ return NULL;
+ }
+
+ const block_t* block = BlockStream::GetFront();
+ LeaveCriticalSection(&this->monitorMutex);
+
+ return block;
+}
+const block_t* SyncedBlockStream::Front () const
+{
+ EnterCriticalSection(&this->monitorMutex);
+
+ while(this->length == 0 && !this->eos)
+ SleepConditionVariableCS(&this->full, &this->monitorMutex, INFINITE);
+
+ if(this->length == 0)
+ {
+ LeaveCriticalSection(&this->monitorMutex);
+ return NULL;
+ }
+
+ const block_t* block = BlockStream::Front();
+ LeaveCriticalSection(&this->monitorMutex);
+
+ return block;
+}
+uint8_t SyncedBlockStream::ByteAt (uint64_t position) const
+{
+ EnterCriticalSection(&this->monitorMutex);
+
+ while(this->length < position && !this->eos)
+ SleepConditionVariableCS(&this->full, &this->monitorMutex, INFINITE);
+
+ if(this->length < position)
+ {
+ LeaveCriticalSection(&this->monitorMutex);
+ return 0;
+ }
+
+ uint8_t ret = BlockStream::ByteAt(position);
+ LeaveCriticalSection(&this->monitorMutex);
+
+ return ret;
+}
+const block_t* SyncedBlockStream::ToBlock ()
+{
+ EnterCriticalSection(&this->monitorMutex);
+
+ while(this->length == 0 && !this->eos)
+ SleepConditionVariableCS(&this->full, &this->monitorMutex, INFINITE);
+
+ if(this->length == 0)
+ {
+ LeaveCriticalSection(&this->monitorMutex);
+ return NULL;
+ }
+
+ const block_t* block = BlockStream::ToBlock();
+ LeaveCriticalSection(&this->monitorMutex);
+
+ return block;
+}
+void SyncedBlockStream::Clear ()
+{
+ EnterCriticalSection(&this->monitorMutex);
+
+ BlockStream::Clear();
+
+ LeaveCriticalSection(&this->monitorMutex);
+}
+void SyncedBlockStream::EraseFront (uint64_t len)
+{
+ EnterCriticalSection(&this->monitorMutex);
+
+ BlockStream::EraseFront(len);
+
+ LeaveCriticalSection(&this->monitorMutex);
+}
+BlockStream* SyncedBlockStream::GetBlocks (uint64_t len)
+{
+ EnterCriticalSection(&this->monitorMutex);
+
+ while(this->length == 0 && !this->eos)
+ SleepConditionVariableCS(&this->full, &this->monitorMutex, INFINITE);
+
+ if(this->length == 0)
+ {
+ LeaveCriticalSection(&this->monitorMutex);
+ return NULL;
+ }
+
+ BlockStream *stream = BlockStream::GetBlocks(len);
+ LeaveCriticalSection(&this->monitorMutex);
+
+ return stream;
+}
+void SyncedBlockStream::SetEOS (bool value)
+{
+ EnterCriticalSection(&this->monitorMutex);
+
+ this->eos = value;
+
+ WakeAllConditionVariable(&this->full);
+ LeaveCriticalSection(&this->monitorMutex);
+}
diff --git a/src/libdash/source/helpers/SyncedBlockStream.h b/src/libdash/source/helpers/SyncedBlockStream.h
new file mode 100644
index 00000000..9e266c60
--- /dev/null
+++ b/src/libdash/source/helpers/SyncedBlockStream.h
@@ -0,0 +1,57 @@
+/*
+ * SyncedBlockStream.h
+ *****************************************************************************
+ * Copyright (C) 2012, bitmovin Softwareentwicklung OG, All Rights Reserved
+ *
+ * Email: libdash-dev@vicky.bitmovin.net
+ *
+ * This source code and its use and distribution, is subject to the terms
+ * and conditions of the applicable license agreement.
+ *****************************************************************************/
+
+#ifndef __SYNCEDBLOCKSTREAM_H__
+#define __SYNCEDBLOCKSTREAM_H__
+
+#include "config.h"
+
+#include "BlockStream.h"
+#include "../portable/MultiThreading.h"
+
+namespace dash
+{
+ namespace helpers
+ {
+ class SyncedBlockStream : public BlockStream
+ {
+ public:
+ SyncedBlockStream ();
+ virtual ~SyncedBlockStream ();
+
+ virtual void PushBack (block_t *block);
+ virtual void PushFront (block_t *block);
+ virtual const block_t* GetBytes (uint32_t len);
+ virtual size_t GetBytes (uint8_t *data, size_t len);
+ virtual size_t PeekBytes (uint8_t *data, size_t len);
+ virtual size_t PeekBytes (uint8_t *data, size_t len, size_t offset);
+ virtual const block_t* GetFront ();
+ virtual const block_t* Front () const;
+ virtual uint64_t Length () const;
+ virtual uint8_t ByteAt (uint64_t position) const;
+ virtual const block_t* ToBlock ();
+ virtual void Clear ();
+ virtual void EraseFront (uint64_t len);
+ virtual BlockStream* GetBlocks (uint64_t len);
+ virtual void PopAndDeleteFront ();
+ virtual void SetEOS (bool value);
+
+ private:
+ bool eos;
+
+ mutable CRITICAL_SECTION monitorMutex;
+ mutable CONDITION_VARIABLE full;
+
+ };
+ }
+}
+
+#endif // __SYNCEDBLOCKSTREAM_H__ \ No newline at end of file
diff --git a/src/libdash/source/helpers/Time.cpp b/src/libdash/source/helpers/Time.cpp
new file mode 100644
index 00000000..e6ca2b81
--- /dev/null
+++ b/src/libdash/source/helpers/Time.cpp
@@ -0,0 +1,33 @@
+/*
+ * Time.cpp
+ *****************************************************************************
+ * Copyright (C) 2013, bitmovin Softwareentwicklung OG, All Rights Reserved
+ *
+ * Email: libdash-dev@vicky.bitmovin.net
+ *
+ * This source code and its use and distribution, is subject to the terms
+ * and conditions of the applicable license agreement.
+ *****************************************************************************/
+
+#include "Time.h"
+
+using namespace dash::helpers;
+
+uint32_t Time::GetCurrentUTCTimeInSec ()
+{
+ return mktime(Time::GetCurrentUTCTime());
+}
+std::string Time::GetCurrentUTCTimeStr ()
+{
+ char timeString[30];
+ strftime(timeString, 30, "%Y-%m-%dT%H:%M:%SZ", Time::GetCurrentUTCTime());
+
+ return std::string(timeString);
+}
+struct tm* Time::GetCurrentUTCTime ()
+{
+ time_t rawTime;
+
+ time(&rawTime);
+ return gmtime(&rawTime);
+}
diff --git a/src/libdash/source/helpers/Time.h b/src/libdash/source/helpers/Time.h
new file mode 100644
index 00000000..e7de0cd9
--- /dev/null
+++ b/src/libdash/source/helpers/Time.h
@@ -0,0 +1,35 @@
+/*
+ * Time.h
+ *****************************************************************************
+ * Copyright (C) 2013, bitmovin Softwareentwicklung OG, All Rights Reserved
+ *
+ * Email: libdash-dev@vicky.bitmovin.net
+ *
+ * This source code and its use and distribution, is subject to the terms
+ * and conditions of the applicable license agreement.
+ *****************************************************************************/
+
+#ifndef DASH_HELPERS_TIME_H_
+#define DASH_HELPERS_TIME_H_
+
+#include <time.h>
+#include "config.h"
+
+namespace dash
+{
+ namespace helpers
+ {
+ class Time
+ {
+ public:
+ static uint32_t GetCurrentUTCTimeInSec ();
+ static std::string GetCurrentUTCTimeStr ();
+
+ private:
+ static struct tm* GetCurrentUTCTime ();
+
+ };
+ }
+}
+
+#endif /* DASH_HELPERS_TIME_H_ */