• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 "media_source_ffi.h"
17 #include "cj_avplayer_utils.h"
18 #include "player.h"
19 
20 using namespace OHOS::FFI;
21 
22 namespace OHOS {
23 namespace Media {
ConvertArrHeaders(ArrHeaders & headers)24 std::map<std::string, std::string> ConvertArrHeaders(ArrHeaders &headers)
25 {
26     std::map<std::string, std::string> mapHeaders;
27     for (int64_t i = 0; i < headers.size; i++) {
28         auto key = std::string(headers.headers[i].key);
29         auto value = std::string(headers.headers[i].value);
30         mapHeaders.insert({key, value});
31     }
32     return mapHeaders;
33 }
34 
35 extern "C" {
FfiMediaCreateMediaSourceWithUrl(char * url,ArrHeaders headers,int32_t * errCode)36 int64_t FfiMediaCreateMediaSourceWithUrl(char *url, ArrHeaders headers, int32_t *errCode)
37 {
38     auto mediaSrcImpl = FFIData::Create<CJMediaSource>(std::string(url), ConvertArrHeaders(headers));
39     if (mediaSrcImpl == nullptr) {
40         *errCode = MSERR_EXT_API9_NO_MEMORY;
41         return INVALID_ID;
42     }
43     return mediaSrcImpl->GetID();
44 }
45 } // extern "C"
46 
CJMediaSource(std::string sourceUrl,std::map<std::string,std::string> sourceHeader)47 CJMediaSource::CJMediaSource(std::string sourceUrl, std::map<std::string, std::string> sourceHeader)
48 {
49     AVMediaSource mediaSrc(sourceUrl, sourceHeader);
50     mediaSource = std::make_shared<AVMediaSource>(mediaSrc);
51 }
52 } // namespace Media
53 } // namespace OHOS