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