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 GST_MSG_PROCESSOR_H 17 #define GST_MSG_PROCESSOR_H 18 19 #include <mutex> 20 #include <condition_variable> 21 #include <string> 22 #include <vector> 23 #include <gst/gst.h> 24 #include "inner_msg_define.h" 25 #include "task_queue.h" 26 #include "gst_msg_converter.h" 27 #include "nocopyable.h" 28 29 namespace OHOS { 30 namespace Media { 31 class GstMsgProcessor : public NoCopyable { 32 public: 33 GstMsgProcessor(GstBus &gstBus, const InnerMsgNotifier ¬ifier, 34 const std::shared_ptr<IGstMsgConverter> &converter = nullptr); 35 ~GstMsgProcessor(); 36 37 int32_t Init(); 38 39 /** 40 * Add the gst msg filter except the error msg. 41 * The filter string will be compared with the gst msg src's name. 42 * If matched, the msg will be notified, or the msg will be ignored. 43 */ 44 void AddMsgFilter(const std::string &filter); 45 void FlushBegin(); 46 void FlushEnd(); 47 void Reset() noexcept; 48 49 private: 50 int32_t DoInit(); 51 static gboolean MainLoopRunDone(GstMsgProcessor *thiz); 52 static gboolean BusCallback(const GstBus *bus, GstMessage *msg, GstMsgProcessor *thiz); 53 void ProcessGstMessage(GstMessage &msg); 54 void DoReset(); 55 56 GstBus *gstBus_ = nullptr; 57 GMainLoop *mainLoop_ = nullptr; 58 GMainContext *context_ = nullptr; 59 GSource *busSource_ = 0; 60 InnerMsgNotifier notifier_; 61 TaskQueue guardTask_; 62 std::mutex mutex_; 63 std::condition_variable cond_; 64 bool needWaiting_ = true; 65 std::shared_ptr<IGstMsgConverter> msgConverter_; 66 std::vector<std::string> filters_; 67 }; 68 } // namespace Media 69 } // namespace OHOS 70 #endif // GST_MSG_PROCESSOR_H