* fix sigsegv bug

This commit is contained in:
lxowalle
2024-05-11 19:40:16 +08:00
parent abee94e936
commit 5eec37e8ef
7 changed files with 18 additions and 17 deletions

View File

@@ -166,6 +166,8 @@ namespace maix::video
class Video
{
public:
static maix::image::Image *NoneImage;
/**
* @brief Construct a new Video object
* @param path video path. the path determines the location where you load or save the file, if path is none, the video module will not save or load file.
@@ -215,7 +217,7 @@ namespace maix::video
* @return encode result
* @maixpy maix.video.Video.encode
*/
video::Packet *encode(image::Image *img = &maix::video::NoneImage);
video::Packet *encode(image::Image *img = maix::video::Video::NoneImage);
/**
* Decode frame

View File

@@ -14,7 +14,9 @@
namespace maix::video
{
Video::Video(std::string path, int width, int height, image::Format format, int time_base, int framerate, bool open)
maix::image::Image *Video::NoneImage = new maix::image::Image();
Video::Video(std::string path, int width, int height, image::Format format, int time_base, int framerate, bool capture, bool open)
{
throw err::Exception(err::ERR_NOT_IMPL);
}

View File

@@ -21,7 +21,7 @@
#define MMF_VENC_CHN (1)
namespace maix::video
{
maix::image::Image NoneImage = maix::image::Image();
maix::image::Image *Video::NoneImage = new maix::image::Image();
Video::Video(std::string path, int width, int height, image::Format format, int time_base, int framerate, bool capture, bool open)
{

View File

@@ -754,18 +754,7 @@ namespace maix::image
params.push_back(95);
cv::imencode(".jpg", input, jpeg_buff, params);
image::Image *img;
if(buff)
{
if(buff_size < jpeg_buff.size())
{
log::error("convert format failed, buffer size not enough\n");
throw err::Exception(err::ERR_ARGS, "convert format failed, buffer size not enough");
}
memcpy(buff, jpeg_buff.data(), jpeg_buff.size());
img = new image::Image(src.cols, src.rows, format, (uint8_t*)buff, jpeg_buff.size(), false);
}
else
img = new image::Image(src.cols, src.rows, format, (uint8_t*)jpeg_buff.data(), jpeg_buff.size(), true);
img = new image::Image(src.cols, src.rows, format, (uint8_t*)jpeg_buff.data(), jpeg_buff.size(), true);
if(src_alloc)
{
delete p_img;
@@ -776,6 +765,8 @@ namespace maix::image
break;
}
}
return nullptr;
}
image::Image *Image::draw_image(int x, int y, image::Image &img)

View File

@@ -133,6 +133,8 @@ namespace maix::audio
size_t _buffer_size;
FILE *_file;
public:
static maix::Bytes *NoneBytes;
/**
* @brief Construct a new Player object
* @param path player path. the path determines the location where you save the file, if path is none, the audio module will not save file.
@@ -160,7 +162,7 @@ namespace maix::audio
* @return error code, err::ERR_NONE means success, others means failed
* @maixpy maix.audio.Player.play
*/
err::Err play(maix::Bytes *data = nullptr);
err::Err play(maix::Bytes *data = maix::audio::Player::NoneBytes);
/**
* Get sample rate

View File

@@ -40,6 +40,8 @@ namespace maix::audio
return err::ERR_NOT_IMPL;
}
maix::Bytes *Player::NoneBytes = new maix::Bytes();
Player::Player(std::string path, int sample_rate, audio::Format format, int channel) {
(void)path;
(void)sample_rate;

View File

@@ -405,6 +405,8 @@ namespace maix::audio
return err::ERR_NONE;
}
maix::Bytes *Player::NoneBytes = new maix::Bytes();
Player::Player(std::string path, int sample_rate, audio::Format format, int channel) {
_path = path;
_sample_rate = sample_rate;
@@ -459,7 +461,7 @@ namespace maix::audio
unsigned int channel = _channel;
int len = 0;
if (!data) {
if (!data || !data->data) {
if (_file == NULL && _path.size() > 0) {
_file = fopen(_path.c_str(), "rb+");
err::check_null_raise(_file, "Open file failed!");