diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 245e4ee..176c3cd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,13 +16,13 @@ jobs: clang-format: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Install Clang-Format - run: sudo apt-get update && sudo apt-get -y install clang-format - - name: Run Clang-Format - run: | - find . -name "*.cpp" -o -name "*.hpp" | xargs -I {} clang-format -i {} -n --verbose --Werror + - name: Checkout + uses: actions/checkout@v2 + - name: Install Clang-Format + run: sudo apt-get update && sudo apt-get -y install clang-format + - name: Run Clang-Format + run: | + find . -name "*.cpp" -o -name "*.hpp" | xargs -I {} clang-format -i {} -n --verbose --Werror ci-linux-x86_64: strategy: @@ -44,9 +44,9 @@ jobs: - name: Set i386 environment variables if: matrix.platform == 'linux-x86' run: | - echo "CC=cc -m32" >> $GITHUB_ENV - echo "CXX=c++ -m32" >> $GITHUB_ENV - echo "PKG_CONFIG_PATH=/usr/lib/i386-linux-gnu/pkgconfig/" >> $GITHUB_ENV + echo "CC=cc -m32" >> $GITHUB_ENV + echo "CXX=c++ -m32" >> $GITHUB_ENV + echo "PKG_CONFIG_PATH=/usr/lib/i386-linux-gnu/pkgconfig/" >> $GITHUB_ENV - name: Install dependencies run: | @@ -64,7 +64,7 @@ jobs: sudo apt remove --assume-yes zlib1g-dev - name: Configure - run: meson setup builddir --default-library=both + run: meson setup builddir --default-library=both --warnlevel=2 --werror - name: Build run: meson compile --verbose -C builddir @@ -100,7 +100,7 @@ jobs: if: matrix.platform == 'windows-x86' uses: ilammy/msvc-dev-cmd@v1 with: - arch: 'x86' + arch: "x86" - name: Checkout code uses: actions/checkout@v3 @@ -114,13 +114,13 @@ jobs: - name: Install python uses: actions/setup-python@v4 with: - python-version: '3.10' + python-version: "3.10" - name: Install meson run: python -m pip install meson ninja - name: Configure - run: meson setup --vsenv builddir --default-library=both + run: meson setup --vsenv builddir --default-library=both --warnlevel=2 --werror - name: Build run: meson compile --verbose -C builddir diff --git a/lib/esedatareader.cpp b/lib/esedatareader.cpp index 0d0d272..d4ee434 100644 --- a/lib/esedatareader.cpp +++ b/lib/esedatareader.cpp @@ -33,11 +33,11 @@ ESEDataReader::prepare () return true; } -uint32_t -ESEDataReader::readData (int32_t size, int32_t position, bool append) +size_t +ESEDataReader::readData (size_t size, int32_t position, bool append) { ESEBuffer buffer; - int32_t read_size; + size_t read_size; buffer.resize (size); m_streamPosition = position; @@ -52,7 +52,7 @@ ESEDataReader::readData (int32_t size, int32_t position, bool append) } m_readSize += read_size; - m_streamPosition += read_size; + m_streamPosition += static_cast (read_size); if (append) { m_buffer.insert (m_buffer.end (), buffer.begin (), buffer.end ()); @@ -67,9 +67,9 @@ ESEDataReader::readData (int32_t size, int32_t position, bool append) } ESEBuffer -ESEDataReader::getBuffer (uint32_t size) +ESEDataReader::getBuffer (size_t size) { - uint32_t real_size = size; + size_t real_size = size; ESEBuffer buffer; while (m_buffer.size () < size) { diff --git a/lib/esedatareader.h b/lib/esedatareader.h index 9328636..9687ce4 100644 --- a/lib/esedatareader.h +++ b/lib/esedatareader.h @@ -27,12 +27,12 @@ class ESEDataReader : public ESEReader { ~ESEDataReader () { } bool prepare (); - virtual ESEBuffer getBuffer (uint32_t size); + virtual ESEBuffer getBuffer (size_t size); virtual bool isEOS () { return m_eos; } virtual size_t streamSize () { return 0; } private: - uint32_t readData (int32_t data_size, int32_t pos = 0, bool append = false); + size_t readData (size_t data_size, int32_t pos = 0, bool append = false); ese_read_buffer_func m_readFunc; void *m_dataPointer; diff --git a/lib/esefilereader.cpp b/lib/esefilereader.cpp index 9dbcab0..12171f9 100644 --- a/lib/esefilereader.cpp +++ b/lib/esefilereader.cpp @@ -34,7 +34,7 @@ ESEFileReader::prepare () m_file = std::ifstream (m_fileName, std::ios::binary | std::ios::ate); DBG ("The file %s is now %s", m_fileName.c_str (), m_file.is_open () ? "open" : "closed"); - m_fileSize = m_file.tellg (); + m_fileSize = static_cast (m_file.tellg ()); if (!m_file.is_open () || m_fileSize <= 0) { ERR ("Unable to open the file %s", m_fileName.c_str ()); return false; @@ -43,14 +43,14 @@ ESEFileReader::prepare () return true; } -uint32_t -ESEFileReader::readFile (int32_t data_size, int32_t pos, bool append) +size_t +ESEFileReader::readFile (size_t data_size, int32_t pos, bool append) { ESEBuffer buffer; size_t read_size; if (!m_fileSize) - m_fileSize = m_file.tellg (); + m_fileSize = static_cast (m_file.tellg ()); if (m_fileSize <= 0) { ERR ("The file is empty. Exit."); return 0; @@ -63,11 +63,11 @@ ESEFileReader::readFile (int32_t data_size, int32_t pos, bool append) m_streamPosition = pos; buffer.resize (data_size); - m_file.read ((char *)buffer.data (), data_size); - read_size = m_file.gcount (); + m_file.read (reinterpret_cast (buffer.data ()), data_size); + read_size = static_cast (m_file.gcount ()); buffer.resize (read_size); m_readSize += read_size; - m_streamPosition += read_size; + m_streamPosition += static_cast (read_size); if (append) { m_buffer.insert (m_buffer.end (), buffer.begin (), buffer.end ()); DBG ("ReadFile: Append %d to a buffer of new size %zd read %zd", data_size, @@ -81,9 +81,9 @@ ESEFileReader::readFile (int32_t data_size, int32_t pos, bool append) } ESEBuffer -ESEFileReader::getBuffer (uint32_t size) +ESEFileReader::getBuffer (size_t size) { - uint32_t real_size = size; + size_t real_size = size; ESEBuffer buffer; while (m_buffer.size () < size) { @@ -97,6 +97,6 @@ ESEFileReader::getBuffer (uint32_t size) buffer = subVector (m_buffer, 0, real_size); m_buffer.erase (m_buffer.begin (), m_buffer.begin () + real_size); - m_bufferSize = m_buffer.size (); + m_bufferSize = static_cast (m_buffer.size ()); return buffer; } diff --git a/lib/esefilereader.h b/lib/esefilereader.h index e5aa595..e5e254e 100644 --- a/lib/esefilereader.h +++ b/lib/esefilereader.h @@ -33,12 +33,12 @@ class ESEFileReader : public ESEReader { virtual bool prepare (); - virtual ESEBuffer getBuffer (uint32_t size); + virtual ESEBuffer getBuffer (size_t size); virtual size_t streamSize () { return m_fileSize; } virtual bool isEOS () { return m_bufferSize == 0 && m_readSize == streamSize (); } private: - uint32_t readFile (int32_t data_size, int32_t pos = 0, bool append = false); + size_t readFile (size_t data_size, int32_t pos = 0, bool append = false); std::ifstream m_file; std::string m_fileName; diff --git a/lib/eseivfstream.cpp b/lib/eseivfstream.cpp index ac5bbf4..ba9a795 100644 --- a/lib/eseivfstream.cpp +++ b/lib/eseivfstream.cpp @@ -50,7 +50,7 @@ ESEIVFStream::reset () void ESEIVFStream::parseOptions (const char *options) { - INFO ("Create a IFV stream"); + INFO ("Create a IFV stream with options %s", options); } ESEVideoCodec diff --git a/lib/eselogger.h b/lib/eselogger.h index 556f5b3..7fc34ea 100644 --- a/lib/eselogger.h +++ b/lib/eselogger.h @@ -57,13 +57,13 @@ class Logger { va_end (argptr); } - void createLogData (const uint8_t *buffer, uint32_t length, const char *format, ...) + void createLogData (const uint8_t *buffer, size_t length, const char *format, ...) { va_list argptr; va_start (argptr, format); vfprintf (stdout, format, argptr); va_end (argptr); - for (uint32_t i = 0; i < length; i++) { + for (size_t i = 0; i < length; i++) { fprintf (stdout, "0x%.2X ", buffer[i]); } fprintf (stdout, "\n"); diff --git a/lib/esenalstream.cpp b/lib/esenalstream.cpp index 43ff471..3255b7c 100644 --- a/lib/esenalstream.cpp +++ b/lib/esenalstream.cpp @@ -71,7 +71,7 @@ int32_t ESENALStream::parseStream (int32_t start_position) { int32_t pos = start_position; - int32_t buffer_size = m_buffer.size (); + int32_t buffer_size = static_cast (m_buffer.size ()); while (pos < buffer_size) { if (!m_mpegDetected) { @@ -120,12 +120,12 @@ ESENALStream::readStream () return ESE_RESULT_EOS; } - if (m_bufferPosition >= (uint32_t)m_buffer.size ()) { + if (m_bufferPosition >= static_cast (m_buffer.size ())) { m_buffer = m_reader->getBuffer (m_reader->bufferReadLength () >= MINIMUM_HEADER_SEARCH_FRAME ? m_reader->bufferReadLength () : MINIMUM_HEADER_SEARCH_FRAME); } - while (m_bufferPosition <= (uint32_t)m_buffer.size () || !m_reader->isEOS ()) { + while (m_bufferPosition <= static_cast (m_buffer.size ()) || !m_reader->isEOS ()) { pos = parseStream (m_bufferPosition); - if (pos == (int32_t)-1) { + if (pos == static_cast (-1)) { return ESE_RESULT_NO_PACKET; } else { if (m_frameState == ESE_NAL_FRAME_STATE_END) { @@ -139,7 +139,7 @@ ESENALStream::readStream () return ESE_RESULT_NEW_PACKET; } else { m_bufferPosition = pos; - if (m_bufferPosition >= (uint32_t)m_buffer.size ()) { + if (m_bufferPosition >= static_cast (m_buffer.size ())) { if (m_reader->isEOS ()) { m_nextFrame = prepareFrame (m_buffer, m_frameStartPos, m_buffer.size ()); m_nalCount++; @@ -177,14 +177,14 @@ ESENALStream::processToNextFrame () } else { m_currentFrame = {}; while ((res = readStream ()) <= ESE_RESULT_EOS) { - if (!ese_is_aud_nalu (m_nextFrame, (ESENaluCodec)m_codec)) { + if (!ese_is_aud_nalu (m_nextFrame, static_cast (m_codec))) { m_currentFrame.insert (m_currentFrame.end (), m_nextFrame.begin (), m_nextFrame.end ()); } if (res == ESE_RESULT_EOS - || ese_is_new_frame (m_nextFrame, (ESENaluCodec)m_codec)) { + || ese_is_new_frame (m_nextFrame, static_cast (m_codec))) { if (m_currentFrame.size () > 0) { - const ESEBuffer &audNalu = ese_aud_nalu ((ESENaluCodec)m_codec); + const ESEBuffer &audNalu = ese_aud_nalu (static_cast (m_codec)); m_currentFrame.insert (m_currentFrame.begin (), audNalu.begin (), audNalu.end ()); prepareNextPacket (); diff --git a/lib/esereader.h b/lib/esereader.h index c57327f..f12977f 100644 --- a/lib/esereader.h +++ b/lib/esereader.h @@ -30,21 +30,21 @@ class ESEReader { /// @brief Reset the reader virtual void reset (); - virtual bool prepare () = 0; - virtual ESEBuffer getBuffer (uint32_t size) = 0; + virtual bool prepare () = 0; + virtual ESEBuffer getBuffer (size_t size) = 0; - int32_t readSize () { return m_readSize; } + size_t readSize () { return m_readSize; } virtual size_t streamSize () = 0; int32_t streamPosition () { return m_streamPosition; } - uint32_t bufferReadLength () { return m_bufferReadLength; } - void setBufferReadLength (uint32_t bufferReadLength) { m_bufferReadLength = bufferReadLength; } + size_t bufferReadLength () { return m_bufferReadLength; } + void setBufferReadLength (size_t bufferReadLength) { m_bufferReadLength = bufferReadLength; } virtual bool isEOS () = 0; protected: int32_t m_streamPosition; - int32_t m_bufferSize; + size_t m_bufferSize; size_t m_readSize; - uint32_t m_bufferReadLength; + size_t m_bufferReadLength; ESEBuffer m_buffer; }; diff --git a/lib/esestream.cpp b/lib/esestream.cpp index c9483b4..25e09b6 100644 --- a/lib/esestream.cpp +++ b/lib/esestream.cpp @@ -14,6 +14,7 @@ * implied. See the License for the specific language governing * permissions and limitations under the License. */ +#define _CRT_SECURE_NO_WARNINGS 1 #include "esestream.h" #include "esedatareader.h" @@ -89,7 +90,7 @@ ESEStream::prepare (ese_read_buffer_func read_func, void *pointer, const char *o } void -ESEStream::setBufferReadLength (int32_t len) +ESEStream::setBufferReadLength (size_t len) { if (m_reader) m_reader->setBufferReadLength (len); @@ -102,10 +103,10 @@ ESEStream::setOptions (const char *options) } ESEBuffer -ESEStream::prepareFrame (ESEBuffer buffer, uint32_t start, - uint32_t end) +ESEStream::prepareFrame (ESEBuffer buffer, size_t start, + size_t end) { - uint32_t frame_start = start; + size_t frame_start = start; if (start > buffer.size () || end > buffer.size ()) { throw std::out_of_range ("start and end positions must be within the buffer size"); } @@ -263,7 +264,7 @@ ESEStream::parseOptions (const char *options) char *token; if (options == nullptr) return; - token = strtok ((char *)options, "\n"); + token = strtok (const_cast (options), "\n"); while (token != NULL) { std::string s (token); size_t pos = s.find (":"); diff --git a/lib/esestream.h b/lib/esestream.h index e7a2f2c..97bf6e9 100644 --- a/lib/esestream.h +++ b/lib/esestream.h @@ -29,7 +29,7 @@ #define MAX_SEARCH_SIZE 5 #define ESE_MAKE_FOURCC(a, b, c, d) \ - ((uint32_t)(a) | ((uint32_t)(b)) << 8 | ((uint32_t)(c)) << 16 | ((uint32_t)(d)) << 24) + (static_cast (a) | (static_cast (b)) << 8 | (static_cast (c)) << 16 | (static_cast (d)) << 24) class ESEStream { public: @@ -40,7 +40,7 @@ class ESEStream { bool prepare (const char *uri, const char *options = nullptr); bool prepare (ese_read_buffer_func func, void *pointer, const char *options); - void setBufferReadLength (int32_t len); + void setBufferReadLength (size_t len); void setOptions (const char *options); virtual void parseOptions (const char *options); /// @brief This method will build the next frame (NAL or AU) available. @@ -68,7 +68,7 @@ class ESEStream { virtual ESEBuffer getStartCode () { return {}; } // Prepare the next frame available from the given buffer at given position. - ESEBuffer prepareFrame (ESEBuffer buffer, uint32_t start, uint32_t end); + ESEBuffer prepareFrame (ESEBuffer buffer, size_t start, size_t end); ESEPacket *prepareNextPacket (uint64_t pts = 0, uint64_t dts = 0, uint64_t duration = 0); ESEVideoCodec m_codec; diff --git a/lib/eseutils.h b/lib/eseutils.h index 6379329..2c5fb05 100644 --- a/lib/eseutils.h +++ b/lib/eseutils.h @@ -48,7 +48,7 @@ make_unique (Args &&...args) template static inline std::vector -subVector (std::vector const &v, int pos, int size) +subVector (std::vector const &v, size_t pos, size_t size) { auto first = v.cbegin () + pos; auto last = v.cbegin () + pos + size; diff --git a/lib/esextractor.cpp b/lib/esextractor.cpp index 6e2f26f..62b4a00 100644 --- a/lib/esextractor.cpp +++ b/lib/esextractor.cpp @@ -117,7 +117,7 @@ struct ESExtractor { m_stream->processToNextFrame (); } - void setBufferReadLength (uint32_t len) + void setBufferReadLength (size_t len) { m_stream->setBufferReadLength (len); } @@ -170,7 +170,7 @@ es_extractor_read_packet (ESExtractor *extractor, ESEPacket **packet) } void -es_extractor_set_buffer_read_length (ESExtractor *extractor, uint32_t buffer_read_length) +es_extractor_set_buffer_read_length (ESExtractor *extractor, size_t buffer_read_length) { ESE_CHECK_VOID (extractor != NULL); extractor->setBufferReadLength (buffer_read_length); diff --git a/lib/esextractor.h b/lib/esextractor.h index 51f3d6b..da07b91 100644 --- a/lib/esextractor.h +++ b/lib/esextractor.h @@ -19,7 +19,7 @@ #include -typedef int32_t (*ese_read_buffer_func) (void *opaque, unsigned char *buffer, int32_t buffer_size, int32_t offset); +typedef size_t (*ese_read_buffer_func) (void *opaque, unsigned char *buffer, size_t buffer_size, int32_t offset); #define ESEBuffer std::vector typedef enum ESEVideoCodec { @@ -48,7 +48,7 @@ typedef enum _ESEResult { typedef struct _ESEPacket { uint8_t *data; - int32_t data_size; + size_t data_size; int32_t packet_number; uint64_t pts; uint64_t dts; @@ -121,7 +121,7 @@ es_extractor_set_log_level (uint8_t level); ES_EXTRACTOR_API void -es_extractor_set_buffer_read_length (ESExtractor *extractor, uint32_t buffer_read_length); +es_extractor_set_buffer_read_length (ESExtractor *extractor, size_t buffer_read_length); #ifdef __cplusplus } diff --git a/tests/testbin.cpp b/tests/testbin.cpp index 41806d8..72cbd22 100644 --- a/tests/testbin.cpp +++ b/tests/testbin.cpp @@ -40,7 +40,7 @@ class CmdLineParser { static const std::string empty_string (""); return empty_string; } - int optionExists (const std::string &option) const + int64_t optionExists (const std::string &option) const { return std::count (this->tokens.begin (), this->tokens.end (), option); } @@ -50,7 +50,7 @@ class CmdLineParser { }; void -usage (int argc, char *argv[]) +usage (char *argv[]) { std::cout << "Usage: " << argv[0] << " -f input_file" << std::endl; std::cout << std::endl; @@ -69,7 +69,7 @@ main (int argc, char *argv[]) CmdLineParser cmdLine (argc, argv); if (cmdLine.optionExists ("-h")) { - usage (argc, argv); + usage (argv); return 0; } @@ -82,7 +82,7 @@ main (int argc, char *argv[]) const std::string &fileName = cmdLine.getOption ("-f"); if (fileName.empty ()) { std::cerr << "Error: No input file specified." << std::endl; - usage (argc, argv); + usage (argv); return 1; } diff --git a/tests/testese.cpp b/tests/testese.cpp index 269954b..368ca7f 100644 --- a/tests/testese.cpp +++ b/tests/testese.cpp @@ -23,6 +23,7 @@ #include "eselogger.h" #include "eseutils.h" #include "esextractor.h" +#include "testese.h" static void dump_packet (ESExtractor *esextractor, ESEPacket *pkt) @@ -92,7 +93,7 @@ class DataProvider { } } - uint32_t getData (uint8_t *out_buffer, uint32_t data_size, int32_t offset) + size_t getData (uint8_t *out_buffer, size_t data_size, int32_t offset) { ESEBuffer buffer; size_t read_size; @@ -100,8 +101,8 @@ class DataProvider { m_file.clear (); m_file.seekg (offset, m_file.beg); buffer.resize (data_size); - m_file.read ((char *)buffer.data (), data_size); - read_size = m_file.gcount (); + m_file.read (reinterpret_cast (buffer.data ()), data_size); + read_size = static_cast (m_file.gcount ()); buffer.resize (read_size); std::memcpy (out_buffer, buffer.data (), buffer.size ()); @@ -111,10 +112,10 @@ class DataProvider { std::ifstream m_file; }; -static int -ReadBufferFunc (void *opaque, unsigned char *pBuf, int size, int32_t offset) +static size_t +ReadBufferFunc (void *opaque, unsigned char *pBuf, size_t size, int32_t offset) { - int read_size = ((DataProvider *)opaque)->getData (pBuf, size, offset); + size_t read_size = (static_cast (opaque))->getData (pBuf, size, offset); DBG ("ReadBuf read_size=%d size=%d offset=%d", read_size, size, offset); return read_size; } @@ -127,6 +128,7 @@ parse_data (const char *fileName, const char *options, uint8_t debug_level, int std::unique_ptr pDataProvider = make_unique (fileName); ESExtractor *esextractor = es_extractor_new_with_read_func (&ReadBufferFunc, pDataProvider.get (), options); + es_extractor_set_buffer_read_length (esextractor, bufferReadLength); if (!esextractor) { ERR ("Unable to discover a compatible stream. Exit"); return -1; diff --git a/tests/testsuite.cpp b/tests/testsuite.cpp index 2889b2c..de3397d 100644 --- a/tests/testsuite.cpp +++ b/tests/testsuite.cpp @@ -57,7 +57,7 @@ check_ivf_file (const char *uri, int log_level, ESEVideoCodec codec, std::string } int -main (int argc, char *argv[]) +main () { int log_level = ES_LOG_LEVEL_INFO;