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 AAC_DEMUXER_PLUGIN_H 17 #define AAC_DEMUXER_PLUGIN_H 18 19 #include <memory> 20 #include <string> 21 #include <vector> 22 23 #include "plugin/interface/demuxer_plugin.h" 24 25 namespace OHOS { 26 namespace Media { 27 namespace Plugin { 28 namespace AacDemuxer { 29 struct AudioDemuxerUserArg { 30 uint32_t fileSize; 31 void *priv; 32 }; 33 34 struct AACDemuxerRst { 35 uint64_t usedInputLength; 36 uint8_t *frameBuffer; 37 uint32_t frameLength; 38 uint64_t inputNeedOffsetSize; 39 40 uint32_t frameBitrateKbps; 41 uint32_t frameSampleRate; 42 uint8_t frameChannels; 43 uint8_t mpegVersion; 44 uint8_t audioLayer; 45 uint32_t samplesPerFrame; 46 }; 47 48 class AACDemuxerPlugin : public DemuxerPlugin { 49 public: 50 explicit AACDemuxerPlugin(std::string name); 51 ~AACDemuxerPlugin() override; 52 Status Init() override; 53 Status Deinit() override; 54 Status Prepare() override; 55 Status Reset() override; 56 Status Start() override; 57 Status Stop() override; 58 Status GetParameter(Tag tag, ValueType& value) override; 59 Status SetParameter(Tag tag, const ValueType& value) override; 60 std::shared_ptr<Allocator> GetAllocator() override; 61 Status SetCallback(Callback* cb) override; 62 63 Status SetDataSource(const std::shared_ptr<DataSource>& source) override; 64 Status GetMediaInfo(MediaInfo& mediaInfo) override; 65 Status ReadFrame(Buffer& outBuffer, int32_t timeOutMs) override; 66 Status SeekTo(int32_t trackId, int64_t seekTime, SeekMode mode, int64_t& realSeekTime) override; 67 size_t GetTrackCount() override; 68 Status SelectTrack(int32_t trackId) override; 69 Status UnselectTrack(int32_t trackId) override; 70 Status GetSelectedTracks(std::vector<int32_t>& trackIds) override; 71 72 private: 73 struct IOContext { 74 std::shared_ptr<DataSource> dataSource {nullptr}; 75 int64_t offset {0}; 76 bool eos {false}; 77 }; 78 Status DoReadFromSource(uint32_t readSize); 79 Status GetDataFromSource(); 80 int GetFrameLength(const uint8_t *data); 81 int AudioDemuxerAACOpen(AudioDemuxerUserArg *userArg); 82 int AudioDemuxerAACClose(); 83 int AudioDemuxerAACPrepare(const uint8_t *buf, uint32_t len, AACDemuxerRst *rst); 84 int AudioDemuxerAACProcess(const uint8_t *buffer, uint32_t bufferLen, AACDemuxerRst *rst); 85 int AudioDemuxerAACFreeFrame(uint8_t *frame); 86 87 AACDemuxerRst aacDemuxerRst_; 88 IOContext ioContext_; 89 uint64_t fileSize_; 90 bool isSeekable_; 91 unsigned char *inIoBuffer_; 92 int inIoBufferSize_; 93 unsigned int ioDataRemainSize_; 94 }; 95 } // namespace AacDemuxer 96 } // namespace Plugin 97 } // namespace Media 98 } // namespace OHOS 99 100 #endif // AAC_DEMUXER_PLUGIN_H