Fix MacOS compile error

This commit is contained in:
dijunkun
2023-10-07 10:07:45 +08:00
parent 36305eef46
commit 0a7dd291f1
5 changed files with 36 additions and 8 deletions

View File

@@ -231,7 +231,7 @@ std::string GetMac(char *mac_addr) {
(const struct sockaddr_dl *)cursor->ifa_addr;
if ((cursor->ifa_addr->sa_family == AF_LINK) &&
(socAddr->sdl_type == IFT_ETHER) &&
strcmp(if_name, cursor->ifa_name) == 0) {
strcmp(if_name.c_str(), cursor->ifa_name) == 0) {
dlAddr = (const struct sockaddr_dl *)cursor->ifa_addr;
const unsigned char *base =
(const unsigned char *)&dlAddr->sdl_data[dlAddr->sdl_nlen];

View File

@@ -101,10 +101,8 @@ int FfmpegVideoDecoder::Decode(
std::function<void(VideoFrame)> on_receive_decoded_frame) {
if (!first_) {
if ((*(data + 4) & 0x1f) != 0x07) {
LOG_ERROR("1");
return -1;
} else {
LOG_ERROR("2");
first_ = true;
}
}
@@ -149,7 +147,7 @@ int FfmpegVideoDecoder::Decode(
std::chrono::high_resolution_clock::now().time_since_epoch())
.count());
LOG_ERROR("cost {}", now_ts - start_ts);
// LOG_ERROR("cost {}", now_ts - start_ts);
on_receive_decoded_frame(*decoded_frame_);
if (SAVE_DECODER_STREAM) {

View File

@@ -1,8 +1,13 @@
#include "video_decoder_factory.h"
#if __APPLE__
#include "ffmpeg/ffmpeg_video_decoder.h"
#else
#include "ffmpeg/ffmpeg_video_decoder.h"
#include "log.h"
#include "nvcodec/nvidia_video_decoder.h"
#endif
#include "log.h"
VideoDecoderFactory::VideoDecoderFactory() {}
@@ -10,6 +15,9 @@ VideoDecoderFactory::~VideoDecoderFactory() {}
std::unique_ptr<VideoDecoder> VideoDecoderFactory::CreateVideoDecoder(
bool hardware_acceleration) {
#if __APPLE__
return std::make_unique<FfmpegVideoDecoder>(FfmpegVideoDecoder());
#else
if (hardware_acceleration) {
if (CheckIsHardwareAccerlerationSupported()) {
return std::make_unique<NvidiaVideoDecoder>(NvidiaVideoDecoder());
@@ -19,9 +27,13 @@ std::unique_ptr<VideoDecoder> VideoDecoderFactory::CreateVideoDecoder(
} else {
return std::make_unique<FfmpegVideoDecoder>(FfmpegVideoDecoder());
}
#endif
}
bool VideoDecoderFactory::CheckIsHardwareAccerlerationSupported() {
#if __APPLE__
return false;
#else
CUresult cuResult;
CUvideoctxlock cudaCtxLock;
@@ -34,4 +46,5 @@ bool VideoDecoderFactory::CheckIsHardwareAccerlerationSupported() {
}
return true;
#endif
}

View File

@@ -1,8 +1,13 @@
#include "video_encoder_factory.h"
#if __APPLE__
#include "ffmpeg/ffmpeg_video_encoder.h"
#else
#include "ffmpeg/ffmpeg_video_encoder.h"
#include "log.h"
#include "nvcodec/nvidia_video_encoder.h"
#endif
#include "log.h"
VideoEncoderFactory::VideoEncoderFactory() {}
@@ -10,6 +15,9 @@ VideoEncoderFactory::~VideoEncoderFactory() {}
std::unique_ptr<VideoEncoder> VideoEncoderFactory::CreateVideoEncoder(
bool hardware_acceleration) {
#if __APPLE__
return std::make_unique<FFmpegVideoEncoder>(FFmpegVideoEncoder());
#else
if (hardware_acceleration) {
if (CheckIsHardwareAccerlerationSupported()) {
return std::make_unique<NvidiaVideoEncoder>(NvidiaVideoEncoder());
@@ -19,9 +27,13 @@ std::unique_ptr<VideoEncoder> VideoEncoderFactory::CreateVideoEncoder(
} else {
return std::make_unique<FFmpegVideoEncoder>(FFmpegVideoEncoder());
}
#endif
}
bool VideoEncoderFactory::CheckIsHardwareAccerlerationSupported() {
#if __APPLE__
return false;
#else
CUresult cuResult;
NV_ENCODE_API_FUNCTION_LIST functionList = {NV_ENCODE_API_FUNCTION_LIST_VER};
@@ -42,4 +54,5 @@ bool VideoEncoderFactory::CheckIsHardwareAccerlerationSupported() {
}
return true;
#endif
}

View File

@@ -139,9 +139,13 @@ target("media")
add_linkdirs("thirdparty/nvcodec/Lib/x64")
add_links("cuda", "nvidia-encode", "nvcuvid")
elseif is_os("macosx") then
add_files("src/media/video/encode/ffmpeg/*.cpp",
add_files("src/media/video/encode/*.cpp",
"src/media/video/decode/*.cpp",
"src/media/video/encode/ffmpeg/*.cpp",
"src/media/video/decode/ffmpeg/*.cpp")
add_includedirs("src/media/video/encode/ffmpeg",
add_includedirs("src/media/video/encode",
"src/media/video/decode",
"src/media/video/encode/ffmpeg",
"src/media/video/decode/ffmpeg", {public = true})
end