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