129 lines
4.4 KiB
C++
129 lines
4.4 KiB
C++
/*----------------------------------------------------------------------------
|
|
* Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved.
|
|
*
|
|
* Description: TjdUiAppPlayDialModel.cpp
|
|
*
|
|
* Author: liuguanwu
|
|
*
|
|
* Create: 2024-10
|
|
*--------------------------------------------------------------------------*/
|
|
#ifndef TJD_UI_APP_PLAY_DIAL_MODEL_H
|
|
#define TJD_UI_APP_PLAY_DIAL_MODEL_H
|
|
|
|
#include "TjdUiAppPlayDialPresenter.h"
|
|
#include "ble_api.h"
|
|
#include "cmsis_os2.h"
|
|
#include "graphic_timer.h"
|
|
#include "image_info.h"
|
|
#include "media_thread_adapt.h"
|
|
#include "player.h"
|
|
#include <audio_manager.h>
|
|
#include <fstream>
|
|
#include <iostream>
|
|
#include <list>
|
|
#include <string>
|
|
|
|
#define MAX_HISTORY 10
|
|
#define PLAY_DIAL_DRAW_BIN_TEMP_PATH TJD_FS_DIR_WFP "/wfp_bg_0.temp"
|
|
#define PLAY_DIAL_DRAW_BIN_PATH TJD_FS_DIR_WFP "/wfp_bg_0.bin"
|
|
#define PLAY_DIAL_DRAW_PREVIEW_BIN_PATH TJD_FS_DIR_WFP "/wfp_preview_0.hbm"
|
|
// using namespace OHOS;
|
|
// using namespace OHOS::Audio;
|
|
// using Audio::AudioInterrupt;
|
|
// using Audio::AudioManager;
|
|
// using Audio::AudioStreamIn;
|
|
// using Audio::AudioStreamOut;
|
|
|
|
namespace TJD {
|
|
|
|
class TjdUiAppPlayDialModel
|
|
{
|
|
public:
|
|
typedef struct
|
|
{
|
|
std::string question;
|
|
std::string answer;
|
|
} QARecord_t;
|
|
|
|
typedef struct
|
|
{
|
|
QARecord_t records[MAX_HISTORY];
|
|
int total_records; // 当前记录数
|
|
} History;
|
|
|
|
TjdUiAppPlayDialModel();
|
|
~TjdUiAppPlayDialModel();
|
|
static TjdUiAppPlayDialModel &GetInstance(void)
|
|
{
|
|
static TjdUiAppPlayDialModel instance;
|
|
return instance;
|
|
};
|
|
|
|
int FileExists(const char *filename);
|
|
int FileDelete(const char *filename);
|
|
void AudioInit(void);
|
|
int RecordStart();
|
|
void RecordStop();
|
|
void AudioCaptureProcess(void);
|
|
void RecordDestroy(void);
|
|
void addRecord(History *history, std::string question, std::string answer);
|
|
void displayHistory(const History *history);
|
|
void saveToJson(const History *history, const char *filename);
|
|
void loadFromJson(History *history);
|
|
void createInitialJson(const char *filename);
|
|
uint8_t get_total_records_from_json();
|
|
uint8_t UpdateHistoryFileList(uint8_t max_file);
|
|
std::vector<std::string> *GetHistoryFileList();
|
|
uint8_t MakeingWfConfig0Json(const char *filename);
|
|
void RequestIntoLefunAi();
|
|
void LefunAiRequestExitLefunAi();
|
|
void LefunAiRequestIntoAudioTransmit();
|
|
void LefunAiRequestStartAudioTransmit();
|
|
void LefunAiRequestEndAudioTransmit();
|
|
void LefunAiRequestImageData();
|
|
void LefunAiRequestTransmitImageData();
|
|
void TransmitAudioData(uint8_t *data, uint16_t len);
|
|
bool GetAiAudioTransFlag();
|
|
void RegisterLefunAiDataCallback(lefun_ai_data_callback_t callback);
|
|
void RegisterLefunAiDataEndCallback(lefun_ai_data_callback_t callback);
|
|
void RegisterAppImageReadyCallback(play_dial_request_generate_picture_callback_t callback);
|
|
void RegisterOriginalImageEndCallback(play_dial_original_callback_t callback);
|
|
void UnregisterLefunAiDataEndCallback();
|
|
void UnregisterLefunAiDataCallback();
|
|
void UnregisterAppImageReadyCallback();
|
|
void UnregisterOriginalImageEndCallback();
|
|
void ResendAudioData(); // 发送缓存数据的函数
|
|
void DeleDataFlow(void);
|
|
static void lefun_ai_data_callback(struct data_flow *data);
|
|
static void lefun_ai_data_end_callback(struct data_flow *data);
|
|
static void play_dial_app_ready_callback(bool isSuccess);
|
|
static void play_dial_original_end_callback(char *original_picture_name);
|
|
uint16_t dialStyle_ = 1;
|
|
|
|
private:
|
|
uint32_t lastTime_ = 0;
|
|
int32_t ret;
|
|
std::vector<uint8_t *> audioCache_; // 用于缓存音频数据
|
|
std::vector<std::string> wfFileList;
|
|
std::atomic<bool> needStop_{false};
|
|
std::atomic<bool> needPause_{false};
|
|
uint8_t *lefunAiRecordBuffer_{nullptr};
|
|
std::mutex pauseMutex_;
|
|
size_t framesize_{0};
|
|
std::string url_{""};
|
|
std::ofstream pfd_;
|
|
AudioSession sessionId_;
|
|
Audio::AudioInterrupt interrupt_;
|
|
bool recordIsRuning_{false};
|
|
bool audioInitStatus_{false};
|
|
bool isActivateAudioInterrupt_{false};
|
|
MediaThreadIdHandle threadIdHandle_;
|
|
std::condition_variable pauseCondVar_;
|
|
// std::shared_ptr<OHOS::Audio::AudioCapturer> lefunAiCapturer_{nullptr};
|
|
std::shared_ptr<OHOS::Media::Player> playerCtr_{nullptr};
|
|
std::shared_ptr<OHOS::Media::PlayerCallback> playerCallback_{nullptr};
|
|
};
|
|
|
|
} // namespace TJD
|
|
|
|
#endif |