1fa7767c5Sopenharmony_ci/*
2fa7767c5Sopenharmony_ci * Copyright (c) 2022-2022 Huawei Device Co., Ltd.
3fa7767c5Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4fa7767c5Sopenharmony_ci * you may not use this file except in compliance with the License.
5fa7767c5Sopenharmony_ci * You may obtain a copy of the License at
6fa7767c5Sopenharmony_ci *
7fa7767c5Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8fa7767c5Sopenharmony_ci *
9fa7767c5Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10fa7767c5Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11fa7767c5Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12fa7767c5Sopenharmony_ci * See the License for the specific language governing permissions and
13fa7767c5Sopenharmony_ci * limitations under the License.
14fa7767c5Sopenharmony_ci */
15fa7767c5Sopenharmony_ci
16fa7767c5Sopenharmony_ci#ifndef HISTREAMER_PIPELINE_COMMON_MEDIA_STAT_STUB_H
17fa7767c5Sopenharmony_ci#define HISTREAMER_PIPELINE_COMMON_MEDIA_STAT_STUB_H
18fa7767c5Sopenharmony_ci
19fa7767c5Sopenharmony_ci#include <cstdint>
20fa7767c5Sopenharmony_ci#include <atomic>
21fa7767c5Sopenharmony_ci#include <vector>
22fa7767c5Sopenharmony_ci
23fa7767c5Sopenharmony_ci#include "foundation/osal/thread/mutex.h"
24fa7767c5Sopenharmony_ci#include "pipeline/core/event.h"
25fa7767c5Sopenharmony_ci
26fa7767c5Sopenharmony_cinamespace OHOS {
27fa7767c5Sopenharmony_cinamespace Media {
28fa7767c5Sopenharmony_ciclass MediaStatStub {
29fa7767c5Sopenharmony_cipublic:
30fa7767c5Sopenharmony_ci    struct MediaStat {
31fa7767c5Sopenharmony_ci        std::string reporter;
32fa7767c5Sopenharmony_ci        std::atomic<bool> completeEventReceived {false};
33fa7767c5Sopenharmony_ci        explicit MediaStat(std::string rep) : reporter(std::move(rep))
34fa7767c5Sopenharmony_ci        {
35fa7767c5Sopenharmony_ci        }
36fa7767c5Sopenharmony_ci        MediaStat(const MediaStat& other)
37fa7767c5Sopenharmony_ci            : reporter(other.reporter), completeEventReceived(other.completeEventReceived.load())
38fa7767c5Sopenharmony_ci        {
39fa7767c5Sopenharmony_ci        }
40fa7767c5Sopenharmony_ci        MediaStat& operator=(const MediaStat& other)
41fa7767c5Sopenharmony_ci        {
42fa7767c5Sopenharmony_ci            reporter = other.reporter;
43fa7767c5Sopenharmony_ci            completeEventReceived = other.completeEventReceived.load();
44fa7767c5Sopenharmony_ci            return *this;
45fa7767c5Sopenharmony_ci        }
46fa7767c5Sopenharmony_ci    };
47fa7767c5Sopenharmony_ci
48fa7767c5Sopenharmony_ci    MediaStatStub() = default;
49fa7767c5Sopenharmony_ci    void Reset();
50fa7767c5Sopenharmony_ci    void Append(const std::string& reporter);
51fa7767c5Sopenharmony_ci    void ReceiveEvent(const Event& event);
52fa7767c5Sopenharmony_ci    bool IsEventCompleteAllReceived();
53fa7767c5Sopenharmony_ci    void ResetEventCompleteAllReceived();
54fa7767c5Sopenharmony_ci
55fa7767c5Sopenharmony_ciprivate:
56fa7767c5Sopenharmony_ci    OSAL::Mutex mediaStatMutex_ {};
57fa7767c5Sopenharmony_ci    std::vector<MediaStat> mediaStats_;
58fa7767c5Sopenharmony_ci};
59fa7767c5Sopenharmony_ci} // Media
60fa7767c5Sopenharmony_ci} // OHOS
61fa7767c5Sopenharmony_ci#endif // HISTREAMER_PIPELINE_COMMON_MEDIA_STAT_STUB_H
62