@@ -107,7 +107,7 @@ bool ImageHandler::load(const MMContent& content,
107107
108108bool ImageHandler::decode (MMInputItem& input) {
109109 OpenCVImageDecoder decoder;
110- return decoder.decode (input.raw_data_ , input.decode_data_ );
110+ return decoder.decode (input.raw_data_ , input.decode_image_ );
111111}
112112
113113bool VideoHandler::load (const MMContent& content,
@@ -135,14 +135,51 @@ bool VideoHandler::load(const MMContent& content,
135135}
136136
137137bool VideoHandler::decode (MMInputItem& input) {
138+ FFmpegAudioDecoder audio_decoder;
139+ if (audio_decoder.decode (
140+ input.raw_data_ , input.decode_audio_ , input.audio_meta_ )) {
141+ input.type_ |= MMType::AUDIO;
142+ }
143+
138144 OpenCVVideoDecoder decoder;
139- return decoder.decode (input.raw_data_ , input.decode_data_ , input.video_meta_ );
145+ return decoder.decode (
146+ input.raw_data_ , input.decode_video_ , input.video_meta_ );
147+ }
148+
149+ bool AudioHandler::load (const MMContent& content,
150+ MMInputItem& input,
151+ MMPayload& payload) {
152+ input.clear ();
153+
154+ const auto & audio_url = content.audio_url ;
155+ const auto & url = audio_url.url ;
156+
157+ if (url.compare (0 , dataurl_prefix_.size (), dataurl_prefix_) ==
158+ 0 ) { // data url
159+
160+ input.type_ = MMType::AUDIO;
161+ return this ->load_from_dataurl (url, input.raw_data_ , payload);
162+ } else if (url.compare (0 , httpurl_prefix_.size (), httpurl_prefix_) ==
163+ 0 ) { // http url
164+
165+ input.type_ = MMType::AUDIO;
166+ return this ->load_from_http (url, input.raw_data_ );
167+ } else {
168+ LOG (ERROR) << " audio url is invalid, url is " << url;
169+ return false ;
170+ }
171+ }
172+
173+ bool AudioHandler::decode (MMInputItem& input) {
174+ FFmpegAudioDecoder decoder;
175+ return decoder.decode (
176+ input.raw_data_ , input.decode_audio_ , input.audio_meta_ );
140177}
141178
142179MMHandlerSet::MMHandlerSet () {
143180 handlers_[" image_url" ] = std::make_unique<ImageHandler>();
144181 handlers_[" video_url" ] = std::make_unique<VideoHandler>();
145- // handlers_["audio_url"] = std::make_unique<AudioHandler>();
182+ handlers_[" audio_url" ] = std::make_unique<AudioHandler>();
146183 handlers_[" image_embedding" ] =
147184 std::make_unique<MMEmbeddingHandler>(MMType::IMAGE);
148185 handlers_[" video_embedding" ] =
0 commit comments