1 /* 2 * Copyright (c) 2021 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 PLAYER_LITE_TEST_H 17 #define PLAYER_LITE_TEST_H 18 #include <sys/prctl.h> 19 #include <fcntl.h> 20 #include <climits> 21 #include "securec.h" 22 #include "gtest/gtest.h" 23 #include "source.h" 24 #include "player.h" 25 #include "format.h" 26 #include "fstream" 27 #include "iostream" 28 #include "thread" 29 #include "unistd.h" 30 31 namespace OHOS { 32 using OHOS::Media::Player; 33 using OHOS::Media::PlayerSeekMode; 34 using OHOS::Media::Source; 35 using OHOS::Media::Format; 36 using OHOS::Media::StreamSource; 37 using OHOS::Media::StreamCallback; 38 using OHOS::Media::SourceType; 39 using OHOS::Media::PlayerCallback; 40 41 using namespace std; 42 using namespace OHOS::Media; 43 using namespace testing::ext; 44 45 const int FILE_PATH_LEN = 2048; 46 47 class StreamSourceSample; 48 using TestSample = struct TagTestSample { 49 std::shared_ptr<Player> adaptr; 50 pthread_t process; 51 pthread_mutex_t mutex; 52 int32_t isThreadRunning; 53 int32_t sourceType; 54 char filePath[FILE_PATH_LEN]; 55 std::shared_ptr<StreamSourceSample> streamSample; 56 }; 57 58 using IdleBuffer = struct TagIdleBuffer { 59 size_t idx; 60 size_t offset; 61 size_t size; 62 }; 63 64 class StreamSourceSample : public StreamSource { 65 public: 66 StreamSourceSample(void); 67 ~StreamSourceSample(void); 68 void OnBufferAvailable(size_t index, size_t offset, size_t size); 69 void SetStreamCallback(const std::shared_ptr<StreamCallback> &callback); 70 uint8_t *GetBufferAddress(size_t idx); 71 void QueueBuffer(size_t index, size_t offset, size_t size, int64_t timestampUs, uint32_t flags); 72 int GetAvailableBuffer(IdleBuffer *buffer); 73 std::weak_ptr<StreamCallback> m_callBack; 74 pthread_mutex_t m_mutex; 75 private: 76 std::vector<IdleBuffer> aviableBuffer; 77 }; 78 79 void *StreamProcess(const void *arg); 80 void SetSchParam(void); 81 82 const int32_t HI_SUCCESS = 0; 83 const int32_t HI_FAILURE = -1; 84 static TagTestSample g_tagTestSample; 85 static Surface *g_surface = Surface::CreateSurface(); 86 } // namespace OHOS 87 #endif // PLAYER_LITE_TEST_H