|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include <e32std.h> |
|
22 #include <es_sock.h> |
|
23 #include <e32math.h> |
|
24 #include "mccfilevideo.h" |
|
25 #include "mmcccodecinformation.h" |
|
26 #include "mccperiodicrunner.h" |
|
27 #include "mccfilesourcelogs.h" |
|
28 #include "mccfilesourceimpl.h" |
|
29 #include "mccinternaldef.h" |
|
30 #include "mccresources.h" |
|
31 |
|
32 |
|
33 const TUint32 KMccFileSourceParameterSetsIntervalInMicroSeconds = 2000000; |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // CMccFileVideo::NewL |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 CMccFileVideo* CMccFileVideo::NewL( |
|
40 CMccFileSourceImpl& aSource, |
|
41 MMccResources* aMccResources, |
|
42 TUint32 aEndpointId ) |
|
43 { |
|
44 CMccFileVideo* self = |
|
45 new (ELeave) CMccFileVideo( aSource, aMccResources, aEndpointId ); |
|
46 CleanupStack::PushL( self ); |
|
47 self->ConstructL(); |
|
48 CleanupStack::Pop( self ); |
|
49 |
|
50 return self; |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CMccFileVideo::ConstructL |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 void CMccFileVideo::ConstructL() |
|
58 { |
|
59 CMccFileSourceTypeBase::ConstructL(); |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CMccFileVideo::CMccFileVideo |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 CMccFileVideo::CMccFileVideo( |
|
67 CMccFileSourceImpl& aSource, MMccResources* aMccResources, TUint32 aEndpointId ) |
|
68 : CMccFileSourceTypeBase ( aSource, KUidMediaTypeVideo ), |
|
69 iMccResources( aMccResources ), |
|
70 iEndpointId( aEndpointId ), |
|
71 iBufferType ( CCMRMediaBuffer::EVideoH263 ) |
|
72 { |
|
73 } |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // CMccFileVideo::~CMccFileVideo |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 CMccFileVideo::~CMccFileVideo() |
|
80 { |
|
81 delete iAVCNALUsBuffer; |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CMccFileVideo::FillBufferL |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 void CMccFileVideo::FillBufferL( |
|
89 CMMFBuffer* aBuffer, |
|
90 MDataSink* aConsumer ) |
|
91 { |
|
92 CMccFileSourceTypeBase::FillBufferL( aBuffer, aConsumer ); |
|
93 |
|
94 // There might be pending video frames, read the oldest one immediately |
|
95 WriteBufferL(); |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CMccFileVideo::ParseUpdateAudioDescriptions |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 TBool CMccFileVideo::ParseUpdateVideoDescriptions( MP4Handle aMP4Handle ) |
|
103 { |
|
104 TBool containVideo = EFalse; |
|
105 mp4_u32 timeScale = 0; |
|
106 if ( MP4ParseRequestVideoDescription( aMP4Handle, |
|
107 ( mp4_u32* ) &iLength, &iFrameRate, ( mp4_u32* ) &iType, |
|
108 ( mp4_u32* ) &iWidth, ( mp4_u32* ) &iHeight, |
|
109 ( mp4_u32* ) &timeScale ) |
|
110 == MP4_OK ) |
|
111 { |
|
112 if ( iType == MP4_TYPE_H263_PROFILE_0 ) |
|
113 { |
|
114 __FILESOURCE_CONTROLL( "CMccFileVideo::ParseUpdateVideoDescriptions \ |
|
115 MP4_TYPE_H263_PROFILE_0" ) |
|
116 |
|
117 iBufferType = CCMRMediaBuffer::EVideoH263; |
|
118 containVideo = ETrue; |
|
119 iFourCC = TFourCC( KMccFourCCIdH263 ); |
|
120 |
|
121 TVideoClipProperties clipProperties; |
|
122 MP4ParseGetVideoClipProperties( aMP4Handle, clipProperties ); |
|
123 iLevel = clipProperties.iH263Level; |
|
124 } |
|
125 else if ( iType == MP4_TYPE_MPEG4_VIDEO ) |
|
126 { |
|
127 __FILESOURCE_CONTROLL( "CMccFileVideo::ParseUpdateVideoDescriptions \ |
|
128 MP4_TYPE_MPEG4_VIDEO!" ) |
|
129 |
|
130 iBufferType = CCMRMediaBuffer::EVideoH263; |
|
131 containVideo = ETrue; |
|
132 iFourCC = TFourCC( KMccFourCCIdAVC ); |
|
133 } |
|
134 else if ( IsAVC() ) |
|
135 { |
|
136 __FILESOURCE_CONTROLL( "CMccFileVideo::\ |
|
137 ParseUpdateVideoDescriptions AVC!" ) |
|
138 |
|
139 iBufferType = CCMRMediaBuffer::EVideoH263; |
|
140 containVideo = ETrue; |
|
141 iFourCC = TFourCC( KMccFourCCIdAVC ); |
|
142 iIsFirstFrame = ETrue; |
|
143 iInsertParameterSets = ETrue; |
|
144 } |
|
145 else if ( iType != MP4_TYPE_NONE ) |
|
146 { |
|
147 __FILESOURCE_CONTROLL( "CMccFileVideo::\ |
|
148 ParseUpdateVideoDescriptions contains unsupported video" ) |
|
149 iFourCC = TFourCC( KMccFourCCUnsupported ); |
|
150 } |
|
151 else |
|
152 { |
|
153 // NOP |
|
154 } |
|
155 } |
|
156 |
|
157 return containVideo; |
|
158 } |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // CMccFileVideo::IsAVC |
|
162 // ----------------------------------------------------------------------------- |
|
163 // |
|
164 TBool CMccFileVideo::IsAVC() |
|
165 { |
|
166 if ( ( iType == MP4_TYPE_AVC_PROFILE_BASELINE ) || |
|
167 ( iType == MP4_TYPE_AVC_PROFILE_MAIN ) || |
|
168 ( iType == MP4_TYPE_AVC_PROFILE_EXTENDED ) |
|
169 ) |
|
170 { |
|
171 return ETrue; |
|
172 } |
|
173 |
|
174 return EFalse; |
|
175 } |
|
176 |
|
177 // ----------------------------------------------------------------------------- |
|
178 // CMccFileVideo::DoSetPositionL |
|
179 // ----------------------------------------------------------------------------- |
|
180 // |
|
181 void CMccFileVideo::DoSetPositionL( TUint32 aPosition ) |
|
182 { |
|
183 __FILESOURCE_CONTROLL( "CMccFileVideo::DoSetPositionL" ) |
|
184 |
|
185 __ASSERT_ALWAYS( aPosition <= iLength, User::Leave( KErrArgument ) ); |
|
186 mp4_u32 audioPos = 0; |
|
187 // if retrun value is MP4_OK, iPosition is updated |
|
188 if ( MP4ParseSeek( iMP4Handle, ( mp4_u32 ) aPosition, |
|
189 ( mp4_u32* )&audioPos, ( mp4_u32* ) &iPosition, MP4TRUE ) |
|
190 != MP4_OK ) |
|
191 { |
|
192 User::Leave( KErrGeneral ); |
|
193 } |
|
194 } |
|
195 |
|
196 // ----------------------------------------------------------------------------- |
|
197 // CMccFileVideo::Type |
|
198 // ----------------------------------------------------------------------------- |
|
199 // |
|
200 CCMRMediaBuffer::TBufferType CMccFileVideo::Type() |
|
201 { |
|
202 return iBufferType; |
|
203 } |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // CMccFileVideo::GetFourCC |
|
207 // ----------------------------------------------------------------------------- |
|
208 // |
|
209 TFourCC CMccFileVideo::GetFourCC() |
|
210 { |
|
211 return iFourCC; |
|
212 } |
|
213 |
|
214 // ----------------------------------------------------------------------------- |
|
215 // CMccFileVideo::TickCallBack |
|
216 // ----------------------------------------------------------------------------- |
|
217 // |
|
218 TCallBack CMccFileVideo::TickCallBack() |
|
219 { |
|
220 return TCallBack( TickVideoL, this ); |
|
221 } |
|
222 |
|
223 // ----------------------------------------------------------------------------- |
|
224 // CMccFileVideo::GetConfigKeyL |
|
225 // ----------------------------------------------------------------------------- |
|
226 // |
|
227 HBufC8* CMccFileVideo::GetConfigKeyL() |
|
228 { |
|
229 __ASSERT_ALWAYS( IsAVC(), User::Leave( KErrNotSupported ) ); |
|
230 HBufC8* configKey = NULL; |
|
231 ExtractH264ParameterSetNALUsL( &configKey, ETrue ); |
|
232 return configKey; |
|
233 } |
|
234 |
|
235 // ----------------------------------------------------------------------------- |
|
236 // CMccFileVideo::Position |
|
237 // ----------------------------------------------------------------------------- |
|
238 // |
|
239 TUint32 CMccFileVideo::Position() |
|
240 { |
|
241 return iPosition; |
|
242 } |
|
243 |
|
244 // ----------------------------------------------------------------------------- |
|
245 // CMccFileVideo::DurationL |
|
246 // ----------------------------------------------------------------------------- |
|
247 // |
|
248 TUint32 CMccFileVideo::Duration() |
|
249 { |
|
250 return iLength; |
|
251 } |
|
252 |
|
253 // ----------------------------------------------------------------------------- |
|
254 // CMccFileVideo::AudioBitRateL |
|
255 // ----------------------------------------------------------------------------- |
|
256 // |
|
257 TUint32 CMccFileVideo::AudioBitRate() |
|
258 { |
|
259 return 0; |
|
260 } |
|
261 |
|
262 |
|
263 // ----------------------------------------------------------------------------- |
|
264 // CMccFileVideo::VideoFrameSizeL |
|
265 // ----------------------------------------------------------------------------- |
|
266 // |
|
267 TSize CMccFileVideo::VideoFrameSize() |
|
268 { |
|
269 TSize size; |
|
270 size.iWidth = iWidth; |
|
271 size. iHeight = iHeight; |
|
272 |
|
273 return size; |
|
274 } |
|
275 |
|
276 // ----------------------------------------------------------------------------- |
|
277 // CMccFileVideo::VideoFrameRateL |
|
278 // ----------------------------------------------------------------------------- |
|
279 // |
|
280 TReal CMccFileVideo::VideoFrameRateL() |
|
281 { |
|
282 // Round to have zero decimals for clearness sake |
|
283 TReal roundedFrameRate; |
|
284 User::LeaveIfError( Math::Round( roundedFrameRate, iFrameRate, 0 ) ); |
|
285 return roundedFrameRate; |
|
286 } |
|
287 |
|
288 // ----------------------------------------------------------------------------- |
|
289 // CMccFileVideo::StartTimerL |
|
290 // ----------------------------------------------------------------------------- |
|
291 // |
|
292 void CMccFileVideo::StartTimerL() |
|
293 { |
|
294 __FILESOURCE_CONTROLL( "CMccFileVideo::StartTimerL" ) |
|
295 |
|
296 if ( IsPaused() ) |
|
297 { |
|
298 SetPaused( EFalse ); |
|
299 |
|
300 SetPositionL( iPosition, ETrue ); |
|
301 } |
|
302 else |
|
303 { |
|
304 SetStartTime(); |
|
305 } |
|
306 |
|
307 const TReal KMccSecondInMicroSeconds = 1000000; |
|
308 TInt tickIntervalVideo = (TInt)KMccSecondInMicroSeconds; |
|
309 if ( iFrameRate != 0 ) |
|
310 { |
|
311 // Set interval for video |
|
312 tickIntervalVideo = (TInt)( KMccSecondInMicroSeconds / iFrameRate ); |
|
313 |
|
314 // Increase tick rate 22% |
|
315 const TReal KMccTickModifier = 0.78; |
|
316 tickIntervalVideo =(TInt) (tickIntervalVideo * KMccTickModifier); |
|
317 } |
|
318 |
|
319 __FILESOURCE_CONTROLL_INT1( "CMccFileVideo::StartTimer (timer):", |
|
320 tickIntervalVideo ) |
|
321 |
|
322 iTimerInterval = tickIntervalVideo; |
|
323 iCorrectionInterval = iTimerInterval; |
|
324 |
|
325 iPeriodicRunner->Start( tickIntervalVideo, TCallBack( TickVideoL, this )); |
|
326 |
|
327 __FILESOURCE_CONTROLL( "CMccFileVideo::StartTimerL, exit" ) |
|
328 } |
|
329 |
|
330 // ----------------------------------------------------------------------------- |
|
331 // CMccFileVideo::TickVideoL |
|
332 // ----------------------------------------------------------------------------- |
|
333 // |
|
334 TInt CMccFileVideo::TickVideoL( TAny* aObject ) |
|
335 { |
|
336 __FILESOURCE_CONTROLL( "CMccFileVideo::TickVideoL" ) |
|
337 |
|
338 static_cast<CMccFileVideo*>(aObject)->ReadFrameL(); |
|
339 return KErrNone; |
|
340 } |
|
341 |
|
342 // ----------------------------------------------------------------------------- |
|
343 // CMccFileVideo::ReadFrameL |
|
344 // ----------------------------------------------------------------------------- |
|
345 // |
|
346 void CMccFileVideo::ReadFrameL() |
|
347 { |
|
348 __FILESOURCE_CONTROLL( "CMccFileVideo::ReadFrameL" ) |
|
349 |
|
350 |
|
351 MP4Err retval = MP4ParseIsFrameAvailable( iMP4Handle, iType ); |
|
352 |
|
353 if ( retval != MP4_OK ) |
|
354 { |
|
355 __FILESOURCE_CONTROLL_INT1( "CMccFileVideo::ReadFrameL, no video", retval ) |
|
356 |
|
357 SetPaused( ETrue ); |
|
358 TRAPD( positionErr, SetPositionL( 0 ) ); |
|
359 iSource.PauseVideoL( positionErr ); |
|
360 return; |
|
361 } |
|
362 |
|
363 // Read the size of next video frame |
|
364 __FILESOURCE_CONTROLL( "CMccFileVideo::ReadFrameL, reading frame" ) |
|
365 |
|
366 if ( MP4ParseNextFrameSize( iMP4Handle, iType, |
|
367 ( mp4_u32* ) &iBufferSize ) != MP4_OK ) |
|
368 { |
|
369 __FILESOURCE_CONTROLL( "CMccFileVideo::ReadFrameL, \ |
|
370 MP4ParseNextFrameSize not Ok" ) |
|
371 return; |
|
372 } |
|
373 |
|
374 TInt aVCNALUsBufferLen = 0; |
|
375 if ( IsAVC() && iIsFirstFrame ) |
|
376 { |
|
377 delete iAVCNALUsBuffer; |
|
378 iAVCNALUsBuffer = NULL; |
|
379 |
|
380 ExtractH264ParameterSetNALUsL( &iAVCNALUsBuffer ); |
|
381 if( iAVCNALUsBuffer ) |
|
382 { |
|
383 aVCNALUsBufferLen += iAVCNALUsBuffer->Length(); |
|
384 } |
|
385 iIsFirstFrame = EFalse; |
|
386 } |
|
387 |
|
388 // Allocate a buffer big enough for the next video frame |
|
389 __FILESOURCE_CONTROLL_INT1( "CMccFileVideo::ReadFrameL, reading frame, size", iBufferSize ) |
|
390 HBufC8* mediaBuffer = HBufC8::NewLC( iBufferSize + aVCNALUsBufferLen ); |
|
391 TPtr8 mediaSinkBuffer = mediaBuffer->Des(); |
|
392 mediaSinkBuffer.SetLength( iBufferSize + aVCNALUsBufferLen ); |
|
393 TUint8* ptrMediaBuffer = CONST_CAST(TUint8*, mediaBuffer->Ptr()); |
|
394 |
|
395 TBool keyFrame = EFalse; |
|
396 |
|
397 TUint32 oldPosition = iPosition; |
|
398 if ( MP4ParseReadVideoFrame( iMP4Handle, |
|
399 ( mp4_u8* ) ptrMediaBuffer, ( mp4_u32 ) iBufferSize, |
|
400 ( mp4_u32* ) &iFrameSize, ( mp4_u32* ) &iPosition, |
|
401 ( mp4_bool* ) &keyFrame, NULL ) != MP4_OK ) |
|
402 { |
|
403 __FILESOURCE_CONTROLL( "CMccFileVideo::ReadFrameL, reading frame, NOT OK" ) |
|
404 CleanupStack::PopAndDestroy( mediaBuffer ); |
|
405 } |
|
406 else |
|
407 { |
|
408 __FILESOURCE_CONTROLL_INT1( "CMccFileVideo::ReadFrameL, reading frame, OK, position", |
|
409 iPosition ) |
|
410 |
|
411 DoTimingCorrection( iPosition ); |
|
412 |
|
413 // Update read interval (how much position changes on each frame read) |
|
414 iReadInterval = iPosition - oldPosition; |
|
415 |
|
416 if ( IsAVC() ) |
|
417 { |
|
418 MarkWithNALUDelimiters( iBufferSize, mediaSinkBuffer ); |
|
419 } |
|
420 |
|
421 TTimeIntervalMicroSeconds timeStamp = GetTimeStamp(); |
|
422 |
|
423 CMccFrameItem* item = new (ELeave) CMccFrameItem(); |
|
424 item->iFrame = mediaBuffer; |
|
425 CleanupStack::Pop( mediaBuffer ); |
|
426 CleanupStack::PushL( item ); |
|
427 item->iTimeStamp = timeStamp; |
|
428 item->iKeyFrame = keyFrame; |
|
429 iFrames.AppendL( item ); |
|
430 CleanupStack::Pop( item ); |
|
431 |
|
432 WriteBufferL(); |
|
433 } |
|
434 |
|
435 __FILESOURCE_CONTROLL( "CMccFileVideo::ReadFrameL, Time Check 2" ) |
|
436 |
|
437 __FILESOURCE_CONTROLL( "CMccFileVideo::ReadFrameL, \ |
|
438 writing buffer to sink complete" ) |
|
439 } |
|
440 |
|
441 // ----------------------------------------------------------------------------- |
|
442 // CMccFileVideo::MarkWithNALUDelimiters() |
|
443 // ----------------------------------------------------------------------------- |
|
444 // |
|
445 void CMccFileVideo::MarkWithNALUDelimiters( |
|
446 const TInt aAccessUnitSize, TDes8& aBuffer ) |
|
447 { |
|
448 __FILESOURCE_CONTROLL( "CMccFileVideo::MarkWithNALUDelimiters" ) |
|
449 |
|
450 TUint8* ptrByte = NULL; |
|
451 TInt indx = 0; |
|
452 TUint32 size; |
|
453 const TUint32 size_field_len = 4; |
|
454 |
|
455 do |
|
456 { |
|
457 ptrByte = const_cast<TUint8*> ( aBuffer.Mid( indx ).Ptr() ); // get starting point of NALU size |
|
458 size = BigEndian::Get32(ptrByte); // get NALU size |
|
459 aBuffer[indx+0] = 0x00; |
|
460 aBuffer[indx+1] = 0x00; |
|
461 aBuffer[indx+2] = 0x00; |
|
462 aBuffer[indx+3] = 0x01; |
|
463 indx = indx + size + size_field_len; |
|
464 |
|
465 }while(indx < aAccessUnitSize); |
|
466 |
|
467 } |
|
468 |
|
469 // ----------------------------------------------------------------------------- |
|
470 // CMccFileVideo::ExtractH264ParameterSetNALUsL() |
|
471 // ----------------------------------------------------------------------------- |
|
472 // |
|
473 void CMccFileVideo::ExtractH264ParameterSetNALUsL( |
|
474 HBufC8** aBufferOut, |
|
475 TBool aSdpFormat ) |
|
476 { |
|
477 __FILESOURCE_CONTROLL( "CMccFileVideo::ExtractH264ParameterSetNALUsL" ) |
|
478 |
|
479 *aBufferOut = NULL; |
|
480 |
|
481 HBufC8* buffer = NULL; |
|
482 HBufC8* bufferOut = NULL; |
|
483 TUint32 decspecinfosize; |
|
484 TUint8* ptrByte; |
|
485 |
|
486 // Query for size, buffer too small error is ok as we give zero length buffer |
|
487 MP4Err retval = MP4ParseReadVideoDecoderSpecificInfo( |
|
488 iMP4Handle, ( mp4_u8* ) NULL, 0, ( mp4_u32* ) &decspecinfosize ); |
|
489 |
|
490 if ( retval != MP4_OK && retval != MP4_BUFFER_TOO_SMALL ) |
|
491 { |
|
492 User::Leave(KErrGeneral); |
|
493 } |
|
494 |
|
495 buffer = HBufC8::NewLC(decspecinfosize); |
|
496 ptrByte = const_cast<TUint8*> ( buffer->Des().Ptr() ); |
|
497 |
|
498 if( MP4ParseReadVideoDecoderSpecificInfo( iMP4Handle, |
|
499 ( mp4_u8* ) ptrByte, |
|
500 ( mp4_u32 ) buffer->Des().MaxSize(), |
|
501 ( mp4_u32* ) &decspecinfosize |
|
502 ) != MP4_OK ) |
|
503 { |
|
504 User::Leave(KErrGeneral); |
|
505 } |
|
506 else |
|
507 { |
|
508 buffer->Des().SetLength( decspecinfosize ); |
|
509 } |
|
510 |
|
511 const TUint two = 2; |
|
512 bufferOut = HBufC8::NewLC( buffer->Size() * two ); |
|
513 TPtr8 ptrBufferOut = bufferOut->Des(); |
|
514 TPtr8 ptrBuffer = buffer->Des(); |
|
515 |
|
516 // find NALUs in decoder info and put in buffer by marking with delimiters |
|
517 |
|
518 TUint8 tmpByte; |
|
519 TUint16 size16; |
|
520 TInt indx = 5; // skip other info in the beginning |
|
521 TInt numNALUs = 0; |
|
522 TInt lp_indx; |
|
523 |
|
524 // get number of seq. parameter set NALUs |
|
525 tmpByte = ptrBuffer[indx++]; |
|
526 numNALUs = tmpByte & 0x1F; // get rid of reserved '111' bits |
|
527 |
|
528 // extract seq. parameter set NALUs |
|
529 |
|
530 for ( lp_indx = 0; lp_indx < numNALUs; lp_indx++ ) |
|
531 { |
|
532 size16 = BigEndian::Get16( ptrBuffer.Mid( indx ).Ptr() ); |
|
533 indx += 2; |
|
534 |
|
535 if ( aSdpFormat ) |
|
536 { |
|
537 // TBD: take possibility of multiple nalus into account |
|
538 HBufC8* base64Encoded = |
|
539 MccConversionUtility::Base64EncodeLC( ptrBuffer.Mid( indx, size16 ) ); |
|
540 ptrBufferOut.Append( *base64Encoded ); |
|
541 CleanupStack::PopAndDestroy( base64Encoded ); |
|
542 } |
|
543 else |
|
544 { |
|
545 // insert delimiter |
|
546 tmpByte = 0x00; |
|
547 ptrBufferOut.Append( &tmpByte, 1 ); |
|
548 ptrBufferOut.Append( &tmpByte, 1 ); |
|
549 ptrBufferOut.Append( &tmpByte, 1 ); |
|
550 tmpByte = 0x01; |
|
551 ptrBufferOut.Append( &tmpByte, 1 ); |
|
552 |
|
553 ptrBufferOut.Append( ptrBuffer.Mid( indx, size16 ) ); |
|
554 } |
|
555 |
|
556 indx += size16; |
|
557 } |
|
558 |
|
559 // get number of pic. parameter set NALUs |
|
560 tmpByte = ptrBuffer[indx++]; |
|
561 numNALUs = tmpByte; |
|
562 |
|
563 // extract pic. parameter set NALUs |
|
564 |
|
565 for ( lp_indx = 0; lp_indx < numNALUs; lp_indx++ ) |
|
566 { |
|
567 size16 = BigEndian::Get16( ptrBuffer.Mid( indx ).Ptr() ); |
|
568 indx += 2; |
|
569 |
|
570 if ( aSdpFormat ) |
|
571 { |
|
572 // TBD: take possibility of multiple nalus into account |
|
573 _LIT8( KMccFileSinkNaluSeparator, "," ); |
|
574 ptrBufferOut.Append( KMccFileSinkNaluSeparator ); |
|
575 HBufC8* base64Encoded = |
|
576 MccConversionUtility::Base64EncodeLC( ptrBuffer.Mid( indx, size16 ) ); |
|
577 ptrBufferOut.Append( *base64Encoded ); |
|
578 CleanupStack::PopAndDestroy( base64Encoded ); |
|
579 } |
|
580 else |
|
581 { |
|
582 // insert delimiter |
|
583 tmpByte = 0x00; |
|
584 ptrBufferOut.Append( &tmpByte, 1 ); |
|
585 ptrBufferOut.Append( &tmpByte, 1 ); |
|
586 ptrBufferOut.Append( &tmpByte, 1 ); |
|
587 tmpByte = 0x01; |
|
588 ptrBufferOut.Append( &tmpByte, 1 ); |
|
589 |
|
590 ptrBufferOut.Append( ptrBuffer.Mid( indx, size16 ) ); |
|
591 } |
|
592 |
|
593 indx += size16; |
|
594 } |
|
595 |
|
596 CleanupStack::Pop( bufferOut ); |
|
597 CleanupStack::PopAndDestroy( buffer ); |
|
598 |
|
599 *aBufferOut = bufferOut; |
|
600 |
|
601 __FILESOURCE_CONTROLL( "CMccFileVideo::ExtractH264ParameterSetNALUsL, exit" ) |
|
602 } |
|
603 |
|
604 // ----------------------------------------------------------------------------- |
|
605 // CMccFileVideo::InsertParameterSetNALUs |
|
606 // ----------------------------------------------------------------------------- |
|
607 // |
|
608 TBool CMccFileVideo::InsertParameterSetNALUs() |
|
609 { |
|
610 TBool insertParameterSets( iInsertParameterSets ); |
|
611 if ( insertParameterSets ) |
|
612 { |
|
613 iInsertParameterSets = EFalse; |
|
614 iInsertParameterSetsTime.HomeTime(); |
|
615 } |
|
616 else |
|
617 { |
|
618 TTime currentTime; |
|
619 currentTime.HomeTime(); |
|
620 if ( currentTime.MicroSecondsFrom( iInsertParameterSetsTime ).Int64() > |
|
621 KMccFileSourceParameterSetsIntervalInMicroSeconds ) |
|
622 { |
|
623 // Enough time elapsed from previous parameter set NALUs, |
|
624 // insert them at next round. |
|
625 iInsertParameterSets = ETrue; |
|
626 } |
|
627 } |
|
628 return insertParameterSets; |
|
629 } |
|
630 |
|
631 // ----------------------------------------------------------------------------- |
|
632 // CMccFileVideo::GetTimeStamp |
|
633 // ----------------------------------------------------------------------------- |
|
634 // |
|
635 TTimeIntervalMicroSeconds CMccFileVideo::GetTimeStamp() |
|
636 { |
|
637 TInt64 position = iPosition + iPositionModifier; |
|
638 TUint32 position2 = ( position < 0 ) ? 0 : (TUint32)position; |
|
639 TTimeIntervalMicroSeconds timeStamp = |
|
640 TTimeIntervalMicroSeconds ( (TInt64) position2 * KMccMicroToMilliConst ); |
|
641 |
|
642 __FILESOURCE_CONTROLL_INT1( "CMccFileVideo::GetTimeStamp timestamp (without clock frequency):", |
|
643 timeStamp.Int64() ) |
|
644 return timeStamp; |
|
645 } |
|
646 |
|
647 // ----------------------------------------------------------------------------- |
|
648 // CMccFileVideo::WriteBufferL |
|
649 // If AVC NALUS buffer exists, it is passed always before keyframe and it uses |
|
650 // timestamp of that frame. It is also passed always at beginning even if first |
|
651 // frame wouldn't be keyframe. |
|
652 // ----------------------------------------------------------------------------- |
|
653 // |
|
654 void CMccFileVideo::WriteBufferL() |
|
655 { |
|
656 __FILESOURCE_CONTROLL("CMccFileVideo::WriteBufferL") |
|
657 |
|
658 if ( iFrames.Count() && iConsumer && iConsumerBuffer ) |
|
659 { |
|
660 TBool removeCurrentFrame( ETrue ); |
|
661 |
|
662 CMMFDataBuffer* buf = static_cast<CMMFDataBuffer*>(iConsumerBuffer); |
|
663 |
|
664 CMccFrameItem* item = iFrames[0]; |
|
665 HBufC8* videoFrame = item->iFrame; |
|
666 |
|
667 if ( iAVCNALUsBuffer && InsertParameterSetNALUs() ) |
|
668 { |
|
669 videoFrame = iAVCNALUsBuffer; |
|
670 removeCurrentFrame = EFalse; |
|
671 } |
|
672 |
|
673 if ( buf->Data().MaxLength() >= videoFrame->Des().Length() ) |
|
674 { |
|
675 buf->Data().Delete( 0, buf->BufferSize() ); |
|
676 |
|
677 buf->Data().Append( *videoFrame ); |
|
678 |
|
679 iConsumerBuffer->SetTimeToPlay(item->iTimeStamp); |
|
680 iConsumerBuffer->SetLastBuffer(EFalse); |
|
681 iConsumerBuffer->SetFrameNumber( iSequenceNum ); |
|
682 |
|
683 if ( removeCurrentFrame ) |
|
684 { |
|
685 if ( iMccResources && item->iKeyFrame ) |
|
686 { |
|
687 iMccResources->StoreKeyFrameInfoL( iEndpointId, *iConsumerBuffer ); |
|
688 } |
|
689 |
|
690 delete item; |
|
691 iFrames.Remove(0); |
|
692 } |
|
693 |
|
694 videoFrame = NULL; |
|
695 |
|
696 iConsumer->BufferFilledL( iConsumerBuffer ); |
|
697 iConsumer = NULL; |
|
698 iConsumerBuffer = NULL; |
|
699 iSequenceNum++; |
|
700 __FILESOURCE_CONTROLL("CMccFileVideo::WriteBufferL, done") |
|
701 } |
|
702 else |
|
703 { |
|
704 __FILESOURCE_CONTROLL("CMccFileVideo::WriteBufferL, drop frame") |
|
705 delete iFrames[0]; |
|
706 iFrames.Remove(0); |
|
707 videoFrame = NULL; |
|
708 } |
|
709 } |
|
710 else |
|
711 { |
|
712 __FILESOURCE_CONTROLL("CMccFileVideo::WriteBufferL, writing ignored") |
|
713 } |
|
714 } |
|
715 |
|
716 |