Skip to content

Commit

Permalink
Replace C-style arrays with std::array
Browse files Browse the repository at this point in the history
  • Loading branch information
nschlia committed Oct 1, 2024
1 parent 65034a2 commit 297fe62
Show file tree
Hide file tree
Showing 18 changed files with 230 additions and 182 deletions.
49 changes: 25 additions & 24 deletions src/aiff.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,21 @@
#pragma once

#include <stdint.h>
#include <array>

#pragma pack(push, 1)

typedef uint8_t AIFF_ID[4]; /**< @brief AIFF fourcc ID */
typedef std::array<uint8_t, 4> AIFF_ID; /**< @brief AIFF fourcc ID */

#define AIFF_FORMID "FORM" /**< @brief ckID for Form Chunk */
#define AIFF_FORMID "FORM" /**< @brief ckID for Form Chunk */
/**
* AIFF format chunk
*/
typedef struct
{
AIFF_ID m_ckID; /**< @brief Chunk ID, always "FORM" */
uint32_t m_ckSize; /**< @brief Total file size - 8 */
AIFF_ID formType; /**< @brief */
AIFF_ID m_ckID; /**< @brief Chunk ID, always "FORM" */
uint32_t m_ckSize; /**< @brief Total file size - 8 */
AIFF_ID formType; /**< @brief */
//uint8_t chunks[];
} AIFF_FORMCHUNK;

Expand All @@ -58,49 +59,49 @@ typedef struct
*/
typedef struct
{
AIFF_ID m_ckID; /**< @brief Chunk ID */
uint32_t m_ckSize; /**< @brief Size of this chunk - 8 */
AIFF_ID m_ckID; /**< @brief Chunk ID */
uint32_t m_ckSize; /**< @brief Size of this chunk - 8 */
//uint8_t data[];
} AIFF_CHUNK;

#define AIFF_COMMONID "COMM" /**< @brief ckID for Common Chunk */
#define AIFF_COMMONID "COMM" /**< @brief ckID for Common Chunk */
/**
* AIFF Common chunk
*/
typedef struct
{
AIFF_ID m_ckID; /**< @brief Chunk ID, always "COMM" */
uint32_t m_ckSize; /**< @brief Size of this chunk - 8 */
uint8_t m_numChannels; /**< @brief Number of audio channels for the sound. */
uint32_t m_numSampleFrames; /**< @brief Number of sample frames in the sound data chunk. */
uint8_t m_sampleSize; /**< @brief Number of bits in each sample point. */
AIFF_ID m_ckID; /**< @brief Chunk ID, always "COMM" */
uint32_t m_ckSize; /**< @brief Size of this chunk - 8 */
uint8_t m_numChannels; /**< @brief Number of audio channels for the sound. */
uint32_t m_numSampleFrames; /**< @brief Number of sample frames in the sound data chunk. */
uint8_t m_sampleSize; /**< @brief Number of bits in each sample point. */
//extended sampleRate;
} AIFF_COMMONCHUNK;

#define AIFF_SOUNDATAID "SSND" /**< @brief ckID for Sound Data Chunk */
#define AIFF_SOUNDATAID "SSND" /**< @brief ckID for Sound Data Chunk */
/**
* AIFF sound data chunk
*/
typedef struct
{
AIFF_ID m_ckID; /**< @brief Chunk ID, always "SSND" */
uint32_t m_ckSize; /**< @brief Total size of sound data chunk - 8 */
uint32_t m_offset; /**< @brief Determines where the first sample frame in the soundData starts. */
uint32_t m_blockSize; /**< @brief Contains the size in bytes of the blocks that sound data is aligned to. */
AIFF_ID m_ckID; /**< @brief Chunk ID, always "SSND" */
uint32_t m_ckSize; /**< @brief Total size of sound data chunk - 8 */
uint32_t m_offset; /**< @brief Determines where the first sample frame in the soundData starts. */
uint32_t m_blockSize; /**< @brief Contains the size in bytes of the blocks that sound data is aligned to. */
//uint8_t soundData[];
} AIFF_SOUNDDATACHUNK;

