• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 #include "avmuxer_capi_mock.h"
17 #include "securec.h"
18 #include "avsharedmemorybase.h"
19 
20 namespace OHOS {
21 namespace MediaAVCodec {
Destroy()22 int32_t AVMuxerCapiMock::Destroy()
23 {
24     int ret = OH_AVMuxer_Destroy(muxer_);
25     if (ret != AV_ERR_OK) {
26         return ret;
27     }
28     muxer_ = nullptr;
29     return AV_ERR_OK;
30 }
31 
Start()32 int32_t AVMuxerCapiMock::Start()
33 {
34     return OH_AVMuxer_Start(muxer_);
35 }
36 
Stop()37 int32_t AVMuxerCapiMock::Stop()
38 {
39     return OH_AVMuxer_Stop(muxer_);
40 }
41 
AddTrack(int32_t & trackIndex,std::shared_ptr<FormatMock> & trackFormat)42 int32_t AVMuxerCapiMock::AddTrack(int32_t &trackIndex, std::shared_ptr<FormatMock> &trackFormat)
43 {
44     auto formatMock = std::static_pointer_cast<AVFormatCapiMock>(trackFormat);
45     return OH_AVMuxer_AddTrack(muxer_, &trackIndex, formatMock->GetFormat());
46 }
47 
WriteSample(uint32_t trackIndex,const uint8_t * sample,const AVCodecBufferAttrMock & info)48 int32_t AVMuxerCapiMock::WriteSample(uint32_t trackIndex,
49     const uint8_t *sample, const AVCodecBufferAttrMock &info)
50 {
51     int32_t ret = AV_ERR_NO_MEMORY;
52     OH_AVMemory *avSample = OH_AVMemory_Create(info.size);
53     uint8_t *data = OH_AVMemory_GetAddr(avSample);
54     int32_t size = OH_AVMemory_GetSize(avSample);
55     if (memcpy_s(data, size, sample, info.size) == EOK) {
56         OH_AVCodecBufferAttr bufferAttr;
57         bufferAttr.pts = info.pts;
58         bufferAttr.size = info.size;
59         bufferAttr.offset = info.offset;
60         bufferAttr.flags = info.flags;
61         ret = OH_AVMuxer_WriteSample(muxer_, trackIndex, avSample, bufferAttr);
62     }
63     (void)OH_AVMemory_Destroy(avSample);
64     return ret;
65 }
66 
SetRotation(int32_t rotation)67 int32_t AVMuxerCapiMock::SetRotation(int32_t rotation)
68 {
69     return OH_AVMuxer_SetRotation(muxer_, rotation);
70 }
71 } // namespace MediaAVCodec
72 } // namespace OHOS