• 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 SERVERDEC_SAMPLE_H
17 #define SERVERDEC_SAMPLE_H
18 
19 #include <atomic>
20 #include <cstdio>
21 #include <fstream>
22 #include <iostream>
23 #include <mutex>
24 #include <queue>
25 #include <string>
26 #include <thread>
27 #include <unistd.h>
28 #include <unordered_map>
29 #include "fcodec.h"
30 namespace OHOS {
31 namespace MediaAVCodec {
32 
33 class VDecSignal {
34 public:
35     std::mutex inMutex_;
36     std::condition_variable inCond_;
37     std::queue<uint32_t> inIdxQueue_;
38     std::queue<std::shared_ptr<AVBuffer>> inBufferQueue_;
39 };
40 
41 class VDecServerSample : public NoCopyable {
42 public:
43     VDecServerSample() = default;
44     ~VDecServerSample();
45 
46     void RunVideoServerDecoder();
47     int32_t ConfigServerDecoder();
48     int32_t SetCallback();
49     void GetOutputFormat();
50     void Flush();
51     void Reset();
52     void InputFunc();
53     void WaitForEos();
54     VDecSignal *signal_;
55     const uint8_t *fuzzData;
56     size_t fuzzSize;
57     int sendFrameIndex = 0;
58     int32_t width = 1920;
59     int32_t height = 1080;
60     int32_t frameRate = 30;
61     int32_t frameIndex = 10;
62 protected:
63     std::shared_ptr<CodecBase> codec_;
64     std::atomic<bool> isRunning_ { false };
65     std::unique_ptr<std::thread> inputLoop_;
66     struct CallBack : public MediaCodecCallback {
CallBackCallBack67         explicit CallBack(VDecServerSample* tester) : tester(tester) {}
68         ~CallBack() override = default;
69         void OnError(AVCodecErrorType errorType, int32_t errorCode) override;
70         void OnOutputFormatChanged(const Format &format) override;
71         void OnInputBufferAvailable(uint32_t index, std::shared_ptr<AVBuffer> buffer) override;
72         void OnOutputBufferAvailable(uint32_t index, std::shared_ptr<AVBuffer> buffer) override;
73     private:
74         VDecServerSample* tester;
75     };
76 };
77 } // namespace Media
78 } // namespace OHOS
79 
80 #endif // SERVERDEC_SAMPLE_H
81