| 199 | void stop() override { this->stopped = true; } |
| 200 | |
| 201 | bool load(IFile &file) |
| 202 | { |
| 203 | double usf; // uSeconds per frame |
| 204 | this->video_data = file.readAll(); |
| 205 | this->video_data_size = file.size(); |
| 206 | |
| 207 | auto video_path = file.systemPath(); |
| 208 | this->file_path = video_path; |
| 209 | |
| 210 | LogInfo("Read %llu bytes from video", |
| 211 | static_cast<unsigned long long>(this->video_data_size)); |
| 212 | |
| 213 | this->smk_ctx = smk_open_memory(reinterpret_cast<unsigned char *>(this->video_data.get()), |
| 214 | static_cast<unsigned long>(this->video_data_size)); |
| 215 | if (!this->smk_ctx) |
| 216 | { |
| 217 | LogWarning("Failed to read SMK file \"%s\"", video_path); |
| 218 | this->video_data.reset(); |
| 219 | return false; |
| 220 | } |
| 221 | LogInfo("Successfully created SMK context"); |
| 222 | |
| 223 | if (smk_info_all(this->smk_ctx, nullptr, &this->frame_count, &usf)) |
| 224 | { |
| 225 | LogWarning("Failed to read SMK file info from \"%s\"", video_path); |
| 226 | this->video_data.reset(); |
| 227 | smk_close(this->smk_ctx); |
| 228 | this->smk_ctx = nullptr; |
| 229 | return false; |
| 230 | } |
| 231 | |
| 232 | this->frame_time = std::chrono::nanoseconds((unsigned int)(usf * 1000)); |
| 233 | |
| 234 | LogInfo("Video frame count %lu, ns per frame = %u (USF: %f)", this->frame_count, |
| 235 | this->frame_time.count(), usf); |
| 236 | |
| 237 | unsigned long height, width; |
| 238 | if (smk_info_video(this->smk_ctx, &width, &height, nullptr)) |
| 239 | { |
| 240 | LogWarning("Failed to read SMK video info from \"%s\"", video_path); |
| 241 | this->video_data.reset(); |
| 242 | smk_close(this->smk_ctx); |
| 243 | this->smk_ctx = nullptr; |
| 244 | return false; |
| 245 | } |
| 246 | |
| 247 | this->frame_size = {width, height}; |
| 248 | LogInfo("Video frame size {%u,%u}", this->frame_size.x, this->frame_size.y); |
| 249 | |
| 250 | auto ret = smk_enable_video(this->smk_ctx, 1); |
| 251 | if (ret == SMK_ERROR) |
| 252 | { |
| 253 | LogWarning("Error enabling video for \"%s\"", video_path); |
| 254 | return false; |
| 255 | } |
| 256 | |
| 257 | unsigned char audio_track_mask; |
| 258 | unsigned char channels[7]; |