1 /* 2 * Copyright (C) 2021 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 RECORDER_PIPELINE_BUILDER_H 17 #define RECORDER_PIPELINE_BUILDER_H 18 19 #include <memory> 20 #include "nocopyable.h" 21 #include "recorder_inner_defines.h" 22 #include "recorder_pipeline.h" 23 #include "recorder_element.h" 24 #include "recorder_pipeline_link_helper.h" 25 26 namespace OHOS { 27 namespace Media { 28 class RecorderPipelineBuilder : public NoCopyable { 29 public: 30 RecorderPipelineBuilder(int32_t appUid, int32_t appPid, uint32_t appTokenId); 31 ~RecorderPipelineBuilder(); 32 33 int32_t SetSource(const RecorderSourceDesc &desc); 34 int32_t SetOutputFormat(OutputFormatType formatType); 35 int32_t Configure(int32_t sourceId, const RecorderParam ¶m); 36 int32_t Build(std::shared_ptr<RecorderPipeline> &pipeline); 37 void Reset(); 38 39 private: 40 int32_t SetVideoSource(const RecorderSourceDesc &desc); 41 int32_t SetAudioSource(const RecorderSourceDesc &desc); 42 int32_t CreateMuxSink(); 43 std::shared_ptr<RecorderElement> CreateElement( 44 const std::string &name, const RecorderSourceDesc &desc, bool isSource); 45 void EnsureSourceOrder(bool isVideo); 46 int32_t CheckConfigure(int32_t sourceId, const RecorderParam ¶m); 47 int32_t CheckPipeline(); 48 49 int32_t ExecuteLink(); 50 51 std::shared_ptr<RecorderPipelineDesc> pipelineDesc_; 52 std::shared_ptr<RecorderPipeline> pipeline_; 53 std::shared_ptr<RecorderElement> muxSink_; 54 std::shared_ptr<RecorderElement> videoSrcElem_; 55 std::shared_ptr<RecorderElement> videoEncElem_; 56 std::shared_ptr<RecorderElement> videoParseElem_; 57 std::shared_ptr<RecorderElement> videoConverElem_; 58 59 bool outputFormatConfiged_ = false; 60 bool needVideoParse_ = false; 61 std::unique_ptr<RecorderPipelineLinkHelper> linkHelper_; 62 size_t videoSrcCount_ = 0; 63 size_t otherSrcCount_ = 0; 64 int32_t currentVideoSourceType_ = VideoSourceType::VIDEO_SOURCE_BUTT; 65 int32_t appUid_; 66 int32_t appPid_; 67 uint32_t appTokenId_; 68 }; 69 } // namespace Media 70 } // namespace OHOS 71 #endif 72