1 /* 2 * Copyright (C) 2022 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 PLAYER_CODEC_CTRL_H 17 #define PLAYER_CODEC_CTRL_H 18 19 #include <mutex> 20 #include <string> 21 #include <list> 22 #include <unordered_map> 23 #include <gst/gst.h> 24 #include <gst/player/player.h> 25 26 namespace OHOS { 27 namespace Media { 28 class PlayerCodecCtrl { 29 public: 30 using CapsFixErrorNotifier = std::function<void()>; 31 PlayerCodecCtrl(); 32 ~PlayerCodecCtrl(); 33 void DetectCodecSetup(const std::string &metaStr, GstElement *src, GstElement *videoSink, 34 CapsFixErrorNotifier notifier); 35 void DetectCodecUnSetup(GstElement *src, GstElement *videoSink); 36 void EnhanceSeekPerformance(bool enable); 37 int32_t GetHEBCMode() const; 38 int32_t HandleCodecBuffers(bool enable); 39 void StopFormatChange(); 40 41 private: 42 void SetupCodecCb(const std::string &metaStr, GstElement *src, GstElement *videoSink, 43 CapsFixErrorNotifier notifier); 44 void HlsSwichSoftAndHardCodec(GstElement *videoSink); 45 void SetupCodecBufferNum(const std::string &metaStr, GstElement *src) const; 46 static void CapsFixErrorCb(const GstElement *decoder, gpointer userData); 47 bool IsFirstCodecSetup() const; 48 void DisablePerformanceBySysParam(); 49 50 bool isHardwareDec_ = false; 51 bool isHEBCMode_ = false; 52 struct DecoderElement { 53 bool isHardware = false; 54 gulong signalId = 0; 55 }; 56 std::unordered_map<GstElement *, DecoderElement> elementMap_; 57 std::list<bool> codecTypeList_; 58 std::mutex mutex_; 59 CapsFixErrorNotifier notifier_; 60 bool isEnablePerformanceMode_ = true; 61 }; 62 } // Media 63 } // OHOS 64 #endif // PLAYER_CODEC_CTRL_H