#define AIFF_NAMEID "NAME" /**< @brief ckID for Name Chunk. */
#define AIFF_AUTHORID "AUTH" /**< @brief ckID for Author Chunk. */
#define AIFF_COPYRIGHTID "(c) " /**< @brief ckID for Copyright Chunk. */
#define AIFF_ANNOTATIONID "ANNO" /**< @brief ckID for Annotation Chunk. */
#define AIFF_NAMEID "NAME" /**< @brief ckID for Name Chunk. */
#define AIFF_AUTHORID "AUTH" /**< @brief ckID for Author Chunk. */
#define AIFF_COPYRIGHTID "(c) " /**< @brief ckID for Copyright Chunk. */
#define AIFF_ANNOTATIONID "ANNO" /**< @brief ckID for Annotation Chunk. */
/**
* AIFF name chunk
*/
typedef struct
{
AIFF_ID m_ckID; /**< @brief Chunk ID, one of "NAME", "AUTH", "(c) ", "ANNO" */
uint32_t m_ckSize; /**< @brief Size of this chunk - 8 */
AIFF_ID m_ckID; /**< @brief Chunk ID, one of "NAME", "AUTH", "(c) ", "ANNO" */
uint32_t m_ckSize; /**< @brief Size of this chunk - 8 */
//uint8_t text[];
} AIFF_TEXTCHUNK;

Expand Down
8 changes: 4 additions & 4 deletions src/blurayio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ BlurayIO::BlurayIO()
, m_angle_idx(0)
, m_duration(AV_NOPTS_VALUE)
{
std::memset(&m_data, 0, sizeof(m_data));
m_data.fill(0);
}

BlurayIO::~BlurayIO()
Expand Down Expand Up @@ -202,7 +202,7 @@ size_t BlurayIO::readio(void * data, size_t size)
maxsize = static_cast<int>(m_end_pos - m_cur_pos);
}

int res = bd_read(m_bd, m_data, maxsize);
int res = bd_read(m_bd, m_data.data(), maxsize);
if (res < 0)
{
Logging::error(path(), "bd_read has failed.");
Expand All @@ -216,15 +216,15 @@ size_t BlurayIO::readio(void * data, size_t size)
if (bytes > size)
{
result_len = size;
std::memcpy(data, m_data, result_len);
std::memcpy(data, m_data.data(), result_len);

m_rest_size = bytes - size;
m_rest_pos = size;
}
else
{
result_len = bytes;
std::memcpy(data, m_data, result_len);
std::memcpy(data, m_data.data(), result_len);
}
}

Expand Down
30 changes: 16 additions & 14 deletions src/blurayio.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

#include "fileio.h"

#include <array>

typedef struct bluray BLURAY; /**< @brief Forward declaration of libbluray handle */

/**
Expand Down Expand Up @@ -138,24 +140,24 @@ class BlurayIO : public FileIO
void pvt_close();

protected:
BLURAY * m_bd; /**< @brief Blu-ray disk handle */
BLURAY * m_bd; /**< @brief Blu-ray disk handle */

bool m_is_eof; /**< @brief true if at end of virtual file */
int m_errno; /**< @brief Last errno */
size_t m_rest_size; /**< @brief Rest bytes in buffer */
size_t m_rest_pos; /**< @brief Position in buffer */
int64_t m_cur_pos; /**< @brief Current position in virtual file */
int64_t m_start_pos; /**< @brief Start offset in bytes */
int64_t m_end_pos; /**< @brief End offset in bytes (not including this byte) */
bool m_is_eof; /**< @brief true if at end of virtual file */
int m_errno; /**< @brief Last errno */
size_t m_rest_size; /**< @brief Rest bytes in buffer */
size_t m_rest_pos; /**< @brief Position in buffer */
int64_t m_cur_pos; /**< @brief Current position in virtual file */
int64_t m_start_pos; /**< @brief Start offset in bytes */
int64_t m_end_pos; /**< @brief End offset in bytes (not including this byte) */

bool m_full_title; /**< @brief If true, ignore m_chapter_no and provide full track */
uint32_t m_title_idx; /**< @brief Track index (track number - 1) */
unsigned m_chapter_idx; /**< @brief Chapter index (chapter number - 1) */
unsigned m_angle_idx; /**< @brief Selected angle index (angle number -1) */
bool m_full_title; /**< @brief If true, ignore m_chapter_no and provide full track */
uint32_t m_title_idx; /**< @brief Track index (track number - 1) */
unsigned m_chapter_idx; /**< @brief Chapter index (chapter number - 1) */
unsigned m_angle_idx; /**< @brief Selected angle index (angle number -1) */

