]> git.vomp.tv Git - vompclient.git/blob - imageomx2.h
61 CWFs
[vompclient.git] / 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 "osdvector.h"
51 #include "osdopenvg.h"
52
53 class LogNT;
54 class OMX_Image_Decode;
55 class OMX_EGL_Render;
56
57 class ImageOMX2 : public OsdVector::PictureDecoder
58 {
59 // PictureDecoder Interface
60   public:
61     ImageOMX2(/*EGLDisplay egl_display*/);
62     virtual ~ImageOMX2() {};
63
64     void init();
65     void shutdown();
66
67     unsigned char* decodePicture(LoadIndex index, unsigned char* buffer, unsigned int length, bool freemem) noexcept;
68     bool getDecodedPicture(struct OsdVector::PictureInfo& pict_inf);
69     void freeReference(void*) {};
70
71 // Internal stuff
72
73   private:
74     LogNT* log{};
75     //EGLDisplay egl_display;
76     OMX_Image_Decode* omx_imagedecode{};
77     OMX_EGL_Render* omx_eglrender{};
78
79     // State data for the decode
80     struct OsdVector::PictureInfo currentDecode{}; // There's only one user so no locking required
81     bool currentDecodeValid{};
82
83     // Internal functions
84
85     void reinit();
86     void decode(char* inputData, int inputDataSize, char** outRawData, int* outRawDataSize, int* outWidth, int* outHeight, int* outStride); // throws
87     void render(char* inputData, int inputDataSize, int imageWidth, int imageHeight, int imageStride); // throws
88 };
89
90 #endif