Skip to content

Commit 5e63cba

Browse files
committed
Using QByteArray instead base::ByteArray.
1 parent 31fbdd1 commit 5e63cba

File tree

210 files changed

+1450
-1837
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

210 files changed

+1450
-1837
lines changed

source/base/CMakeLists.txt

+13-7
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ list(APPEND SOURCE_BASE
5454
scoped_logging.h
5555
scoped_task_runner.cc
5656
scoped_task_runner.h
57+
serialization.h
5758
service.h
5859
session_id.cc
5960
session_id.h
@@ -501,10 +502,6 @@ endif()
501502
list(APPEND SOURCE_BASE_MEMORY
502503
memory/aligned_memory.cc
503504
memory/aligned_memory.h
504-
memory/byte_array.cc
505-
memory/byte_array.h
506-
memory/serializer.cc
507-
memory/serializer.h
508505
memory/local_memory.h
509506
memory/typed_buffer.h
510507
memory/local_memory_impl/bad_local_weak_ptr.h
@@ -519,8 +516,7 @@ list(APPEND SOURCE_BASE_MEMORY
519516
memory/local_memory_impl/sp_counted_impl.h)
520517

521518
list(APPEND SOURCE_BASE_MEMORY_TESTS
522-
memory/aligned_memory_unittest.cc
523-
memory/byte_array_unittest.cc)
519+
memory/aligned_memory_unittest.cc)
524520

525521
list(APPEND SOURCE_BASE_NET
526522
net/adapter_enumerator.cc
@@ -829,6 +825,16 @@ target_link_libraries(aspia_base_tests PRIVATE
829825
aspia_proto
830826
GTest::gtest
831827
${BASE_TESTS_PLATFORM_LIBS}
832-
${THIRD_PARTY_LIBS})
828+
${THIRD_PARTY_LIBS}
829+
${QT_COMMON_LIBS}
830+
${QT_PLATFORM_LIBS})
831+
set_property(TARGET aspia_base_tests PROPERTY AUTOMOC ON)
832+
set_property(TARGET aspia_base_tests PROPERTY AUTOUIC ON)
833+
set_property(TARGET aspia_base_tests PROPERTY AUTORCC ON)
834+
qt5_import_plugins(aspia_base_tests
835+
INCLUDE ""
836+
EXCLUDE ""
837+
INCLUDE_BY_TYPE ""
838+
EXCLUDE_BY_TYPE imageformats)
833839

834840
add_test(NAME aspia_base_tests COMMAND aspia_base_tests)

source/base/audio/audio_capturer_wrapper.cc

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "base/audio/audio_capturer_wrapper.h"
2020

2121
#include "base/logging.h"
22+
#include "base/serialization.h"
2223
#include "base/audio/audio_capturer.h"
2324
#include "base/ipc/ipc_channel_proxy.h"
2425

source/base/codec/cursor_decoder.cc

+9-9
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,24 @@ CursorDecoder::~CursorDecoder()
4545
}
4646

