1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13 * express or implied.
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
17 */
18 //////////////////////////////////////////////////////////////////////////////////
19 // //
20 // File: pvm4vdecoder.cpp //
21 // //
22 //////////////////////////////////////////////////////////////////////////////////
23
24 #include "oscl_mem.h"
25 #include "mp4dec_api.h"
26 #include "pvm4vdecoder.h"
27
28
29 #define OSCL_DISABLE_WARNING_FORCING_INT_TO_BOOL
30 #include "osclconfig_compiler_warnings.h"
31
32
33 /////////////////////////////////////////////////////////////////////////////
PVM4VDecoder()34 PVM4VDecoder::PVM4VDecoder() : iVideoCtrls(NULL)
35 {
36 }
37
38
New(void)39 PVM4VDecoder* PVM4VDecoder::New(void)
40 {
41 PVM4VDecoder* self = new PVM4VDecoder;
42
43 if (self)
44 {
45 if (!self->Construct())
46 {
47 OSCL_DELETE(self);
48 self = NULL;
49 }
50 }
51
52 return self;
53 }
54
Construct()55 bool PVM4VDecoder::Construct()
56 {
57 iVideoCtrls = (VideoDecControls *) new VideoDecControls;
58 if (iVideoCtrls)
59 {
60 oscl_memset(iVideoCtrls, 0, sizeof(VideoDecControls));
61 return true;
62 }
63 else
64 {
65 return false;
66 }
67 }
68
69 /////////////////////////////////////////////////////////////////////////////
~PVM4VDecoder()70 PVM4VDecoder::~PVM4VDecoder()
71 {
72 if (iVideoCtrls)
73 {
74 OSCL_DELETE((VideoDecControls *)iVideoCtrls);
75 iVideoCtrls = NULL;
76 }
77 }
78
79 /////////////////////////////////////////////////////////////////////////////
InitVideoDecoder(uint8 * volbuf[],int32 * volbuf_size,int32 nLayers,int32 * iWidth,int32 * iHeight,int * mode)80 bool PVM4VDecoder::InitVideoDecoder(uint8 *volbuf[],
81 int32 *volbuf_size,
82 int32 nLayers,
83 int32* iWidth,
84 int32* iHeight,
85 int *mode)
86 {
87 if (PVInitVideoDecoder((VideoDecControls *)iVideoCtrls, (uint8 **) volbuf, (int32*)volbuf_size, (int32)nLayers, *iWidth, *iHeight, (MP4DecodingMode) *mode))
88 {
89 GetVideoDimensions(iWidth, iHeight);
90 *mode = (int)PVGetDecBitstreamMode((VideoDecControls *)iVideoCtrls);
91 return true;
92 }
93 else
94 {
95 return false;
96 }
97
98 }
99
100 /////////////////////////////////////////////////////////////////////////////
GetVolInfo(VolInfo * pVolInfo)101 bool PVM4VDecoder::GetVolInfo(VolInfo* pVolInfo)
102 {
103 if (!iVideoCtrls || !pVolInfo) return false;
104 if (PVGetVolInfo((VideoDecControls *)iVideoCtrls, pVolInfo))
105 {
106 return true;
107 }
108 else
109 {
110 return false;
111 }
112 }
113
114 /////////////////////////////////////////////////////////////////////////////
CleanUpVideoDecoder(void)115 void PVM4VDecoder::CleanUpVideoDecoder(void)
116 {
117 PVCleanUpVideoDecoder((VideoDecControls *)iVideoCtrls);
118 }
119
120 /////////////////////////////////////////////////////////////////////////////
DecodeVideoFrame(uint8 * bitstream[],uint32 * timestamp,int32 * buffer_size,uint * use_ext_timestamp,uint8 * currYUV)121 bool PVM4VDecoder::DecodeVideoFrame(uint8 *bitstream[], uint32 *timestamp, int32 *buffer_size, uint *use_ext_timestamp, uint8 *currYUV)
122 {
123 return PVDecodeVideoFrame((VideoDecControls *)iVideoCtrls, (uint8 **) bitstream, (uint32*)timestamp, (int32*)buffer_size, (uint *) use_ext_timestamp, (uint8 *) currYUV) ? true : false;
124 }
125
126 //////////////////////////////////////////////////////////////////////////////
SetReferenceYUV(uint8 * YUV)127 void PVM4VDecoder::SetReferenceYUV(uint8 *YUV)
128 {
129 PVSetReferenceYUV((VideoDecControls *)iVideoCtrls, YUV);
130 }
131
132 /////////////////////////////////////////////////////////////////////////////
GetVideoDimensions(int32 * display_width,int32 * display_height)133 void PVM4VDecoder::GetVideoDimensions(int32 *display_width, int32 *display_height)
134 {
135 PVGetVideoDimensions((VideoDecControls *)iVideoCtrls, display_width, display_height);
136 }
137
138 /////////////////////////////////////////////////////////////////////////////
SetPostProcType(int32 mode)139 void PVM4VDecoder::SetPostProcType(int32 mode)
140 {
141 PVSetPostProcType((VideoDecControls *)iVideoCtrls, mode);
142 }
143
144 /////////////////////////////////////////////////////////////////////////////
GetVideoTimestamp(void)145 uint32 PVM4VDecoder::GetVideoTimestamp(void)
146 {
147 return PVGetVideoTimeStamp((VideoDecControls *)iVideoCtrls);
148 }
149
150 /////////////////////////////////////////////////////////////////////////////
IsIFrame(void)151 bool PVM4VDecoder::IsIFrame(void)
152 {
153 return IsIntraFrame((VideoDecControls *)iVideoCtrls) ? true : false;
154 }
155
156 /////////////////////////////////////////////////////////////////////////////
DecPostProcess(uint8 * YUV)157 void PVM4VDecoder::DecPostProcess(uint8 *YUV)
158 {
159 PVDecPostProcess((VideoDecControls *)iVideoCtrls, (uint8 *) YUV);
160 }
161
162 /////////////////////////////////////////////////////////////////////////////
GetDecOutputFrame(void)163 uint8* PVM4VDecoder::GetDecOutputFrame(void)
164 {
165 PVDecPostProcess((VideoDecControls *)iVideoCtrls, NULL);
166 return (uint8 *) PVGetDecOutputFrame((VideoDecControls *)iVideoCtrls);
167 }
168
169 /////////////////////////////////////////////////////////////////////////////
ResetVideoDecoder(void)170 bool PVM4VDecoder::ResetVideoDecoder(void)
171 {
172 return PVResetVideoDecoder((VideoDecControls *)iVideoCtrls) ? true : false;
173 }
174
175 /////////////////////////////////////////////////////////////////////////////
DecSetReference(uint8 * refYUV,uint32 timestamp)176 void PVM4VDecoder::DecSetReference(uint8 *refYUV, uint32 timestamp)
177 {
178 PVDecSetReference((VideoDecControls *)iVideoCtrls, (uint8*)refYUV, timestamp);
179 return ;
180 }
181
182 /////////////////////////////////////////////////////////////////////////////
DecSetEnhReference(uint8 * refYUV,uint32 timestamp)183 void PVM4VDecoder::DecSetEnhReference(uint8 *refYUV, uint32 timestamp)
184 {
185 PVDecSetEnhReference((VideoDecControls *)iVideoCtrls, (uint8*)refYUV, timestamp);
186 return ;
187 }
188 /////////////////////////////////////////////////////////////////////////////
GetDecBitrate(void)189 uint32 PVM4VDecoder::GetDecBitrate(void)
190 {
191 return ((uint32)PVGetDecBitrate((VideoDecControls *)iVideoCtrls));
192 }
193
194 /////////////////////////////////////////////////////////////////////////////
GetProfileAndLevel(void)195 uint32 PVM4VDecoder::GetProfileAndLevel(void)
196 {
197 VolInfo iVolInfo;
198 if (GetVolInfo(&iVolInfo))
199 {
200 return iVolInfo.profile_level_id;
201 }
202 else
203 {
204 return 0;
205 }
206 }
207