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 #include "sample_base.h" 17 #include "video_decoder_sample.h" 18 #include "video_encoder_sample.h" 19 #include "av_codec_sample_log.h" 20 #include "av_codec_sample_error.h" 21 #include "yuv_viewer.h" 22 23 namespace { 24 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_TEST, "SampleBase"}; 25 } 26 27 namespace OHOS { 28 namespace MediaAVCodec { 29 namespace Sample { WaitForSampleDone()30int32_t SampleBase::WaitForSampleDone() 31 { 32 AVCODEC_LOGI("In"); 33 std::unique_lock<std::mutex> lock(mutex_); 34 doneCond_.wait(lock); 35 AVCODEC_LOGI("Done"); 36 return AVCODEC_SAMPLE_ERR_OK; 37 } 38 NotifySampleDone()39int32_t SampleBase::NotifySampleDone() 40 { 41 std::unique_lock<std::mutex> lock(mutex_); 42 AVCODEC_LOGI(">>"); 43 doneCond_.notify_all(); 44 return AVCODEC_SAMPLE_ERR_OK; 45 } 46 CreateSample(const SampleInfo & info)47std::shared_ptr<SampleBase> SampleFactory::CreateSample(const SampleInfo &info) 48 { 49 std::shared_ptr<SampleBase> sample; 50 51 switch (info.sampleType) { 52 case SampleType::VIDEO_SAMPLE: 53 sample = (info.codecType & 0b10) ? // 0b10: Video encoder mask 54 std::static_pointer_cast<SampleBase>(std::make_shared<VideoEncoderSample>()) : 55 std::static_pointer_cast<SampleBase>(std::make_shared<VideoDecoderSample>()); 56 break; 57 case SampleType::YUV_VIEWER: 58 sample = std::static_pointer_cast<SampleBase>(std::make_shared<YuvViewer>()); 59 break; 60 default: 61 AVCODEC_LOGE("Not supported sample type, type: %{public}d", info.sampleType); 62 break; 63 } 64 return sample; 65 } 66 } // Sample 67 } // MediaAVCodec 68 } // OHOS