From ed95388324f10ebad71fd3a8e3691400ba6ff7f8 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 11 Aug 2003 21:17:13 +0000 Subject: [PATCH] Changed the return value of the bit cursor get_bit* functions. They now return true if the operation was successfull to be more consistent with the rest of this code. --- src/aac_common.cpp | 12 ++++++------ src/common.h | 16 ++++++++++------ src/dts_common.cpp | 2 +- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/aac_common.cpp b/src/aac_common.cpp index f612a61c0..12bc9ed95 100644 --- a/src/aac_common.cpp +++ b/src/aac_common.cpp @@ -45,7 +45,7 @@ int parse_aac_adif_header(unsigned char *buf, int size, bc.get_bit(b); // copyright_id_present if (b) { for (i = 0; i < 3; i++) - eob = bc.get_bits(24, bits); // copyright_id + eob = !bc.get_bits(24, bits); // copyright_id } bc.get_bit(b); // original_copy bc.get_bit(b); // home @@ -74,7 +74,7 @@ int parse_aac_adif_header(unsigned char *buf, int size, bc.get_bit(b); // matrix_mixdown_idx_present if (b) { bc.get_bits(2, bits); // matrix_mixdown_idx - eob = bc.get_bits(1, bits); // pseudo_surround_enable + eob = !bc.get_bits(1, bits); // pseudo_surround_enable } channels = nfront_c_e + nside_c_e + nback_c_e; for (k = 0; k < (nfront_c_e + nside_c_e + nback_c_e); k++) { @@ -91,9 +91,9 @@ int parse_aac_adif_header(unsigned char *buf, int size, bc.get_bits(4, bits); // valid_cc_e_tag_select } bc.byte_align(); - eob = bc.get_bits(8, bits); + eob = !bc.get_bits(8, bits); for (k = 0; k < comment_field_bytes; k++) - eob = bc.get_bits(8, bits); + eob = !bc.get_bits(8, bits); } if (eob) @@ -139,9 +139,9 @@ static int is_adts_header(unsigned char *buf, int size, int bpos, bc.get_bit(b); // copyright_id_start bc.get_bits(13, frame_length); bc.get_bits(11, bits); // adts_buffer_fullness - eob = bc.get_bits(2, bits); // no_raw_blocks_in_frame + eob = !bc.get_bits(2, bits); // no_raw_blocks_in_frame if (!protection_absent) - eob = bc.get_bits(16, bits); + eob = !bc.get_bits(16, bits); if (eob) return 0; diff --git a/src/common.h b/src/common.h index 2ff0bb0a1..3dbff2ecd 100644 --- a/src/common.h +++ b/src/common.h @@ -143,13 +143,13 @@ public: } bool get_bits(unsigned int n, unsigned long &r) { - // returns true if less bits are available than asked for + // returns false if less bits are available than asked for r = 0; while (n > 0) { if (byte_position >= end_of_data) { out_of_data = true; - return true; + return false; } unsigned int b = 8; // number of bits to extract from the current byte @@ -172,7 +172,7 @@ public: n -= b; } - return false; + return true; } bool get_bits(unsigned int n, int &r) { @@ -198,12 +198,12 @@ public: bool byte_align() { if (out_of_data) - return true; - if (bits_valid == 8) return false; + if (bits_valid == 8) + return true; bits_valid = 0; byte_position += 1; - return false; + return true; } bool set_bit_position(unsigned int pos) { @@ -219,6 +219,10 @@ public: int get_bit_position() { return byte_position - start_of_data + 8 - bits_valid; } + + bool skip_bits(unsigned int num) { + return set_bit_position(get_bit_position() + num); + } }; class byte_cursor_c { diff --git a/src/dts_common.cpp b/src/dts_common.cpp index 246ab3fd6..73b1a48ce 100644 --- a/src/dts_common.cpp +++ b/src/dts_common.cpp @@ -241,7 +241,7 @@ int find_dts_header(const unsigned char *buf, unsigned int size, bc.get_bit(dts_header->surround_sum_difference); - bool out_of_data = bc.get_bits(4, t); + bool out_of_data = !bc.get_bits(4, t); if (dts_header->encoder_software_revision == 7) { dts_header->dialog_normalization_gain = -((int)t); } else if (dts_header->encoder_software_revision == 6) {