• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "codec/common/codec_decoder.h"
17 #include "codec/util/codec_util.h"
18 #include "media_log.h"
19 
20 namespace OHOS {
21 namespace Media {
22 namespace {
23 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_VIDEOEDITOR, "VideoEditorDecode"};
24 }
25 
CodecDecoder(uint64_t id,std::string logTag)26 CodecDecoder::CodecDecoder(uint64_t id, std::string logTag)
27     : id_(id), logTag_(logTag + " " + std::to_string(id))
28 {
29 }
30 
~CodecDecoder()31 CodecDecoder::~CodecDecoder()
32 {
33 }
34 
GetAVCodecAsyncCallback()35 OH_AVCodecAsyncCallback CodecDecoder::GetAVCodecAsyncCallback()
36 {
37     auto CodecOnErrorImpl = [](OH_AVCodec* codec, int32_t errorCode, void* context) {
38         auto error = static_cast<OH_AVErrCode>(errorCode);
39         CodecDecoder* decoder = static_cast<CodecDecoder*>(context);
40         if (decoder == nullptr) {
41             MEDIA_LOGE("decoder CodecOnError, context is nullptr, error: %{public}d(%{public}s).", error,
42                 CodecUtil::GetCodecErrorStr(error));
43             return;
44         }
45         decoder->CodecOnErrorInner(codec, errorCode);
46     };
47     auto CodecOnStreamChangedImpl = [](OH_AVCodec*, OH_AVFormat* format, void* context) {
48         CodecDecoder* decoder = static_cast<CodecDecoder*>(context);
49         if (decoder == nullptr) {
50             MEDIA_LOGE("decoder CodecOnStreamChanged, context is nullptr.");
51             return;
52         }
53         decoder->CodecOnStreamChangedInner(format);
54     };
55     auto CodecOnNeedInputDataImpl = [](OH_AVCodec* codec, uint32_t index, OH_AVMemory* data, void* context) {
56         CodecDecoder* decoder = static_cast<CodecDecoder*>(context);
57         if (decoder == nullptr) {
58             MEDIA_LOGE("decoder CodecOnNeedInputData, context is nullptr.");
59             return;
60         }
61         decoder->CodecOnNeedInputDataInner(codec, index, data);
62     };
63     auto CodecOnNewOutputDataImpl = [](OH_AVCodec* codec, uint32_t index, OH_AVMemory* data, OH_AVCodecBufferAttr* attr,
64         void* context) {
65         CodecDecoder* decoder = static_cast<CodecDecoder*>(context);
66         if (decoder == nullptr) {
67             MEDIA_LOGE("decoder CodecOnNewOutputData, context is nullptr.");
68             return;
69         }
70         decoder->CodecOnNewOutputDataInner(codec, index, data, attr);
71     };
72     // 设置回调
73     return { CodecOnErrorImpl, CodecOnStreamChangedImpl, CodecOnNeedInputDataImpl, CodecOnNewOutputDataImpl };
74 }
75 } // namespace Media
76 } // namespace OHOS