1 /* ********************************************************************* *\
2 
3 Copyright (C) 2013 Intel Corporation.  All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7 - Redistributions of source code must retain the above copyright notice,
8 this list of conditions and the following disclaimer.
9 - Redistributions in binary form must reproduce the above copyright notice,
10 this list of conditions and the following disclaimer in the documentation
11 and/or other materials provided with the distribution.
12 - Neither the name of Intel Corporation nor the names of its contributors
13 may be used to endorse or promote products derived from this software
14 without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 
27 \* ********************************************************************* */
28 
29 #ifndef HANDBRAKE_QSV_FILTER_PP_H
30 #define HANDBRAKE_QSV_FILTER_PP_H
31 
32 #include "handbrake/project.h"
33 
34 #if HB_PROJECT_FEATURE_QSV
35 
36 #include "mfx/mfxplugin.h"
37 
38 struct qsv_filter_task_s;
39 
40 typedef struct{
41         mfxFrameAllocator *alloc;
42         mfxStatus             (*process)(struct qsv_filter_task_s*,void*);
43         mfxCoreInterface    *core;
44 }qsv_filter_processor_t;
45 
46 typedef  struct qsv_filter_task_s{
47         mfxFrameSurface1 *in;
48         mfxFrameSurface1 *out;
49         int              busy;
50         hb_filter_private_t *pv;
51         qsv_filter_processor_t processor;
52 } qsv_filter_task_t;
53 
54 typedef struct qsv_filter_private_s{
55 
56         int                 is_init_done;
57 
58         mfxCoreInterface    *core;
59         mfxVideoParam       *videoparam;
60         mfxPluginParam      pluginparam;
61 
62         hb_filter_private_t *pv;
63 
64         mfxPlugin           plug;
65         hb_list_t           *tasks;
66 } qsv_filter_t;
67 
68 typedef struct hb_qsv_sync_s{
69     int                 frame_go;
70     int                 status;
71     hb_cond_t           *frame_completed;
72     hb_lock_t           *frame_completed_lock;
73 
74     hb_buffer_t         *in;
75     hb_buffer_t         *out;
76 } hb_qsv_sync_t;
77 
78 typedef struct hb_filter_private_s
79 {
80     hb_job_t            *job;
81     hb_list_t           *list;
82 
83     hb_qsv_sync_t       pre;
84     hb_qsv_sync_t       pre_busy;
85 
86     hb_qsv_sync_t       post;
87     hb_qsv_sync_t       post_busy;
88 
89     hb_qsv_space        *vpp_space;
90     hb_list_t           *qsv_user;
91 
92     struct SwsContext* sws_context_to_nv12;
93     struct SwsContext* sws_context_from_nv12;
94 } hb_filter_private_t_qsv;
95 
96 // methods to be called by Media SDK
97 mfxStatus MFX_CDECL qsv_PluginInit(mfxHDL pthis, mfxCoreInterface *core);
98 mfxStatus MFX_CDECL qsv_PluginClose (mfxHDL pthis);
99 mfxStatus MFX_CDECL qsv_GetPluginParam(mfxHDL pthis, mfxPluginParam *par);
100 mfxStatus MFX_CDECL qsv_Submit(mfxHDL pthis, const mfxHDL *in, mfxU32 in_num, const mfxHDL *out, mfxU32 out_num, mfxThreadTask *task);
101 mfxStatus MFX_CDECL qsv_Execute(mfxHDL pthis, mfxThreadTask task, mfxU32 uid_p, mfxU32 uid_a);
102 mfxStatus MFX_CDECL qsv_FreeResources(mfxHDL pthis, mfxThreadTask task, mfxStatus sts);
103 
104 // methods to be called by us
105 mfxStatus plugin_init(qsv_filter_t*,mfxVideoParam*);
106 mfxStatus plugin_close(qsv_filter_t*);
107 
108 //internal functions
109 mfxExtBuffer* get_ext_buffer(mfxExtBuffer**, mfxU32, mfxU32);
110 int get_free_task(hb_list_t*);
111 mfxStatus           process_filter(qsv_filter_task_t*,void*);
112 mfxStatus lock_frame(mfxFrameAllocator *,mfxFrameSurface1*);
113 mfxStatus unlock_frame(mfxFrameAllocator *,mfxFrameSurface1*);
114 
115 
116 #endif // HB_PROJECT_FEATURE_QSV
117 #endif // HANDBRAKE_QSV_FILTER_PP_H
118