1 /* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_MEDIA_RECORDER_MESSAGE_PROCESSOR_H 17 #define OHOS_MEDIA_RECORDER_MESSAGE_PROCESSOR_H 18 19 #include <gst/gst.h> 20 #include <functional> 21 #include <vector> 22 #include <mutex> 23 #include "nocopyable.h" 24 #include "recorder_message_handler.h" 25 #include "task_queue.h" 26 27 namespace OHOS { 28 namespace Media { 29 using MessageResCb = std::function<void(const RecorderMessage&)>; 30 31 class RecorderMsgProcessor : public NoCopyable { 32 public: 33 RecorderMsgProcessor(GstBus &gstBus, const MessageResCb &resCb); 34 ~RecorderMsgProcessor(); 35 int32_t Init(); 36 int32_t Reset(); 37 void AddMsgHandler(std::shared_ptr<RecorderMsgHandler> handler); 38 39 private: 40 static gboolean BusCallback(GstBus *bus, GstMessage *msg, gpointer data); 41 void ProcessMessage(GstMessage &msg); 42 RecorderMsgProcResult ProcessExtendMessage(const GstMessage &msg, const RecorderMessage &prettyMsg) const; 43 RecorderMsgProcResult ProcessMessageFinal(GstMessage &msg, RecorderMessage &prettyMsg); 44 void NotifyInternalError(RecorderMessage &msg); 45 void ReportMsgProcResult(const RecorderMessage &msg); 46 void ClearResource(); 47 48 GstBus *gstBus_ = nullptr; 49 GMainLoop *mainLoop_ = nullptr; 50 TaskQueue mainLoopGuard_; 51 guint busWatchId_ = 0; 52 53 MessageResCb msgResultCb_; 54 std::vector<std::shared_ptr<RecorderMsgHandler>> msgHandlers_; 55 std::unique_ptr<TaskQueue> errorProcQ_; 56 std::mutex mutex_; 57 }; 58 } // namespace Media 59 } // namespace OHOS 60 #endif