• 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 OH_VEF_VIDEO_DECODER_H
17 #define OH_VEF_VIDEO_DECODER_H
18 
19 #include <string>
20 #include "ffrt.h"
21 #include <native_avdemuxer.h>
22 #include <native_avsource.h>
23 #include <native_avformat.h>
24 #include "codec/video_decoder_engine.h"
25 #include "codec/video/decoder/video_demuxer.h"
26 #include "codec/common/codec_common.h"
27 #include "video_editor.h"
28 
29 namespace OHOS {
30 namespace Media {
31 
32 class VideoDecoder {
33 public:
34     VideoDecoder(uint64_t id, const CodecOnInData& packetReadFunc,
35         const CodecOnDecodeFrame& onDecodeFrameCallback, const CodecOnDecodeResult& onDecodeResultCallback);
36     ~VideoDecoder();
37 
38 public:
39     VEFError Init(OH_AVFormat* videoFormat);
40     VEFError SetNativeWindow(OHNativeWindow* surfaceWindow);
41     VEFError Start();
42     VEFError Stop();
43 
44 private:
45     VEFError CreateDecoder();
46     VEFError ConfigureDecoder(OH_AVFormat* videoFormat);
47     void CodecOnStreamChangedInner(OH_AVFormat* format);
48     void CodecOnNeedInputDataInner(OH_AVCodec* codec, uint32_t index, OH_AVMemory* data);
49     void CodecOnNewOutputData(OH_AVCodec* codec, uint32_t index, OH_AVMemory* data, OH_AVCodecBufferAttr* attr);
50 
51 private:
52     std::string logTag_ = "";
53     OH_AVCodec* decoder_{ nullptr };
54     std::string codecMime_ = "";
55     CodecOnInData packetReadFunc_{ nullptr };
56     CodecOnDecodeFrame onDecodeFrameCallback_{ nullptr };
57     CodecOnDecodeResult onDecodeResultCallback_{ nullptr };
58     CodecState state_{ CodecState::INIT };
59     ffrt::task_handle taskHandle_{ nullptr };
60 };
61 } // namespace Media
62 } // namespace OHOS
63 
64 #endif // OH_VEF_VIDEO_DECODER_H
65