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_ENGINE_IMPL_H 17 #define OH_VEF_VIDEO_DECODER_ENGINE_IMPL_H 18 19 #include <cstdint> 20 #include <string> 21 #include <list> 22 #include "native_avsource.h" 23 #include <native_avdemuxer.h> 24 #include <native_avcodec_videodecoder.h> 25 #include "video_decoder.h" 26 #include "video_demuxer.h" 27 #include "codec/audio/decoder/audio_decoder.h" 28 #include "codec/video_decoder_engine.h" 29 30 namespace OHOS { 31 namespace Media { 32 33 class VideoDecoderEngineImpl : public IVideoDecoderEngine { 34 public: 35 VideoDecoderEngineImpl(uint64_t id, int fd, VideoDecodeCallback* cb); 36 virtual ~VideoDecoderEngineImpl(); 37 38 public: 39 uint64_t GetId() const override; 40 VEFError SetVideoOutputWindow(OHNativeWindow* surfaceWindow) override; 41 void SetAudioOutputBufferQueue(std::shared_ptr<PcmBufferQueue>& queue) override; 42 VEFError StartDecode() override; 43 VEFError StopDecode() override; 44 OH_AVFormat* GetVideoFormat() override; 45 OH_AVFormat* GetAudioFormat() override; 46 int32_t GetRotation() const override; 47 int64_t GetVideoDuration() const override; 48 49 VEFError Init() override; 50 51 private: 52 VEFError InitDeMuxer(); 53 VEFError InitDecoder(); 54 VEFError InitAudioDecoder(); 55 VEFError ReadVideoPacket(OH_AVMemory* packet, OH_AVCodecBufferAttr* attr); 56 VEFError ReadAudioPacket(OH_AVMemory* packet, OH_AVCodecBufferAttr* attr); 57 void OnAudioDecodeFrame(uint64_t pts); 58 void OnAudioDecodeResult(CodecResult result); 59 void OnVideoDecoderFrame(uint64_t pts); 60 void OnVideoDecodeResult(CodecResult result); 61 void NotifyDecodeResult(); 62 63 private: 64 uint64_t id_ = 0; 65 int fd_ = -1; 66 std::string logTag_ = ""; 67 VideoDecodeCallback* cb_ { nullptr }; 68 std::shared_ptr<VideoDeMuxer> deMuxer_{ nullptr }; 69 std::shared_ptr<VideoDecoder> videoDecoder_ { nullptr }; 70 std::shared_ptr<AudioDecoder> audioDecoder_ { nullptr }; 71 CodecState audioDecoderState_{ CodecState::INIT }; 72 CodecState videoDecoderState_{ CodecState::INIT }; 73 }; 74 75 } // namespace Media 76 } // namespace OHOS 77 78 #endif // OH_VEF_VIDEO_DECODER_ENGINE_IMPL_H