1 /* ============================================================ 2 * 3 * This file is a part of digiKam project 4 * https://www.digikam.org 5 * 6 * Date : 2016-04-21 7 * Description : video thumbnails extraction based on ffmpeg 8 * 9 * Copyright (C) 2010 by Dirk Vanden Boer <dirk dot vdb at gmail dot com> 10 * Copyright (C) 2016-2018 by Maik Qualmann <metzpinguin at gmail dot com> 11 * Copyright (C) 2016-2021 by Gilles Caulier <caulier dot gilles at gmail dot com> 12 * 13 * This program is free software; you can redistribute it 14 * and/or modify it under the terms of the GNU General 15 * Public License as published by the Free Software Foundation; 16 * either version 2, or (at your option) any later version. 17 * 18 * This program is distributed in the hope that it will be useful, 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 * GNU General Public License for more details. 22 * 23 * ============================================================ */ 24 25 #ifndef DIGIKAM_VIDEO_DECODER_PRIVATE_H 26 #define DIGIKAM_VIDEO_DECODER_PRIVATE_H 27 28 #include "videodecoder.h" 29 30 // FFMpeg includes 31 32 extern "C" 33 { 34 #include <libswscale/swscale.h> 35 #include <libavcodec/avcodec.h> 36 #include <libavutil/imgutils.h> 37 #include <libavformat/avformat.h> 38 #include <libavfilter/avfilter.h> 39 #include <libavfilter/buffersrc.h> 40 #include <libavfilter/buffersink.h> 41 } 42 43 namespace Digikam 44 { 45 46 class Q_DECL_HIDDEN VideoDecoder::Private 47 { 48 public: 49 50 explicit Private(); 51 ~Private(); 52 53 public: 54 55 int videoStream; 56 AVFormatContext* pFormatContext; 57 AVCodecContext* pVideoCodecContext; 58 AVCodecParameters* pVideoCodecParameters; 59 AVCodec* pVideoCodec; 60 AVStream* pVideoStream; 61 AVFrame* pFrame; 62 quint8* pFrameBuffer; 63 AVPacket* pPacket; 64 bool allowSeek; 65 bool initialized; 66 AVFilterContext* bufferSinkContext; 67 AVFilterContext* bufferSourceContext; 68 AVFilterGraph* filterGraph; 69 AVFrame* filterFrame; 70 int lastWidth; 71 int lastHeight; 72 enum AVPixelFormat lastPixfmt; 73 74 public: 75 76 bool initializeVideo(); 77 bool getVideoPacket(); 78 bool decodeVideoPacket() const; 79 80 void convertAndScaleFrame(AVPixelFormat format, 81 int scaledSize, 82 bool maintainAspectRatio, 83 int& scaledWidth, 84 int& scaledHeight); 85 86 bool processFilterGraph(AVFrame* const dst, 87 const AVFrame* const src, 88 enum AVPixelFormat pixfmt, 89 int width, 90 int height); 91 92 void deleteFilterGraph(); 93 94 private: 95 96 bool initFilterGraph(enum AVPixelFormat pixfmt, int width, int height); 97 98 void calculateDimensions(int squareSize, 99 bool maintainAspectRatio, 100 int& destWidth, 101 int& destHeight); 102 103 void createAVFrame(AVFrame** const avFrame, 104 quint8** const frameBuffer, 105 int width, 106 int height, 107 AVPixelFormat format); 108 109 // cppcheck-suppress unusedPrivateFunction 110 int decodeVideoNew(AVCodecContext* const avContext, 111 AVFrame* const avFrame, 112 int* gotFrame, 113 AVPacket* const avPacket) const; 114 }; 115 116 } // namespace Digikam 117 118 #endif // DIGIKAM_VIDEO_DECODER_PRIVATE_H 119