uint8_t m_data[192 * 1024]; /**< @brief Buffer for readio() data */
std::array<uint8_t, 192 * 1024> m_data; /**< @brief Buffer for readio() data */

int64_t m_duration; /**< @brief Track/chapter duration, in AV_TIME_BASE fractional seconds. */
int64_t m_duration; /**< @brief Track/chapter duration, in AV_TIME_BASE fractional seconds. */
};
#endif // USE_LIBBLURAY

Expand Down
2 changes: 1 addition & 1 deletion src/buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ size_t Buffer::write_frame(const uint8_t *data, size_t length, uint32_t frame_no
{
// Create new frame if not existing or not enough space
std::memset(&new_image_frame, 0xFF, sizeof(new_image_frame));
std::memcpy(new_image_frame.m_tag, IMAGE_FRAME_TAG, sizeof(new_image_frame.m_tag));
std::memcpy(new_image_frame.m_tag.data(), IMAGE_FRAME_TAG, sizeof(new_image_frame.m_tag));
new_image_frame.m_frame_no = frame_no;
new_image_frame.m_offset = buffer_watermark();
new_image_frame.m_size = static_cast<uint32_t>(length);
Expand Down
8 changes: 4 additions & 4 deletions src/cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ bool Cache::read_info(LPCACHE_INFO cache_info)
throw false;
}

if (SQLITE_OK != (ret = sqlite3_bind_text(m_cacheidx_select_stmt, 2, cache_info->m_desttype, -1, nullptr)))
if (SQLITE_OK != (ret = sqlite3_bind_text(m_cacheidx_select_stmt, 2, cache_info->m_desttype.data(), -1, nullptr)))
{
Logging::error(m_cacheidx_file, "SQLite3 select error binding 'desttype': (%1) %2", ret, sqlite3_errstr(ret));
throw false;
Expand All @@ -808,7 +808,7 @@ bool Cache::read_info(LPCACHE_INFO cache_info)
if (text != nullptr)
{
cache_info->m_desttype[0] = '\0';
strncat(cache_info->m_desttype, text, sizeof(cache_info->m_desttype) - 1);
strncat(cache_info->m_desttype.data(), text, cache_info->m_desttype.size() - 1);
}
//cache_info->m_enable_ismv = sqlite3_column_int(m_cacheidx_select_stmt, 1);
cache_info->m_audiobitrate = sqlite3_column_int(m_cacheidx_select_stmt, 2);
Expand Down Expand Up @@ -886,7 +886,7 @@ bool Cache::write_info(LPCCACHE_INFO cache_info)
assert(sqlite3_bind_parameter_count(m_cacheidx_insert_stmt) == 22);

SQLBINDTXT(1, cache_info->m_destfile.c_str());
SQLBINDTXT(2, cache_info->m_desttype);
SQLBINDTXT(2, cache_info->m_desttype.data());
//SQLBINDNUM(sqlite3_bind_int, 3, cache_info->m_enable_ismv);
SQLBINDNUM(sqlite3_bind_int, 3, enable_ismv_dummy);
SQLBINDNUM(sqlite3_bind_int64, 4, cache_info->m_audiobitrate);
Expand Down Expand Up @@ -1031,7 +1031,7 @@ bool Cache::delete_entry(Cache_Entry ** cache_entry, int flags)
// If CACHE_CLOSE_FREE is set, also free memory
if (CACHE_CHECK_BIT(CACHE_CLOSE_FREE, flags))
{
m_cache.erase(make_pair((*cache_entry)->m_cache_info.m_destfile, (*cache_entry)->m_cache_info.m_desttype));
m_cache.erase(make_pair((*cache_entry)->m_cache_info.m_destfile, (*cache_entry)->m_cache_info.m_desttype.data()));

deleted = (*cache_entry)->destroy();
*cache_entry = nullptr;
Expand Down
Loading

0 comments on commit 297fe62

Please sign in to comment.