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 VIDEO_STREAM_PLAYER_H 17 #define VIDEO_STREAM_PLAYER_H 18 19 #include <set> 20 21 #include "surface.h" 22 #include "meta/format.h" 23 #include "lpp_audio_streamer.h" 24 #include "lpp_common.h" 25 26 namespace OHOS { 27 namespace Media { 28 29 class VideoStreamerKeys { 30 public: 31 static constexpr std::string_view LPP_CURRENT_POSITION = "current_position"; 32 static constexpr std::string_view LPP_VIDEO_MAX_BUFFER_SIZE = "lpp_video_max_buffer_size"; 33 static constexpr std::string_view LPP_VIDEO_MAX_FRAME_NUM = "lpp_video_max_frame_num"; 34 static constexpr std::string_view LPP_VIDEO_TARGET_PTS = "lpp_video_target_pts"; 35 static constexpr std::string_view LPP_VIDEO_IS_TIMEOUT = "lpp_video_is_timeout"; 36 }; 37 38 enum VideoStreamerOnInfoType : int32_t { 39 VIDEO_INFO_TYPE_LPP_DATA_NEEDED, 40 VIDEO_INFO_TYPE_LPP_ANCHOR_UPDATED, 41 VIDEO_INFO_TYPE_LPP_TARGET_ARRIVED, 42 VIDEO_INFO_TYPE_LPP_RENDER_STARTED, 43 VIDEO_INFO_TYPE_LPP_EOS, 44 VIDEO_INFO_TYPE_LPP_FIRST_FRAME_READY, 45 VIDEO_INFO_TYPE_LPP_STREAM_CHANGED, 46 }; 47 48 class VideoStreamerCallback { 49 public: 50 virtual ~VideoStreamerCallback() = default; 51 52 virtual void OnError(int32_t errorCode, const std::string &errorMsg) = 0; 53 54 virtual void OnInfo(VideoStreamerOnInfoType type, int32_t extra, const Format &infoBody) = 0; 55 }; 56 57 class VideoStreamer { 58 public: 59 virtual ~VideoStreamer() = default; 60 61 virtual int32_t SetParameter(const Format ¶m) = 0; 62 63 virtual int32_t Configure(const Format ¶m) = 0; 64 65 virtual int32_t SetOutputSurface(sptr<Surface> surface) = 0; 66 67 virtual int32_t Prepare() = 0; 68 69 virtual int32_t StartDecode() = 0; 70 71 virtual int32_t StartRender() = 0; 72 73 virtual int32_t Start() = 0; 74 75 virtual int32_t Pause() = 0; 76 77 virtual int32_t Resume() = 0; 78 79 virtual int32_t Flush() = 0; 80 81 virtual int32_t Stop() = 0; 82 83 virtual int32_t Reset() = 0; 84 85 virtual int32_t Release() = 0; 86 87 virtual int32_t SetSyncAudioStreamer(std::shared_ptr<AudioStreamer> audioStreamer) = 0; 88 89 virtual int32_t SetTargetStartFrame(const int64_t targetPts, const int timeoutMs) = 0; 90 91 virtual int32_t SetVolume(float volume) = 0; 92 93 virtual int32_t SetPlaybackSpeed(float speed) = 0; 94 95 virtual int32_t ReturnFrames(sptr<LppDataPacket> framePacket) = 0; 96 97 virtual int32_t RegisterCallback() = 0; 98 99 virtual int32_t SetLppVideoStreamerCallback(const std::shared_ptr<VideoStreamerCallback> &callback) = 0; 100 101 virtual std::shared_ptr<VideoStreamerCallback> GetLppVideoStreamerCallback() = 0; 102 103 virtual int32_t RenderFirstFrame() = 0; 104 105 virtual std::string GetStreamerId() = 0; 106 }; 107 108 class __attribute__((visibility("default"))) VideoStreamerFactory { 109 public: 110 #ifdef UNSUPPORT_LPP_AUDIO_STRAMER CreateByMime(const std::string & mime)111 static std::shared_ptr<VideoStreamer> CreateByMime(const std::string &mime) 112 { 113 (void)mime; 114 return nullptr; 115 } 116 #else 117 static std::shared_ptr<VideoStreamer> CreateByMime(const std::string &mime); 118 #endif 119 private: 120 VideoStreamerFactory() = default; 121 ~VideoStreamerFactory() = default; 122 }; 123 } // namespace Media 124 } // namespace OHOS 125 #endif // VIDEO_STREAM_PLAYER_H 126