• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 TEMPORAL_SCALABILITY_H
17 #define TEMPORAL_SCALABILITY_H
18 
19 #include <cstdint>
20 #include <shared_mutex>
21 #include <unordered_map>
22 #include "av_common.h"
23 #include "avcodec_dfx_component.h"
24 #include "block_queue.h"
25 #include "buffer/avbuffer.h"
26 
27 namespace OHOS {
28 namespace MediaAVCodec {
29 constexpr double DEFAULT_FRAMERATE = 30.0;
30 constexpr int32_t DEFAULT_I_FRAME_INTERVAL = 1000;
31 constexpr int32_t MIN_TEMPORAL_GOPSIZE = 2;
32 constexpr int32_t DEFAULT_TEMPORAL_GOPSIZE = 4;
33 constexpr int32_t DEFAULT_GOPSIZE = 30;
34 
35 class TemporalScalability : public AVCodecDfxComponent {
36 public:
37     explicit TemporalScalability(const std::string &name);
38     virtual ~TemporalScalability();
39     bool svcLTR_ = false; // true: LTR
40     void ValidateTemporalGopParam(Format &format);
41     uint32_t GetFirstBufferIndex();
42     void StoreAVBuffer(uint32_t index, std::shared_ptr<Media::AVBuffer> buffer);
43     void ConfigureLTR(uint32_t index);
44     void SetDisposableFlag(std::shared_ptr<Media::AVBuffer> buffer);
45     void SetBlockQueueActive();
46 
47 private:
48     std::string name_;
49     bool isMarkLTR_ = false;
50     bool isUseLTR_ = false;
51     int32_t ltrPoc_ = 0;
52     int32_t poc_ = 0;
53     int32_t temporalPoc_ = 0;
54     uint32_t inputFrameCounter_ = 0;
55     uint32_t outputFrameCounter_ = 0;
56     int32_t frameNum_ = 0;
57     int32_t gopSize_ = DEFAULT_GOPSIZE;
58     int32_t temporalGopSize_ = 0;
59     int32_t tRefMode_ = 0;
60     std::shared_mutex inputBufMutex_;
61     std::shared_mutex frameFlagMapMutex_;
62     std::unordered_map<uint32_t, uint32_t> frameFlagMap_;
63     std::unordered_map<uint32_t, std::shared_ptr<Media::AVBuffer>> inputBufferMap_;
64     std::shared_ptr<BlockQueue<uint32_t>> inputIndexQueue_;
65     bool IsLTRSolution();
66     int32_t LTRFrameNumCalculate(int32_t tGopSize) const;
67     void MarkLTRDecision();
68     static int32_t LTRPocDecision(int32_t tPoc);
69     void AdjacentJumpLTRDecision();
70     void UniformlyScaledLTRDecision();
71     void LTRDecision();
72     uint32_t DisposableDecision() const;
73 };
74 
75 } // namespace MediaAVCodec
76 } // namespace OHOS
77 #endif // TEMPORAL_SCALABILITY_H