1 /*
2  * Copyright (c) 2022-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 #ifndef HISTREAMER_PIPELINE_COMMON_MEDIA_STAT_STUB_H
17 #define HISTREAMER_PIPELINE_COMMON_MEDIA_STAT_STUB_H
18 
19 #include <cstdint>
20 #include <atomic>
21 #include <vector>
22 
23 #include "foundation/osal/thread/mutex.h"
24 #include "pipeline/core/event.h"
25 
26 namespace OHOS {
27 namespace Media {
28 class MediaStatStub {
29 public:
30     struct MediaStat {
31         std::string reporter;
32         std::atomic<bool> completeEventReceived {false};
MediaStatMediaStat33         explicit MediaStat(std::string rep) : reporter(std::move(rep))
34         {
35         }
MediaStatMediaStat36         MediaStat(const MediaStat& other)
37             : reporter(other.reporter), completeEventReceived(other.completeEventReceived.load())
38         {
39         }
40         MediaStat& operator=(const MediaStat& other)
41         {
42             reporter = other.reporter;
43             completeEventReceived = other.completeEventReceived.load();
44             return *this;
45         }
46     };
47 
48     MediaStatStub() = default;
49     void Reset();
50     void Append(const std::string& reporter);
51     void ReceiveEvent(const Event& event);
52     bool IsEventCompleteAllReceived();
53     void ResetEventCompleteAllReceived();
54 
55 private:
56     OSAL::Mutex mediaStatMutex_ {};
57     std::vector<MediaStat> mediaStats_;
58 };
59 } // Media
60 } // OHOS
61 #endif // HISTREAMER_PIPELINE_COMMON_MEDIA_STAT_STUB_H
62