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 #ifndef HISTREAMER_ST_TEST_PLAYER 16 #define HISTREAMER_ST_TEST_PLAYER 17 18 #include <cstring> 19 #include <format.h> 20 #include <string> 21 #include <vector> 22 #include "media_data_source_impl.h" 23 #include "plugin/common/plugin_types.h" 24 #include "securec.h" 25 #include "player.h" 26 27 #ifndef WIN32 28 #define HST_TEST(UtObject, function, level) HWTEST_F(UtObject, function, level) 29 #else 30 #define HST_TEST(UtObject, function, level) TEST_F(UtObject, function) 31 #endif 32 33 namespace OHOS::Media::Test { 34 enum class TestSourceType : int32_t { 35 URI = 0, 36 STREAM = 1 37 }; 38 39 class TestSource { 40 public: 41 static TestSource CreateTestSource(std::string& url, TestSourceType type, Plugin::Seekable seekable); TestSource(std::string url)42 explicit TestSource(std::string url) : url_(std::move(url)), type_(TestSourceType::URI) {} TestSource(std::string url,Plugin::Seekable seekable)43 TestSource(std::string url, Plugin::Seekable seekable) : url_(std::move(url)), 44 type_(TestSourceType::STREAM), seekable_(seekable) {} 45 46 std::string url_; 47 TestSourceType type_; 48 Plugin::Seekable seekable_ {Plugin::Seekable::INVALID}; 49 }; 50 51 class TestPlayer { 52 public: 53 static std::unique_ptr<TestPlayer> Create(); 54 virtual ~TestPlayer() = default; 55 virtual int32_t SetSource(const TestSource& source) = 0; 56 virtual int32_t SetSingleLoop(bool loop) = 0; 57 virtual bool IsPlaying() = 0; 58 virtual int32_t Prepare() = 0; 59 virtual int32_t Play() = 0; 60 virtual int32_t Pause() = 0; 61 virtual int32_t Stop() = 0; 62 virtual int32_t Reset() = 0; 63 virtual int32_t Release() = 0; 64 virtual int32_t Seek(int64_t timeMs, PlayerSeekMode mode = PlayerSeekMode::SEEK_NEXT_SYNC) = 0; 65 virtual int32_t GetCurrentTime(int64_t& currentMs) = 0; 66 virtual int32_t GetDuration(int64_t& durationMs) = 0; 67 virtual int32_t SetVolume(float leftVolume, float rightVolume) = 0; 68 virtual int32_t GetAudioTrackInfo(std::vector<Format> &audioTrack) = 0; 69 virtual int32_t SetPlaybackSpeed(PlaybackRateMode mode) = 0; 70 virtual int32_t GetPlaybackSpeed(PlaybackRateMode &mode) = 0; 71 }; 72 } 73 #endif