• 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 <memory>
17 #include <vector>
18 #include <map>
19 #include <sys/stat.h>
20 #include <string>
21 #include "avsource_demo.h"
22 
23 namespace OHOS {
24 namespace MediaAVCodec {
AVSourceDemo()25 AVSourceDemo::AVSourceDemo()
26 {
27     printf("AVSourceDemo construtor\n");
28 }
29 
~AVSourceDemo()30 AVSourceDemo::~AVSourceDemo()
31 {
32     printf("AVSourceDemo deconstrutor\n");
33 }
34 
CreateWithURI(char * uri)35 int32_t AVSourceDemo::CreateWithURI(char* uri)
36 {
37     this->avsource_ = OH_AVSource_CreateWithURI(uri);
38     if (!avsource_) {
39         printf("OH_AVSource_CreateWithURI is failed\n");
40         return -1;
41     }
42     return 0;
43 }
44 
GetFileSize(const std::string & fileName)45 size_t AVSourceDemo::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 AVSourceDemo::CreateWithFD(int32_t fd, int64_t offset, int64_t size)
58 {
59     this->avsource_ = OH_AVSource_CreateWithFD(fd, offset, size);
60     if (!avsource_) {
61         printf("OH_AVSource_CreateWithFD is failed\n");
62         return -1;
63     }
64     return 0;
65 }
GetAVSource()66 OH_AVSource* AVSourceDemo::GetAVSource()
67 {
68     return this->avsource_;
69 }
70 
Destroy()71 int32_t AVSourceDemo::Destroy()
72 {
73     int32_t ret = static_cast<int32_t>(OH_AVSource_Destroy(this->avsource_));
74     if (ret != 0) {
75         printf("destroy failed\n");
76         return ret;
77     }
78     return ret;
79 }
80 
GetSourceFormat()81 OH_AVFormat* AVSourceDemo::GetSourceFormat()
82 {
83     this->avformat_ = OH_AVSource_GetSourceFormat(this->avsource_);
84     if (!this->avformat_) {
85         printf("OH_AVSource_GetSourceFormat is failed\n");
86         return nullptr;
87     }
88     return this->avformat_;
89 }
90 
GetTrackFormat(uint32_t trackIndex)91 OH_AVFormat* AVSourceDemo::GetTrackFormat(uint32_t trackIndex)
92 {
93     this->trackFormat_ = OH_AVSource_GetTrackFormat(this->avsource_, trackIndex);
94     if (!this->trackFormat_) {
95         printf("OH_AVSourceTrack_GetTrackFormat is failed\n");
96         return nullptr;
97     }
98     return this->trackFormat_;
99 }
100 }  // namespace MediaAVCodec
101 }  // namespace OHOS
102