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 <sys/stat.h>
17 #include <string>
18 #include "inner_source_demo.h"
19
20 using namespace std;
21 using namespace OHOS::MediaAVCodec;
22
23 namespace OHOS {
24 namespace MediaAVCodec {
25 using namespace Media;
InnerSourceDemo()26 InnerSourceDemo::InnerSourceDemo()
27 {
28 printf("SourceDemo ()\n");
29 }
30
~InnerSourceDemo()31 InnerSourceDemo::~InnerSourceDemo()
32 {
33 printf("~SourceDemo ()\n");
34 }
35
CreateWithURI(const std::string & uri)36 int32_t InnerSourceDemo::CreateWithURI(const std::string& uri)
37 {
38 this->avsource_ = AVSourceFactory::CreateWithURI(uri.c_str());
39 if (!avsource_) {
40 printf("Source is null\n");
41 return -1;
42 }
43 return 0;
44 }
45
GetFileSize(const std::string & fileName)46 size_t InnerSourceDemo::GetFileSize(const std::string& fileName)
47 {
48 size_t fileSize = 0;
49 if (!fileName.empty()) {
50 struct stat fileStatus {};
51 if (stat(fileName.c_str(), &fileStatus) == 0) {
52 fileSize = static_cast<size_t>(fileStatus.st_size);
53 }
54 }
55 return fileSize;
56 }
57
CreateWithFD(int32_t fd,int64_t offset,int64_t size)58 int32_t InnerSourceDemo::CreateWithFD(int32_t fd, int64_t offset, int64_t size)
59 {
60 this->avsource_ = AVSourceFactory::CreateWithFD(fd, offset, size);
61 if (!avsource_) {
62 printf("Source is null\n");
63 return -1;
64 }
65 return 0;
66 }
67
GetSourceFormat()68 Format InnerSourceDemo::GetSourceFormat()
69 {
70 if (this->avsource_ != nullptr) {
71 int32_t ret = this->avsource_->GetSourceFormat(source_format_);
72 if (ret != 0) {
73 printf("GetSourceFormat is failed\n");
74 }
75 }
76 return source_format_;
77 }
78
GetTrackFormat(uint32_t trackIndex)79 Format InnerSourceDemo::GetTrackFormat(uint32_t trackIndex)
80 {
81 if (this->avsource_ != nullptr) {
82 int32_t ret = this->avsource_->GetTrackFormat(track_format_, trackIndex);
83 if (ret != 0) {
84 printf("GetTrackFormat is failed\n");
85 }
86 }
87 return track_format_;
88 }
89 } // namespace MediaAVCodec
90 } // namespace OHOS
91