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_sample.h"
17 #include "nocopyable.h"
18 using namespace std;
19
20 namespace OHOS {
21 namespace MediaAVCodec {
AVMuxerSample()22 AVMuxerSample::AVMuxerSample()
23 {
24 }
25
~AVMuxerSample()26 AVMuxerSample::~AVMuxerSample()
27 {
28 }
29
CreateMuxer(int32_t fd,const OH_AVOutputFormat format)30 bool AVMuxerSample::CreateMuxer(int32_t fd, const OH_AVOutputFormat format)
31 {
32 muxer_ = AVMuxerMockFactory::CreateMuxer(fd, format);
33 return muxer_ != nullptr;
34 }
35
Destroy()36 int32_t AVMuxerSample::Destroy()
37 {
38 if (muxer_ == nullptr) {
39 return AV_ERR_INVALID_VAL;
40 }
41 return muxer_->Destroy();
42 }
43
Start()44 int32_t AVMuxerSample::Start()
45 {
46 if (muxer_ == nullptr) {
47 return AV_ERR_INVALID_VAL;
48 }
49 return muxer_->Start();
50 }
51
Stop()52 int32_t AVMuxerSample::Stop()
53 {
54 if (muxer_ == nullptr) {
55 return AV_ERR_INVALID_VAL;
56 }
57 return muxer_->Stop();
58 }
59
AddTrack(int32_t & trackIndex,std::shared_ptr<FormatMock> & trackFormat)60 int32_t AVMuxerSample::AddTrack(int32_t &trackIndex, std::shared_ptr<FormatMock> &trackFormat)
61 {
62 if (muxer_ == nullptr) {
63 return AV_ERR_INVALID_VAL;
64 }
65 return muxer_->AddTrack(trackIndex, trackFormat);
66 }
67
WriteSample(uint32_t trackIndex,const uint8_t * sample,const OH_AVCodecBufferAttr & info)68 int32_t AVMuxerSample::WriteSample(uint32_t trackIndex, const uint8_t *sample, const OH_AVCodecBufferAttr &info)
69 {
70 if (muxer_ == nullptr) {
71 return AV_ERR_INVALID_VAL;
72 }
73 return muxer_->WriteSample(trackIndex, sample, info);
74 }
75
WriteSampleBuffer(uint32_t trackIndex,const OH_AVBuffer * sample)76 int32_t AVMuxerSample::WriteSampleBuffer(uint32_t trackIndex, const OH_AVBuffer *sample)
77 {
78 if (muxer_ == nullptr) {
79 return AV_ERR_INVALID_VAL;
80 }
81 return muxer_->WriteSampleBuffer(trackIndex, sample);
82 }
83
SetTimedMetadata()84 int32_t AVMuxerSample::SetTimedMetadata()
85 {
86 if (muxer_ == nullptr) {
87 return AV_ERR_INVALID_VAL;
88 }
89 return muxer_->SetTimedMetadata();
90 }
91
SetRotation(int32_t rotation)92 int32_t AVMuxerSample::SetRotation(int32_t rotation)
93 {
94 if (muxer_ == nullptr) {
95 return AV_ERR_INVALID_VAL;
96 }
97 return muxer_->SetRotation(rotation);
98 }
99 } // namespace MediaAVCodec
100 } // namespace OHOS
101