1 /* 2 * Copyright (c) 2023-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 OHOS_CAMERA_DPS_MPEG_MANAGER_H 17 #define OHOS_CAMERA_DPS_MPEG_MANAGER_H 18 19 #include "avcodec_video_encoder.h" 20 #include "ipc_file_descriptor.h" 21 #include "media_manager.h" 22 23 namespace OHOS { 24 namespace CameraStandard { 25 namespace DeferredProcessing { 26 class MpegManager : public std::enable_shared_from_this<MpegManager> { 27 public: 28 MpegManager(); 29 ~MpegManager(); 30 MpegManager(const MpegManager&) =delete; 31 MpegManager& operator=(const MpegManager&) = delete; 32 MpegManager(MediaManager&&) = delete; 33 MpegManager& operator=(MediaManager&&) = delete; 34 35 MediaManagerError Init(const std::string& requestId, const sptr<IPCFileDescriptor>& inputFd); 36 MediaManagerError UnInit(const MediaResult result); 37 sptr<Surface> GetSurface(); 38 uint64_t GetProcessTimeStamp(); 39 MediaManagerError NotifyEnd(); 40 MediaManagerError ReleaseBuffer(uint32_t index); 41 sptr<IPCFileDescriptor> GetResultFd(); 42 43 private: 44 class VideoCodecCallback; 45 46 MediaManagerError InitVideoCodec(); 47 void UnInitVideoCodec(); 48 void OnBufferAvailable(uint32_t index, const std::shared_ptr<AVBuffer>& buffer); 49 sptr<IPCFileDescriptor> GetFileFd(const std::string& requestId, int flags, const std::string& tag); 50 51 std::unique_ptr<MediaManager> mediaManager_ {nullptr}; 52 sptr<Surface> codecSurface_ {nullptr}; 53 std::shared_ptr<AVCodecVideoEncoder> encoder_ {nullptr}; 54 std::atomic_bool isRunning_ {false}; 55 std::unique_ptr<std::thread> processThread_ {nullptr}; 56 std::shared_ptr<MediaInfo> mediaInfo_ {nullptr}; 57 std::string outPath_; 58 std::string tempPath_; 59 sptr<IPCFileDescriptor> outputFd_ {nullptr}; 60 sptr<IPCFileDescriptor> tempFd_ {nullptr}; 61 MediaResult result_ {FAIL}; 62 }; 63 } // namespace DeferredProcessing 64 } // namespace CameraStandard 65 } // namespace OHOS 66 #endif // OHOS_CAMERA_DPS_MPEG_MANAGER_H