• 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_inner_mock.h"
17 #include "securec.h"
18 #include "avsharedmemorybase.h"
19 
20 namespace OHOS {
21 namespace MediaAVCodec {
Destroy()22 int32_t AVMuxerInnerMock::Destroy()
23 {
24     if (muxer_ != nullptr) {
25         muxer_ = nullptr;
26         return AV_ERR_OK;
27     }
28     return AV_ERR_UNKNOWN;
29 }
30 
Start()31 int32_t AVMuxerInnerMock::Start()
32 {
33     if (muxer_ != nullptr) {
34         return muxer_->Start();
35     }
36     return AV_ERR_UNKNOWN;
37 }
38 
Stop()39 int32_t AVMuxerInnerMock::Stop()
40 {
41     if (muxer_ != nullptr) {
42         return muxer_->Stop();
43     }
44     return AV_ERR_UNKNOWN;
45 }
46 
AddTrack(int32_t & trackIndex,std::shared_ptr<FormatMock> & trackFormat)47 int32_t AVMuxerInnerMock::AddTrack(int32_t &trackIndex, std::shared_ptr<FormatMock> &trackFormat)
48 {
49     if (muxer_ != nullptr) {
50         auto formatMock = std::static_pointer_cast<AVFormatInnerMock>(trackFormat);
51         return muxer_->AddTrack(trackIndex, static_cast<MediaDescription>(formatMock->GetFormat()));
52     }
53     return AV_ERR_UNKNOWN;
54 }
55 
WriteSample(uint32_t trackIndex,const uint8_t * sample,const AVCodecBufferAttrMock & info)56 int32_t AVMuxerInnerMock::WriteSample(uint32_t trackIndex,
57     const uint8_t *sample, const AVCodecBufferAttrMock &info)
58 {
59     if (muxer_ != nullptr) {
60         std::shared_ptr<AVSharedMemoryBase> avSample =
61             std::make_shared<AVSharedMemoryBase>(info.size, AVSharedMemory::FLAGS_READ_ONLY, "sampleData");
62         (void)avSample->Init();
63         (void)memcpy_s(avSample->GetBase(), avSample->GetSize(), sample, info.size);
64         AVCodecBufferInfo sampleInfo;
65         sampleInfo.presentationTimeUs = info.pts;
66         sampleInfo.size = info.size;
67         sampleInfo.offset = info.offset;
68         AVCodecBufferFlag flag = static_cast<AVCodecBufferFlag>(info.flags);
69         return muxer_->WriteSample(trackIndex, avSample, sampleInfo, flag);
70     }
71     return AV_ERR_UNKNOWN;
72 }
73 
SetRotation(int32_t rotation)74 int32_t AVMuxerInnerMock::SetRotation(int32_t rotation)
75 {
76     if (muxer_ != nullptr) {
77         return muxer_->SetRotation(rotation);
78     }
79     return AV_ERR_UNKNOWN;
80 }
81 } // namespace MediaAVCodec
82 } // namespace OHOS