• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 SAMPLE_QUEUE_UNIT_TEST_H
17 #define SAMPLE_QUEUE_UNIT_TEST_H
18 
19 
20 #include "gtest/gtest.h"
21 #include "buffer/avbuffer_queue.h"
22 #include "sample_queue.h"
23 
24 namespace OHOS {
25 namespace Media {
26 
27 class SampleQueueCallbackMock : public SampleQueueCallback {
28 public:
SampleQueueCallbackMock()29     explicit SampleQueueCallbackMock() {}
30     virtual ~SampleQueueCallbackMock() = default;
OnSelectBitrateOk(int64_t startPts,uint32_t bitRate)31     virtual Status OnSelectBitrateOk(int64_t startPts, uint32_t bitRate)
32     {
33         std::cout << "<===> OnSelectBitrateOk startPts=" << startPts << " ,bitRate=" << bitRate << std::endl;
34         switchPtsVec_.push_back(startPts);
35         return Status::OK;
36     }
OnSampleQueueBufferAvailable(uint32_t queueId)37     virtual Status OnSampleQueueBufferAvailable(uint32_t queueId)
38     {
39         OnAvailableSum_++;
40         return Status::OK;
41     }
OnSampleQueueBufferConsume(uint32_t queueId)42     virtual Status OnSampleQueueBufferConsume(uint32_t queueId)
43     {
44         OnConsumeSum_++;
45         return Status::OK;
46     }
47 
48     int32_t OnConsumeSum_ = 0;
49     int32_t OnAvailableSum_ = 0;
50     std::vector<uint64_t> switchPtsVec_;
51 };
52 
53 class SampleQueueUnitTest : public std::enable_shared_from_this<SampleQueueUnitTest>,
54                             public testing::Test {
55 public:
56 
57     static void SetUpTestCase(void);
58 
59     static void TearDownTestCase(void);
60 
61     void SetUp(void) override;
62 
63     void TearDown(void) override;
64 
65     Status InitLargeSampleQueue();
66 
67     Status InitNormalSampleQueue();
68 
69     Status SetCallback();
70 
71     Status UpdateBufferInfo(
72         const std::shared_ptr<AVBuffer>& buffer, int64_t pts, size_t bufferSize, bool isKeyFrame = false);
73 
74     void ProducerLoop(int64_t frameCount, int64_t frameIntervalMs, size_t bufferSize);
75 
76     void ConsumerLoop(int64_t frameCount, int64_t frameIntervalMs);
77 
78     std::shared_ptr<SampleQueue> sampleQueue_;
79 
80     std::shared_ptr<std::thread> producerThread_ = nullptr;
81 
82     uint32_t pushFrames_ = 0;
83 
84     bool isProducerThreadStop_ = false;
85 
86     std::shared_ptr<std::thread> consumerThread_ = nullptr;
87 
88     std::shared_ptr<SampleQueueCallbackMock> sqCb_;
89 };
90 }
91 }
92 
93 #endif