Vorbis started on prettyprint
This commit is contained in:
		
							parent
							
								
									37df1716de
								
							
						
					
					
						commit
						9ed5a5e28c
					
				
					 4 changed files with 170 additions and 1 deletions
				
			
		
							
								
								
									
										11
									
								
								lib/ogg.cpp
									
										
									
									
									
								
							
							
						
						
									
										11
									
								
								lib/ogg.cpp
									
										
									
									
									
								
							|  | @ -299,6 +299,17 @@ namespace OGG{ | ||||||
|         } |         } | ||||||
|         offset += len; |         offset += len; | ||||||
|       } |       } | ||||||
|  |     }else if(codec == "vorbis"){ | ||||||
|  |       r << "Vorbis Data" << std::endl; | ||||||
|  |       int offset = 0; | ||||||
|  |       for (int i = 0; i < getSegmentTableDeque().size(); i++){ | ||||||
|  |         vorbis::header tmpHeader; | ||||||
|  |         int len = getSegmentTableDeque()[i]; | ||||||
|  |         if (tmpHeader.read(getFullPayload()+offset,len)){ | ||||||
|  |           r << tmpHeader.toPrettyString(indent + 4); | ||||||
|  |         } | ||||||
|  |         offset += len; | ||||||
|  |       } | ||||||
|     } |     } | ||||||
|     return r.str(); |     return r.str(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | @ -4,6 +4,7 @@ | ||||||
| #include<deque> | #include<deque> | ||||||
| #include"dtsc.h" | #include"dtsc.h" | ||||||
| #include "theora.h" | #include "theora.h" | ||||||
|  | #include "vorbis.h" | ||||||
| 
 | 
 | ||||||
| namespace OGG{ | namespace OGG{ | ||||||
|   class Page{ |   class Page{ | ||||||
|  |  | ||||||
							
								
								
									
										143
									
								
								lib/vorbis.cpp
									
										
									
									
									
								
							
							
						
						
									
										143
									
								
								lib/vorbis.cpp
									
										
									
									
									
								
							|  | @ -1,13 +1,93 @@ | ||||||
| #include"vorbis.h" | #include"vorbis.h" | ||||||
| #include<stdlib.h> | #include<stdlib.h> | ||||||
| #include<string.h> | #include<string.h> | ||||||
|  | #include<sstream> | ||||||
| #include <arpa/inet.h> | #include <arpa/inet.h> | ||||||
| 
 | 
 | ||||||
| namespace vorbis{ | namespace vorbis{ | ||||||
|  | 
 | ||||||
|   header::header(){ |   header::header(){ | ||||||
|     data = NULL; |     data = NULL; | ||||||
|     datasize = 0; |     datasize = 0; | ||||||
|   } |   } | ||||||
|  |    | ||||||
|  |   int header::getHeaderType(){ | ||||||
|  |     return (int)(data[0]); | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |   long unsigned int header::getVorbisVersion(){ | ||||||
|  |     if (getHeaderType() == 1){ | ||||||
|  |       return getInt32(7); | ||||||
|  |     }else{ | ||||||
|  |       return 0; | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |   char header::getAudioChannels(){ | ||||||
|  |     if (getHeaderType() == 1){ | ||||||
|  |       return data[11]; | ||||||
|  |     }else{ | ||||||
|  |       return 0; | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |   long unsigned int header::getAudioSampleRate(){ | ||||||
|  |     if (getHeaderType() == 1){ | ||||||
|  |       return getInt32(12); | ||||||
|  |     }else{ | ||||||
|  |       return 0; | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |   long unsigned int header::getBitrateMaximum(){ | ||||||
|  |     if (getHeaderType() == 1){ | ||||||
|  |       return getInt32(16); | ||||||
|  |     }else{ | ||||||
|  |       return 0; | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |   long unsigned int header::getBitrateNominal(){ | ||||||
|  |     if (getHeaderType() == 1){ | ||||||
|  |       return getInt32(20); | ||||||
|  |     }else{ | ||||||
|  |       return 0; | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |   long unsigned int header::getBitrateMinimum(){ | ||||||
|  |     if (getHeaderType() == 1){ | ||||||
|  |       return getInt32(24); | ||||||
|  |     }else{ | ||||||
|  |       return 0; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |   char header::getBlockSize0(){ | ||||||
|  |     if (getHeaderType() == 1){ | ||||||
|  |       return data[28]>>4; | ||||||
|  |     }else{ | ||||||
|  |       return 0; | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |   char header::getBlockSize1(){ | ||||||
|  |     if (getHeaderType() == 1){ | ||||||
|  |       return data[28] & 0x0F; | ||||||
|  |     }else{ | ||||||
|  |       return 0; | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |   char header::getFramingFlag(){ | ||||||
|  |     if (getHeaderType() == 1){ | ||||||
|  |       return data[29]; | ||||||
|  |     }else{ | ||||||
|  |       return 0; | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |    | ||||||
|   bool header::checkDataSize(unsigned int size){ |   bool header::checkDataSize(unsigned int size){ | ||||||
|     if (size > datasize){ |     if (size > datasize){ | ||||||
|       void* tmp = realloc(data,size); |       void* tmp = realloc(data,size); | ||||||
|  | @ -23,12 +103,73 @@ namespace vorbis{ | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   bool header::validate(){ | ||||||
|  |     switch(getHeaderType()){ | ||||||
|  |       case 1://ID header
 | ||||||
|  |         if (datasize!=29) return false; | ||||||
|  |         //if (getVorbisVersion()!=0) return false;
 | ||||||
|  |         //if (getAudioChannels()<=0) return false;
 | ||||||
|  |         //if (getAudioSampleRate()<=0) return false;
 | ||||||
|  |         //if (getBlockSize0()>getBlockSize1()) return false;
 | ||||||
|  |         //if (getFramingFlag()!=1) return false;
 | ||||||
|  |       break;       | ||||||
|  |       case 3://comment header
 | ||||||
|  |       break;       | ||||||
|  |       case 5://init header
 | ||||||
|  |       break;       | ||||||
|  |       default: | ||||||
|  |         return false; | ||||||
|  |       break; | ||||||
|  |     } | ||||||
|  |     return true; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   bool header::read(char* newData, unsigned int length){ |   bool header::read(char* newData, unsigned int length){ | ||||||
|  |     if (length < 7){ | ||||||
|  |       return false; | ||||||
|  |     } | ||||||
|  |     /*if (! (newData[0] & 0x80)){
 | ||||||
|  |       return false; | ||||||
|  |     }*/ | ||||||
|  |     if(memcmp(newData+1, "vorbis", 6)!=0){ | ||||||
|  |       return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     if (checkDataSize(length)){ |     if (checkDataSize(length)){ | ||||||
|       memcpy(data, newData, length); |       memcpy(data, newData, length); | ||||||
|     }else{ |     }else{ | ||||||
|       return false; |       return false; | ||||||
|     } |     } | ||||||
|     return true; |     return validate(); | ||||||
|   } |   } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |   uint32_t header::getInt32(size_t index){ | ||||||
|  |     if (datasize >= (index + 3)){ | ||||||
|  |       return (data[index] << 24) + (data[index + 1] << 16) + (data[index + 2] << 8) + data[index + 3]; | ||||||
|  |     } | ||||||
|  |     return 0; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   uint32_t header::getInt24(size_t index){ | ||||||
|  |     if (datasize >= (index + 2)){ | ||||||
|  |       return 0 + (data[index] << 16) + (data[index + 1] << 8) + data[index + 2]; | ||||||
|  |     } | ||||||
|  |     return 0; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   uint16_t header::getInt16(size_t index){ | ||||||
|  |     if (datasize >= (index + 1)){ | ||||||
|  |       return 0 + (data[index] << 8) + data[index + 1]; | ||||||
|  |     } | ||||||
|  |     return 0; | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |   std::string header::toPrettyString(size_t indent){ | ||||||
|  |     std::stringstream r; | ||||||
|  |     r << "Testing vorbis Pretty string" << std::endl; | ||||||
|  |     return r.str(); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
							
								
								
									
										16
									
								
								lib/vorbis.h
									
										
									
									
									
								
							
							
						
						
									
										16
									
								
								lib/vorbis.h
									
										
									
									
									
								
							|  | @ -8,9 +8,25 @@ namespace vorbis{ | ||||||
|     public: |     public: | ||||||
|       header(); |       header(); | ||||||
|       bool read(char* newData, unsigned int length); |       bool read(char* newData, unsigned int length); | ||||||
|  |       int getHeaderType(); | ||||||
|  |       long unsigned int getVorbisVersion(); | ||||||
|  |       char getAudioChannels(); | ||||||
|  |       long unsigned int getAudioSampleRate(); | ||||||
|  |       long unsigned int getBitrateMaximum(); | ||||||
|  |       long unsigned int getBitrateNominal(); | ||||||
|  |       long unsigned int getBitrateMinimum(); | ||||||
|  |       char getBlockSize0(); | ||||||
|  |       char getBlockSize1(); | ||||||
|  |       char getFramingFlag(); | ||||||
|  |       std::string toPrettyString(size_t indent = 0); | ||||||
|  |     protected: | ||||||
|  |       uint32_t getInt32(size_t index); | ||||||
|  |       uint32_t getInt24(size_t index); | ||||||
|  |       uint16_t getInt16(size_t index); | ||||||
|     private: |     private: | ||||||
|       char* data; |       char* data; | ||||||
|       unsigned int datasize; |       unsigned int datasize; | ||||||
|       bool checkDataSize(unsigned int size); |       bool checkDataSize(unsigned int size); | ||||||
|  |       bool validate(); | ||||||
|   }; |   }; | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Oswald Auguste de Bruin
						Oswald Auguste de Bruin