]> git.vomp.tv Git - vompclient.git/blob - src/imageomx2.h
Switch to cmake
[vompclient.git] / src / imageomx2.h
1 /*
2     Copyright 2021 Chris Tallon
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP.  If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 /*
21
22 TL;DR:
23
24 The OMX image_decode "hardware" is buggy when given an image with height not divisible
25 by 16. Extensive testing shows there is no way to use tunneled communication between
26 image_decode and egl_render when the image height is not divisible by 16 and guarantee
27 correct image display.
28
29 ImageOMX1 mitigated this by cropping the image height to a value divisible by 16
30 but this introduced a new race condition bug which corrupted some images.
31 ImageOMX1 works most of the time because it happens to pull down the tunnel before
32 it has finished. If a 0.1s delay is inserted after the
33   if (!video->ChangeComponentState(omx_egl_render,OMX_StateExecuting)) {
34 if block, it will break every image with height not divisible by 16.
35
36 The solution is to not use tunneled communication between image_decode and
37 egl_render. If the input image height is not divisible by 16, set the slice height
38 to 16. Then feed egl_render separately.
39
40 This ImageOMX2 is a rework of my clean-implementation test programs used to debug
41 the problem. Future work: Fix ImageOMX1 or swap over to ImageOMX2 if it works
42 well enough? (Is it even possible to run image_decode/egl_render without integration
43 with VideoOMX?)
44
45 */
46
47 #ifndef IMAGEOMX2_H
48 #define IMAGEOMX2_H
49
50 #include "osdvectortypes.h"
51
52 class LogNT;
53 class OMX_Image_Decode;
54 class OMX_EGL_Render;
55
56 class ImageOMX2 : public PictureDecoder
57 {
58 // PictureDecoder Interface
59   public:
60     ImageOMX2(/*EGLDisplay egl_display*/);
61     virtual ~ImageOMX2() {};
62
63     void init();
64     void shutdown();
65
66     unsigned char* decodePicture(LoadingIndex index, unsigned char* buffer, unsigned int length, bool freemem) noexcept;
67     bool getDecodedPicture(struct PictureInfo& pict_inf);
68     void freeReference(void*) {};
69
70 // Internal stuff
71
72   private:
73     LogNT* log{};
74     //EGLDisplay egl_display;
75     OMX_Image_Decode* omx_imagedecode{};
76     OMX_EGL_Render* omx_eglrender{};
77
78     // State data for the decode
79     struct PictureInfo currentDecode{}; // There's only one user so no locking required
80     bool currentDecodeValid{};
81
82     // Internal functions
83
84     void reinit();
85     void decode(char* inputData, int inputDataSize, char** outRawData, int* outRawDataSize, int* outWidth, int* outHeight, int* outStride); // throws
86     void render(char* inputData, int inputDataSize, int imageWidth, int imageHeight, int imageStride); // throws
87 };
88
89 #endif