Use Api::fail() for error returns (241 sites)
Mechanically convert std::unexpected(Api::Error(ErrorCode::X, msg[, src])) to Api::fail(ErrorCode::X, msg[, src]) across Core. Pure syntax; forwards of existing errors (std::unexpected(x.error())) are unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
f8757d6040
commit
23759899bb
14 files changed
+344
-435
No files matched your search
+33
-46
@@ -75,16 +75,15 @@ namespace Echoion::Core
|
||||
hwType = AV_HWDEVICE_TYPE_VIDEOTOOLBOX;
|
||||
break;
|
||||
default:
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::InvalidArgument,
|
||||
"Unsupported hardware acceleration type"));
|
||||
return Api::fail(Api::ErrorCode::InvalidArgument,
|
||||
"Unsupported hardware acceleration type");
|
||||
}
|
||||
|
||||
if (av_hwdevice_find_type_by_name(av_hwdevice_get_type_name(hwType)) ==
|
||||
AV_HWDEVICE_TYPE_NONE) {
|
||||
return std::unexpected(Api::Error(
|
||||
return Api::fail(
|
||||
Api::ErrorCode::NotSupported,
|
||||
"Hardware acceleration not available on this system"));
|
||||
"Hardware acceleration not available on this system");
|
||||
}
|
||||
|
||||
hwAccelType_ = config.type;
|
||||
@@ -122,8 +121,8 @@ namespace Echoion::Core
|
||||
Api::Result<void> AudioDecoder::openSource(const std::string& url)
|
||||
{
|
||||
if (!initialized_) {
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::ServiceUnavailable, "Decoder not initialized"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::ServiceUnavailable, "Decoder not initialized");
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
@@ -192,9 +191,8 @@ namespace Echoion::Core
|
||||
// Allocate format context first (needed for interrupt callback)
|
||||
formatContext_ = avformat_alloc_context();
|
||||
if (!formatContext_) {
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::AudioError,
|
||||
"Failed to allocate format context"));
|
||||
return Api::fail(Api::ErrorCode::AudioError,
|
||||
"Failed to allocate format context");
|
||||
}
|
||||
|
||||
// Set up interrupt callback to allow graceful shutdown during blocking
|
||||
@@ -218,11 +216,11 @@ namespace Echoion::Core
|
||||
av_strerror(ret, errbuf, sizeof(errbuf));
|
||||
ECHOION_LOG_ERROR(std::format(
|
||||
"FFmpeg failed to open input (error {}): {}", ret, errbuf));
|
||||
return std::unexpected(Api::Error(
|
||||
return Api::fail(
|
||||
Api::ErrorCode::AudioError,
|
||||
std::format(
|
||||
"Failed to open audio source: {} (FFmpeg error {}: {})",
|
||||
url.substr(0, 80), ret, errbuf)));
|
||||
url.substr(0, 80), ret, errbuf));
|
||||
}
|
||||
ECHOION_LOG_DEBUG("avformat_open_input succeeded");
|
||||
|
||||
@@ -234,9 +232,9 @@ namespace Echoion::Core
|
||||
std::format("FFmpeg failed to find stream info (error {}): {}",
|
||||
ret, errbuf));
|
||||
avformat_close_input(&formatContext_);
|
||||
return std::unexpected(Api::Error(
|
||||
return Api::fail(
|
||||
Api::ErrorCode::AudioError,
|
||||
std::format("Failed to find stream info: {}", errbuf)));
|
||||
std::format("Failed to find stream info: {}", errbuf));
|
||||
}
|
||||
const AVCodec* decoder = nullptr;
|
||||
audioStreamIndex_ = -1;
|
||||
@@ -246,16 +244,15 @@ namespace Echoion::Core
|
||||
|
||||
if (audioStreamIndex_ == -1) {
|
||||
avformat_close_input(&formatContext_);
|
||||
return std::unexpected(Api::Error(Api::ErrorCode::AudioError,
|
||||
"No audio stream found"));
|
||||
return Api::fail(Api::ErrorCode::AudioError,
|
||||
"No audio stream found");
|
||||
}
|
||||
|
||||
codecContext_ = avcodec_alloc_context3(decoder);
|
||||
if (!codecContext_) {
|
||||
avformat_close_input(&formatContext_);
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::AudioError,
|
||||
"Failed to allocate codec context"));
|
||||
return Api::fail(Api::ErrorCode::AudioError,
|
||||
"Failed to allocate codec context");
|
||||
}
|
||||
codecContext_->thread_count = 0; // Auto-detect CPU cores
|
||||
codecContext_->thread_type = FF_THREAD_FRAME | FF_THREAD_SLICE;
|
||||
@@ -265,16 +262,15 @@ namespace Echoion::Core
|
||||
if (ret < 0) {
|
||||
avcodec_free_context(&codecContext_);
|
||||
avformat_close_input(&formatContext_);
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::AudioError, "Failed to copy codec parameters"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::AudioError, "Failed to copy codec parameters");
|
||||
}
|
||||
|
||||
ret = avcodec_open2(codecContext_, decoder, nullptr);
|
||||
if (ret < 0) {
|
||||
avcodec_free_context(&codecContext_);
|
||||
avformat_close_input(&formatContext_);
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::AudioError, "Failed to open codec"));
|
||||
return Api::fail(Api::ErrorCode::AudioError, "Failed to open codec");
|
||||
}
|
||||
|
||||
frame_ = av_frame_alloc();
|
||||
@@ -282,8 +278,8 @@ namespace Echoion::Core
|
||||
|
||||
if (!frame_ || !packet_) {
|
||||
cleanupFfmpeg();
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::AudioError, "Failed to allocate frame/packet"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::AudioError, "Failed to allocate frame/packet");
|
||||
}
|
||||
|
||||
streamInfo_.sampleRate = codecContext_->sample_rate;
|
||||
@@ -338,8 +334,8 @@ namespace Echoion::Core
|
||||
}
|
||||
if (ret < 0 || swr_init(swrContext_) < 0) {
|
||||
cleanupFfmpeg();
|
||||
return std::unexpected(Api::Error(
|
||||
Api::ErrorCode::AudioError, "Failed to initialize resampler"));
|
||||
return Api::fail(
|
||||
Api::ErrorCode::AudioError, "Failed to initialize resampler");
|
||||
}
|
||||
|
||||
// Allocate output buffer for S16 samples (like reference)
|
||||
@@ -401,12 +397,10 @@ namespace Echoion::Core
|
||||
}
|
||||
|
||||
if (eof_) {
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::AudioError, "End of stream"));
|
||||
return Api::fail(Api::ErrorCode::AudioError, "End of stream");
|
||||
}
|
||||
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::AudioError, "Decoder stopped"));
|
||||
return Api::fail(Api::ErrorCode::AudioError, "Decoder stopped");
|
||||
}
|
||||
static int callCount = 0;
|
||||
|
||||
@@ -443,8 +437,7 @@ namespace Echoion::Core
|
||||
Api::Result<void> AudioDecoder::seek(std::chrono::milliseconds position)
|
||||
{
|
||||
if (!formatContext_ || audioStreamIndex_ < 0) {
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::AudioError, "No source open"));
|
||||
return Api::fail(Api::ErrorCode::AudioError, "No source open");
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
@@ -454,8 +447,7 @@ namespace Echoion::Core
|
||||
av_seek_frame(formatContext_, -1, targetPts, AVSEEK_FLAG_BACKWARD);
|
||||
|
||||
if (ret < 0) {
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::AudioError, "Seek failed"));
|
||||
return Api::fail(Api::ErrorCode::AudioError, "Seek failed");
|
||||
}
|
||||
|
||||
avcodec_flush_buffers(codecContext_);
|
||||
@@ -472,8 +464,7 @@ namespace Echoion::Core
|
||||
Api::Result<Api::AudioStreamInfo> AudioDecoder::getStreamInfo() const
|
||||
{
|
||||
if (!initialized_ || !formatContext_) {
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::AudioError, "No source open"));
|
||||
return Api::fail(Api::ErrorCode::AudioError, "No source open");
|
||||
}
|
||||
return streamInfo_;
|
||||
}
|
||||
@@ -629,18 +620,15 @@ namespace Echoion::Core
|
||||
int ret = av_read_frame(formatContext_, packet_);
|
||||
if (ret < 0) {
|
||||
if (ret == AVERROR_EOF) {
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::AudioError, "End of file"));
|
||||
return Api::fail(Api::ErrorCode::AudioError, "End of file");
|
||||
}
|
||||
if (ret == AVERROR_EXIT) {
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::AudioError, "Interrupted"));
|
||||
return Api::fail(Api::ErrorCode::AudioError, "Interrupted");
|
||||
}
|
||||
char errbuf[256];
|
||||
av_strerror(ret, errbuf, sizeof(errbuf));
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::AudioError,
|
||||
std::format("Error reading frame: {}", errbuf)));
|
||||
return Api::fail(Api::ErrorCode::AudioError,
|
||||
std::format("Error reading frame: {}", errbuf));
|
||||
}
|
||||
|
||||
if (packet_->stream_index != audioStreamIndex_) {
|
||||
@@ -698,8 +686,7 @@ namespace Echoion::Core
|
||||
int converted = swr_convert(swrContext_, &outData, outSamples, inData,
|
||||
frame_->nb_samples);
|
||||
if (converted < 0) {
|
||||
return std::unexpected(
|
||||
Api::Error(Api::ErrorCode::AudioError, "Resampling failed"));
|
||||
return Api::fail(Api::ErrorCode::AudioError, "Resampling failed");
|
||||
}
|
||||
|
||||
outputBuffer.resize(converted * outputChannels_);
|
||||
|
||||
Reference in new issue
Block a user