1 /*
2 * Copyright (c) 2015-2020, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 //!
23 //! \file media_libva_cp_interface.h
24 //! \brief This file defines the C++ class/interface for DDI interface of content protection
25 //! \details Other components will call this interface for content protection operations directly
26 //!
27
28 #ifndef __MEDIA_LIBVA_CP_INTERFACE_H__
29 #define __MEDIA_LIBVA_CP_INTERFACE_H__
30
31 #include <map>
32 #include "media_libva.h"
33 #include "codechal_encoder_base.h"
34 #include "mos_os.h"
35
36 typedef struct _DDI_ENCODE_STATUS_REPORT_INFO *PDDI_ENCODE_STATUS_REPORT_INFO;
37 class CodechalSetting;
38 struct CodechalDecodeParams;
39
40 class DdiCpInterface;
41
42 //core structure for CP DDI
43 typedef struct DDI_CP_CONTEXT
44 {
45 PDDI_MEDIA_CONTEXT pMediaCtx;
46 DdiCpInterface *pCpDdiInterface;
47 std::shared_ptr<void> pDrvPrivate;
48 std::multimap<uint32_t, void *> mapAttaching;
49
50 } DDI_CP_CONTEXT, *PDDI_CP_CONTEXT;
51
DdiCp_GetCpContextFromPVOID(void * cpCtx)52 static __inline PDDI_CP_CONTEXT DdiCp_GetCpContextFromPVOID(void *cpCtx)
53 {
54 return (PDDI_CP_CONTEXT)cpCtx;
55 }
56
57 struct DDI_DECODE_CONTEXT;
58
59 class DdiCpInterface
60 {
61 public:
DdiCpInterface(MOS_CONTEXT & mosCtx)62 DdiCpInterface(MOS_CONTEXT& mosCtx) {}
63
~DdiCpInterface()64 virtual ~DdiCpInterface() {}
65
66 virtual void SetCpParams(uint32_t encryptionType, CodechalSetting *setting);
67
68 virtual VAStatus RenderCencPicture(
69 VADriverContextP vaDrvctx,
70 VAContextID contextId,
71 DDI_MEDIA_BUFFER *buf,
72 void *data);
73
74 virtual VAStatus CreateBuffer(
75 VABufferType type,
76 DDI_MEDIA_BUFFER* buffer,
77 uint32_t size,
78 uint32_t num_elements);
79
80 virtual VAStatus InitHdcp2Buffer(DDI_CODEC_COM_BUFFER_MGR* bufMgr);
81
82 virtual VAStatus StatusReportForHdcp2Buffer(
83 DDI_CODEC_COM_BUFFER_MGR* bufMgr,
84 void* encodeStatusReport);
85
86 virtual void FreeHdcp2Buffer(DDI_CODEC_COM_BUFFER_MGR* bufMgr);
87
88 virtual MOS_STATUS StoreCounterToStatusReport(
89 PDDI_ENCODE_STATUS_REPORT_INFO info);
90
91 virtual VAStatus ParseCpParamsForEncode();
92
93 virtual void SetCpFlags(int32_t flag);
94
95 virtual bool IsHdcp2Enabled();
96
97 virtual void SetInputResourceEncryption(PMOS_INTERFACE osInterface, PMOS_RESOURCE resource);
98
99 virtual VAStatus CreateCencDecode(
100 CodechalDebugInterface *debugInterface,
101 PMOS_CONTEXT osContext,
102 CodechalSetting * settings);
103
104 virtual VAStatus SetDecodeParams(
105 DDI_DECODE_CONTEXT *ddiDecodeContext,
106 CodechalSetting *setting);
107
108 virtual bool IsCencProcessing();
109
110 virtual VAStatus EndPicture(
111 VADriverContextP ctx,
112 VAContextID context
113 );
114
115 virtual VAStatus IsAttachedSessionAlive();
116
117 };
118
119 //!
120 //! \brief Create DdiCpInterface Object
121 //! Must use Delete_DdiCpInterface to delete created Object to avoid ULT Memory Leak errors
122 //!
123 //! \param [in] *pMosCtx
124 //! MOS_CONTEXT*
125 //!
126 //! \return Return CP Wrapper Object
127 //!
128 DdiCpInterface* Create_DdiCpInterface(MOS_CONTEXT& mosCtx);
129
130 //!
131 //! \brief Delete the MhwCpInterface Object
132 //!
133 //! \param [in] *pDdiCpInterface
134 //! DdiCpInterface
135 //!
136 void Delete_DdiCpInterface(DdiCpInterface* pDdiCpInterface);
137 #endif
138