1 /* 2 * Copyright (c) 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 HISTREAMER_AUDIO_MP3_ENCODER_PLUGIN_H 17 #define HISTREAMER_AUDIO_MP3_ENCODER_PLUGIN_H 18 19 #include <functional> 20 #include <mutex> 21 #include <vector> 22 #include "buffer/avbuffer.h" 23 #include "meta/meta.h" 24 #include "nocopyable.h" 25 #include "plugin/codec_plugin.h" 26 #include "plugin/plugin_definition.h" 27 28 namespace OHOS { 29 namespace Media { 30 namespace Plugins { 31 namespace Mp3 { 32 class AudioMp3EncoderPlugin : public CodecPlugin { 33 public: 34 explicit AudioMp3EncoderPlugin(const std::string& name); 35 36 ~AudioMp3EncoderPlugin(); 37 38 Status Init() override; 39 40 Status Prepare() override; 41 42 Status Reset() override; 43 44 Status Start() override; 45 46 Status Stop() override; 47 48 Status SetParameter(const std::shared_ptr<Meta> ¶meter) override; 49 50 Status GetParameter(std::shared_ptr<Meta> ¶meter) override; 51 52 Status QueueInputBuffer(const std::shared_ptr<AVBuffer> &inputBuffer) override; 53 54 Status QueueOutputBuffer(std::shared_ptr<AVBuffer> &outputBuffer) override; 55 56 Status GetInputBuffers(std::vector<std::shared_ptr<AVBuffer>> &inputBuffers) override; 57 58 Status GetOutputBuffers(std::vector<std::shared_ptr<AVBuffer>> &outputBuffers) override; 59 60 Status Flush() override; 61 62 Status Release() override; 63 SetDataCallback(DataCallback * dataCallback)64 Status SetDataCallback(DataCallback* dataCallback) override 65 { 66 dataCallback_ = dataCallback; 67 return Status::OK; 68 } 69 70 private: 71 bool CheckFormat(); 72 Meta audioParameter_ ; 73 mutable std::mutex avMutex_ {}; 74 75 DataCallback* dataCallback_ {nullptr}; 76 AudioSampleFormat audioSampleFormat_; 77 78 struct LameInfo; 79 std::unique_ptr<LameInfo> lameInfo; 80 81 int32_t lameInitFlag; 82 int32_t channels_; 83 int64_t bitrate_; 84 int64_t pts_; 85 86 int32_t sampleRate_; 87 int32_t maxInputSize_; 88 int32_t maxOutputSize_; 89 int32_t outputSize_; 90 std::unique_ptr<unsigned char[]> lameMp3Buffer; 91 }; 92 } // namespace Mp3 93 } // namespace Plugins 94 } // namespace Media 95 } // namespace OHOS 96 97 #endif // HISTREAMER_AUDIO_MP3_ENCODER_PLUGIN_H