1 /* 2 * Copyright (c) 2021-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 MINIMP4_DEMUXER_PLUGIN_H 17 #define MINIMP4_DEMUXER_PLUGIN_H 18 19 #include <memory> 20 #include <string> 21 #include <vector> 22 #include <set> 23 #include "minimp4.h" 24 #include "plugin/interface/demuxer_plugin.h" 25 26 namespace OHOS { 27 namespace Media { 28 namespace Plugin { 29 namespace Minimp4 { 30 class MiniMP4DemuxerPlugin : public DemuxerPlugin { 31 public: 32 explicit MiniMP4DemuxerPlugin(std::string name); 33 ~MiniMP4DemuxerPlugin() override; 34 Status Init() override; 35 Status Deinit() override; 36 Status Prepare() override; 37 Status Reset() override; 38 Status Stop() override; 39 Status GetParameter(Tag tag, ValueType& value) override; 40 Status SetParameter(Tag tag, const ValueType& value) override; 41 std::shared_ptr<Allocator> GetAllocator() override; 42 Status SetCallback(Callback* cb) override; 43 Status SetDataSource(const std::shared_ptr<DataSource>& source) override; 44 Status GetMediaInfo(MediaInfo& mediaInfo) override; 45 Status ReadFrame(Buffer& outBuffer, int32_t timeOutMs) override; 46 Status SeekTo(int32_t trackId, int64_t seekTime, SeekMode mode, int64_t& realSeekTime) override; 47 size_t GetTrackCount() override; 48 Status SelectTrack(int32_t trackId) override; 49 Status UnselectTrack(int32_t trackId) override; 50 Status GetSelectedTracks(std::vector<int32_t>& trackIds) override; 51 uint64_t GetFileSize(); 52 std::shared_ptr<DataSource> GetInputBuffer(); 53 Status AudioAdapterForDecoder(); 54 Status DoReadFromSource(uint32_t readSize); 55 Status GetDataFromSource(); 56 private: 57 void FillADTSHead(std::shared_ptr<Memory> &data, unsigned int frameSize); 58 static int ReadCallback(int64_t offset, void* buffer, size_t size, void* token); 59 struct IOContext { 60 std::shared_ptr<DataSource> dataSource {nullptr}; 61 int64_t offset {0}; 62 bool eos {false}; 63 }; 64 IOContext ioContext_; 65 std::shared_ptr<Callback> callback_ {nullptr}; 66 MP4D_demux_t miniMP4_; 67 uint64_t fileSize_; 68 std::unique_ptr<MediaInfo> mediaInfo_; 69 unsigned char *inIoBuffer_; 70 unsigned int ioDataRemainSize_; 71 int inIoBufferSize_; 72 unsigned int sampleIndex_; 73 }; 74 } // namespace Minimp4 75 } // namespace Plugin 76 } // namespace Media 77 } // namespace OHOS 78 #endif 79 80