1 /* 2 * Copyright (c) 2024 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 REFERENCE_PARSER_DEMO_H 17 #define REFERENCE_PARSER_DEMO_H 18 19 #include <map> 20 #include "avdemuxer.h" 21 #include "avsource.h" 22 #include "nlohmann/json.hpp" 23 24 struct JsonFrameLayerInfo { 25 int32_t frameId; 26 int64_t dts; 27 int32_t layer; 28 bool discardable; 29 }; 30 31 struct JsonGopInfo { 32 int32_t gopId; 33 int32_t gopSize; 34 int32_t startFrameId; 35 }; 36 37 namespace OHOS { 38 namespace MediaAVCodec { 39 enum struct MP4Scene : uint32_t { 40 IPB_0 = 0, 41 IPB_1 = 1, 42 IPPP_0 = 2, 43 IPPP_1 = 3, 44 IPPP_SCALA_0 = 4, 45 IPPP_SCALA_1 = 5, 46 SDTP = 6, 47 SDTP_EXT = 7, 48 SCENE_MAX 49 }; 50 51 class ReferenceParserDemo : public NoCopyable { 52 public: 53 ~ReferenceParserDemo(); 54 void SetDecIntervalMs(int64_t decIntervalMs); 55 int32_t InitScene(MP4Scene scene); 56 bool DoAccurateSeek(int64_t seekTimeMs); 57 bool DoVariableSpeedPlay(int64_t playTimeMs); 58 59 private: 60 bool CheckFrameLayerResult(const FrameLayerInfo &info, int64_t dts); 61 bool CheckGopLayerResult(GopLayerInfo &GopLayerInfo, uint32_t gopid); 62 int32_t GetMaxDiscardLayer(const GopLayerInfo &GopLayerInfo); 63 int32_t IsFrameDiscard(FrameLayerInfo &frameInfo, bool &isDiscard); 64 void LoadJson(); 65 int32_t InitDemuxer(int64_t size); 66 MP4Scene scene_ = MP4Scene::IPB_0; 67 int64_t decIntervalUs_ = 0; 68 nlohmann::json gopJson_; 69 nlohmann::json frameLayerJson_; 70 std::vector<JsonGopInfo> gopVec_; 71 std::vector<JsonFrameLayerInfo> frameVec_; 72 std::map<int64_t, JsonFrameLayerInfo> frameMap_; 73 int32_t fd_ = 0; 74 std::shared_ptr<AVBuffer> buffer_ = nullptr; 75 std::shared_ptr<AVSource> source_ = nullptr; 76 std::shared_ptr<AVDemuxer> demuxer_ = nullptr; 77 int32_t videoTrackId_ = 0; 78 int32_t checkedGopId_ = -1; 79 int32_t maxDiscardLayer_ = -1; 80 bool isDiscard_ = false; 81 }; 82 83 } // namespace MediaAVCodec 84 } // namespace OHOS 85 86 #endif // REFERENCE_PARSER_DEMO_H