180922886Sopenharmony_ci/*
280922886Sopenharmony_ci * Copyright (c) 2022-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_AVSESSION_STUB_H
1780922886Sopenharmony_ci#define OHOS_AVSESSION_STUB_H
1880922886Sopenharmony_ci
1980922886Sopenharmony_ci#include <map>
2080922886Sopenharmony_ci#include "iav_session.h"
2180922886Sopenharmony_ci#include "iremote_stub.h"
2280922886Sopenharmony_ci#include "want_agent.h"
2380922886Sopenharmony_ci#include "want_params.h"
2480922886Sopenharmony_ci#include "avsession_log.h"
2580922886Sopenharmony_ci#include "avsession_errors.h"
2680922886Sopenharmony_ci
2780922886Sopenharmony_ci#ifdef CASTPLUS_CAST_ENGINE_ENABLE
2880922886Sopenharmony_ci#include "avcast_controller.h"
2980922886Sopenharmony_ci#endif
3080922886Sopenharmony_ci
3180922886Sopenharmony_cinamespace OHOS::AVSession {
3280922886Sopenharmony_ciclass AVSessionStub : public IRemoteStub<IAVSession> {
3380922886Sopenharmony_cipublic:
3480922886Sopenharmony_ci    int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
3580922886Sopenharmony_ci
3680922886Sopenharmony_ci    int32_t RegisterCallback(const std::shared_ptr<AVSessionCallback>& callback) override
3780922886Sopenharmony_ci    {
3880922886Sopenharmony_ci        return ERR_NONE;
3980922886Sopenharmony_ci    }
4080922886Sopenharmony_ci
4180922886Sopenharmony_ci    std::shared_ptr<AVSessionController> GetController() override
4280922886Sopenharmony_ci    {
4380922886Sopenharmony_ci        return nullptr;
4480922886Sopenharmony_ci    }
4580922886Sopenharmony_ci
4680922886Sopenharmony_ci#ifdef CASTPLUS_CAST_ENGINE_ENABLE
4780922886Sopenharmony_ci    std::shared_ptr<AVCastController> GetAVCastController() override
4880922886Sopenharmony_ci    {
4980922886Sopenharmony_ci        return nullptr;
5080922886Sopenharmony_ci    }
5180922886Sopenharmony_ci#endif
5280922886Sopenharmony_ci
5380922886Sopenharmony_ciprivate:
5480922886Sopenharmony_ci    int32_t HandleGetSessionId(MessageParcel& data, MessageParcel& reply);
5580922886Sopenharmony_ci
5680922886Sopenharmony_ci    int32_t HandleGetSessionType(MessageParcel& data, MessageParcel& reply);
5780922886Sopenharmony_ci
5880922886Sopenharmony_ci    int32_t HandleSetAVCallMetaData(MessageParcel& data, MessageParcel& reply);
5980922886Sopenharmony_ci
6080922886Sopenharmony_ci    int32_t HandleSetAVCallState(MessageParcel& data, MessageParcel& reply);
6180922886Sopenharmony_ci
6280922886Sopenharmony_ci    int32_t HandleGetAVMetaData(MessageParcel& data, MessageParcel& reply);
6380922886Sopenharmony_ci
6480922886Sopenharmony_ci    int32_t SetImageData(AVMetaData& meta, const char *buffer, int twoImageLength);
6580922886Sopenharmony_ci
6680922886Sopenharmony_ci    int32_t HandleSetAVMetaData(MessageParcel& data, MessageParcel& reply);
6780922886Sopenharmony_ci
6880922886Sopenharmony_ci    int32_t HandleGetAVPlaybackState(MessageParcel& data, MessageParcel& reply);
6980922886Sopenharmony_ci
7080922886Sopenharmony_ci    int32_t HandleSetAVPlaybackState(MessageParcel& data, MessageParcel& reply);
7180922886Sopenharmony_ci
7280922886Sopenharmony_ci    int32_t HandleSetLaunchAbility(MessageParcel& data, MessageParcel& reply);
7380922886Sopenharmony_ci
7480922886Sopenharmony_ci    int32_t HandleGetExtras(MessageParcel& data, MessageParcel& reply);
7580922886Sopenharmony_ci
7680922886Sopenharmony_ci    int32_t HandleSetExtras(MessageParcel& data, MessageParcel& reply);
7780922886Sopenharmony_ci
7880922886Sopenharmony_ci    int32_t HandleGetController(MessageParcel& data, MessageParcel& reply);
7980922886Sopenharmony_ci
8080922886Sopenharmony_ci#ifdef CASTPLUS_CAST_ENGINE_ENABLE
8180922886Sopenharmony_ci    int32_t HandleGetAVCastController(MessageParcel& data, MessageParcel& reply);
8280922886Sopenharmony_ci
8380922886Sopenharmony_ci    int32_t HandleReleaseCast(MessageParcel& data, MessageParcel& reply);
8480922886Sopenharmony_ci
8580922886Sopenharmony_ci    int32_t HandleStartCastDisplayListener(MessageParcel& data, MessageParcel& reply);
8680922886Sopenharmony_ci
8780922886Sopenharmony_ci    int32_t HandleStopCastDisplayListener(MessageParcel& data, MessageParcel& reply);
8880922886Sopenharmony_ci
8980922886Sopenharmony_ci    int32_t HandleGetAllCastDisplays(MessageParcel& data, MessageParcel& reply);
9080922886Sopenharmony_ci#endif
9180922886Sopenharmony_ci
9280922886Sopenharmony_ci    int32_t HandleRegisterCallbackInner(MessageParcel& data, MessageParcel& reply);
9380922886Sopenharmony_ci
9480922886Sopenharmony_ci    int32_t HandleActivate(MessageParcel& data, MessageParcel& reply);
9580922886Sopenharmony_ci
9680922886Sopenharmony_ci    int32_t HandleDeactivate(MessageParcel& data, MessageParcel& reply);
9780922886Sopenharmony_ci
9880922886Sopenharmony_ci    int32_t HandleIsActive(MessageParcel& data, MessageParcel& reply);
9980922886Sopenharmony_ci
10080922886Sopenharmony_ci    int32_t HandleDestroy(MessageParcel& data, MessageParcel& reply);
10180922886Sopenharmony_ci
10280922886Sopenharmony_ci    int32_t HandleAddSupportCommand(MessageParcel& data, MessageParcel& reply);
10380922886Sopenharmony_ci
10480922886Sopenharmony_ci    int32_t HandleDeleteSupportCommand(MessageParcel& data, MessageParcel& reply);
10580922886Sopenharmony_ci
10680922886Sopenharmony_ci    int32_t HandleSetSessionEvent(MessageParcel& data, MessageParcel& reply);
10780922886Sopenharmony_ci
10880922886Sopenharmony_ci    int32_t HandleGetAVQueueItems(MessageParcel& data, MessageParcel& reply);
10980922886Sopenharmony_ci
11080922886Sopenharmony_ci    int32_t HandleSetAVQueueItems(MessageParcel& data, MessageParcel& reply);
11180922886Sopenharmony_ci
11280922886Sopenharmony_ci    int32_t HandleGetAVQueueTitle(MessageParcel& data, MessageParcel& reply);
11380922886Sopenharmony_ci
11480922886Sopenharmony_ci    int32_t HandleSetAVQueueTitle(MessageParcel& data, MessageParcel& reply);
11580922886Sopenharmony_ci
11680922886Sopenharmony_ci    static bool CheckInterfaceToken(MessageParcel& data);
11780922886Sopenharmony_ci
11880922886Sopenharmony_ci    using HandlerFunc = std::function<int32_t(MessageParcel&, MessageParcel&)>;
11980922886Sopenharmony_ci    std::map<uint32_t, HandlerFunc> handlers = {
12080922886Sopenharmony_ci        {SESSION_CMD_GET_SESSION_ID,
12180922886Sopenharmony_ci            [this](MessageParcel& data, MessageParcel& reply) { return HandleGetSessionId(data, reply); }},
12280922886Sopenharmony_ci        {SESSION_CMD_GET_SESSION_TYPE,
12380922886Sopenharmony_ci            [this](MessageParcel& data, MessageParcel& reply) { return HandleGetSessionType(data, reply); }},
12480922886Sopenharmony_ci        {SESSION_CMD_GET_META_DATA,
12580922886Sopenharmony_ci            [this](MessageParcel& data, MessageParcel& reply) { return HandleGetAVMetaData(data, reply); }},
12680922886Sopenharmony_ci        {SESSION_CMD_SET_META_DATA,
12780922886Sopenharmony_ci            [this](MessageParcel& data, MessageParcel& reply) { return HandleSetAVMetaData(data, reply); }},
12880922886Sopenharmony_ci        {SESSION_CMD_GET_PLAYBACK_STATE,
12980922886Sopenharmony_ci            [this](MessageParcel& data, MessageParcel& reply) { return HandleGetAVPlaybackState(data, reply); }},
13080922886Sopenharmony_ci        {SESSION_CMD_SET_PLAYBACK_STATE,
13180922886Sopenharmony_ci            [this](MessageParcel& data, MessageParcel& reply) { return HandleSetAVPlaybackState(data, reply); }},
13280922886Sopenharmony_ci        {SESSION_CMD_GET_QUEUE_ITEMS,
13380922886Sopenharmony_ci            [this](MessageParcel& data, MessageParcel& reply) { return HandleGetAVQueueItems(data, reply); }},
13480922886Sopenharmony_ci        {SESSION_CMD_SET_QUEUE_ITEMS,
13580922886Sopenharmony_ci            [this](MessageParcel& data, MessageParcel& reply) { return HandleSetAVQueueItems(data, reply); }},
13680922886Sopenharmony_ci        {SESSION_CMD_GET_QUEUE_TITLE,
13780922886Sopenharmony_ci            [this](MessageParcel& data, MessageParcel& reply) { return HandleGetAVQueueTitle(data, reply); }},
13880922886Sopenharmony_ci        {SESSION_CMD_SET_QUEUE_TITLE,
13980922886Sopenharmony_ci            [this](MessageParcel& data, MessageParcel& reply) { return HandleSetAVQueueTitle(data, reply); }},
14080922886Sopenharmony_ci        {SESSION_CMD_GET_EXTRAS,
14180922886Sopenharmony_ci            [this](MessageParcel& data, MessageParcel& reply) { return HandleGetExtras(data, reply); }},
14280922886Sopenharmony_ci        {SESSION_CMD_SET_EXTRAS,
14380922886Sopenharmony_ci            [this](MessageParcel& data, MessageParcel& reply) { return HandleSetExtras(data, reply); }},
14480922886Sopenharmony_ci        {SESSION_CMD_SET_LAUNCH_ABILITY,
14580922886Sopenharmony_ci            [this](MessageParcel& data, MessageParcel& reply) { return HandleSetLaunchAbility(data, reply); }},
14680922886Sopenharmony_ci        {SESSION_CMD_GET_CONTROLLER,
14780922886Sopenharmony_ci            [this](MessageParcel& data, MessageParcel& reply) { return HandleGetController(data, reply); }},
14880922886Sopenharmony_ci#ifdef CASTPLUS_CAST_ENGINE_ENABLE
14980922886Sopenharmony_ci        {SESSION_CMD_GET_AVCAST_CONTROLLER,
15080922886Sopenharmony_ci            [this](MessageParcel& data, MessageParcel& reply) { return HandleGetAVCastController(data, reply); }},
15180922886Sopenharmony_ci        {SESSION_CMD_START_CAST_DISPLAY_LISTENER,
15280922886Sopenharmony_ci            [this](MessageParcel& data, MessageParcel& reply) { return HandleStartCastDisplayListener(data, reply); }},
15380922886Sopenharmony_ci        {SESSION_CMD_STOP_CAST_DISPLAY_LISTENER,
15480922886Sopenharmony_ci            [this](MessageParcel& data, MessageParcel& reply) { return HandleStopCastDisplayListener(data, reply); }},
15580922886Sopenharmony_ci        {SESSION_CMD_GET_ALL_CAST_DISPLAYS,
15680922886Sopenharmony_ci            [this](MessageParcel& data, MessageParcel& reply) { return HandleGetAllCastDisplays(data, reply); }},
15780922886Sopenharmony_ci#endif
15880922886Sopenharmony_ci        {SESSION_CMD_REGISTER_CALLBACK,
15980922886Sopenharmony_ci            [this](MessageParcel& data, MessageParcel& reply) { return HandleRegisterCallbackInner(data, reply); }},
16080922886Sopenharmony_ci        {SESSION_CMD_ACTIVATE,
16180922886Sopenharmony_ci            [this](MessageParcel& data, MessageParcel& reply) { return HandleActivate(data, reply); }},
16280922886Sopenharmony_ci        {SESSION_CMD_DEACTIVATE,
16380922886Sopenharmony_ci            [this](MessageParcel& data, MessageParcel& reply) { return HandleDeactivate(data, reply); }},
16480922886Sopenharmony_ci        {SESSION_CMD_ISACTIVE,
16580922886Sopenharmony_ci            [this](MessageParcel& data, MessageParcel& reply) { return HandleIsActive(data, reply); }},
16680922886Sopenharmony_ci        {SESSION_CMD_DESTROY,
16780922886Sopenharmony_ci            [this](MessageParcel& data, MessageParcel& reply) { return HandleDestroy(data, reply); }},
16880922886Sopenharmony_ci        {SESSION_CMD_ADD_SUPPORT_COMMAND,
16980922886Sopenharmony_ci            [this](MessageParcel& data, MessageParcel& reply) { return HandleAddSupportCommand(data, reply); }},
17080922886Sopenharmony_ci        {SESSION_CMD_DELETE_SUPPORT_COMMAND,
17180922886Sopenharmony_ci            [this](MessageParcel& data, MessageParcel& reply) { return HandleDeleteSupportCommand(data, reply); }},
17280922886Sopenharmony_ci        {SESSION_CMD_SET_SESSION_EVENT,
17380922886Sopenharmony_ci            [this](MessageParcel& data, MessageParcel& reply) { return HandleSetSessionEvent(data, reply); }},
17480922886Sopenharmony_ci#ifdef CASTPLUS_CAST_ENGINE_ENABLE
17580922886Sopenharmony_ci        {SESSION_CMD_RELEASE_CAST,
17680922886Sopenharmony_ci            [this](MessageParcel& data, MessageParcel& reply) { return HandleReleaseCast(data, reply); }},
17780922886Sopenharmony_ci#endif
17880922886Sopenharmony_ci        {SESSION_CMD_SET_AVCALL_META_DATA,
17980922886Sopenharmony_ci            [this](MessageParcel& data, MessageParcel& reply) { return HandleSetAVCallMetaData(data, reply); }},
18080922886Sopenharmony_ci        {SESSION_CMD_SET_AVCALL_STATE,
18180922886Sopenharmony_ci            [this](MessageParcel& data, MessageParcel& reply) { return HandleSetAVCallState(data, reply); }}
18280922886Sopenharmony_ci    };
18380922886Sopenharmony_ci    std::map<uint32_t, std::string> mapCodeToFuncNameXCollie = {
18480922886Sopenharmony_ci        {SESSION_CMD_GET_SESSION_ID, "HandleGetSessionId"},
18580922886Sopenharmony_ci        {SESSION_CMD_GET_SESSION_TYPE, "HandleGetSessionType"},
18680922886Sopenharmony_ci        {SESSION_CMD_GET_META_DATA, "HandleGetAVMetaData"},
18780922886Sopenharmony_ci        {SESSION_CMD_SET_META_DATA, "HandleSetAVMetaData"},
18880922886Sopenharmony_ci        {SESSION_CMD_GET_PLAYBACK_STATE, "HandleGetAVPlaybackState"},
18980922886Sopenharmony_ci        {SESSION_CMD_SET_PLAYBACK_STATE, "HandleSetAVPlaybackState"},
19080922886Sopenharmony_ci        {SESSION_CMD_GET_QUEUE_ITEMS, "HandleGetAVQueueItems"},
19180922886Sopenharmony_ci        {SESSION_CMD_SET_QUEUE_ITEMS, "HandleSetAVQueueItems"},
19280922886Sopenharmony_ci        {SESSION_CMD_GET_QUEUE_TITLE, "HandleGetAVQueueTitle"},
19380922886Sopenharmony_ci        {SESSION_CMD_SET_QUEUE_TITLE, "HandleSetAVQueueTitle"},
19480922886Sopenharmony_ci        {SESSION_CMD_GET_EXTRAS, "HandleGetExtras"},
19580922886Sopenharmony_ci        {SESSION_CMD_SET_EXTRAS, "HandleSetExtras"},
19680922886Sopenharmony_ci        {SESSION_CMD_SET_LAUNCH_ABILITY, "HandleSetLaunchAbility"},
19780922886Sopenharmony_ci        {SESSION_CMD_GET_CONTROLLER, "HandleGetController"},
19880922886Sopenharmony_ci#ifdef CASTPLUS_CAST_ENGINE_ENABLE
19980922886Sopenharmony_ci        {SESSION_CMD_GET_AVCAST_CONTROLLER, "HandleGetAVCastController"},
20080922886Sopenharmony_ci        {SESSION_CMD_START_CAST_DISPLAY_LISTENER, "HandleStartCastDisplayListener"},
20180922886Sopenharmony_ci        {SESSION_CMD_STOP_CAST_DISPLAY_LISTENER, "HandleStopCastDisplayListener"},
20280922886Sopenharmony_ci        {SESSION_CMD_GET_ALL_CAST_DISPLAYS, "HandleGetAllCastDisplays"},
20380922886Sopenharmony_ci#endif
20480922886Sopenharmony_ci        {SESSION_CMD_REGISTER_CALLBACK, "HandleRegisterCallbackInner"},
20580922886Sopenharmony_ci        {SESSION_CMD_ACTIVATE, "HandleActivate"},
20680922886Sopenharmony_ci        {SESSION_CMD_DEACTIVATE, "HandleDeactivate"},
20780922886Sopenharmony_ci        {SESSION_CMD_ISACTIVE, "HandleIsActive"},
20880922886Sopenharmony_ci        {SESSION_CMD_DESTROY, "HandleDestroy"},
20980922886Sopenharmony_ci        {SESSION_CMD_ADD_SUPPORT_COMMAND, "HandleAddSupportCommand"},
21080922886Sopenharmony_ci        {SESSION_CMD_DELETE_SUPPORT_COMMAND, "HandleDeleteSupportCommand"},
21180922886Sopenharmony_ci        {SESSION_CMD_SET_SESSION_EVENT, "HandleSetSessionEvent"},
21280922886Sopenharmony_ci#ifdef CASTPLUS_CAST_ENGINE_ENABLE
21380922886Sopenharmony_ci        {SESSION_CMD_RELEASE_CAST, "HandleReleaseCast"},
21480922886Sopenharmony_ci#endif
21580922886Sopenharmony_ci        {SESSION_CMD_SET_AVCALL_META_DATA, "HandleSetAVCallMetaData"},
21680922886Sopenharmony_ci        {SESSION_CMD_SET_AVCALL_STATE, "HandleSetAVCallState"}
21780922886Sopenharmony_ci    };
21880922886Sopenharmony_ci
21980922886Sopenharmony_ci    int32_t MAX_IMAGE_SIZE = 10 * 1024 * 1024;
22080922886Sopenharmony_ci    const size_t defaultIpcCapacity = 1048576; // Increase the IPC default capacity(200K) to 1M
22180922886Sopenharmony_ci};
22280922886Sopenharmony_ci}
22380922886Sopenharmony_ci#endif // OHOS_AVSESSION_STUB_H
224