1 /** 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef VIDEO_MANAGER_INCLUDED 18 #define VIDEO_MANAGER_INCLUDED 19 20 #include <ImsMediaDefine.h> 21 #include <ImsMediaEventHandler.h> 22 #include <BaseManager.h> 23 #include <VideoSession.h> 24 #include <VideoConfig.h> 25 #include <MediaQualityThreshold.h> 26 #include <android/native_window.h> 27 #include <unordered_map> 28 29 using namespace std; 30 using namespace android::telephony::imsmedia; 31 32 class VideoManager : public BaseManager 33 { 34 public: 35 /** 36 * @brief the request handler to handle request message in an individual thread 37 */ 38 class RequestHandler : public ImsMediaEventHandler 39 { 40 protected: 41 virtual void processEvent( 42 uint32_t event, uint64_t sessionId, uint64_t paramA, uint64_t paramB); 43 }; 44 45 /** 46 * @brief the response handler to handle request message in an individual thread 47 */ 48 class ResponseHandler : public ImsMediaEventHandler 49 { 50 protected: 51 virtual void processEvent( 52 uint32_t event, uint64_t sessionId, uint64_t paramA, uint64_t paramB); 53 }; 54 55 static VideoManager* getInstance(); 56 virtual int getState(int sessionId); 57 virtual void sendMessage(const int sessionId, const android::Parcel& parcel); 58 59 /** 60 * @brief Set the Preview Surface to use to display camera preview and pause image 61 * 62 * @param sessionId unique identifier of the session 63 * @param surface the ANativeWindow object to set 64 */ 65 void setPreviewSurface(const int sessionId, ANativeWindow* surface); 66 67 /** 68 * @brief Set the Display Surface to use to display decoded receiving video frames 69 * 70 * @param sessionId unique identifier of the session 71 * @param surface the ANativeWindow object to set 72 */ 73 void setDisplaySurface(const int sessionId, ANativeWindow* surface); 74 75 /** 76 * @brief Send interval event to be handled in the StreamGraph 77 * 78 * @param event The event type 79 * @param sessionId The session id 80 */ 81 virtual void SendInternalEvent( 82 uint32_t event, uint64_t sessionId, uint64_t paramA = 0, uint64_t paramB = 0); 83 84 protected: 85 VideoManager(); 86 virtual ~VideoManager(); 87 ImsMediaResult openSession( 88 const int sessionId, const int rtpFd, const int rtcpFd, VideoConfig* config); 89 ImsMediaResult closeSession(const int sessionId); 90 virtual ImsMediaResult setPreviewSurfaceToSession(const int sessionId, ANativeWindow* surface); 91 virtual ImsMediaResult setDisplaySurfaceToSession(const int sessionId, ANativeWindow* surface); 92 ImsMediaResult modifySession(const int sessionId, VideoConfig* config); 93 virtual void setMediaQualityThreshold(const int sessionId, MediaQualityThreshold* threshold); 94 95 static VideoManager* sManager; 96 std::unordered_map<int, std::unique_ptr<VideoSession>> mSessions; 97 RequestHandler mRequestHandler; 98 ResponseHandler mResponseHandler; 99 }; 100 101 #endif