• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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_SERVER_H
17 #define AVCODEC_SERVER_H
18 
19 #include "i_avcodec_engine.h"
20 #include "i_avcodec_service.h"
21 #include "time_monitor.h"
22 #include "nocopyable.h"
23 
24 namespace OHOS {
25 namespace Media {
26 class AVCodecServer : public IAVCodecService, public IAVCodecEngineObs, public NoCopyable {
27 public:
28     static std::shared_ptr<IAVCodecService> Create();
29     AVCodecServer();
30     virtual ~AVCodecServer();
31 
32     enum AVCodecStatus {
33         AVCODEC_UNINITIALIZED = 0,
34         AVCODEC_INITIALIZED,
35         AVCODEC_CONFIGURED,
36         AVCODEC_PREPARED,
37         AVCODEC_RUNNING,
38         AVCODEC_END_OF_STREAM,
39         AVCODEC_ERROR,
40     };
41 
42     int32_t InitParameter(AVCodecType type, bool isMimeType, const std::string &name) override;
43     int32_t Configure(const Format &format) override;
44     int32_t Prepare() override;
45     int32_t Start() override;
46     int32_t Stop() override;
47     int32_t Flush() override;
48     int32_t Reset() override;
49     int32_t Release() override;
50     sptr<Surface> CreateInputSurface() override;
51     int32_t SetOutputSurface(sptr<Surface> surface) override;
52     std::shared_ptr<AVSharedMemory> GetInputBuffer(uint32_t index) override;
53     int32_t QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) override;
54     std::shared_ptr<AVSharedMemory> GetOutputBuffer(uint32_t index) override;
55     int32_t GetOutputFormat(Format &format) override;
56     std::shared_ptr<AudioCaps> GetAudioCaps() override;
57     std::shared_ptr<VideoCaps> GetVideoCaps() override;
58     int32_t ReleaseOutputBuffer(uint32_t index, bool render) override;
59     int32_t SetParameter(const Format &format) override;
60     int32_t SetCallback(const std::shared_ptr<AVCodecCallback> &callback) override;
61 
62     // IAVCodecEngineObs override
63     void OnError(int32_t errorType, int32_t errorCode) override;
64     void OnOutputFormatChanged(const Format &format) override;
65     void OnInputBufferAvailable(uint32_t index) override;
66     void OnOutputBufferAvailable(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) override;
67 
68 private:
69     int32_t Init();
70 
71     AVCodecStatus status_ = AVCODEC_UNINITIALIZED;
72     std::unique_ptr<IAVCodecEngine> codecEngine_;
73     std::shared_ptr<AVCodecCallback> codecCb_;
74     std::mutex mutex_;
75     std::mutex cbMutex_;
76 };
77 } // namespace Media
78 } // namespace OHOS
79 #endif // AVCODEC_SERVER_H