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