st/omx/dec: Correct the timestamping
[mesa.git] / src / gallium / state_trackers / omx / vid_dec.h
1 /**************************************************************************
2 *
3 * Copyright 2013 Advanced Micro Devices, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /*
29 * Authors:
30 * Christian König <christian.koenig@amd.com>
31 *
32 */
33
34 #ifndef OMX_VID_DEC_H
35 #define OMX_VID_DEC_H
36
37 #include <X11/Xlib.h>
38
39 #include <string.h>
40
41 #include <OMX_Types.h>
42 #include <OMX_Component.h>
43 #include <OMX_Core.h>
44
45 #include <bellagio/st_static_component_loader.h>
46 #include <bellagio/omx_base_filter.h>
47 #include <bellagio/omx_base_video_port.h>
48
49 #include "pipe/p_video_state.h"
50 #include "state_tracker/drm_driver.h"
51 #include "os/os_thread.h"
52 #include "util/list.h"
53
54 #define OMX_VID_DEC_BASE_NAME "OMX.mesa.video_decoder"
55
56 #define OMX_VID_DEC_MPEG2_NAME "OMX.mesa.video_decoder.mpeg2"
57 #define OMX_VID_DEC_MPEG2_ROLE "video_decoder.mpeg2"
58
59 #define OMX_VID_DEC_AVC_NAME "OMX.mesa.video_decoder.avc"
60 #define OMX_VID_DEC_AVC_ROLE "video_decoder.avc"
61
62 #define OMX_VID_DEC_TIMESTAMP_INVALID ((OMX_TICKS) -1)
63
64 struct vl_vlc;
65
66 DERIVEDCLASS(vid_dec_PrivateType, omx_base_filter_PrivateType)
67 #define vid_dec_PrivateType_FIELDS omx_base_filter_PrivateType_FIELDS \
68 enum pipe_video_profile profile; \
69 struct vl_screen *screen; \
70 struct pipe_context *pipe; \
71 struct pipe_video_codec *codec; \
72 void (*Decode)(vid_dec_PrivateType *priv, struct vl_vlc *vlc, unsigned min_bits_left); \
73 void (*EndFrame)(vid_dec_PrivateType *priv); \
74 struct pipe_video_buffer *(*Flush)(vid_dec_PrivateType *priv, OMX_TICKS *timestamp); \
75 struct pipe_video_buffer *target, *shadow; \
76 union { \
77 struct { \
78 uint8_t intra_matrix[64]; \
79 uint8_t non_intra_matrix[64]; \
80 } mpeg12; \
81 struct { \
82 unsigned nal_ref_idc; \
83 bool IdrPicFlag; \
84 unsigned idr_pic_id; \
85 unsigned pic_order_cnt_lsb; \
86 unsigned pic_order_cnt_msb; \
87 unsigned delta_pic_order_cnt_bottom; \
88 unsigned delta_pic_order_cnt[2]; \
89 unsigned prevFrameNumOffset; \
90 struct pipe_h264_sps sps[32]; \
91 struct pipe_h264_pps pps[256]; \
92 struct list_head dpb_list; \
93 unsigned dpb_num; \
94 } h264; \
95 } codec_data; \
96 union { \
97 struct pipe_picture_desc base; \
98 struct pipe_mpeg12_picture_desc mpeg12; \
99 struct pipe_h264_picture_desc h264; \
100 } picture; \
101 unsigned num_in_buffers; \
102 OMX_BUFFERHEADERTYPE *in_buffers[2]; \
103 const void *inputs[2]; \
104 unsigned sizes[2]; \
105 OMX_TICKS timestamps[2]; \
106 OMX_TICKS timestamp; \
107 bool first_buf_in_frame; \
108 bool frame_finished; \
109 bool frame_started; \
110 unsigned bytes_left; \
111 const void *slice;
112 ENDCLASS(vid_dec_PrivateType)
113
114 OMX_ERRORTYPE vid_dec_LoaderComponent(stLoaderComponentType *comp);
115
116 /* used by MPEG12 and H264 implementation */
117 void vid_dec_NeedTarget(vid_dec_PrivateType *priv);
118
119 /* vid_dec_mpeg12.c */
120 void vid_dec_mpeg12_Init(vid_dec_PrivateType *priv);
121
122 /* vid_dec_h264.c */
123 void vid_dec_h264_Init(vid_dec_PrivateType *priv);
124
125 #endif