1 /* 2 * Copyright (c) 2024-2024 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 STREAM_DEMUXER_H 17 #define STREAM_DEMUXER_H 18 19 #include <atomic> 20 #include <limits> 21 #include <string> 22 #include <shared_mutex> 23 24 #include "base_stream_demuxer.h" 25 26 #include "avcodec_common.h" 27 #include "buffer/avbuffer.h" 28 #include "common/media_source.h" 29 #include "demuxer/type_finder.h" 30 #include "filter/filter.h" 31 #include "meta/media_types.h" 32 #include "osal/task/task.h" 33 #include "plugin/plugin_base.h" 34 #include "plugin/plugin_info.h" 35 #include "plugin/plugin_time.h" 36 #include "plugin/demuxer_plugin.h" 37 38 namespace OHOS { 39 namespace Media { 40 41 class StreamDemuxer : public BaseStreamDemuxer { 42 public: 43 explicit StreamDemuxer(); 44 ~StreamDemuxer() override; 45 46 Status Init(const std::string& uri) override; 47 Status Pause() override; 48 Status Resume() override; 49 Status Start() override; 50 Status Stop() override; 51 Status Flush() override; 52 Status CallbackReadAt(int32_t streamID, int64_t offset, std::shared_ptr<Buffer>& buffer, 53 size_t expectedLen) override; 54 Status ResetCache(int32_t streamID) override; 55 Status ResetAllCache() override; 56 private: 57 Status PullData(int32_t streamID, uint64_t offset, size_t size, std::shared_ptr<Plugins::Buffer>& data); 58 Status PullDataWithoutCache(int32_t streamID, uint64_t offset, size_t size, std::shared_ptr<Buffer>& bufferPtr); 59 Status PullDataWithCache(int32_t streamID, uint64_t offset, size_t size, std::shared_ptr<Buffer>& bufferPtr); 60 Status GetPeekRange(int32_t streamID, uint64_t offset, size_t size, std::shared_ptr<Buffer>& bufferPtr); 61 Status ReadHeaderData(int32_t streamID, uint64_t offset, size_t size, std::shared_ptr<Buffer>& bufferPtr); 62 Status ReadFrameData(int32_t streamID, uint64_t offset, size_t size, std::shared_ptr<Buffer>& bufferPtr); 63 Status ReadRetry(int32_t streamID, uint64_t offset, size_t size, std::shared_ptr<Plugins::Buffer>& data); 64 Status HandleReadHeader(int32_t streamID, int64_t offset, std::shared_ptr<Buffer>& buffer, size_t expectedLen); 65 Status HandleReadPacket(int32_t streamID, int64_t offset, std::shared_ptr<Buffer>& buffer, size_t expectedLen); 66 Status CheckChangeStreamID(int32_t streamID, std::shared_ptr<Buffer>& buffer); 67 Status ProcInnerDash(int32_t streamID, uint64_t offset, std::shared_ptr<Buffer>& bufferPtr); 68 private: 69 std::map<int32_t, CacheData> cacheDataMap_; 70 uint64_t position_; 71 }; 72 } // namespace Media 73 } // namespace OHOS 74 #endif // STREAM_DEMUXER_H 75