1 /*
2  * Copyright (C) 2023 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 AVCODEC_SAMPLE_VIDEO_SAMPLE_BASE_H
17 #define AVCODEC_SAMPLE_VIDEO_SAMPLE_BASE_H
18 
19 #include <fstream>
20 #include <thread>
21 #include "sample_base.h"
22 #include "sample_info.h"
23 #include "video_codec_base.h"
24 #include "data_producer_base.h"
25 #include "sample_context.h"
26 
27 namespace OHOS {
28 namespace MediaAVCodec {
29 namespace Sample {
30 class VideoSampleBase : public SampleBase {
31 public:
32     ~VideoSampleBase() override;
33 
34     int32_t Create(SampleInfo sampleInfo) override;
35     int32_t Start() override;
36 
37 protected:
38     virtual int32_t Init();
39     virtual int32_t Prepare();
40     virtual void Release();
41     void InnerRelease();
42     void DumpOutput(const CodecBufferInfo &bufferInfo);
43     void WriteOutputFileWithStrideYUV420(uint8_t *bufferAddr);
44     void PushEosFrame();
45 
46     std::unique_ptr<std::ofstream> outputFile_ = nullptr;
47     std::shared_ptr<DataProducerBase> dataProducer_ = nullptr;
48     std::unique_ptr<std::thread> inputThread_ = nullptr;
49     std::unique_ptr<std::thread> outputThread_ = nullptr;
50 
51     std::shared_ptr<SampleContext> context_ = nullptr;
52 };
53 } // Sample
54 } // MediaAVCodec
55 } // OHOS
56 #endif // AVCODEC_SAMPLE_VIDEO_SAMPLE_BASE_H