180922886Sopenharmony_ci/* 280922886Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 380922886Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 480922886Sopenharmony_ci * you may not use this file except in compliance with the License. 580922886Sopenharmony_ci * You may obtain a copy of the License at 680922886Sopenharmony_ci * 780922886Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 880922886Sopenharmony_ci * 980922886Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1080922886Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1180922886Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1280922886Sopenharmony_ci * See the License for the specific language governing permissions and 1380922886Sopenharmony_ci * limitations under the License. 1480922886Sopenharmony_ci */ 1580922886Sopenharmony_ci 1680922886Sopenharmony_ci#ifndef OHOS_OHAVSESSION_H 1780922886Sopenharmony_ci#define OHOS_OHAVSESSION_H 1880922886Sopenharmony_ci 1980922886Sopenharmony_ci#include <unordered_map> 2080922886Sopenharmony_ci#include "native_avsession.h" 2180922886Sopenharmony_ci#include "native_avsession_errors.h" 2280922886Sopenharmony_ci#include "avsession_info.h" 2380922886Sopenharmony_ci#include "av_session.h" 2480922886Sopenharmony_ci#include "OHAVSessionCallbackImpl.h" 2580922886Sopenharmony_ci#include "avsession_log.h" 2680922886Sopenharmony_ci#include "avcast_control_command.h" 2780922886Sopenharmony_ci 2880922886Sopenharmony_cinamespace OHOS::AVSession { 2980922886Sopenharmony_ciclass OHAVSession { 3080922886Sopenharmony_cipublic: 3180922886Sopenharmony_ci ~OHAVSession(); 3280922886Sopenharmony_ci OHAVSession(); 3380922886Sopenharmony_ci OHAVSession(AVSession_Type sessionType, const char* sessionTag, 3480922886Sopenharmony_ci const char* bundleName, const char* abilityName); 3580922886Sopenharmony_ci bool IsAVSessionNull(); 3680922886Sopenharmony_ci AVSession_ErrCode Activate(); 3780922886Sopenharmony_ci AVSession_ErrCode Deactivate(); 3880922886Sopenharmony_ci std::string GetSessionType(); 3980922886Sopenharmony_ci const std::string& GetSessionId(); 4080922886Sopenharmony_ci 4180922886Sopenharmony_ci AVSession_ErrCode SetAVMetaData(OH_AVMetadata *metadata); 4280922886Sopenharmony_ci AVSession_ErrCode SetPlaybackState(AVSession_PlaybackState playbackState); 4380922886Sopenharmony_ci AVSession_ErrCode SetPlaybackPosition(AVSession_PlaybackPosition* playbackPosition); 4480922886Sopenharmony_ci AVSession_ErrCode SetFavorite(bool favorite); 4580922886Sopenharmony_ci AVSession_ErrCode SetLoopMode(AVSession_LoopMode loopMode); 4680922886Sopenharmony_ci 4780922886Sopenharmony_ci AVSession_ErrCode RegisterCommandCallback(AVSession_ControlCommand command, 4880922886Sopenharmony_ci OH_AVSessionCallback_OnCommand callback, void* userData); 4980922886Sopenharmony_ci AVSession_ErrCode UnregisterCommandCallback(AVSession_ControlCommand command, 5080922886Sopenharmony_ci OH_AVSessionCallback_OnCommand callback); 5180922886Sopenharmony_ci AVSession_ErrCode RegisterForwardCallback(OH_AVSessionCallback_OnFastForward callback, void* userData); 5280922886Sopenharmony_ci AVSession_ErrCode UnregisterForwardCallback(OH_AVSessionCallback_OnFastForward callback); 5380922886Sopenharmony_ci AVSession_ErrCode RegisterRewindCallback(OH_AVSessionCallback_OnRewind callback, void* userData); 5480922886Sopenharmony_ci AVSession_ErrCode UnregisterRewindCallback(OH_AVSessionCallback_OnRewind callback); 5580922886Sopenharmony_ci AVSession_ErrCode RegisterSeekCallback(OH_AVSessionCallback_OnSeek callback, void* userData); 5680922886Sopenharmony_ci AVSession_ErrCode UnregisterSeekCallback(OH_AVSessionCallback_OnSeek callback); 5780922886Sopenharmony_ci AVSession_ErrCode RegisterSetLoopModeCallback(OH_AVSessionCallback_OnSetLoopMode callback, void* userData); 5880922886Sopenharmony_ci AVSession_ErrCode UnregisterSetLoopModeCallback(OH_AVSessionCallback_OnSetLoopMode callback); 5980922886Sopenharmony_ci AVSession_ErrCode RegisterToggleFavoriteCallback(OH_AVSessionCallback_OnToggleFavorite callback, void* userData); 6080922886Sopenharmony_ci AVSession_ErrCode UnregisterToggleFavoriteCallback(OH_AVSessionCallback_OnToggleFavorite callback); 6180922886Sopenharmony_ci AVSession_ErrCode Destroy(); 6280922886Sopenharmony_ci AVSession_ErrCode CheckAndRegister(); 6380922886Sopenharmony_ci 6480922886Sopenharmony_ci AVSession_ErrCode GetEncodeErrcode(int32_t ret); 6580922886Sopenharmony_ci std::unordered_map<int32_t, AVSession_ErrCode> errcodes = { 6680922886Sopenharmony_ci {0, AV_SESSION_ERR_SUCCESS}, 6780922886Sopenharmony_ci {6600101, AV_SESSION_ERR_SERVICE_EXCEPTION}, 6880922886Sopenharmony_ci {6600102, AV_SESSION_ERR_CODE_SESSION_NOT_EXIST}, 6980922886Sopenharmony_ci {6600105, AV_SESSION_ERR_CODE_COMMAND_INVALID}, 7080922886Sopenharmony_ci {6600106, AV_SESSION_ERR_CODE_SESSION_INACTIVE}, 7180922886Sopenharmony_ci {6600107, AV_SESSION_ERR_CODE_MESSAGE_OVERLOAD}, 7280922886Sopenharmony_ci }; 7380922886Sopenharmony_ci std::unordered_map<std::string, AVSession_Type> avsessionTypes = { 7480922886Sopenharmony_ci {"audio", SESSION_TYPE_AUDIO}, 7580922886Sopenharmony_ci {"video", SESSION_TYPE_VIDEO}, 7680922886Sopenharmony_ci {"voice_call", SESSION_TYPE_VOICE_CALL}, 7780922886Sopenharmony_ci {"video_call", SESSION_TYPE_VIDEO_CALL}, 7880922886Sopenharmony_ci }; 7980922886Sopenharmony_ci 8080922886Sopenharmony_ciprivate: 8180922886Sopenharmony_ci std::mutex lock_; 8280922886Sopenharmony_ci std::shared_ptr<AVSession> avSession_; 8380922886Sopenharmony_ci std::shared_ptr<OHAVSessionCallbackImpl> ohAVSessionCallbackImpl_; 8480922886Sopenharmony_ci std::string sessionId_; 8580922886Sopenharmony_ci}; 8680922886Sopenharmony_ci} 8780922886Sopenharmony_ci#endif // OHOS_OHAVSESSION_H