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