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 sptr<Surface> GetMakerSurface(); 39 uint64_t GetProcessTimeStamp(); 40 MediaManagerError NotifyEnd(); 41 sptr<IPCFileDescriptor> GetResultFd(); 42 void AddUserMeta(std::unique_ptr<MediaUserInfo> userInfo); 43 44 private: 45 class VideoCodecCallback; 46 class VideoMakerListener; 47 48 MediaManagerError InitVideoCodec(); 49 void UnInitVideoCodec(); 50 MediaManagerError ReleaseBuffer(uint32_t index); 51 MediaManagerError InitVideoMakerSurface(); 52 void UnInitVideoMaker(); 53 sptr<SurfaceBuffer> AcquireMakerBuffer(int64_t& timestamp); 54 MediaManagerError ReleaseMakerBuffer(sptr<SurfaceBuffer>& buffer); 55 void OnBufferAvailable(uint32_t index, const std::shared_ptr<AVBuffer>& buffer); 56 void OnMakerBufferAvailable(); 57 sptr<IPCFileDescriptor> GetFileFd(const std::string& requestId, int flags, const std::string& tag); 58 59 std::mutex mediaInfoMutex_; 60 std::mutex makerMutex_; 61 std::unique_ptr<MediaManager> mediaManager_ {nullptr}; 62 sptr<Surface> codecSurface_ {nullptr}; 63 sptr<Surface> makerSurface_ {nullptr}; 64 std::shared_ptr<AVCodecVideoEncoder> encoder_ {nullptr}; 65 std::atomic_bool isRunning_ {false}; 66 std::unique_ptr<std::thread> processThread_ {nullptr}; 67 std::shared_ptr<MediaInfo> mediaInfo_ {nullptr}; 68 std::string outPath_; 69 std::string tempPath_; 70 sptr<IPCFileDescriptor> outputFd_ {nullptr}; 71 sptr<IPCFileDescriptor> tempFd_ {nullptr}; 72 MediaResult result_ {FAIL}; 73 }; 74 } // namespace DeferredProcessing 75 } // namespace CameraStandard 76 } // namespace OHOS 77 #endif // OHOS_CAMERA_DPS_MPEG_MANAGER_H