From 8cae5f1fc6720e33360b1fc5e7ed50c59a63a07c Mon Sep 17 00:00:00 2001 From: Oswald de Bruin Date: Fri, 14 Jun 2013 16:30:55 +0200 Subject: [PATCH] Merge branch 'oggLib' of github.com:DDVTECH/libmist into oggLib Conflicts: lib/Makefile.am lib/ogg.cpp Ogg completed further --- lib/Makefile.am | 4 +- lib/theora.cpp | 100 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/theora.h | 19 +++++++++ 3 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 lib/theora.cpp create mode 100644 lib/theora.h diff --git a/lib/Makefile.am b/lib/Makefile.am index d0fb29e1..41c0c207 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,5 +1,5 @@ lib_LTLIBRARIES=libmist-1.0.la -libmist_1_0_la_SOURCES=amf.h amf.cpp auth.h auth.cpp base64.h base64.cpp config.h config.cpp dtsc.h dtsc.cpp flv_tag.h flv_tag.cpp http_parser.h http_parser.cpp json.h json.cpp procs.h procs.cpp rtmpchunks.h rtmpchunks.cpp socket.h socket.cpp mp4.h mp4.cpp ftp.h ftp.cpp filesystem.h filesystem.cpp stream.h stream.cpp timing.h timing.cpp ts_packet.cpp ts_packet.h converter.cpp converter.h ogg.h ogg.cpp +libmist_1_0_la_SOURCES=amf.h amf.cpp auth.h auth.cpp base64.h base64.cpp config.h config.cpp dtsc.h dtsc.cpp flv_tag.h flv_tag.cpp http_parser.h http_parser.cpp json.h json.cpp procs.h procs.cpp rtmpchunks.h rtmpchunks.cpp socket.h socket.cpp mp4.h mp4.cpp ftp.h ftp.cpp filesystem.h filesystem.cpp stream.h stream.cpp timing.h timing.cpp ts_packet.cpp ts_packet.h converter.cpp converter.h ogg.h ogg.cpp theora.cpp theora.h libmist_1_0_la_LDFLAGS = -version-info 5:1:2 libmist_1_0_la_CPPFLAGS=$(DEPS_CFLAGS) $(global_CFLAGS) libmist_1_0_la_LIBADD=$(DEPS_LIBS) $(CLOCK_LIB) @@ -8,4 +8,4 @@ pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = mist-1.0.pc library_includedir=$(includedir)/mist-1.0/mist -library_include_HEADERS = amf.h auth.h base64.h config.h dtsc.h flv_tag.h http_parser.h json.h procs.h rtmpchunks.h socket.h mp4.h ftp.h filesystem.h stream.h timing.h nal.h ts_packet.h converter.h ogg.h +library_include_HEADERS = amf.h auth.h base64.h config.h dtsc.h flv_tag.h http_parser.h json.h procs.h rtmpchunks.h socket.h mp4.h ftp.h filesystem.h stream.h timing.h nal.h ts_packet.h converter.h ogg.h theora.h diff --git a/lib/theora.cpp b/lib/theora.cpp new file mode 100644 index 00000000..2640033b --- /dev/null +++ b/lib/theora.cpp @@ -0,0 +1,100 @@ +#include +#include +#include +#include + +namespace theora{ + bool header::checkDataSize(unsigned int size){ + if (size > datasize){ + void* tmp = realloc(data,size); + if (tmp){ + data = (char*)tmp; + datasize = size; + return true; + }else{ + return false; + } + }else{ + return true; + } + } + + /// Gets the 32 bits integer at the given index. + /// Attempts to resize the data pointer if the index is out of range. + /// Returns zero if resizing failed. + uint32_t header::getInt32(size_t index){ + /*if (index + 3 >= datasize){ + if ( !reserve(index, 0, 4)){ + return 0; + } + setInt32(0, index); + }*/ + uint32_t result; + memcpy((char*) &result, data + index, 4); + return ntohl(result); + } + + header::header(){ + data = NULL; + datasize = 0; + } + + bool header::read(char* newData, unsigned int length){ + if (length < 7){ + return false; + } + if(memcmp(newData+1, "theora", 6)!=0){ + return false; + } + switch(newData[0]){ + case 0x80: + //if (length != 42) return false; + break; + case 0x81: + break; + case 0x82: + break; + default: + return false; + break; + }; + if (checkDataSize(length)){ + memcpy(data, newData, length); + }else{ + return false; + } + return true; + } + + int header::getHeaderType(){ + switch(data[0]){ + case 0x80: + return 0; + break; + case 0x81: + return 1; + break; + case 0x82: + return 2; + break; + default: + return -1; + break; + }; + } + + long unsigned int header::getFRN(){ + if (getHeaderType() == 0){ + return getInt32(22); + } + return 0; + } + + long unsigned int header::getFRD(){ + if (getHeaderType() == 0){ + return getInt32(26); + } + return 0; + } + +} diff --git a/lib/theora.h b/lib/theora.h new file mode 100644 index 00000000..bd472ece --- /dev/null +++ b/lib/theora.h @@ -0,0 +1,19 @@ +#include +#include + +namespace theora{ + class header{ + public: + header(); + bool read(char* newData, unsigned int length); + int getHeaderType(); + long unsigned int getFRN(); + long unsigned int getFRD(); + protected: + uint32_t getInt32(size_t index); + private: + char* data; + unsigned int datasize; + bool checkDataSize(unsigned int size); + }; +}