Skip to content

Commit 58c2126

Browse files
committed
fix android decode error
1 parent 1dc2068 commit 58c2126

38 files changed

+342
-267
lines changed

src/base/Time.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ using std::chrono::microseconds;
2020
return std::chrono::milliseconds(static_cast<uint64_t>( std::round(static_cast<double>(count) / 1000.0)));
2121
}
2222

23-
long double Time::TimePoint::second() const noexcept {
24-
return std::round(static_cast<long double>(count) / 1000.0) / 1000;
23+
double Time::TimePoint::second() const noexcept {
24+
return std::round(static_cast<double>(count) / 1000.0) / 1000;
2525
}
2626

2727
Time::TimePoint Time::TimePoint::operator+(std::chrono::milliseconds delta) const noexcept {

src/base/Time.hpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,21 @@ struct Time {
4848
: count(static_cast<uint64_t>(ms.count() * 1000)) {
4949

5050
}
51+
52+
static TimePoint fromMilliSeconds(std::chrono::milliseconds ms) noexcept {
53+
return {static_cast<uint64_t>(ms.count() * 1000)};
54+
}
55+
56+
57+
template <typename T> requires std::is_floating_point_v<T>
58+
static TimePoint fromSeconds(T seconds) noexcept {
59+
return {static_cast<uint64_t>(seconds * kMicroSecondScale)};
60+
}
61+
62+
5163
#pragma clang diagnostic pop
5264
[[nodiscard]] std::chrono::milliseconds toMilliSeconds() const noexcept;
53-
[[nodiscard]] long double second() const noexcept;
65+
[[nodiscard]] double second() const noexcept;
5466
TimePoint operator+(std::chrono::milliseconds delta) const noexcept;
5567
TimePoint& operator+=(std::chrono::milliseconds delta) noexcept;
5668
TimePoint operator-(std::chrono::milliseconds delta) const noexcept;
@@ -70,7 +82,7 @@ struct Time {
7082

7183
struct CTime {
7284
private:
73-
constexpr static long double kTimePrecision = std::numeric_limits<double>::epsilon();
85+
constexpr static double kTimePrecision = std::numeric_limits<double>::epsilon();
7486
constexpr static uint64_t kDefaultScale = 1000U;
7587
public:
7688
int64_t value;
@@ -87,12 +99,12 @@ struct CTime {
8799
}
88100

89101
/// init with seconds
90-
explicit CTime(long double t)
102+
explicit CTime(double t)
91103
: value(static_cast<int64_t>(kDefaultScale * t))
92104
, scale(kDefaultScale) {
93105
}
94106

95-
[[nodiscard]] inline long double second() const noexcept {
107+
[[nodiscard]] inline double second() const noexcept {
96108
bool isValid = this->isValid();
97109
SAssert(isValid, "time is invalid");
98110
if (isValid) {
@@ -123,12 +135,12 @@ struct CTime {
123135

124136
inline CTime operator-(const CTime& rhs) const noexcept {
125137
auto t = second() - rhs.second();
126-
return CTime(static_cast<int64_t>(t * static_cast<long double>(scale)), scale);
138+
return CTime(static_cast<int64_t>(t * static_cast<double>(scale)), scale);
127139
}
128140

129141
inline CTime operator+(const CTime& rhs) const noexcept {
130142
auto t = second() + rhs.second();
131-
return CTime(static_cast<int64_t>(t * static_cast<long double>(scale)), scale);
143+
return CTime(static_cast<int64_t>(t * static_cast<double>(scale)), scale);
132144
}
133145

134146
[[nodiscard]] inline bool isValid() const noexcept {

src/core/AVFrame.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ enum class FrameFormat {
2929
Unknown = 0,
3030
VideoToolBox = 1,
3131
MediaCodecSurface = 2,
32+
MediaCodecByteBuffer = 3,
3233
};
3334

3435
struct Statistics {
@@ -47,14 +48,14 @@ struct FrameInfo {
4748
};
4849

4950
struct AudioFrameInfo : public FrameInfo {
50-
void copy(std::shared_ptr<AudioFrameInfo> info) noexcept {
51+
void copy(std::shared_ptr<AudioFrameInfo> info) const noexcept {
5152
if (!info) {
5253
return;
5354
}
5455
*info = *this;
5556
}
5657

57-
double duration(uint64_t size) const noexcept {
58+
[[nodiscard]] double duration(uint64_t size) const noexcept {
5859
return static_cast<double>(size) / static_cast<double>(bitsPerSample / 8 * channels * sampleRate);
5960
}
6061

@@ -138,12 +139,12 @@ struct AVFrame {
138139
return d;
139140
}
140141

141-
long double dtsTime() const noexcept {
142-
return std::round(static_cast<long double>(dts) / static_cast<long double>(timeScale) * 1000) / 1000;
142+
[[nodiscard]] double dtsTime() const noexcept {
143+
return std::round(static_cast<double>(dts) / static_cast<double>(timeScale) * 1000) / 1000;
143144
}
144145

145-
long double ptsTime() const noexcept {
146-
return std::round(static_cast<long double>(pts) / static_cast<long double>(timeScale) * 1000) / 1000;
146+
[[nodiscard]] double ptsTime() const noexcept {
147+
return std::round(static_cast<double>(pts) / static_cast<double>(timeScale) * 1000) / 1000;
147148
}
148149

149150
[[nodiscard]] inline std::unique_ptr<AVFrame> copy() const noexcept {
@@ -192,7 +193,7 @@ struct AVFrame {
192193
return frameType == AVFrameType::Audio;
193194
}
194195

195-
DataView view() const noexcept {
196+
[[nodiscard]] DataView view() const noexcept {
196197
if (data) {
197198
return data->view();
198199
}

src/core/HLSReader.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
//
77

88
#include "HLSReader.h"
9+
10+
#include <utility>
911
#include "Log.hpp"
1012
#include "Util.hpp"
1113

@@ -15,7 +17,7 @@ static constexpr std::string_view kM3u8Tag = "HLSRequestM3u8";
1517
static constexpr std::string_view kTsTag = "HLSRequestTs";
1618

1719
bool parseTsTag(const std::string& tag, uint32_t& tsIndex) noexcept {
18-
auto pos = tag.find("_");
20+
auto pos = tag.find('_');
1921
if (pos == std::string::npos) {
2022
return false;
2123
}
@@ -99,7 +101,7 @@ void HLSReader::sendM3u8Request(const std::string& m3u8Url) noexcept {
99101
LogI("send m3u8 request:{}", m3u8Url);
100102
}
101103

102-
void HLSReader::setupDataProvoider() noexcept {
104+
void HLSReader::setupDataProvider() noexcept {
103105
std::lock_guard<std::mutex> lock(requestMutex_);
104106
if (requestSession_) {
105107
requestSession_->close();
@@ -155,7 +157,7 @@ bool HLSReader::open(ReaderTaskPtr task) noexcept {
155157
if (isClosed_ || !task) {
156158
return false;
157159
}
158-
setupDataProvoider();
160+
setupDataProvider();
159161
auto m3u8Url = task->path;
160162
DemuxerConfig config;
161163
config.filePath = m3u8Url;
@@ -207,13 +209,12 @@ IOState HLSReader::state() noexcept {
207209

208210
void HLSReader::setDemuxer(std::shared_ptr<HLSDemuxer> demuxer) noexcept {
209211
std::lock_guard<std::mutex> lock(taskMutex_);
210-
demuxer_ = demuxer;
212+
demuxer_ = std::move(demuxer);
211213
}
212214

213215
void HLSReader::fetchTSData(uint32_t tsIndex) noexcept {
214216
const auto& tsInfos = demuxer_->getTSInfos();
215-
if (tsIndex < 0 ||
216-
tsIndex >= tsInfos.size()) {
217+
if (tsIndex >= tsInfos.size()) {
217218
isCompleted_ = true;
218219
return;
219220
}
@@ -269,14 +270,14 @@ uint64_t HLSReader::size() noexcept {
269270
}
270271

271272
void HLSReader::seek(uint64_t pos) noexcept {
272-
setupDataProvoider();
273+
setupDataProvider();
273274
requestTasks_.withLock([](auto& tasks) {
274275
tasks.clear();
275276
});
276277
auto tsIndex = static_cast<size_t>(pos);
277278
const auto& infos = demuxer_->getTSInfos();
278279
if (0 <= tsIndex && tsIndex < infos.size()) {
279-
fetchTSData(tsIndex);
280+
fetchTSData(static_cast<uint32_t>(tsIndex));
280281
worker_.start();
281282
} else {
282283
LogE("seek error:{}, info size:{}", tsIndex, infos.size());

src/core/HLSReader.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,26 @@ class HLSReader : public IReader {
4949

5050
void setDemuxer(std::shared_ptr<HLSDemuxer> demuxer) noexcept;
5151
private:
52-
void setupDataProvoider() noexcept;
52+
void setupDataProvider() noexcept;
53+
5354
void addRequest(http::RequestInfoPtr) noexcept;
55+
5456
void sendRequest() noexcept;
57+
5558
void fetchTSData(uint32_t tsIndex) noexcept;
59+
5660
void sendM3u8Request(const std::string& m3u8Url) noexcept;
61+
5762
void sendTSRequest(uint32_t index, const std::string& url, Range range) noexcept;
58-
59-
void handleM3u8Header(const http::ResponseHeader& header) noexcept;
63+
6064
void handleM3u8Data(DataPtr dataPtr) noexcept;
65+
6166
void handleM3u8Completed() noexcept;
62-
63-
void handleTSHeader(const http::ResponseHeader& header) noexcept;
67+
6468
void handleTSData(uint32_t index, DataPtr dataPtr) noexcept;
69+
6570
void handleTSCompleted(uint32_t tsIndex) noexcept;
71+
6672
void handleError(const http::ErrorInfo& info) noexcept;
6773
private:
6874
std::atomic_bool isPause_ = false;

0 commit comments

Comments
 (0)