• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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_client.h"
17 #include "media_errors.h"
18 #include "media_log.h"
19 
20 namespace {
21     constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "AVMuxerClient"};
22 }
23 
24 namespace OHOS {
25 namespace Media {
Create(const sptr<IStandardAVMuxerService> & ipcProxy)26 std::shared_ptr<AVMuxerClient> AVMuxerClient::Create(const sptr<IStandardAVMuxerService> &ipcProxy)
27 {
28     std::shared_ptr<AVMuxerClient> avmuxerClient = std::make_shared<AVMuxerClient>(ipcProxy);
29     CHECK_AND_RETURN_RET_LOG(avmuxerClient != nullptr, nullptr, "Failed to create avmuxer client");
30     return avmuxerClient;
31 }
32 
AVMuxerClient(const sptr<IStandardAVMuxerService> & ipcProxy)33 AVMuxerClient::AVMuxerClient(const sptr<IStandardAVMuxerService> &ipcProxy)
34     : avmuxerProxy_(ipcProxy)
35 {
36     MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this));
37 }
38 
~AVMuxerClient()39 AVMuxerClient::~AVMuxerClient()
40 {
41     std::lock_guard<std::mutex> lock(mutex_);
42     if (avmuxerProxy_ != nullptr) {
43         (void)avmuxerProxy_->DestroyStub();
44         avmuxerProxy_ = nullptr;
45     }
46     MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances destroy", FAKE_POINTER(this));
47 }
48 
MediaServerDied()49 void AVMuxerClient::MediaServerDied()
50 {
51     std::lock_guard<std::mutex> lock(mutex_);
52     avmuxerProxy_ = nullptr;
53 }
54 
GetAVMuxerFormatList()55 std::vector<std::string> AVMuxerClient::GetAVMuxerFormatList()
56 {
57     std::lock_guard<std::mutex> lock(mutex_);
58     CHECK_AND_RETURN_RET_LOG(avmuxerProxy_ != nullptr, std::vector<std::string>(), "AVMuxer Service does not exist");
59     return avmuxerProxy_->GetAVMuxerFormatList();
60 }
61 
SetOutput(int32_t fd,const std::string & format)62 int32_t AVMuxerClient::SetOutput(int32_t fd, const std::string &format)
63 {
64     std::lock_guard<std::mutex> lock(mutex_);
65     CHECK_AND_RETURN_RET_LOG(avmuxerProxy_ != nullptr, MSERR_NO_MEMORY, "AVMuxer Service does not exist");
66     return avmuxerProxy_->SetOutput(fd, format);
67 }
68 
SetLocation(float latitude,float longitude)69 int32_t AVMuxerClient::SetLocation(float latitude, float longitude)
70 {
71     std::lock_guard<std::mutex> lock(mutex_);
72     CHECK_AND_RETURN_RET_LOG(avmuxerProxy_ != nullptr, MSERR_NO_MEMORY, "AVMuxer Service does not exist");
73     return avmuxerProxy_->SetLocation(latitude, longitude);
74 }
75 
SetRotation(int32_t rotation)76 int32_t AVMuxerClient::SetRotation(int32_t rotation)
77 {
78     std::lock_guard<std::mutex> lock(mutex_);
79     CHECK_AND_RETURN_RET_LOG(avmuxerProxy_ != nullptr, MSERR_NO_MEMORY, "AVMuxer Service does not exist");
80     return avmuxerProxy_->SetRotation(rotation);
81 }
82 
AddTrack(const MediaDescription & trackDesc,int32_t & trackId)83 int32_t AVMuxerClient::AddTrack(const MediaDescription &trackDesc, int32_t &trackId)
84 {
85     std::lock_guard<std::mutex> lock(mutex_);
86     CHECK_AND_RETURN_RET_LOG(avmuxerProxy_ != nullptr, MSERR_NO_MEMORY, "AVMuxer Service does not exist");
87     return avmuxerProxy_->AddTrack(trackDesc, trackId);
88 }
89 
Start()90 int32_t AVMuxerClient::Start()
91 {
92     std::lock_guard<std::mutex> lock(mutex_);
93     CHECK_AND_RETURN_RET_LOG(avmuxerProxy_ != nullptr, MSERR_NO_MEMORY, "AVMuxer Service does not exist");
94     return avmuxerProxy_->Start();
95 }
96 
WriteTrackSample(std::shared_ptr<AVSharedMemory> sampleData,const TrackSampleInfo & sampleInfo)97 int32_t AVMuxerClient::WriteTrackSample(std::shared_ptr<AVSharedMemory> sampleData, const TrackSampleInfo &sampleInfo)
98 {
99     std::lock_guard<std::mutex> lock(mutex_);
100     CHECK_AND_RETURN_RET_LOG(sampleData != nullptr, MSERR_INVALID_VAL, "sampleData is nullptr");
101     CHECK_AND_RETURN_RET_LOG(avmuxerProxy_ != nullptr, MSERR_NO_MEMORY, "AVMuxer Service does not exist");
102     return avmuxerProxy_->WriteTrackSample(sampleData, sampleInfo);
103 }
104 
Stop()105 int32_t AVMuxerClient::Stop()
106 {
107     std::lock_guard<std::mutex> lock(mutex_);
108     CHECK_AND_RETURN_RET_LOG(avmuxerProxy_ != nullptr, MSERR_NO_MEMORY, "AVMuxer Service does not exist");
109     return avmuxerProxy_->Stop();
110 }
111 
Release()112 void AVMuxerClient::Release()
113 {
114     std::lock_guard<std::mutex> lock(mutex_);
115     CHECK_AND_RETURN_LOG(avmuxerProxy_ != nullptr, "AVMuxer Service does not exist");
116     avmuxerProxy_->Release();
117 }
118 }  // namespace Media
119 }  // namespace OHOS