diff --git a/build/VS2010/HEVC_encoder.vcxproj b/build/VS2010/HEVC_encoder.vcxproj index 8fe98280..6b6ede4e 100644 --- a/build/VS2010/HEVC_encoder.vcxproj +++ b/build/VS2010/HEVC_encoder.vcxproj @@ -52,6 +52,7 @@ Level3 Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + CompileAsC Console @@ -67,6 +68,7 @@ true true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + CompileAsC Console @@ -76,10 +78,12 @@ + + diff --git a/build/VS2010/HEVC_encoder.vcxproj.filters b/build/VS2010/HEVC_encoder.vcxproj.filters index 78155193..d59e7d17 100644 --- a/build/VS2010/HEVC_encoder.vcxproj.filters +++ b/build/VS2010/HEVC_encoder.vcxproj.filters @@ -21,6 +21,9 @@ Source Files + + Source Files + @@ -29,5 +32,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/src/bitstream.c b/src/bitstream.c new file mode 100644 index 00000000..067e1674 --- /dev/null +++ b/src/bitstream.c @@ -0,0 +1,121 @@ +#include +#include +#include +#include +#include + +#include "global.h" +#include "bitstream.h" + + +void printf_bitstream(char *msg, ...) +{ + +va_list fmtargs; +char buffer[1024]; + + va_start(fmtargs,msg); + vsnprintf(buffer,sizeof(buffer)-1,msg,fmtargs); + va_end(fmtargs); + printf("%s",buffer); + +} + + +/* + * Clear bitstream + */ +void bitstream_init(bitstream* stream) +{ + stream->cur_byte=0; + stream->cur_bit=0; + memset(stream->data, 0, sizeof(uint32_t)*32); + +} + + +/* + * Put bits to bitstream + * Input: + * stream = pointer bitstream to put the data + * data = pointer to actual data + * bits = number of bits to write + */ + +void bitstream_put(bitstream* stream, uint32_t data, uint8_t bits) +{ + uint8_t i=0; + uint32_t bitsleft=32-stream->cur_bit; + printf_bitstream("put: "); + for(i=0;idata[stream->cur_byte] |= (data<<((bitsleft-bits))); + stream->cur_bit+=bits; + bits=0; + } + //No space for everything, store the bits we can and continue later + else + { + stream->data[stream->cur_byte] |= (data>>(bits-bitsleft)); + stream->cur_bit=32; + bits-=bitsleft; + } + + //Check if the buffer is full + if(stream->cur_bit==32) + { + stream->cur_byte++; + bitsleft=32; + if(stream->cur_byte==32) + { + //Flush data out + bitstream_flush(stream); + } + } + + //..still some writing to do + if(bits!=0) + { + stream->data[stream->cur_byte] |= (data<<(bitsleft-bits)); + stream->cur_bit+=bits; + } + + + +} + +/* + * Align the bitstream + */ +void bitstream_align(bitstream* stream) +{ + if(stream->cur_byte==32) + { + //Stream flushed, zero out the values + bitstream_init(stream); + } + else + { + stream->cur_byte++; + } +} + +void bitstream_flush(bitstream* stream) +{ + + /* + * SAVE DATA TO OUTPUT + */ + + //Stream flushed, zero out the values + bitstream_init(stream); +} + \ No newline at end of file diff --git a/src/bitstream.h b/src/bitstream.h new file mode 100644 index 00000000..3b9af93b --- /dev/null +++ b/src/bitstream.h @@ -0,0 +1,21 @@ +#ifndef _BITSTREAM_H +#define _BITSTREAM_H + + +typedef struct +{ + uint32_t data[32]; + uint8_t cur_byte; + uint8_t cur_bit; + +} bitstream; + +void bitstream_init(bitstream* stream); + +void bitstream_put(bitstream* stream, uint32_t* data, uint8_t bits); + +void bitstream_align(bitstream* stream); + +void bitstream_flush(bitstream* stream); + +#endif \ No newline at end of file