1 /*--------------------------------------------------------------------------
2 Copyright (c) 2010-2017, 2020 The Linux Foundation. All rights reserved.
3 
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are
6 met:
7     * Redistributions of source code must retain the above copyright
8       notice, this list of conditions and the following disclaimer.
9     * Redistributions in binary form must reproduce the above
10       copyright notice, this list of conditions and the following
11       disclaimer in the documentation and/or other materials provided
12       with the distribution.
13     * Neither the name of The Linux Foundation nor the names of its
14       contributors may be used to endorse or promote products derived
15       from this software without specific prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 --------------------------------------------------------------------------*/
29 #ifndef __OMX_VENC__H
30 #define __OMX_VENC__H
31 
32 #include <unistd.h>
33 #include <dlfcn.h>
34 #include "omx_video_base.h"
35 #include "video_encoder_device_v4l2.h"
36 
37 extern "C" {
38     OMX_API void * get_omx_component_factory_fn(void);
39 }
40 
41 class omx_venc: public omx_video
42 {
43     public:
44         omx_venc(); //constructor
45         ~omx_venc(); //des
46         static int async_message_process (void *context, void* message);
47         OMX_ERRORTYPE component_init(OMX_STRING role);
48         OMX_ERRORTYPE set_parameter(OMX_HANDLETYPE hComp,
49                 OMX_INDEXTYPE  paramIndex,
50                 OMX_PTR        paramData);
51         OMX_ERRORTYPE set_config(OMX_HANDLETYPE hComp,
52                 OMX_INDEXTYPE  configIndex,
53                 OMX_PTR        configData);
54         OMX_ERRORTYPE component_deinit(OMX_HANDLETYPE hComp);
55         bool is_secure_session();
56         //OMX strucutres
57         OMX_U32 m_nVenc_format;
58         char m_platform_name[PROPERTY_VALUE_MAX] = {0};
59         class venc_dev *handle;
60         int dev_handle_output_extradata(void *, int);
61         int dev_set_format(int);
62     private:
63         OMX_U32 dev_stop(void);
64         OMX_U32 dev_pause(void);
65         OMX_U32 dev_start(void);
66         OMX_U32 dev_flush(unsigned);
67         OMX_U32 dev_resume(void);
68         OMX_U32 dev_start_done(void);
69         OMX_U32 dev_set_message_thread_id(pthread_t);
70         bool dev_use_buf(unsigned);
71         bool dev_handle_empty_eos_buffer(void);
72         bool dev_free_buf( void *,unsigned);
73         bool dev_empty_buf(void *, void *,unsigned,unsigned);
74         bool dev_fill_buf(void *, void *,unsigned,unsigned);
75         bool dev_is_meta_mode(void);
76         bool dev_is_avtimer_needed(void);
77         bool dev_buffer_ready_to_queue(OMX_BUFFERHEADERTYPE *buffer);
78         bool dev_get_buf_req(OMX_U32 *,OMX_U32 *,OMX_U32 *,OMX_U32);
79         bool dev_get_dimensions(OMX_U32 ,OMX_U32 *,OMX_U32 *);
80         bool is_streamon_done(OMX_U32 port);
81         bool dev_set_buf_req(OMX_U32 *,OMX_U32 *,OMX_U32 *,OMX_U32);
82         bool update_profile_level();
83         bool dev_get_seq_hdr(void *, unsigned, unsigned *);
84         bool dev_loaded_start(void);
85         bool dev_loaded_stop(void);
86         bool dev_loaded_start_done(void);
87         bool dev_loaded_stop_done(void);
88         bool dev_get_capability_ltrcount(OMX_U32 *, OMX_U32 *, OMX_U32 *);
89         bool dev_get_vui_timing_info(OMX_U32 *);
90         bool dev_get_peak_bitrate(OMX_U32 *);
91         bool dev_get_batch_size(OMX_U32 *);
92         bool dev_get_temporal_layer_caps(OMX_U32 * /*nMaxLayers*/,
93                 OMX_U32 * /*nMaxBLayers*/, OMX_VIDEO_ANDROID_TEMPORALLAYERINGPATTERNTYPE */*SupportedPattern*/);
94         OMX_ERRORTYPE dev_get_supported_profile_level(OMX_VIDEO_PARAM_PROFILELEVELTYPE *);
95         bool dev_get_supported_color_format(unsigned index, OMX_U32 *colorFormat);
96         bool dev_is_video_session_supported(OMX_U32 width, OMX_U32 height);
97         bool dev_color_align(OMX_BUFFERHEADERTYPE *buffer, OMX_U32 width,
98                         OMX_U32 height);
99         bool dev_get_output_log_flag();
100         int dev_output_log_buffers(const char *buffer_addr,
101                                    int buffer_len, uint64_t timestamp);
102         int dev_extradata_log_buffers(char *buffer, int index, bool input);
103         bool dev_get_hevc_profile(OMX_U32* profile);
104         void dev_get_color_format_as_string(char * buf, int buf_len, unsigned colorformat);
105         void dev_get_consumer_usage(OMX_U32* usage);
106         class perf_control {
107             typedef int (*perf_lock_acquire_t)(int, int, int*, int);
108             typedef int (*perf_lock_release_t)(int);
109             public:
110                 perf_control();
111                 ~perf_control();
112                 bool load_perf_library();
113                 int perf_lock_acquire();
114                 void perf_lock_release();
115                 int m_perf_control_enable;
116             private:
117                 int m_perf_handle;
118                 void *m_perf_lib;
119                 perf_lock_acquire_t m_perf_lock_acquire;
120                 perf_lock_release_t m_perf_lock_release;
121         };
122         perf_control m_perf_control;
123         bool dev_handle_client_input_extradata(void* buffer);
124 };
125 
126 #ifdef _UBWC_
127     #define QOMX_DEFAULT_COLOR_FMT    QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mCompressed
128     #define V4L2_DEFAULT_OUTPUT_COLOR_FMT   V4L2_PIX_FMT_NV12_UBWC
129 #else
130     #define QOMX_DEFAULT_COLOR_FMT    QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m
131     #define V4L2_DEFAULT_OUTPUT_COLOR_FMT   V4L2_PIX_FMT_NV12
132 #endif
133 #endif //__OMX_VENC__H
134