/* * Copyright (c) 2023 Fancy Code. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef FFMPEG_DECODER_V2_H #define FFMPEG_DECODER_V2_H #ifdef __cplusplus extern "C" { #endif #include #include #include #include #include #include #include #include #include #include #include #include #ifdef __cplusplus } #endif #include // constexpr int DECODER_UNSUPORTED = 0; class FfmpegDecoderV2 { public: /** * @brief When decoding a video stream, you need to use this constructor to provide the required parameters. * @param codecId Video stream format * @param width Video height * @param height Video width */ FfmpegDecoderV2(const enum AVCodecID &codecId, const AVPixelFormat &decodePixelFormat, const int &width, const int &height); virtual ~FfmpegDecoderV2() = default; bool Init(void); bool UnInit(void); void DecodeData(const void *data, const size_t &size, const unsigned long long &pts, std::function callback); private: void AVParseData(const void *data, const size_t &size, std::function callback); void AVDecodeData(AVPacket *pkt, std::function callback); private: static int select_sample_rate(const AVCodec *codec); static int select_channel_layout(const AVCodec *codec, AVChannelLayout *dst); static int check_sample_fmt(const AVCodec *codec, enum AVSampleFormat sample_fmt); private: const enum AVCodecID mCodecId; AVCodec *mCodec; AVCodecContext *mCodecCtx; AVFrame *mFrame; AVPacket *mPacket; AVCodecParserContext *mParser; const int mVideoWidth; const int mVideoHeight; const AVPixelFormat mDecodePixelFormat; }; #endif