4747
//--------------------------------------------------------------------------------------------------
48-
ByteArray CursorDecoder::decompressCursor(const proto::CursorShape& cursor_shape) const
48+
QByteArray CursorDecoder::decompressCursor(const proto::CursorShape& cursor_shape) const
4949
{
5050
const std::string& data = cursor_shape.data();
5151

5252
if (data.empty())
5353
{
5454
LOG(LS_ERROR) << "No cursor data";
55-
return ByteArray();
55+
return QByteArray();
5656
}
5757

5858
if (cursor_shape.width() <= 0 || cursor_shape.height() <= 0)
5959
{
6060
LOG(LS_ERROR) << "Invalid cursor size: "
6161
<< cursor_shape.width() << "x" << cursor_shape.height();
62-
return ByteArray();
62+
return QByteArray();
6363
}
6464

65-
ByteArray image;
65+
QByteArray image;
6666
image.resize(static_cast<size_t>(cursor_shape.width()) *
6767
static_cast<size_t>(cursor_shape.height()) *
6868
sizeof(uint32_t));
@@ -72,11 +72,11 @@ ByteArray CursorDecoder::decompressCursor(const proto::CursorShape& cursor_shape
7272
{
7373
LOG(LS_ERROR) << "ZSTD_initDStream failed: " << ZSTD_getErrorName(ret)
7474
<< " (" << ret << ")";
75-
return ByteArray();
75+
return QByteArray();
7676
}
7777

7878
ZSTD_inBuffer input = { data.data(), data.size(), 0 };
79-
ZSTD_outBuffer output = { image.data(), image.size(), 0 };
79+
ZSTD_outBuffer output = { image.data(), static_cast<size_t>(image.size()), 0 };
8080

8181
while (input.pos < input.size)
8282
{
@@ -85,7 +85,7 @@ ByteArray CursorDecoder::decompressCursor(const proto::CursorShape& cursor_shape
8585
{
8686
LOG(LS_ERROR) << "ZSTD_decompressStream failed: " << ZSTD_getErrorName(ret)
8787
<< " (" << ret << ")";
88-
return ByteArray();
88+
return QByteArray();
8989
}
9090
}
9191

@@ -123,8 +123,8 @@ std::shared_ptr<MouseCursor> CursorDecoder::decode(const proto::CursorShape& cur
123123
return nullptr;
124124
}
125125

126-
ByteArray image = decompressCursor(cursor_shape);
127-
if (image.empty())
126+
QByteArray image = decompressCursor(cursor_shape);
127+
if (image.isEmpty())
128128
{
129129
LOG(LS_ERROR) << "decompressCursor failed";
130130
return nullptr;

source/base/codec/cursor_decoder.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121

2222
#include "base/macros_magic.h"
2323
#include "base/codec/scoped_zstd_stream.h"
24-
#include "base/memory/byte_array.h"
24+
25+
#include <QByteArray>
2526

2627
#include <optional>
28+
#include <vector>
2729

2830
namespace proto {
2931
class CursorShape;
@@ -45,7 +47,7 @@ class CursorDecoder
4547
int takenCursorsFromCache() const;
4648

4749
private:
48-
ByteArray decompressCursor(const proto::CursorShape& cursor_shape) const;
50+
QByteArray decompressCursor(const proto::CursorShape& cursor_shape) const;
4951

5052
std::vector<std::shared_ptr<MouseCursor>> cache_;
5153
std::optional<size_t> cache_size_;

source/base/codec/cursor_encoder.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ bool CursorEncoder::compressCursor(
8282
return false;
8383
}
8484

85-
const ByteArray& image = mouse_cursor.constImage();
86-
if (image.empty())
85+
const QByteArray& image = mouse_cursor.constImage();
86+
if (image.isEmpty())
8787
{
8888
LOG(LS_ERROR) << "Invalid cursor image buffer";
8989
return false;
@@ -98,7 +98,7 @@ bool CursorEncoder::compressCursor(
9898
}
9999

100100
const size_t input_size = image.size();
101-
const uint8_t* input_data = image.data();
101+
const uint8_t* input_data = reinterpret_cast<const uint8_t*>(image.data());
102102

103103
const size_t output_size = ZSTD_compressBound(input_size);
104104
uint8_t* output_data = outputBuffer(cursor_shape, output_size);
@@ -144,7 +144,7 @@ bool CursorEncoder::encode(const MouseCursor& mouse_cursor, proto::CursorShape*
144144
}
145145

146146
// Calculate the hash of the cursor to search in the cache.
147-
uint32_t hash = libyuv::HashDjb2(mouse_cursor.constImage().data(),
147+
uint32_t hash = libyuv::HashDjb2(reinterpret_cast<const uint8_t*>(mouse_cursor.constImage().data()),
148148
mouse_cursor.constImage().size(),
149149
kHashingSeed);
150150

source/base/codec/video_encoder_vpx.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void setCommonCodecParameters(vpx_codec_enc_cfg_t* config, const Size& size)
8080
//--------------------------------------------------------------------------------------------------
8181
void createImage(const Size& size,
8282
std::unique_ptr<vpx_image_t>* out_image,
83-
ByteArray* out_image_buffer)
83+
QByteArray* out_image_buffer)
8484
{
8585
std::unique_ptr<vpx_image_t> image = std::make_unique<vpx_image_t>();
8686

@@ -107,7 +107,7 @@ void createImage(const Size& size,
107107
const int y_rows = ((image->h - 1) & ~(kMacroBlockSize - 1)) + kMacroBlockSize;
108108
const int uv_rows = y_rows >> image->y_chroma_shift;
109109

110-
ByteArray image_buffer;
110+
QByteArray image_buffer;
111111

112112
// Allocate a YUV buffer large enough for the aligned data & padding.
113113
image_buffer.resize(static_cast<size_t>(y_stride * y_rows + (2 * uv_stride) * uv_rows));
@@ -116,7 +116,7 @@ void createImage(const Size& size,
116116
memset(image_buffer.data(), 128, image_buffer.size());
117117

118118
// Fill in the information.
119-
image->planes[0] = image_buffer.data();
119+
image->planes[0] = reinterpret_cast<uint8_t*>(image_buffer.data());
120120
image->planes[1] = image->planes[0] + y_stride * y_rows;
121121
image->planes[2] = image->planes[1] + uv_stride * uv_rows;
122122

@@ -352,7 +352,7 @@ void VideoEncoderVPX::createActiveMap(const Size& size)
352352
(size.height() + kMacroBlockSize - 1) / kMacroBlockSize);
353353

354354
active_map_buffer_.resize(active_map_.cols * active_map_.rows);
355-
active_map_.active_map = active_map_buffer_.data();
355+
active_map_.active_map = reinterpret_cast<uint8_t*>(active_map_buffer_.data());
356356

357357
clearActiveMap();
358358
}

source/base/codec/video_encoder_vpx.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
2323
#include "base/codec/scoped_vpx_codec.h"
2424
#include "base/codec/video_encoder.h"
2525
#include "base/desktop/region.h"
26-
#include "base/memory/byte_array.h"
2726

2827
#define VPX_CODEC_DISABLE_COMPAT 1
2928
#include <vpx/vpx_encoder.h>
3029
#include <vpx/vp8cx.h>
3130

31+
#include <QByteArray>
32+
3233
namespace base {
3334

3435
class VideoEncoderVPX final : public VideoEncoder
@@ -59,12 +60,12 @@ class VideoEncoderVPX final : public VideoEncoder
5960
vpx_codec_enc_cfg_t config_;
6061
ScopedVpxCodec codec_;
6162

62-
ByteArray active_map_buffer_;
63+
QByteArray active_map_buffer_;
6364
vpx_active_map_t active_map_;
6465

6566
// VPX image and buffer to hold the actual YUV planes.
6667
std::unique_ptr<vpx_image_t> image_;
67-
ByteArray image_buffer_;
68+
QByteArray image_buffer_;
6869

6970
DISALLOW_COPY_AND_ASSIGN(VideoEncoderVPX);
7071
};

source/base/codec/webm_file_writer.h

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
#include "base/macros_magic.h"
2323
#include "base/desktop/geometry.h"
24-
#include "base/memory/byte_array.h"
2524
#include "proto/desktop.pb.h"
2625

2726
#include <chrono>

source/base/codec/webm_video_encoder.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ void WebmVideoEncoder::createImage()
193193
memset(image_buffer_.data(), 128, image_buffer_.size());
194194

195195
// Fill in the information.
196-
image_->planes[0] = image_buffer_.data();
196+
image_->planes[0] = reinterpret_cast<uint8_t*>(image_buffer_.data());
197197
image_->planes[1] = image_->planes[0] + y_stride * y_rows;
198198
image_->planes[2] = image_->planes[1] + uv_stride * uv_rows;
199199

source/base/codec/webm_video_encoder.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@
2222
#include "base/macros_magic.h"
2323
#include "base/codec/scoped_vpx_codec.h"
2424
#include "base/desktop/geometry.h"
25-
#include "base/memory/byte_array.h"
2625

2726
#define VPX_CODEC_DISABLE_COMPAT 1
2827
#include <vpx/vpx_encoder.h>
2928
#include <vpx/vp8cx.h>
3029

30+
#include <QByteArray>
31+
3132
namespace proto {
3233
class VideoPacket;
3334
} // namespace proto
@@ -52,7 +53,7 @@ class WebmVideoEncoder
5253

5354
// VPX image and buffer to hold the actual YUV planes.
5455
std::unique_ptr<vpx_image_t> image_;
55-
ByteArray image_buffer_;
56+
QByteArray image_buffer_;
5657

5758
vpx_codec_enc_cfg_t config_;
5859
ScopedVpxCodec codec_;

source/base/codec/zstd_compress.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ std::string ZstdCompress::compress(const std::string& source, int compress_level
143143

144144
//--------------------------------------------------------------------------------------------------
145145
// static
146-
ByteArray ZstdCompress::compress(const ByteArray& source, int compress_level)
146+
QByteArray ZstdCompress::compress(const QByteArray& source, int compress_level)
147147
{
148148
return compressT(source, compress_level);
149149
}
@@ -157,7 +157,7 @@ std::string ZstdCompress::decompress(const std::string& source)
157157

158158
//--------------------------------------------------------------------------------------------------
159159
// static
160-
ByteArray ZstdCompress::decompress(const ByteArray& source)
160+
QByteArray ZstdCompress::decompress(const QByteArray& source)
161161
{
162162
return decompressT(source);
163163
}

source/base/codec/zstd_compress.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
#define BASE_CODEC_ZSTD_COMPRESS_H
2121

2222
#include "base/macros_magic.h"
23-
#include "base/memory/byte_array.h"
23+
24+
#include <QByteArray>
2425

2526
namespace base {
2627

@@ -32,10 +33,10 @@ class ZstdCompress
3233
static const int kDefCompressLevel = 8;
3334

3435
static std::string compress(const std::string& source, int compress_level = kDefCompressLevel);
35-
static ByteArray compress(const ByteArray& source, int compress_level = kDefCompressLevel);
36+
static QByteArray compress(const QByteArray& source, int compress_level = kDefCompressLevel);
3637

3738
static std::string decompress(const std::string& source);
38-
static ByteArray decompress(const ByteArray& source);
39+
static QByteArray decompress(const QByteArray& source);
3940

4041
private:
4142
DISALLOW_COPY_AND_ASSIGN(ZstdCompress);

source/base/converter.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@
2121

2222
#include "build/build_config.h"
2323
#include "base/files/file_path.h"
24-
#include "base/memory/byte_array.h"
2524
#include "base/strings/string_number_conversions.h"
2625
#include "base/strings/string_util.h"
2726
#include "base/strings/unicode.h"
2827

2928
#include <filesystem>
3029
#include <optional>
3130

31+
#include <QByteArray>
32+
3233
namespace base {
3334

3435
namespace internal {
@@ -85,17 +86,17 @@ struct ConverterImpl<std::wstring>
8586
#endif // defined(OS_WIN)
8687

8788
template <>
88-
struct ConverterImpl<ByteArray>
89+
struct ConverterImpl<QByteArray>
8990
{
90-
static bool fromString(std::string_view str, ByteArray* value)
91+
static bool fromString(std::string_view str, QByteArray* value)
9192
{
92-
*value = fromHex(str);
93+
*value = QByteArray::fromHex(str.data());
9394
return true;
9495
}
9596

96-
static std::string toString(const ByteArray& value)
97+
static std::string toString(const QByteArray& value)
9798
{
98-
return toHex(value);
99+
return value.toHex().toStdString();
99100
}
100101
};
101102

source/base/crypto/big_num.cc

+7-7
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,19 @@ std::string BigNum::toStdString() const
7878
}
7979

8080
//--------------------------------------------------------------------------------------------------
81-
ByteArray BigNum::toByteArray() const
81+
QByteArray BigNum::toByteArray() const
8282
{
8383
if (!isValid())
84-
return ByteArray();
84+
return QByteArray();
8585

8686
int length = BN_num_bytes(num_.get());
8787
if (length <= 0)
88-
return ByteArray();
88+
return QByteArray();
8989

90-
ByteArray result;
90+
QByteArray result;
9191
result.resize(static_cast<std::string::size_type>(length));
9292

93-
BN_bn2bin(num_.get(), result.data());
93+
BN_bn2bin(num_.get(), reinterpret_cast<uint8_t*>(result.data()));
9494
return result;
9595
}
9696

@@ -110,9 +110,9 @@ BigNum BigNum::fromStdString(std::string_view string)
110110

111111
//--------------------------------------------------------------------------------------------------
112112
// static
113-
BigNum BigNum::fromByteArray(const ByteArray& array)
113+
BigNum BigNum::fromByteArray(const QByteArray& array)
114114
{
115-
return BigNum(array.data(), array.size());
115+
return BigNum(reinterpret_cast<const uint8_t*>(array.data()), array.size());
116116
}
117117

118118
//--------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)