[Test] Added tests for CUtil::SplitParams
[xbmc.git] / xbmc / guilib / FFmpegImage.h
blob0f7cee380c25359b5c64f63d3f6dec42ae074a65
1 /*
2 * Copyright (C) 2012-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #pragma once
11 #include "iimage.h"
12 #include <memory>
14 extern "C"
16 #include <libavutil/pixfmt.h>
19 class Frame
21 public:
22 friend class CFFmpegImage;
24 Frame() = default;
25 virtual ~Frame();
27 int GetPitch() const { return m_pitch; }
29 unsigned char* m_pImage = nullptr;
30 unsigned int m_delay = 0;
32 private:
33 Frame(const Frame& src);
35 int m_pitch = 0;
36 unsigned int m_imageSize = 0;
37 unsigned int m_height = 0;
38 unsigned int m_width = 0;
42 struct MemBuffer
44 uint8_t* data = nullptr;
45 size_t size = 0;
46 size_t pos = 0;
49 struct AVFrame;
50 struct AVIOContext;
51 struct AVFormatContext;
52 struct AVCodecContext;
53 struct AVPacket;
55 class CFFmpegImage : public IImage
57 public:
58 explicit CFFmpegImage(const std::string& strMimeType);
59 ~CFFmpegImage() override;
61 bool LoadImageFromMemory(unsigned char* buffer, unsigned int bufSize,
62 unsigned int width, unsigned int height) override;
63 bool Decode(unsigned char * const pixels, unsigned int width, unsigned int height,
64 unsigned int pitch, unsigned int format) override;
65 bool CreateThumbnailFromSurface(unsigned char* bufferin, unsigned int width,
66 unsigned int height, unsigned int format,
67 unsigned int pitch, const std::string& destFile,
68 unsigned char* &bufferout,
69 unsigned int &bufferoutSize) override;
70 void ReleaseThumbnailBuffer() override;
72 bool Initialize(unsigned char* buffer, size_t bufSize);
74 std::shared_ptr<Frame> ReadFrame();
76 private:
77 static void FreeIOCtx(AVIOContext** ioctx);
78 AVFrame* ExtractFrame();
79 bool DecodeFrame(AVFrame* m_pFrame, unsigned int width, unsigned int height, unsigned int pitch, unsigned char * const pixels);
80 static int EncodeFFmpegFrame(AVCodecContext *avctx, AVPacket *pkt, int *got_packet, AVFrame *frame);
81 static int DecodeFFmpegFrame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt);
82 static AVPixelFormat ConvertFormats(AVFrame* frame);
83 std::string m_strMimeType;
84 void CleanupLocalOutputBuffer();
87 MemBuffer m_buf;
89 AVIOContext* m_ioctx = nullptr;
90 AVFormatContext* m_fctx = nullptr;
91 AVCodecContext* m_codec_ctx = nullptr;
93 AVFrame* m_pFrame;
94 uint8_t* m_outputBuffer;