本文整理汇总了C++中BitstreamReader类的典型用法代码示例。如果您正苦于以下问题:C++ BitstreamReader类的具体用法?C++ BitstreamReader怎么用?C++ BitstreamReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BitstreamReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[]) {
/*perform simple round-trip using page reader and writer*/
BitstreamReader *reader = br_open(stdin, BS_LITTLE_ENDIAN);
BitstreamWriter *writer = bw_open(stdout, BS_LITTLE_ENDIAN);
struct ogg_page page;
do {
ogg_status result;
if ((result = read_ogg_page(reader, &page)) == OGG_OK) {
write_ogg_page(writer, &page);
} else {
fprintf(stderr, "*** Error: %s", ogg_strerror(result));
goto error;
}
} while (!page.header.stream_end);
reader->close(reader);
writer->close(writer);
return 0;
error:
reader->close(reader);
writer->close(writer);
return 1;
}
示例2: processSubLayerHrdParameters
SubLayerHrdParameters HevcNalDecode::processSubLayerHrdParameters(uint8_t sub_pic_hrd_params_present_flag, std::size_t CpbCnt, BitstreamReader &bs)
{
SubLayerHrdParameters slhrd;
slhrd.toDefault();
slhrd.bit_rate_value_minus1.resize(CpbCnt + 1);
slhrd.cpb_size_value_minus1.resize(CpbCnt + 1);
slhrd.cpb_size_du_value_minus1.resize(CpbCnt + 1);
slhrd.bit_rate_du_value_minus1.resize(CpbCnt + 1);
slhrd.cbr_flag.resize(CpbCnt + 1);
for(std::size_t i=0; i<=CpbCnt; i++)
{
slhrd.bit_rate_value_minus1[i] = bs.getGolombU();
slhrd.cpb_size_value_minus1[i] = bs.getGolombU();
if(sub_pic_hrd_params_present_flag)
{
slhrd.cpb_size_du_value_minus1[i] = bs.getGolombU();
slhrd.bit_rate_du_value_minus1[i] = bs.getGolombU();
}
slhrd.cbr_flag[i] = bs.getBits(1);
}
return slhrd;
}
示例3: decode_frameset
static status_t
decode_frameset(decoders_ALACDecoder *self,
unsigned *pcm_frames_read,
int *samples)
{
BitstreamReader *br = self->bitstream;
int channel_0[self->params.block_size];
int channel_1[self->params.block_size];
unsigned c = 0;
unsigned block_size = self->params.block_size;
unsigned channels = br->read(br, 3) + 1;
while (channels != 8) {
status_t status;
unsigned frame_block_size;
if ((channels != 1) && (channels != 2)) {
/*only handle 1 or 2 channel frames*/
return INVALID_FRAME_CHANNEL_COUNT;
} else if ((c + channels) > self->channels) {
/*ensure one doesn't decode too many channels*/
return EXCESSIVE_FRAME_CHANNEL_COUNT;
}
if ((status = decode_frame(br,
&(self->params),
self->bits_per_sample,
c == 0 ? &block_size : &frame_block_size,
channels,
channel_0,
channel_1)) != OK) {
return status;
} else if ((c != 0) && (block_size != frame_block_size)) {
return FRAME_BLOCK_SIZE_MISMATCH;
}
put_channel_data(samples,
c++,
self->channels,
block_size,
channel_0);
if (channels == 2) {
put_channel_data(samples,
c++,
self->channels,
block_size,
channel_1);
}
channels = br->read(br, 3) + 1;
}
br->byte_align(br);
*pcm_frames_read = block_size;
return OK;
}
示例4: processNALUnitHeader
NALUnitType HevcNalDecode::processNALUnitHeader(BitstreamReader &bs)
{
//forbidden_zero_bit
bs.getBit();
NALUnitType type = (NALUnitType)bs.getBits(6);
//nuh_layer_id
bs.getBits(6);
//nuh_temporal_id_plus1
bs.getBits(3);
return type;
}
示例5: processScalingListData
ScalingListData HevcNalDecode::processScalingListData(BitstreamReader &bs)
{
ScalingListData sc;
sc.scaling_list_pred_mode_flag.resize(4);
sc.scaling_list_pred_matrix_id_delta.resize(4);
sc.scaling_list_dc_coef_minus8.resize(2);
sc.scaling_list_delta_coef.resize(4);
for(std::size_t sizeId = 0; sizeId < 4; sizeId++)
{
if(sizeId == 3)
{
sc.scaling_list_pred_mode_flag[sizeId].resize(2);
sc.scaling_list_pred_matrix_id_delta[sizeId].resize(2);
sc.scaling_list_dc_coef_minus8[sizeId-2].resize(2);
sc.scaling_list_delta_coef[sizeId].resize(2);
}
else
{
sc.scaling_list_pred_mode_flag[sizeId].resize(6);
sc.scaling_list_pred_matrix_id_delta[sizeId].resize(6);
sc.scaling_list_delta_coef[sizeId].resize(6);
if(sizeId >= 2)
sc.scaling_list_dc_coef_minus8[sizeId-2].resize(6);
}
for(std::size_t matrixId = 0; matrixId<((sizeId == 3)?2:6); matrixId++)
{
sc.scaling_list_pred_mode_flag[sizeId][matrixId] = bs.getBits(1);
if(!sc.scaling_list_pred_mode_flag[sizeId][matrixId])
sc.scaling_list_pred_matrix_id_delta[sizeId][matrixId] = bs.getGolombU();
else
{
std::size_t nextCoef = 8;
std::size_t coefNum = std::min(64, (1 << (4 + (sizeId << 1))));
if(sizeId > 1)
sc.scaling_list_dc_coef_minus8[sizeId-2][matrixId] = bs.getGolombS();
sc.scaling_list_delta_coef[sizeId][matrixId].resize(coefNum);
for(std::size_t i = 0; i < coefNum; i++)
sc.scaling_list_delta_coef[sizeId][matrixId][i] = bs.getGolombS();
}
}
}
return sc;
}
示例6: main
int main(int argc, char *argv[]) {
FILE *f = fopen(argv[1], "rb");
OggReader *reader = oggreader_open(f);
BitstreamReader *packet = bs_substream_new(BS_LITTLE_ENDIAN);
ogg_status result;
do {
result = oggreader_next_packet(reader, packet);
if (result < 0) {
fprintf(stderr, "Error : %s\n", ogg_error(result));
} else if (result == OGG_OK) {
printf("packet size %u\n", packet->input.substream->buffer_size);
}
} while (result == OGG_OK);
packet->close(packet);
oggreader_close(reader);
fclose(f);
return 0;
}
示例7: parseAPP14
static Status parseAPP14(DataReader *pReader, JPEGAPP14Header *pHeader)
{
BitstreamReader bs;
Ipp8u iMarker[5];
size_t iSize = 5;
pReader->Get16uSwap(&pHeader->iLength);
pReader->CacheData(&iMarker[0], iSize);
if(iMarker[0] == 'a' && iMarker[1] == 'd' && iMarker[2] == 'o' && iMarker[3] == 'b' && iMarker[4] == 'e')
{
pReader->MovePosition(5);
bs.Init(pReader);
pHeader->bAdobeDetected = true;
pHeader->iAdobeVersion = bs.GetBits(16);
pHeader->iAdobeFlags0 = bs.GetBits(16);
pHeader->iAdobeFlags1 = bs.GetBits(16);
pHeader->iAdobeTransform = bs.GetBits(8);
bs.AlignReader();
}
return UMC_OK;
}
示例8: Status
Status Mpeg2FrameConstructor::ParsePictureHeader(Ipp8u *buf, Ipp32s iLen, Mpeg2TrackInfo *pInfo) {
BitstreamReader bs;
bs.SkipBits(32 + 4 + 4 + 4 + 4 + 4 + 2);
bs.SkipBits(1 + 1 + 1 + 1 + 1 + 1 + 1);
bs.SkipBits(5);
bs.SkipBits(3);
Ipp8u source_format;
bs.SkipBits(22);
bs.SkipBits(8);
if (7 == source_format) {
Ipp8u ufep = (Ipp8u)bs.GetBits(3);
if (0x01 == ufep) {
bs.SkipBits(10);
}
}
return Status();
}
示例9: parseSOF
static Status parseSOF(DataReader *pReader, JPEGSOFHeader *pHeader)
{
BitstreamReader bs;
bs.Init(pReader);
pHeader->iLength = bs.GetBits(16);
pHeader->iPrecision = bs.GetBits(8);
pHeader->iHeight = bs.GetBits(16);
pHeader->iWidth = bs.GetBits(16);
pHeader->iComonents = bs.GetBits(8);
for(Ipp32u i = 0; i < pHeader->iComonents; i++)
{
pHeader->comonent[i].iID = bs.GetBits(8);
pHeader->comonent[i].iHSampling = bs.GetBits(4);
pHeader->comonent[i].iVSampling = bs.GetBits(4);
pHeader->comonent[i].iQSelector = bs.GetBits(8);
}
bs.AlignReader();
return UMC_OK;
}
示例10: ALACDecoder_read
static PyObject*
ALACDecoder_read(decoders_ALACDecoder* self, PyObject *args)
{
unsigned channel_count;
BitstreamReader* mdat = self->bitstream;
array_ia* frameset_channels = self->frameset_channels;
PyThreadState *thread_state;
/*return an empty framelist if total samples are exhausted*/
if (self->remaining_frames == 0) {
return empty_FrameList(self->audiotools_pcm,
self->channels,
self->bits_per_sample);
}
thread_state = PyEval_SaveThread();
if (!setjmp(*br_try(mdat))) {
frameset_channels->reset(frameset_channels);
/*get initial frame's channel count*/
channel_count = mdat->read(mdat, 3) + 1;
while (channel_count != 8) {
/*read a frame from the frameset into "channels"*/
if (read_frame(self, mdat,
frameset_channels, channel_count) != OK) {
br_etry(mdat);
PyEval_RestoreThread(thread_state);
PyErr_SetString(PyExc_ValueError, self->error_message);
return NULL;
} else {
/*ensure all frames have the same sample count*/
/*FIXME*/
/*read the channel count of the next frame
in the frameset, if any*/
channel_count = mdat->read(mdat, 3) + 1;
}
}
/*once all the frames in the frameset are read,
byte-align the output stream*/
mdat->byte_align(mdat);
br_etry(mdat);
PyEval_RestoreThread(thread_state);
/*decrement the remaining sample count*/
self->remaining_frames -= MIN(self->remaining_frames,
frameset_channels->_[0]->len);
/*convert ALAC channel assignment to standard audiotools assignment*/
alac_order_to_wave_order(frameset_channels);
/*finally, build and return framelist object from the sample data*/
return array_ia_to_FrameList(self->audiotools_pcm,
frameset_channels,
self->bits_per_sample);
} else {
br_etry(mdat);
PyEval_RestoreThread(thread_state);
PyErr_SetString(PyExc_IOError, "EOF during frame reading");
return NULL;
}
}
示例11: ParseBlock
/// ParseBlock - Read a block, updating statistics, etc.
static bool ParseBlock(BitstreamReader &Stream, unsigned IndentLevel) {
std::string Indent(IndentLevel*2, ' ');
uint64_t BlockBitStart = Stream.GetCurrentBitNo();
unsigned BlockID = Stream.ReadSubBlockID();
// Get the statistics for this BlockID.
PerBlockIDStats &BlockStats = BlockIDStats[BlockID];
BlockStats.NumInstances++;
// BLOCKINFO is a special part of the stream.
if (BlockID == bitc::BLOCKINFO_BLOCK_ID) {
if (Dump) std::cerr << Indent << "<BLOCKINFO_BLOCK/>\n";
if (Stream.ReadBlockInfoBlock())
return Error("Malformed BlockInfoBlock");
uint64_t BlockBitEnd = Stream.GetCurrentBitNo();
BlockStats.NumBits += BlockBitEnd-BlockBitStart;
return false;
}
unsigned NumWords = 0;
if (Stream.EnterSubBlock(BlockID, &NumWords))
return Error("Malformed block record");
const char *BlockName = 0;
if (Dump) {
std::cerr << Indent << "<";
if ((BlockName = GetBlockName(BlockID)))
std::cerr << BlockName;
else
std::cerr << "UnknownBlock" << BlockID;
if (NonSymbolic && BlockName)
std::cerr << " BlockID=" << BlockID;
std::cerr << " NumWords=" << NumWords
<< " BlockCodeSize=" << Stream.GetAbbrevIDWidth() << ">\n";
}
SmallVector<uint64_t, 64> Record;
// Read all the records for this block.
while (1) {
if (Stream.AtEndOfStream())
return Error("Premature end of bitstream");
// Read the code for this record.
unsigned AbbrevID = Stream.ReadCode();
switch (AbbrevID) {
case bitc::END_BLOCK: {
if (Stream.ReadBlockEnd())
return Error("Error at end of block");
uint64_t BlockBitEnd = Stream.GetCurrentBitNo();
BlockStats.NumBits += BlockBitEnd-BlockBitStart;
if (Dump) {
std::cerr << Indent << "</";
if (BlockName)
std::cerr << BlockName << ">\n";
else
std::cerr << "UnknownBlock" << BlockID << ">\n";
}
return false;
}
case bitc::ENTER_SUBBLOCK: {
uint64_t SubBlockBitStart = Stream.GetCurrentBitNo();
if (ParseBlock(Stream, IndentLevel+1))
return true;
++BlockStats.NumSubBlocks;
uint64_t SubBlockBitEnd = Stream.GetCurrentBitNo();
// Don't include subblock sizes in the size of this block.
BlockBitStart += SubBlockBitEnd-SubBlockBitStart;
break;
}
case bitc::DEFINE_ABBREV:
Stream.ReadAbbrevRecord();
++BlockStats.NumAbbrevs;
break;
default:
++BlockStats.NumRecords;
if (AbbrevID != bitc::UNABBREV_RECORD)
++BlockStats.NumAbbreviatedRecords;
Record.clear();
unsigned Code = Stream.ReadRecord(AbbrevID, Record);
// Increment the # occurrences of this code.
if (BlockStats.CodeFreq.size() <= Code)
BlockStats.CodeFreq.resize(Code+1);
BlockStats.CodeFreq[Code]++;
if (Dump) {
std::cerr << Indent << " <";
if (const char *CodeName = GetCodeName(Code, BlockID))
std::cerr << CodeName;
else
std::cerr << "UnknownCode" << Code;
if (NonSymbolic && GetCodeName(Code, BlockID))
std::cerr << " codeid=" << Code;
//.........这里部分代码省略.........
示例12: main
int main(int argc, char *argv[])
{
BitstreamReader *br;
BitstreamReader::STATUS sts;
struct _stati64 st;
unsigned __int64 file_size;
const char *in_file;
const char *out_file;
int bit_count = 0;
int bit_count_mod_8 = 0;
unsigned __int64 byte_count = 0;
srand(0);
FILE *out_fp;
int i;
u32 bits;
HANDLE h_in_file;
HANDLE h_mem_mapping;
unsigned char *mem_buf;
if (argc != 3) {
fprintf(stderr,"Usage: %s <in_file> <out_file>\n",argv[0]);
exit(1);
}
in_file = argv[1];
out_file = argv[2];
if (_stati64(in_file,&st) < 0) {
perror("Error: Cannot stat input file");
exit(1);
}
file_size = st.st_size;
printf("Size of file '%s' is: %I64u bytes\n",in_file,(__int64)file_size);
if (file_size >= 0x10000000I64) {
fprintf(stderr,"Error: File is larger than %I64 bytes\n",0x10000000I64);
exit(1);
}
h_in_file = CreateFile(in_file,GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL);
if (h_in_file == INVALID_HANDLE_VALUE) {
fprintf(stderr,"Error: Cannot open input file '%s'\n",in_file);
exit(1);
}
h_mem_mapping = CreateFileMapping(h_in_file,NULL,PAGE_READONLY,0,0,NULL);
if (h_mem_mapping == NULL) {
fprintf(stderr,"Error: Cannot create file mapping object for file: %s\n",in_file);
CloseHandle(h_in_file);
exit(1);
}
mem_buf = (unsigned char*)MapViewOfFile(h_mem_mapping,FILE_MAP_READ,0,0,(DWORD)file_size);
if (mem_buf == NULL) {
fprintf(stderr,"Error: Cannot map file '%s'\n",in_file);
CloseHandle(h_mem_mapping);
CloseHandle(h_in_file);
exit(1);
}
sts = BitstreamReader::create(mem_buf,(size_t)file_size,&br);
if (sts != BitstreamReader::STS_OK) {
fprintf(stderr,"Error: Cannot create bitstream reader\n");
CloseHandle(h_mem_mapping);
CloseHandle(h_in_file);
exit(1);
}
out_fp = fopen(out_file,"w");
if (out_fp == NULL) {
perror("Error: Cannot open output file");
br->destroy();
CloseHandle(h_mem_mapping);
CloseHandle(h_in_file);
exit(1);
}
while (file_size - byte_count >= 4) {
int num_bits = (int)((double)rand()/RAND_MAX*32);
// printf("Attempting to read %d bytes\n",num_bits);
sts = br->readBits(&bits,num_bits);
if (sts != BitstreamReader::STS_OK) {
fprintf(stderr,"Error reading %d bits from the input file\n",num_bits);
fclose(out_fp);
br->destroy();
CloseHandle(h_mem_mapping);
CloseHandle(h_in_file);
exit(1);
}
for (i = num_bits-1; i>=0; i--) {
//.........这里部分代码省略.........
示例13: flacdec_read_metadata
int
flacdec_read_metadata(BitstreamReader *bitstream,
struct flac_STREAMINFO *streaminfo,
a_obj *seektable,
int *channel_mask)
{
BitstreamReader *comment = br_substream_new(BS_LITTLE_ENDIAN);
enum {
fL = 0x1,
fR = 0x2,
fC = 0x4,
LFE = 0x8,
bL = 0x10,
bR = 0x20,
bC = 0x100,
sL = 0x200,
sR = 0x400
};
if (!setjmp(*br_try(bitstream))) {
unsigned last_block;
if (bitstream->read(bitstream, 32) != 0x664C6143u) {
#ifndef STANDALONE
PyErr_SetString(PyExc_ValueError, "not a FLAC file");
#endif
br_etry(bitstream);
comment->close(comment);
return 1;
}
do {
last_block = bitstream->read(bitstream, 1);
const unsigned block_type = bitstream->read(bitstream, 7);
const unsigned block_length = bitstream->read(bitstream, 24);
switch (block_type) {
case 0: /*STREAMINFO*/
streaminfo->minimum_block_size =
bitstream->read(bitstream, 16);
streaminfo->maximum_block_size =
bitstream->read(bitstream, 16);
streaminfo->minimum_frame_size =
bitstream->read(bitstream, 24);
streaminfo->maximum_frame_size =
bitstream->read(bitstream, 24);
streaminfo->sample_rate =
bitstream->read(bitstream, 20);
streaminfo->channels =
bitstream->read(bitstream, 3) + 1;
streaminfo->bits_per_sample =
bitstream->read(bitstream, 5) + 1;
streaminfo->total_samples =
bitstream->read_64(bitstream, 36);
bitstream->read_bytes(bitstream, streaminfo->md5sum, 16);
/*default channel mask based on channel count*/
switch (streaminfo->channels) {
case 1:
*channel_mask = fC;
break;
case 2:
*channel_mask = fL | fR;
break;
case 3:
*channel_mask = fL | fR | fC;
break;
case 4:
*channel_mask = fL | fR | bL | bR;
break;
case 5:
*channel_mask = fL | fR | fC | bL | bR;
break;
case 6:
*channel_mask = fL | fR | fC | LFE | bL | bR;
break;
case 7:
*channel_mask = fL | fR | fC | LFE | bC | sL | sR;
break;
case 8:
*channel_mask = fL | fR | fC | LFE | bL | bR | sL | sR;
break;
default:
/*shouldn't be able to happen*/
*channel_mask = 0;
break;
}
break;
case 3: /*SEEKTABLE*/
{
unsigned seekpoints = block_length / 18;
seektable->reset_for(seektable, seekpoints);
for (; seekpoints > 0; seekpoints--) {
struct flac_SEEKPOINT seekpoint;
seekpoint.sample_number =
bitstream->read_64(bitstream, 64);
seekpoint.byte_offset =
//.........这里部分代码省略.........
示例14: processHrdParameters
HrdParameters HevcNalDecode::processHrdParameters(uint8_t commonInfPresentFlag, std::size_t maxNumSubLayersMinus1, BitstreamReader &bs)
{
HrdParameters hrd;
hrd.toDefault();
hrd.nal_hrd_parameters_present_flag = 0;
hrd.vcl_hrd_parameters_present_flag = 0;
hrd.sub_pic_hrd_params_present_flag = 0;
hrd.sub_pic_cpb_params_in_pic_timing_sei_flag = 0;
if(commonInfPresentFlag)
{
hrd.nal_hrd_parameters_present_flag = bs.getBits(1);
hrd.vcl_hrd_parameters_present_flag = bs.getBits(1);
if(hrd.nal_hrd_parameters_present_flag || hrd.vcl_hrd_parameters_present_flag)
{
hrd.sub_pic_hrd_params_present_flag = bs.getBits(1);
if(hrd.sub_pic_hrd_params_present_flag)
{
hrd.tick_divisor_minus2 = bs.getBits(8);
hrd.du_cpb_removal_delay_increment_length_minus1 = bs.getBits(5);
hrd.sub_pic_cpb_params_in_pic_timing_sei_flag = bs.getBits(1);
hrd.dpb_output_delay_du_length_minus1 = bs.getBits(5);
}
hrd.bit_rate_scale = bs.getBits(4);
hrd.cpb_size_scale = bs.getBits(4);
if(hrd.sub_pic_hrd_params_present_flag)
hrd.cpb_size_du_scale = bs.getBits(4);
hrd.initial_cpb_removal_delay_length_minus1 = bs.getBits(5);
hrd.au_cpb_removal_delay_length_minus1 = bs.getBits(5);
hrd.dpb_output_delay_length_minus1 = bs.getBits(5);
}
}
hrd.fixed_pic_rate_general_flag.resize(maxNumSubLayersMinus1 + 1);
hrd.fixed_pic_rate_within_cvs_flag.resize(maxNumSubLayersMinus1 + 1);
hrd.elemental_duration_in_tc_minus1.resize(maxNumSubLayersMinus1 + 1);
hrd.low_delay_hrd_flag.resize(maxNumSubLayersMinus1 + 1, 0);
hrd.cpb_cnt_minus1.resize(maxNumSubLayersMinus1 + 1, 0);
if(hrd.nal_hrd_parameters_present_flag)
hrd.nal_sub_layer_hrd_parameters.resize(maxNumSubLayersMinus1 + 1);
if(hrd.vcl_hrd_parameters_present_flag)
hrd.vcl_sub_layer_hrd_parameters.resize(maxNumSubLayersMinus1 + 1);
for(std::size_t i = 0; i <= maxNumSubLayersMinus1; i++ )
{
hrd.fixed_pic_rate_general_flag[i] = bs.getBits(1);
if(hrd.fixed_pic_rate_general_flag[i])
hrd.fixed_pic_rate_within_cvs_flag[i] = 1;
if(!hrd.fixed_pic_rate_general_flag[i])
hrd.fixed_pic_rate_within_cvs_flag[i] = bs.getBits(1);
if(hrd.fixed_pic_rate_within_cvs_flag[i])
hrd.elemental_duration_in_tc_minus1[i] = bs.getGolombU();
else
hrd.low_delay_hrd_flag[i] = bs.getBits(1);
if(!hrd.low_delay_hrd_flag[i])
hrd.cpb_cnt_minus1[i] = bs.getGolombU();
if(hrd.nal_hrd_parameters_present_flag)
hrd.nal_sub_layer_hrd_parameters[i] = processSubLayerHrdParameters(hrd.sub_pic_hrd_params_present_flag, hrd.cpb_cnt_minus1[i], bs);
if(hrd.vcl_hrd_parameters_present_flag)
hrd.vcl_sub_layer_hrd_parameters[i] = processSubLayerHrdParameters(hrd.sub_pic_hrd_params_present_flag, hrd.cpb_cnt_minus1[i], bs);
}
return hrd;
}
示例15: verifymodule_ogg
PyObject*
verifymodule_ogg(PyObject *dummy, PyObject *args) {
PyObject *file_obj;
BitstreamReader *bitstream;
int has_previous_header = 0;
struct ogg_header previous_header;
struct ogg_header header;
uint8_t *data_buffer = NULL;
int data_buffer_size = 0;
int i;
uint32_t checksum;
/*fixes a "may be used unitialized" warning*/
previous_header.bitstream_serial_number =
previous_header.page_sequence_number = 0;
if (!PyArg_ParseTuple(args, "O", &file_obj))
return NULL;
if (!PyFile_CheckExact(file_obj)) {
PyErr_SetString(PyExc_TypeError,
"first argument must be an actual file object");
return NULL;
} else {
bitstream = br_open(PyFile_AsFile(file_obj), BS_LITTLE_ENDIAN);
br_add_callback(bitstream, ogg_crc, &checksum);
}
if (!setjmp(*br_try(bitstream))) {
do {
checksum = 0;
if (verifymodule_read_ogg_header(bitstream, &header) == OK) {
if (data_buffer_size < header.segment_length_total) {
data_buffer = realloc(data_buffer,
header.segment_length_total);
data_buffer_size = header.segment_length_total;
}
if (fread(data_buffer,
sizeof(uint8_t),
header.segment_length_total,
bitstream->input.file) !=
header.segment_length_total) {
PyErr_SetString(PyExc_IOError, "I/O error reading stream");
goto error;
}
for (i = 0; i < header.segment_length_total; i++)
ogg_crc(data_buffer[i], &checksum);
if (header.checksum != checksum) {
PyErr_SetString(PyExc_ValueError,
"checksum mismatch in stream");
goto error;
}
/* printf("calculated checksum : 0x%8.8X\n", checksum); */
if (has_previous_header) {
if (header.bitstream_serial_number !=
previous_header.bitstream_serial_number) {
PyErr_SetString(PyExc_ValueError,
"differing serial numbers in stream");
goto error;
}
if (header.page_sequence_number !=
(previous_header.page_sequence_number + 1)) {
PyErr_SetString(PyExc_ValueError,
"page sequence number not incrementing");
goto error;
}
previous_header = header;
} else {
previous_header = header;
has_previous_header = 1;
}
} else {
goto error;
}
} while (!(header.type & 0x4));
} else {
PyErr_SetString(PyExc_IOError, "I/O error reading stream");
goto error;
}
br_etry(bitstream);
free(data_buffer);
bitstream->input.file = NULL;
bitstream->free(bitstream);
Py_INCREF(Py_None);
return Py_None;
error:
br_etry(bitstream);
if (data_buffer != NULL)
free(data_buffer);
bitstream->input.file = NULL;
bitstream->free(bitstream);
return NULL;
}