diff --git a/components/vision/include/maix_video.hpp b/components/vision/include/maix_video.hpp index a1663d81..327f6db1 100644 --- a/components/vision/include/maix_video.hpp +++ b/components/vision/include/maix_video.hpp @@ -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 diff --git a/components/vision/port/linux/maix_video_linux.cpp b/components/vision/port/linux/maix_video_linux.cpp index 766f1db5..6eb99355 100644 --- a/components/vision/port/linux/maix_video_linux.cpp +++ b/components/vision/port/linux/maix_video_linux.cpp @@ -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); } diff --git a/components/vision/port/maixcam/maix_video_mmf.cpp b/components/vision/port/maixcam/maix_video_mmf.cpp index c6bb3d29..f9e02da5 100644 --- a/components/vision/port/maixcam/maix_video_mmf.cpp +++ b/components/vision/port/maixcam/maix_video_mmf.cpp @@ -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) { diff --git a/components/vision/src/maix_image.cpp b/components/vision/src/maix_image.cpp index 48cbef6e..92c90108 100644 --- a/components/vision/src/maix_image.cpp +++ b/components/vision/src/maix_image.cpp @@ -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) diff --git a/components/voice/include/maix_audio.hpp b/components/voice/include/maix_audio.hpp index b1e77446..cae721cd 100644 --- a/components/voice/include/maix_audio.hpp +++ b/components/voice/include/maix_audio.hpp @@ -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 diff --git a/components/voice/port/linux/maix_audio_linux.cpp b/components/voice/port/linux/maix_audio_linux.cpp index 079481f5..286c881c 100644 --- a/components/voice/port/linux/maix_audio_linux.cpp +++ b/components/voice/port/linux/maix_audio_linux.cpp @@ -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; diff --git a/components/voice/port/maixcam/maix_audio_mmf.cpp b/components/voice/port/maixcam/maix_audio_mmf.cpp index 68fb6582..0fd273a9 100644 --- a/components/voice/port/maixcam/maix_audio_mmf.cpp +++ b/components/voice/port/maixcam/maix_audio_mmf.cpp @@ -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!");