digiKam
videodecoder_p.h
Go to the documentation of this file.
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-2022 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 
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;
66  AVFilterContext* bufferSinkContext;
67  AVFilterContext* bufferSourceContext;
68  AVFilterGraph* filterGraph;
69  AVFrame* filterFrame;
70  int lastWidth;
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
Definition: videodecoder_p.h:47
int lastWidth
Definition: videodecoder_p.h:70
int videoStream
Definition: videodecoder_p.h:55
bool allowSeek
Definition: videodecoder_p.h:64
quint8 * pFrameBuffer
Definition: videodecoder_p.h:62
AVFilterContext * bufferSinkContext
Definition: videodecoder_p.h:66
AVFilterGraph * filterGraph
Definition: videodecoder_p.h:68
AVFrame * filterFrame
Definition: videodecoder_p.h:69
AVPacket * pPacket
Definition: videodecoder_p.h:63
AVCodecContext * pVideoCodecContext
Definition: videodecoder_p.h:57
AVStream * pVideoStream
Definition: videodecoder_p.h:60
AVCodec * pVideoCodec
Definition: videodecoder_p.h:59
int lastHeight
Definition: videodecoder_p.h:71
bool initialized
Definition: videodecoder_p.h:65
AVFilterContext * bufferSourceContext
Definition: videodecoder_p.h:67
AVFrame * pFrame
Definition: videodecoder_p.h:61
AVFormatContext * pFormatContext
Definition: videodecoder_p.h:56
AVCodecParameters * pVideoCodecParameters
Definition: videodecoder_p.h:58
Definition: videodecoder.h:40
Definition: datefolderview.cpp:43