os/mm/mmplugins/lib3gp/impl/src/mp4compose.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include <3gplibrary/mp4config.h>
sl@0
    17
#include <3gplibrary/mp4lib.h>
sl@0
    18
#include "mp4atom.h"
sl@0
    19
#include "mp4memwrap.h"
sl@0
    20
#include "mp4file.h"
sl@0
    21
#include "mp4compose.h"
sl@0
    22
#include "mp4utils.h"
sl@0
    23
sl@0
    24
// MACROS
sl@0
    25
// Debug print macro
sl@0
    26
#ifdef _DEBUG
sl@0
    27
#include <e32svr.h>
sl@0
    28
#define PRINT(x) 
sl@0
    29
#else
sl@0
    30
#define PRINT(x)
sl@0
    31
#endif
sl@0
    32
sl@0
    33
#define STTSMAXENTRYCOUNT  100
sl@0
    34
#define STSZMAXSAMPLECOUNT 100
sl@0
    35
#define STSCMAXENTRYCOUNT    2
sl@0
    36
#define STCOMAXENTRYCOUNT  100
sl@0
    37
#define STSSMAXENTRYCOUNT  100
sl@0
    38
#define SDTPMAXENTRYCOUNT  100
sl@0
    39
sl@0
    40
sl@0
    41
extern EXPORT_C MP4Err MP4ComposeOpen(MP4Handle *apihandle,
sl@0
    42
                                                   MP4FileName filename,
sl@0
    43
                                                   mp4_u32 type)
sl@0
    44
{
sl@0
    45
  MP4Err error = MP4_OK;
sl@0
    46
  MP4HandleImp* handle = (MP4HandleStruct **)apihandle;
sl@0
    47
sl@0
    48
  if ( filename != NULL )
sl@0
    49
      {
sl@0
    50
      *handle = (MP4HandleImp)mp4malloc(sizeof(MP4HandleStruct));     
sl@0
    51
      if (*handle == NULL)
sl@0
    52
          {
sl@0
    53
          return MP4_OUT_OF_MEMORY;      
sl@0
    54
          }
sl@0
    55
      (*handle)->bufferWrite=MP4FALSE;
sl@0
    56
      }
sl@0
    57
  else
sl@0
    58
      {
sl@0
    59
      if ( *handle == NULL )
sl@0
    60
          {
sl@0
    61
          return MP4_ERROR;
sl@0
    62
          }
sl@0
    63
      }
sl@0
    64
  
sl@0
    65
  (*handle)->file32Duplicate = NULL;
sl@0
    66
  (*handle)->FileHandleFromOutside = EFalse;
sl@0
    67
sl@0
    68
  if(!(*handle)->bufferWrite)
sl@0
    69
  {
sl@0
    70
		if (!filename)
sl@0
    71
		    {
sl@0
    72
			error = MP4_FILE_ERROR;
sl@0
    73
		    }
sl@0
    74
		
sl@0
    75
		if ( error == MP4_OK )
sl@0
    76
		    {
sl@0
    77
    		if (saveFileName(filename, *handle) < 0)
sl@0
    78
	    		error = MP4_OUT_OF_MEMORY;
sl@0
    79
		    }
sl@0
    80
		
sl@0
    81
		if (error == MP4_OK)
sl@0
    82
		{
sl@0
    83
			if (createTmpFileName(filename, &((*handle)->tmpFileName)) == -1)
sl@0
    84
				error = MP4_OUT_OF_MEMORY;
sl@0
    85
		}
sl@0
    86
		
sl@0
    87
		if (error == MP4_OK)
sl@0
    88
		{
sl@0
    89
			if (initFileWrite(filename, *handle) == -1)
sl@0
    90
				error = MP4_FILE_ERROR;
sl@0
    91
		}
sl@0
    92
		
sl@0
    93
		if (error == MP4_OK)
sl@0
    94
		{
sl@0
    95
			if (initTmpFileWrite((*handle)->tmpFileName, *handle) == -1)
sl@0
    96
				error = MP4_FILE_ERROR;
sl@0
    97
		}
sl@0
    98
  }
sl@0
    99
sl@0
   100
  if (error == MP4_OK)
sl@0
   101
  {
sl@0
   102
    (*handle)->diskWriteBuf = (mp4_u8 *)mp4malloc(WRITEBUFSIZE);
sl@0
   103
    if ((*handle)->diskWriteBuf == NULL)
sl@0
   104
      error = MP4_OUT_OF_MEMORY;
sl@0
   105
  }
sl@0
   106
sl@0
   107
  if (error == MP4_OK)
sl@0
   108
  {
sl@0
   109
    (*handle)->audioSampleTable = (sampleTable *)mp4malloc(sizeof(sampleTable));
sl@0
   110
    if ((*handle)->audioSampleTable == NULL)
sl@0
   111
      error = MP4_OUT_OF_MEMORY;
sl@0
   112
  }
sl@0
   113
sl@0
   114
  if (error == MP4_OK)
sl@0
   115
  {
sl@0
   116
    (*handle)->audioSampleTable->sttsSampleCount = (mp4_u32 *)mp4malloc(sizeof(mp4_u32) * STTSMAXENTRYCOUNT);
sl@0
   117
    if ((*handle)->audioSampleTable->sttsSampleCount == NULL)
sl@0
   118
      error = MP4_OUT_OF_MEMORY;
sl@0
   119
  }
sl@0
   120
sl@0
   121
  if (error == MP4_OK)
sl@0
   122
  {
sl@0
   123
    (*handle)->audioSampleTable->sttsSampleDelta = (mp4_u32 *)mp4malloc(sizeof(mp4_u32) * STTSMAXENTRYCOUNT);
sl@0
   124
    if ((*handle)->audioSampleTable->sttsSampleDelta == NULL)
sl@0
   125
      error = MP4_OUT_OF_MEMORY;
sl@0
   126
  }
sl@0
   127
sl@0
   128
  if (error == MP4_OK)
sl@0
   129
  {
sl@0
   130
    (*handle)->audioSampleTable->stszEntrySize = (mp4_u32 *)mp4malloc(sizeof(mp4_u32) * STSZMAXSAMPLECOUNT);
sl@0
   131
    if ((*handle)->audioSampleTable->stszEntrySize == NULL)
sl@0
   132
      error = MP4_OUT_OF_MEMORY;
sl@0
   133
  }
sl@0
   134
sl@0
   135
  if (error == MP4_OK)
sl@0
   136
  {
sl@0
   137
    (*handle)->audioSampleTable->stscFirstChunk = (mp4_u32 *)mp4malloc(sizeof(mp4_u32) * STSCMAXENTRYCOUNT);
sl@0
   138
    if ((*handle)->audioSampleTable->stscFirstChunk == NULL)
sl@0
   139
      error = MP4_OUT_OF_MEMORY;
sl@0
   140
  }
sl@0
   141
sl@0
   142
  if (error == MP4_OK)
sl@0
   143
  {
sl@0
   144
    (*handle)->audioSampleTable->stscSamplesPerChunk = (mp4_u32 *)mp4malloc(sizeof(mp4_u32) * STSCMAXENTRYCOUNT);
sl@0
   145
    if ((*handle)->audioSampleTable->stscSamplesPerChunk == NULL)
sl@0
   146
      error = MP4_OUT_OF_MEMORY;
sl@0
   147
  }
sl@0
   148
sl@0
   149
  if (error == MP4_OK)
sl@0
   150
  {
sl@0
   151
    (*handle)->audioSampleTable->stscSampleDescriptionIndex = (mp4_u32 *)mp4malloc(sizeof(mp4_u32) * STSCMAXENTRYCOUNT);
sl@0
   152
    if ((*handle)->audioSampleTable->stscSampleDescriptionIndex == NULL)
sl@0
   153
      error = MP4_OUT_OF_MEMORY;
sl@0
   154
  }
sl@0
   155
sl@0
   156
  if (error == MP4_OK)
sl@0
   157
  {
sl@0
   158
    (*handle)->audioSampleTable->stcoChunkOffset = (mp4_u64 *)mp4malloc(sizeof(mp4_u64) * STCOMAXENTRYCOUNT);
sl@0
   159
    if ((*handle)->audioSampleTable->stcoChunkOffset == NULL)
sl@0
   160
      error = MP4_OUT_OF_MEMORY;
sl@0
   161
  }
sl@0
   162
sl@0
   163
  if (error == MP4_OK)
sl@0
   164
  {
sl@0
   165
    (*handle)->videoSampleTable = (sampleTable *)mp4malloc(sizeof(sampleTable));
sl@0
   166
    if ((*handle)->videoSampleTable == NULL)
sl@0
   167
      error = MP4_OUT_OF_MEMORY;
sl@0
   168
  }
sl@0
   169
sl@0
   170
  if (error == MP4_OK)
sl@0
   171
  {
sl@0
   172
    (*handle)->videoSampleTable->sttsSampleCount = (mp4_u32 *)mp4malloc(sizeof(mp4_u32) * STTSMAXENTRYCOUNT);
sl@0
   173
    if ((*handle)->videoSampleTable->sttsSampleCount == NULL)
sl@0
   174
      error = MP4_OUT_OF_MEMORY;
sl@0
   175
  }
sl@0
   176
sl@0
   177
  if (error == MP4_OK)
sl@0
   178
  {
sl@0
   179
    (*handle)->videoSampleTable->sttsSampleDelta = (mp4_u32 *)mp4malloc(sizeof(mp4_u32) * STTSMAXENTRYCOUNT);
sl@0
   180
    if ((*handle)->videoSampleTable->sttsSampleDelta == NULL)
sl@0
   181
      error = MP4_OUT_OF_MEMORY;
sl@0
   182
  }
sl@0
   183
sl@0
   184
  if (error == MP4_OK)
sl@0
   185
  {
sl@0
   186
    (*handle)->videoSampleTable->stszEntrySize = (mp4_u32 *)mp4malloc(sizeof(mp4_u32) * STSZMAXSAMPLECOUNT);
sl@0
   187
    if ((*handle)->videoSampleTable->stszEntrySize == NULL)
sl@0
   188
      error = MP4_OUT_OF_MEMORY;
sl@0
   189
  }
sl@0
   190
sl@0
   191
  if (error == MP4_OK)
sl@0
   192
  {
sl@0
   193
    (*handle)->videoSampleTable->stscFirstChunk = (mp4_u32 *)mp4malloc(sizeof(mp4_u32) * STSCMAXENTRYCOUNT);
sl@0
   194
    if ((*handle)->videoSampleTable->stscFirstChunk == NULL)
sl@0
   195
      error = MP4_OUT_OF_MEMORY;
sl@0
   196
  }
sl@0
   197
sl@0
   198
  if (error == MP4_OK)
sl@0
   199
  {
sl@0
   200
    (*handle)->videoSampleTable->stscSamplesPerChunk = (mp4_u32 *)mp4malloc(sizeof(mp4_u32) * STSCMAXENTRYCOUNT);
sl@0
   201
    if ((*handle)->videoSampleTable->stscSamplesPerChunk == NULL)
sl@0
   202
      error = MP4_OUT_OF_MEMORY;
sl@0
   203
  }
sl@0
   204
sl@0
   205
  if (error == MP4_OK)
sl@0
   206
  {
sl@0
   207
    (*handle)->videoSampleTable->stscSampleDescriptionIndex = (mp4_u32 *)mp4malloc(sizeof(mp4_u32) * STSCMAXENTRYCOUNT);
sl@0
   208
    if ((*handle)->videoSampleTable->stscSampleDescriptionIndex == NULL)
sl@0
   209
      error = MP4_OUT_OF_MEMORY;
sl@0
   210
  }
sl@0
   211
sl@0
   212
  if (error == MP4_OK)
sl@0
   213
  {
sl@0
   214
    (*handle)->videoSampleTable->stcoChunkOffset = (mp4_u64 *)mp4malloc(sizeof(mp4_u64) * STCOMAXENTRYCOUNT);
sl@0
   215
    if ((*handle)->videoSampleTable->stcoChunkOffset == NULL)
sl@0
   216
      error = MP4_OUT_OF_MEMORY;
sl@0
   217
  }
sl@0
   218
sl@0
   219
  if (error == MP4_OK)
sl@0
   220
  {
sl@0
   221
    (*handle)->videoSampleTable->stssSampleNumber = (mp4_u32 *)mp4malloc(sizeof(mp4_u32) * STSSMAXENTRYCOUNT);
sl@0
   222
    if ((*handle)->videoSampleTable->stssSampleNumber == NULL)
sl@0
   223
      error = MP4_OUT_OF_MEMORY;
sl@0
   224
  }
sl@0
   225
  
sl@0
   226
  if (error == MP4_OK)
sl@0
   227
  {
sl@0
   228
    (*handle)->videoSampleTable->sdtpSampleDependency = (mp4_u8 *)mp4malloc(sizeof(mp4_u8) * SDTPMAXENTRYCOUNT);
sl@0
   229
    if ((*handle)->videoSampleTable->sdtpSampleDependency == NULL)
sl@0
   230
      error = MP4_OUT_OF_MEMORY;
sl@0
   231
  }
sl@0
   232
sl@0
   233
  // register for stblib use 
sl@0
   234
  if (error == MP4_OK)
sl@0
   235
	  {
sl@0
   236
	  if (openStdlib() !=  MP4_OK)
sl@0
   237
		  {
sl@0
   238
		  error = MP4_ERROR;
sl@0
   239
		  }
sl@0
   240
	  }
sl@0
   241
  
sl@0
   242
  if (error != MP4_OK)
sl@0
   243
  {
sl@0
   244
    if(!(*handle)->bufferWrite)
sl@0
   245
    {
sl@0
   246
        closeFile(*handle);
sl@0
   247
sl@0
   248
        closeTmpFile(*handle);
sl@0
   249
sl@0
   250
        freeTmpFileName((*handle)->tmpFileName);
sl@0
   251
    }
sl@0
   252
sl@0
   253
    if ((*handle)->diskWriteBuf)
sl@0
   254
      mp4free((*handle)->diskWriteBuf);
sl@0
   255
sl@0
   256
    if ((*handle)->videoSampleTable)
sl@0
   257
    {
sl@0
   258
      if ((*handle)->videoSampleTable->stssSampleNumber)
sl@0
   259
        mp4free((*handle)->videoSampleTable->stssSampleNumber);
sl@0
   260
sl@0
   261
      if ((*handle)->videoSampleTable->stcoChunkOffset)
sl@0
   262
        mp4free((*handle)->videoSampleTable->stcoChunkOffset);
sl@0
   263
sl@0
   264
      if ((*handle)->videoSampleTable->stscSampleDescriptionIndex)
sl@0
   265
        mp4free((*handle)->videoSampleTable->stscSampleDescriptionIndex);
sl@0
   266
sl@0
   267
      if ((*handle)->videoSampleTable->stscSamplesPerChunk)
sl@0
   268
        mp4free((*handle)->videoSampleTable->stscSamplesPerChunk);
sl@0
   269
sl@0
   270
      if ((*handle)->videoSampleTable->stscFirstChunk)
sl@0
   271
        mp4free((*handle)->videoSampleTable->stscFirstChunk);
sl@0
   272
sl@0
   273
      if ((*handle)->videoSampleTable->stszEntrySize)
sl@0
   274
        mp4free((*handle)->videoSampleTable->stszEntrySize);
sl@0
   275
sl@0
   276
      if ((*handle)->videoSampleTable->sttsSampleCount)
sl@0
   277
        mp4free((*handle)->videoSampleTable->sttsSampleCount);
sl@0
   278
sl@0
   279
      if ((*handle)->videoSampleTable->sttsSampleDelta)
sl@0
   280
        mp4free((*handle)->videoSampleTable->sttsSampleDelta);
sl@0
   281
      
sl@0
   282
      if ((*handle)->videoSampleTable->sdtpSampleDependency)
sl@0
   283
        mp4free((*handle)->videoSampleTable->sdtpSampleDependency);
sl@0
   284
sl@0
   285
      mp4free((*handle)->videoSampleTable);
sl@0
   286
    }
sl@0
   287
sl@0
   288
    if ((*handle)->audioSampleTable)
sl@0
   289
    {
sl@0
   290
      if ((*handle)->audioSampleTable->stcoChunkOffset)
sl@0
   291
        mp4free((*handle)->audioSampleTable->stcoChunkOffset);
sl@0
   292
sl@0
   293
      if ((*handle)->audioSampleTable->stscSampleDescriptionIndex)
sl@0
   294
        mp4free((*handle)->audioSampleTable->stscSampleDescriptionIndex);
sl@0
   295
sl@0
   296
      if ((*handle)->audioSampleTable->stscSamplesPerChunk)
sl@0
   297
        mp4free((*handle)->audioSampleTable->stscSamplesPerChunk);
sl@0
   298
sl@0
   299
      if ((*handle)->audioSampleTable->stscFirstChunk)
sl@0
   300
        mp4free((*handle)->audioSampleTable->stscFirstChunk);
sl@0
   301
sl@0
   302
      if ((*handle)->audioSampleTable->stszEntrySize)
sl@0
   303
        mp4free((*handle)->audioSampleTable->stszEntrySize);
sl@0
   304
sl@0
   305
      if ((*handle)->audioSampleTable->sttsSampleDelta)
sl@0
   306
        mp4free((*handle)->audioSampleTable->sttsSampleDelta);
sl@0
   307
sl@0
   308
      if ((*handle)->audioSampleTable->sttsSampleCount)
sl@0
   309
        mp4free((*handle)->audioSampleTable->sttsSampleCount);
sl@0
   310
sl@0
   311
      mp4free((*handle)->audioSampleTable);
sl@0
   312
    }
sl@0
   313
sl@0
   314
    if ((*handle)->fileName)
sl@0
   315
      mp4free((*handle)->fileName);
sl@0
   316
sl@0
   317
    mp4free(*handle);
sl@0
   318
    *handle = NULL;
sl@0
   319
sl@0
   320
    return error;
sl@0
   321
  }
sl@0
   322
sl@0
   323
sl@0
   324
  (*handle)->audioSampleTable->sttsMaxEntryCount  = STTSMAXENTRYCOUNT;
sl@0
   325
  (*handle)->audioSampleTable->stszMaxSampleCount = STSZMAXSAMPLECOUNT;
sl@0
   326
  (*handle)->audioSampleTable->stscMaxEntryCount  = STSCMAXENTRYCOUNT;
sl@0
   327
  (*handle)->audioSampleTable->stcoMaxEntryCount  = STCOMAXENTRYCOUNT;
sl@0
   328
  (*handle)->audioSampleTable->stcoNeed64Bits     = EFalse;
sl@0
   329
  
sl@0
   330
  (*handle)->videoSampleTable->sttsMaxEntryCount  = STTSMAXENTRYCOUNT;
sl@0
   331
  (*handle)->videoSampleTable->stszMaxSampleCount = STSZMAXSAMPLECOUNT;
sl@0
   332
  (*handle)->videoSampleTable->stscMaxEntryCount  = STSCMAXENTRYCOUNT;
sl@0
   333
  (*handle)->videoSampleTable->stcoMaxEntryCount  = STCOMAXENTRYCOUNT;
sl@0
   334
  (*handle)->videoSampleTable->stssMaxEntryCount  = STSSMAXENTRYCOUNT;
sl@0
   335
  (*handle)->videoSampleTable->sdtpMaxEntryCount  = SDTPMAXENTRYCOUNT;
sl@0
   336
  (*handle)->videoSampleTable->stcoNeed64Bits     = EFalse;
sl@0
   337
  
sl@0
   338
  (*handle)->type = type;
sl@0
   339
sl@0
   340
  /* Check if a 3GPP2 codec is being used */
sl@0
   341
  if ((*handle)->type & MP4_TYPE_QCELP_13K)
sl@0
   342
      {
sl@0
   343
      (*handle)->generate3G2 = MP4TRUE;
sl@0
   344
      }
sl@0
   345
sl@0
   346
  return MP4_OK;
sl@0
   347
}
sl@0
   348
sl@0
   349
extern EXPORT_C MP4Err MP4ComposeOpenToBuffer(MP4Handle *apihandle,
sl@0
   350
                                                   mp4_u32 type,
sl@0
   351
                                                   mp4_u8* composeBuffer, 
sl@0
   352
                                                   mp4_u32 *composedSize)
sl@0
   353
{
sl@0
   354
  MP4HandleImp* handle = (MP4HandleStruct **)apihandle;
sl@0
   355
sl@0
   356
  *handle = (MP4HandleImp)mp4malloc(sizeof(MP4HandleStruct));
sl@0
   357
  if (*handle == NULL)              
sl@0
   358
    return MP4_OUT_OF_MEMORY;
sl@0
   359
sl@0
   360
  (*handle)->file32Duplicate = NULL;
sl@0
   361
  (*handle)->bufferWrite=MP4TRUE;
sl@0
   362
  (*handle)->FileHandleFromOutside = EFalse;
sl@0
   363
sl@0
   364
  if(composeBuffer == NULL)
sl@0
   365
	{
sl@0
   366
	return MP4_NO_OUTPUT_BUFFER; //This is to indicate that compose buffer has not been initialized
sl@0
   367
	}
sl@0
   368
sl@0
   369
  (*handle)->composeBuffer=composeBuffer;
sl@0
   370
  (*handle)->composedSize=composedSize;
sl@0
   371
sl@0
   372
  return MP4ComposeOpen( apihandle, NULL, type );
sl@0
   373
}
sl@0
   374
sl@0
   375
extern EXPORT_C MP4Err MP4ComposeOpenFileHandle(MP4Handle *apihandle, 
sl@0
   376
                                                             RFile *composedfile, 
sl@0
   377
                                                             TDriveNumber metadataTempDrive, 
sl@0
   378
                                                             mp4_u32 type)
sl@0
   379
{
sl@0
   380
  MP4Err err;
sl@0
   381
  RFile64 *f64 = new RFile64;
sl@0
   382
  if (f64 == NULL)
sl@0
   383
  {
sl@0
   384
    return MP4_OUT_OF_MEMORY;
sl@0
   385
  }
sl@0
   386
  if  (f64->Duplicate(*composedfile) != KErrNone)
sl@0
   387
  {
sl@0
   388
    delete f64;
sl@0
   389
    return MP4_ERROR;
sl@0
   390
  }
sl@0
   391
  err = MP4ComposeOpenFileHandle64(apihandle, f64, metadataTempDrive, type);
sl@0
   392
  if (err == MP4_OK)
sl@0
   393
  {    
sl@0
   394
    MP4HandleImp* handle = (MP4HandleStruct **)apihandle;
sl@0
   395
    (*handle)->file32Duplicate = (void*)f64;
sl@0
   396
  }
sl@0
   397
  return err;
sl@0
   398
}
sl@0
   399
sl@0
   400
sl@0
   401
sl@0
   402
extern EXPORT_C MP4Err MP4ComposeOpenFileHandle64(MP4Handle *apihandle, 
sl@0
   403
                                                             RFile64 *composedfile, 
sl@0
   404
                                                             TDriveNumber metadataTempDrive, 
sl@0
   405
                                                             mp4_u32 type)
sl@0
   406
{
sl@0
   407
  MP4Err error = MP4_OK;
sl@0
   408
  MP4HandleImp* handle = (MP4HandleStruct **)apihandle;
sl@0
   409
sl@0
   410
  *handle = (MP4HandleImp)mp4malloc(sizeof(MP4HandleStruct));     
sl@0
   411
  if (*handle == NULL)
sl@0
   412
      {
sl@0
   413
      return MP4_OUT_OF_MEMORY;      
sl@0
   414
      }
sl@0
   415
  (*handle)->bufferWrite=MP4FALSE;
sl@0
   416
  (*handle)->file32Duplicate = NULL;
sl@0
   417
  // since file handle we can´t use temporary file for mediadata safely.
sl@0
   418
  (*handle)->flags |= MP4_FLAG_METADATALAST;
sl@0
   419
  (*handle)->FileHandleFromOutside = ETrue;
sl@0
   420
  (*handle)->fileHandleDrive = metadataTempDrive;
sl@0
   421
sl@0
   422
  RFs   *fs;
sl@0
   423
  fs = new(RFs);
sl@0
   424
  (*handle)->fs = (void *)fs;
sl@0
   425
  if (fs == NULL)
sl@0
   426
    error = MP4_FILE_ERROR;
sl@0
   427
  
sl@0
   428
  if (error == MP4_OK)
sl@0
   429
    {
sl@0
   430
    if (fs->Connect() != KErrNone)
sl@0
   431
        error = MP4_FILE_ERROR;
sl@0
   432
    }
sl@0
   433
sl@0
   434
  if (error == MP4_OK)
sl@0
   435
    {
sl@0
   436
    (*handle)->rfile = (void *)composedfile;
sl@0
   437
    if (composedfile == NULL)
sl@0
   438
        error = MP4_FILE_ERROR;
sl@0
   439
    
sl@0
   440
    (*handle)->file = (*handle)->rfile;    
sl@0
   441
    
sl@0
   442
    TRAPD(traperror, (*handle)->filewriter = CFileWriter::NewL( *composedfile ));
sl@0
   443
    if ( traperror != KErrNone )
sl@0
   444
        {
sl@0
   445
        error = MP4_FILE_ERROR;
sl@0
   446
        }
sl@0
   447
    }
sl@0
   448
	
sl@0
   449
  if (error == MP4_OK)
sl@0
   450
  {
sl@0
   451
    (*handle)->diskWriteBuf = (mp4_u8 *)mp4malloc(WRITEBUFSIZE);
sl@0
   452
    if ((*handle)->diskWriteBuf == NULL)
sl@0
   453
      error = MP4_OUT_OF_MEMORY;
sl@0
   454
  }
sl@0
   455
sl@0
   456
  if (error == MP4_OK)
sl@0
   457
  {
sl@0
   458
    (*handle)->audioSampleTable = (sampleTable *)mp4malloc(sizeof(sampleTable));
sl@0
   459
    if ((*handle)->audioSampleTable == NULL)
sl@0
   460
      error = MP4_OUT_OF_MEMORY;
sl@0
   461
  }
sl@0
   462
sl@0
   463
  if (error == MP4_OK)
sl@0
   464
  {
sl@0
   465
    (*handle)->audioSampleTable->sttsSampleCount = (mp4_u32 *)mp4malloc(sizeof(mp4_u32) * STTSMAXENTRYCOUNT);
sl@0
   466
    if ((*handle)->audioSampleTable->sttsSampleCount == NULL)
sl@0
   467
      error = MP4_OUT_OF_MEMORY;
sl@0
   468
  }
sl@0
   469
sl@0
   470
  if (error == MP4_OK)
sl@0
   471
  {
sl@0
   472
    (*handle)->audioSampleTable->sttsSampleDelta = (mp4_u32 *)mp4malloc(sizeof(mp4_u32) * STTSMAXENTRYCOUNT);
sl@0
   473
    if ((*handle)->audioSampleTable->sttsSampleDelta == NULL)
sl@0
   474
      error = MP4_OUT_OF_MEMORY;
sl@0
   475
  }
sl@0
   476
sl@0
   477
  if (error == MP4_OK)
sl@0
   478
  {
sl@0
   479
    (*handle)->audioSampleTable->stszEntrySize = (mp4_u32 *)mp4malloc(sizeof(mp4_u32) * STSZMAXSAMPLECOUNT);
sl@0
   480
    if ((*handle)->audioSampleTable->stszEntrySize == NULL)
sl@0
   481
      error = MP4_OUT_OF_MEMORY;
sl@0
   482
  }
sl@0
   483
sl@0
   484
  if (error == MP4_OK)
sl@0
   485
  {
sl@0
   486
    (*handle)->audioSampleTable->stscFirstChunk = (mp4_u32 *)mp4malloc(sizeof(mp4_u32) * STSCMAXENTRYCOUNT);
sl@0
   487
    if ((*handle)->audioSampleTable->stscFirstChunk == NULL)
sl@0
   488
      error = MP4_OUT_OF_MEMORY;
sl@0
   489
  }
sl@0
   490
sl@0
   491
  if (error == MP4_OK)
sl@0
   492
  {
sl@0
   493
    (*handle)->audioSampleTable->stscSamplesPerChunk = (mp4_u32 *)mp4malloc(sizeof(mp4_u32) * STSCMAXENTRYCOUNT);
sl@0
   494
    if ((*handle)->audioSampleTable->stscSamplesPerChunk == NULL)
sl@0
   495
      error = MP4_OUT_OF_MEMORY;
sl@0
   496
  }
sl@0
   497
sl@0
   498
  if (error == MP4_OK)
sl@0
   499
  {
sl@0
   500
    (*handle)->audioSampleTable->stscSampleDescriptionIndex = (mp4_u32 *)mp4malloc(sizeof(mp4_u32) * STSCMAXENTRYCOUNT);
sl@0
   501
    if ((*handle)->audioSampleTable->stscSampleDescriptionIndex == NULL)
sl@0
   502
      error = MP4_OUT_OF_MEMORY;
sl@0
   503
  }
sl@0
   504
sl@0
   505
  if (error == MP4_OK)
sl@0
   506
  {
sl@0
   507
    (*handle)->audioSampleTable->stcoChunkOffset = (mp4_u64 *)mp4malloc(sizeof(mp4_u64) * STCOMAXENTRYCOUNT);
sl@0
   508
    if ((*handle)->audioSampleTable->stcoChunkOffset == NULL)
sl@0
   509
      error = MP4_OUT_OF_MEMORY;
sl@0
   510
  }
sl@0
   511
sl@0
   512
  if (error == MP4_OK)
sl@0
   513
  {
sl@0
   514
    (*handle)->videoSampleTable = (sampleTable *)mp4malloc(sizeof(sampleTable));
sl@0
   515
    if ((*handle)->videoSampleTable == NULL)
sl@0
   516
      error = MP4_OUT_OF_MEMORY;
sl@0
   517
  }
sl@0
   518
sl@0
   519
  if (error == MP4_OK)
sl@0
   520
  {
sl@0
   521
    (*handle)->videoSampleTable->sttsSampleCount = (mp4_u32 *)mp4malloc(sizeof(mp4_u32) * STTSMAXENTRYCOUNT);
sl@0
   522
    if ((*handle)->videoSampleTable->sttsSampleCount == NULL)
sl@0
   523
      error = MP4_OUT_OF_MEMORY;
sl@0
   524
  }
sl@0
   525
sl@0
   526
  if (error == MP4_OK)
sl@0
   527
  {
sl@0
   528
    (*handle)->videoSampleTable->sttsSampleDelta = (mp4_u32 *)mp4malloc(sizeof(mp4_u32) * STTSMAXENTRYCOUNT);
sl@0
   529
    if ((*handle)->videoSampleTable->sttsSampleDelta == NULL)
sl@0
   530
      error = MP4_OUT_OF_MEMORY;
sl@0
   531
  }
sl@0
   532
sl@0
   533
  if (error == MP4_OK)
sl@0
   534
  {
sl@0
   535
    (*handle)->videoSampleTable->stszEntrySize = (mp4_u32 *)mp4malloc(sizeof(mp4_u32) * STSZMAXSAMPLECOUNT);
sl@0
   536
    if ((*handle)->videoSampleTable->stszEntrySize == NULL)
sl@0
   537
      error = MP4_OUT_OF_MEMORY;
sl@0
   538
  }
sl@0
   539
sl@0
   540
  if (error == MP4_OK)
sl@0
   541
  {
sl@0
   542
    (*handle)->videoSampleTable->stscFirstChunk = (mp4_u32 *)mp4malloc(sizeof(mp4_u32) * STSCMAXENTRYCOUNT);
sl@0
   543
    if ((*handle)->videoSampleTable->stscFirstChunk == NULL)
sl@0
   544
      error = MP4_OUT_OF_MEMORY;
sl@0
   545
  }
sl@0
   546
sl@0
   547
  if (error == MP4_OK)
sl@0
   548
  {
sl@0
   549
    (*handle)->videoSampleTable->stscSamplesPerChunk = (mp4_u32 *)mp4malloc(sizeof(mp4_u32) * STSCMAXENTRYCOUNT);
sl@0
   550
    if ((*handle)->videoSampleTable->stscSamplesPerChunk == NULL)
sl@0
   551
      error = MP4_OUT_OF_MEMORY;
sl@0
   552
  }
sl@0
   553
sl@0
   554
  if (error == MP4_OK)
sl@0
   555
  {
sl@0
   556
    (*handle)->videoSampleTable->stscSampleDescriptionIndex = (mp4_u32 *)mp4malloc(sizeof(mp4_u32) * STSCMAXENTRYCOUNT);
sl@0
   557
    if ((*handle)->videoSampleTable->stscSampleDescriptionIndex == NULL)
sl@0
   558
      error = MP4_OUT_OF_MEMORY;
sl@0
   559
  }
sl@0
   560
sl@0
   561
  if (error == MP4_OK)
sl@0
   562
  {
sl@0
   563
    (*handle)->videoSampleTable->stcoChunkOffset = (mp4_u64 *)mp4malloc(sizeof(mp4_u64) * STCOMAXENTRYCOUNT);
sl@0
   564
    if ((*handle)->videoSampleTable->stcoChunkOffset == NULL)
sl@0
   565
      error = MP4_OUT_OF_MEMORY;
sl@0
   566
  }
sl@0
   567
sl@0
   568
  if (error == MP4_OK)
sl@0
   569
  {
sl@0
   570
    (*handle)->videoSampleTable->stssSampleNumber = (mp4_u32 *)mp4malloc(sizeof(mp4_u32) * STSSMAXENTRYCOUNT);
sl@0
   571
    if ((*handle)->videoSampleTable->stssSampleNumber == NULL)
sl@0
   572
      error = MP4_OUT_OF_MEMORY;
sl@0
   573
  }
sl@0
   574
  
sl@0
   575
  if (error == MP4_OK)
sl@0
   576
  {
sl@0
   577
    (*handle)->videoSampleTable->sdtpSampleDependency = (mp4_u8 *)mp4malloc(sizeof(mp4_u8) * SDTPMAXENTRYCOUNT);
sl@0
   578
    if ((*handle)->videoSampleTable->sdtpSampleDependency == NULL)
sl@0
   579
      error = MP4_OUT_OF_MEMORY;
sl@0
   580
  }
sl@0
   581
sl@0
   582
  // register for stblib use 
sl@0
   583
  if (error == MP4_OK)
sl@0
   584
	  {
sl@0
   585
	  if (openStdlib() !=  MP4_OK)
sl@0
   586
		  {
sl@0
   587
		  error = MP4_ERROR;
sl@0
   588
		  }
sl@0
   589
	  }
sl@0
   590
  
sl@0
   591
  if (error != MP4_OK)
sl@0
   592
  {
sl@0
   593
    if(!(*handle)->bufferWrite)
sl@0
   594
    {
sl@0
   595
        closeFile(*handle);
sl@0
   596
    }
sl@0
   597
sl@0
   598
    if ((*handle)->diskWriteBuf)
sl@0
   599
      mp4free((*handle)->diskWriteBuf);
sl@0
   600
sl@0
   601
    if ((*handle)->videoSampleTable)
sl@0
   602
    {
sl@0
   603
      if ((*handle)->videoSampleTable->stssSampleNumber)
sl@0
   604
        mp4free((*handle)->videoSampleTable->stssSampleNumber);
sl@0
   605
sl@0
   606
      if ((*handle)->videoSampleTable->stcoChunkOffset)
sl@0
   607
        mp4free((*handle)->videoSampleTable->stcoChunkOffset);
sl@0
   608
sl@0
   609
      if ((*handle)->videoSampleTable->stscSampleDescriptionIndex)
sl@0
   610
        mp4free((*handle)->videoSampleTable->stscSampleDescriptionIndex);
sl@0
   611
sl@0
   612
      if ((*handle)->videoSampleTable->stscSamplesPerChunk)
sl@0
   613
        mp4free((*handle)->videoSampleTable->stscSamplesPerChunk);
sl@0
   614
sl@0
   615
      if ((*handle)->videoSampleTable->stscFirstChunk)
sl@0
   616
        mp4free((*handle)->videoSampleTable->stscFirstChunk);
sl@0
   617
sl@0
   618
      if ((*handle)->videoSampleTable->stszEntrySize)
sl@0
   619
        mp4free((*handle)->videoSampleTable->stszEntrySize);
sl@0
   620
sl@0
   621
      if ((*handle)->videoSampleTable->sttsSampleCount)
sl@0
   622
        mp4free((*handle)->videoSampleTable->sttsSampleCount);
sl@0
   623
sl@0
   624
      if ((*handle)->videoSampleTable->sttsSampleDelta)
sl@0
   625
        mp4free((*handle)->videoSampleTable->sttsSampleDelta);
sl@0
   626
      
sl@0
   627
      if ((*handle)->videoSampleTable->sdtpSampleDependency)
sl@0
   628
        mp4free((*handle)->videoSampleTable->sdtpSampleDependency);
sl@0
   629
sl@0
   630
      mp4free((*handle)->videoSampleTable);
sl@0
   631
    }
sl@0
   632
sl@0
   633
    if ((*handle)->audioSampleTable)
sl@0
   634
    {
sl@0
   635
      if ((*handle)->audioSampleTable->stcoChunkOffset)
sl@0
   636
        mp4free((*handle)->audioSampleTable->stcoChunkOffset);
sl@0
   637
sl@0
   638
      if ((*handle)->audioSampleTable->stscSampleDescriptionIndex)
sl@0
   639
        mp4free((*handle)->audioSampleTable->stscSampleDescriptionIndex);
sl@0
   640
sl@0
   641
      if ((*handle)->audioSampleTable->stscSamplesPerChunk)
sl@0
   642
        mp4free((*handle)->audioSampleTable->stscSamplesPerChunk);
sl@0
   643
sl@0
   644
      if ((*handle)->audioSampleTable->stscFirstChunk)
sl@0
   645
        mp4free((*handle)->audioSampleTable->stscFirstChunk);
sl@0
   646
sl@0
   647
      if ((*handle)->audioSampleTable->stszEntrySize)
sl@0
   648
        mp4free((*handle)->audioSampleTable->stszEntrySize);
sl@0
   649
sl@0
   650
      if ((*handle)->audioSampleTable->sttsSampleDelta)
sl@0
   651
        mp4free((*handle)->audioSampleTable->sttsSampleDelta);
sl@0
   652
sl@0
   653
      if ((*handle)->audioSampleTable->sttsSampleCount)
sl@0
   654
        mp4free((*handle)->audioSampleTable->sttsSampleCount);
sl@0
   655
sl@0
   656
      mp4free((*handle)->audioSampleTable);
sl@0
   657
    }
sl@0
   658
sl@0
   659
    if ((*handle)->fileName)
sl@0
   660
      mp4free((*handle)->fileName);
sl@0
   661
sl@0
   662
    mp4free(*handle);
sl@0
   663
    *handle = NULL;
sl@0
   664
sl@0
   665
    return error;
sl@0
   666
  }
sl@0
   667
sl@0
   668
  (*handle)->audioSampleTable->sttsMaxEntryCount  = STTSMAXENTRYCOUNT;
sl@0
   669
  (*handle)->audioSampleTable->stszMaxSampleCount = STSZMAXSAMPLECOUNT;
sl@0
   670
  (*handle)->audioSampleTable->stscMaxEntryCount  = STSCMAXENTRYCOUNT;
sl@0
   671
  (*handle)->audioSampleTable->stcoMaxEntryCount  = STCOMAXENTRYCOUNT;
sl@0
   672
  (*handle)->audioSampleTable->stcoNeed64Bits     = EFalse;
sl@0
   673
sl@0
   674
  (*handle)->videoSampleTable->sttsMaxEntryCount  = STTSMAXENTRYCOUNT;
sl@0
   675
  (*handle)->videoSampleTable->stszMaxSampleCount = STSZMAXSAMPLECOUNT;
sl@0
   676
  (*handle)->videoSampleTable->stscMaxEntryCount  = STSCMAXENTRYCOUNT;
sl@0
   677
  (*handle)->videoSampleTable->stcoMaxEntryCount  = STCOMAXENTRYCOUNT;
sl@0
   678
  (*handle)->videoSampleTable->stssMaxEntryCount  = STSSMAXENTRYCOUNT;
sl@0
   679
  (*handle)->videoSampleTable->sdtpMaxEntryCount  = SDTPMAXENTRYCOUNT;
sl@0
   680
  (*handle)->videoSampleTable->stcoNeed64Bits     = EFalse;
sl@0
   681
sl@0
   682
  (*handle)->type = type;
sl@0
   683
sl@0
   684
  /* Check if a 3GPP2 codec is being used */
sl@0
   685
  if ((*handle)->type & MP4_TYPE_QCELP_13K)
sl@0
   686
      {
sl@0
   687
      (*handle)->generate3G2 = MP4TRUE;
sl@0
   688
      }
sl@0
   689
  
sl@0
   690
  return MP4_OK;
sl@0
   691
}
sl@0
   692
sl@0
   693
extern EXPORT_C MP4Err MP4ComposeClose(MP4Handle apihandle)
sl@0
   694
{
sl@0
   695
  PRINT((_L("e_composeclose 1")));
sl@0
   696
sl@0
   697
  mp4_i32  error;
sl@0
   698
  MP4HandleImp handle = (MP4HandleImp)apihandle;
sl@0
   699
sl@0
   700
  if (!handle)
sl@0
   701
    return MP4_ERROR;
sl@0
   702
  
sl@0
   703
  PRINT((_L("e_composeclose_writedatatofile 1")));
sl@0
   704
sl@0
   705
  error = writeDataToFile(handle);
sl@0
   706
sl@0
   707
  PRINT((_L("e_composeclose_writedatatofile 0")));
sl@0
   708
sl@0
   709
  if(handle->bufferWrite && handle->composedSize)
sl@0
   710
  {
sl@0
   711
	   *(handle->composedSize)=handle->bytesProgressed;
sl@0
   712
  }
sl@0
   713
sl@0
   714
  PRINT((_L("e_composeclose_free_decspecinfos 1")));
sl@0
   715
  if (handle->videoDecSpecificInfo)
sl@0
   716
    mp4free(handle->videoDecSpecificInfo);
sl@0
   717
sl@0
   718
  if (handle->audioDecSpecificInfo)
sl@0
   719
    mp4free(handle->audioDecSpecificInfo);
sl@0
   720
  
sl@0
   721
  PRINT((_L("e_composeclose_free_decspecinfos 0")));
sl@0
   722
  PRINT((_L("e_composeclose_free_audiosampletables 1")));
sl@0
   723
  
sl@0
   724
  if (handle->audioSampleTable && handle->audioSampleTable->sttsSampleCount)
sl@0
   725
    mp4free(handle->audioSampleTable->sttsSampleCount);
sl@0
   726
sl@0
   727
  if (handle->audioSampleTable && handle->audioSampleTable->sttsSampleDelta)
sl@0
   728
    mp4free(handle->audioSampleTable->sttsSampleDelta);
sl@0
   729
sl@0
   730
  if (handle->audioSampleTable && handle->audioSampleTable->stszEntrySize)
sl@0
   731
    mp4free(handle->audioSampleTable->stszEntrySize);
sl@0
   732
sl@0
   733
  if (handle->audioSampleTable && handle->audioSampleTable->stscFirstChunk)
sl@0
   734
    mp4free(handle->audioSampleTable->stscFirstChunk);
sl@0
   735
sl@0
   736
  if (handle->audioSampleTable && handle->audioSampleTable->stscSamplesPerChunk)
sl@0
   737
    mp4free(handle->audioSampleTable->stscSamplesPerChunk);
sl@0
   738
sl@0
   739
  if (handle->audioSampleTable && handle->audioSampleTable->stscSampleDescriptionIndex)
sl@0
   740
    mp4free(handle->audioSampleTable->stscSampleDescriptionIndex);
sl@0
   741
sl@0
   742
  if (handle->audioSampleTable && handle->audioSampleTable->stcoChunkOffset)
sl@0
   743
    mp4free(handle->audioSampleTable->stcoChunkOffset);
sl@0
   744
sl@0
   745
  if (handle->audioSampleTable)
sl@0
   746
    mp4free(handle->audioSampleTable);
sl@0
   747
  PRINT((_L("e_composeclose_free_audiosampletables 0")));
sl@0
   748
  PRINT((_L("e_composeclose_free_videosampletables 1")));
sl@0
   749
sl@0
   750
  if (handle->videoSampleTable && handle->videoSampleTable->sttsSampleCount)
sl@0
   751
    mp4free(handle->videoSampleTable->sttsSampleCount);
sl@0
   752
sl@0
   753
  if (handle->videoSampleTable && handle->videoSampleTable->sttsSampleDelta)
sl@0
   754
    mp4free(handle->videoSampleTable->sttsSampleDelta);
sl@0
   755
sl@0
   756
  if (handle->videoSampleTable && handle->videoSampleTable->stszEntrySize)
sl@0
   757
    mp4free(handle->videoSampleTable->stszEntrySize);
sl@0
   758
sl@0
   759
  if (handle->videoSampleTable && handle->videoSampleTable->stscFirstChunk)
sl@0
   760
    mp4free(handle->videoSampleTable->stscFirstChunk);
sl@0
   761
sl@0
   762
  if (handle->videoSampleTable && handle->videoSampleTable->stscSamplesPerChunk)
sl@0
   763
    mp4free(handle->videoSampleTable->stscSamplesPerChunk);
sl@0
   764
sl@0
   765
  if (handle->videoSampleTable && handle->videoSampleTable->stscSampleDescriptionIndex)
sl@0
   766
    mp4free(handle->videoSampleTable->stscSampleDescriptionIndex);
sl@0
   767
sl@0
   768
  if (handle->videoSampleTable && handle->videoSampleTable->stcoChunkOffset)
sl@0
   769
    mp4free(handle->videoSampleTable->stcoChunkOffset);
sl@0
   770
sl@0
   771
  if (handle->videoSampleTable && handle->videoSampleTable->stssSampleNumber)
sl@0
   772
    mp4free(handle->videoSampleTable->stssSampleNumber);
sl@0
   773
  
sl@0
   774
  if (handle->videoSampleTable && handle->videoSampleTable->sdtpSampleDependency)
sl@0
   775
    mp4free(handle->videoSampleTable->sdtpSampleDependency);
sl@0
   776
sl@0
   777
  if (handle->videoSampleTable)
sl@0
   778
    mp4free(handle->videoSampleTable);
sl@0
   779
  PRINT((_L("e_composeclose_free_videosampletables 0")));  
sl@0
   780
  PRINT((_L("e_composeclose_free_dskbuf_and_udta 1")));
sl@0
   781
  if (handle->diskWriteBuf)
sl@0
   782
    mp4free(handle->diskWriteBuf);
sl@0
   783
sl@0
   784
  if (handle->moovUDTA)
sl@0
   785
      {
sl@0
   786
      if ( handle->moovUDTA->contentdata )
sl@0
   787
          {
sl@0
   788
          mp4free(handle->moovUDTA->contentdata);
sl@0
   789
          }
sl@0
   790
      mp4free(handle->moovUDTA);
sl@0
   791
      }
sl@0
   792
  if (handle->audioUDTA)
sl@0
   793
      {
sl@0
   794
      if ( handle->audioUDTA->contentdata )
sl@0
   795
          {
sl@0
   796
          mp4free(handle->audioUDTA->contentdata);
sl@0
   797
          }
sl@0
   798
      mp4free(handle->audioUDTA);
sl@0
   799
      }
sl@0
   800
  if (handle->videoUDTA)
sl@0
   801
      {
sl@0
   802
      if ( handle->videoUDTA->contentdata )
sl@0
   803
          {
sl@0
   804
          mp4free(handle->videoUDTA->contentdata);
sl@0
   805
          }
sl@0
   806
      mp4free(handle->videoUDTA);
sl@0
   807
      }
sl@0
   808
  PRINT((_L("e_composeclose_free_dskbuf_and_udta 0")));
sl@0
   809
sl@0
   810
  if (!(handle->flags & MP4_FLAG_METADATALAST))
sl@0
   811
  {
sl@0
   812
    if (handle->tmpfile)
sl@0
   813
    {
sl@0
   814
      PRINT((_L("e_composeclose_close_temp_files 1")));
sl@0
   815
      closeTmpFile(handle);
sl@0
   816
      PRINT((_L("e_composeclose_close_temp_files 0")));
sl@0
   817
      PRINT((_L("e_composeclose_del_temp_files 1")));      
sl@0
   818
      deleteTmpFile(handle);
sl@0
   819
      PRINT((_L("e_composeclose_del_temp_files 0")));
sl@0
   820
    }
sl@0
   821
  }
sl@0
   822
sl@0
   823
  PRINT((_L("e_composeclose_free_temp_filename 1")));
sl@0
   824
  freeTmpFileName(handle->tmpFileName);
sl@0
   825
  PRINT((_L("e_composeclose_free_temp_filename 0")));
sl@0
   826
sl@0
   827
  if (handle->flags & MP4_FLAG_LONGCLIP)
sl@0
   828
  {
sl@0
   829
  	PRINT((_L("e_composeclose_close_metadata_files 1")));
sl@0
   830
    closeMetaDataFiles(handle);
sl@0
   831
    PRINT((_L("e_composeclose_close_metadata_files 0")));
sl@0
   832
	PRINT((_L("e_composeclose_del_metadata_files 1")));
sl@0
   833
    if (deleteMetaDataFiles(handle) < 0)
sl@0
   834
      error = -1;
sl@0
   835
    PRINT((_L("e_composeclose_del_metadata_files 0")));
sl@0
   836
  }
sl@0
   837
sl@0
   838
  PRINT((_L("e_composeclose_free_filename 1")));
sl@0
   839
  if (handle->fileName)
sl@0
   840
    mp4free(handle->fileName);
sl@0
   841
  PRINT((_L("e_composeclose_free_filename 0")));
sl@0
   842
sl@0
   843
  PRINT((_L("e_composeclose_close_file 1")));
sl@0
   844
  if (handle->file)
sl@0
   845
    closeFile(handle);
sl@0
   846
  PRINT((_L("e_composeclose_close_file 0")));
sl@0
   847
sl@0
   848
  PRINT((_L("e_composeclose_close_std_lib 1")));
sl@0
   849
  closeStdlib();
sl@0
   850
  PRINT((_L("e_composeclose_close_std_lib 0")));
sl@0
   851
sl@0
   852
  if (handle->file32Duplicate)
sl@0
   853
      ((RFile64*)handle->file32Duplicate)->Close();
sl@0
   854
  
sl@0
   855
  PRINT((_L("e_composeclose_free_handle 1")));
sl@0
   856
  if (handle)
sl@0
   857
    {
sl@0
   858
    mp4free(handle);
sl@0
   859
    handle = NULL;
sl@0
   860
    }
sl@0
   861
  PRINT((_L("e_composeclose_free_handle 0")));  
sl@0
   862
sl@0
   863
  if (error)
sl@0
   864
    return MP4_METADATA_ERROR;
sl@0
   865
  
sl@0
   866
  PRINT((_L("e_composeclose 0")));
sl@0
   867
  return MP4_OK;
sl@0
   868
}
sl@0
   869
sl@0
   870
extern EXPORT_C MP4Err MP4ComposeAddVideoDescription(MP4Handle apihandle,
sl@0
   871
                                                                  mp4_u32 timescale,
sl@0
   872
                                                                  mp4_u16 width,
sl@0
   873
                                                                  mp4_u16 height,
sl@0
   874
                                                                  mp4_u32 maxbitrate,
sl@0
   875
                                                                  mp4_u32 avgbitrate)
sl@0
   876
{
sl@0
   877
  MP4HandleImp handle = (MP4HandleImp)apihandle;
sl@0
   878
sl@0
   879
  if (timescale)
sl@0
   880
    handle->videoTimeScale = timescale;
sl@0
   881
  else
sl@0
   882
    return MP4_ERROR;
sl@0
   883
sl@0
   884
  handle->videoWidth = width;
sl@0
   885
  handle->videoHeight = height;
sl@0
   886
  handle->videoMaxBitrate = maxbitrate;
sl@0
   887
  handle->videoAvgBitrate = avgbitrate;
sl@0
   888
sl@0
   889
  if ( handle->type & (MP4_TYPE_H263_PROFILE_0 | MP4_TYPE_H263_PROFILE_3) )
sl@0
   890
      {
sl@0
   891
      // default H.263 level is 10; it may be overwritten by MP4ComposeWriteVideoDecoderSpecificInfo
sl@0
   892
      handle->videoLevel = 10;
sl@0
   893
      }
sl@0
   894
sl@0
   895
  /* Write FTYP and media data size & type if meta data flag is set */
sl@0
   896
  if (handle->flags & MP4_FLAG_METADATALAST)
sl@0
   897
  {
sl@0
   898
    if (handle->ftypWritten != MP4TRUE)
sl@0
   899
    {
sl@0
   900
      if (writeFTYPAndMDATToFile(handle) < 0)
sl@0
   901
        return MP4_ERROR;
sl@0
   902
    }
sl@0
   903
  }
sl@0
   904
sl@0
   905
  return MP4_OK;
sl@0
   906
}
sl@0
   907
sl@0
   908
extern EXPORT_C MP4Err MP4ComposeAddAudioDescription(MP4Handle apihandle,
sl@0
   909
                                                                  mp4_u32 timescale,
sl@0
   910
                                                                  mp4_u8 audioFramesPerSample,
sl@0
   911
                                                                  mp4_u16 modeSet)
sl@0
   912
{
sl@0
   913
  MP4HandleImp handle = (MP4HandleImp)apihandle;
sl@0
   914
  
sl@0
   915
  PRINT((_L("3GPMP4Lib::MP4ComposeAddAudioDescription in. TimeScale=%d, AudioFrames=%d, ModeSet=%d "), timescale, audioFramesPerSample, modeSet));  
sl@0
   916
  if (timescale)
sl@0
   917
  {
sl@0
   918
    if (timescale > (mp4_u32)0xffff)
sl@0
   919
    	{
sl@0
   920
      	return MP4_ERROR;    	
sl@0
   921
    	}
sl@0
   922
    handle->audioTimeScale = timescale;
sl@0
   923
    PRINT((_L("3GPMP4Lib::MP4ComposeAddAudioDescription in. TimeScale set to = %d"), handle->audioTimeScale ));  
sl@0
   924
  }
sl@0
   925
  else
sl@0
   926
    return MP4_ERROR;
sl@0
   927
sl@0
   928
sl@0
   929
  if ((handle->type & MP4_TYPE_AMR_NB) ||
sl@0
   930
      (handle->type & MP4_TYPE_AMR_WB)) /* Audio is AMR */
sl@0
   931
  {
sl@0
   932
    if (audioFramesPerSample)
sl@0
   933
      handle->audioFramesPerSample = audioFramesPerSample;
sl@0
   934
    else
sl@0
   935
      return MP4_ERROR;
sl@0
   936
sl@0
   937
    if (modeSet)
sl@0
   938
      handle->audioModeSet = modeSet;
sl@0
   939
    else
sl@0
   940
      return MP4_ERROR;
sl@0
   941
  }
sl@0
   942
  else if (handle->type & MP4_TYPE_QCELP_13K) /* Audio is QCELP 13K */
sl@0
   943
  {
sl@0
   944
    if (audioFramesPerSample)
sl@0
   945
      handle->audioFramesPerSample = audioFramesPerSample;
sl@0
   946
    else
sl@0
   947
      return MP4_ERROR;
sl@0
   948
  }
sl@0
   949
  else /* MPEG AAC audio */
sl@0
   950
  {
sl@0
   951
    handle->audioFramesPerSample = 1;
sl@0
   952
  }
sl@0
   953
sl@0
   954
  /* Write FTYP and media data size & type if meta data flag is set */
sl@0
   955
  if (handle->flags & MP4_FLAG_METADATALAST)
sl@0
   956
  {
sl@0
   957
    if (handle->ftypWritten != MP4TRUE)
sl@0
   958
    {
sl@0
   959
      if (writeFTYPAndMDATToFile(handle) < 0)
sl@0
   960
        return MP4_ERROR;
sl@0
   961
    }
sl@0
   962
  }
sl@0
   963
  
sl@0
   964
  PRINT((_L("3GPMP4Lib::MP4ComposeAddAudioDescription out")));  
sl@0
   965
  return MP4_OK;
sl@0
   966
}
sl@0
   967
sl@0
   968
extern EXPORT_C MP4Err MP4ComposeWriteVideoFrame(MP4Handle apihandle,
sl@0
   969
                                                              mp4_u8 *buffer,
sl@0
   970
                                                              mp4_u32 framesize,
sl@0
   971
                                                              mp4_u32 duration,
sl@0
   972
                                                              mp4_bool keyframe)
sl@0
   973
{
sl@0
   974
  MP4HandleImp handle = (MP4HandleImp)apihandle;
sl@0
   975
  PRINT((_L("3GPMP4Lib::MP4ComposeWriteVideoFrame in")));
sl@0
   976
  if (handle->videoTimeScale == 0)
sl@0
   977
    return MP4_TIMESCALE_NOT_SET;
sl@0
   978
sl@0
   979
  if (framesize == 0)
sl@0
   980
    return MP4_ERROR;
sl@0
   981
sl@0
   982
  handle->videoDuration += duration;
sl@0
   983
  handle->videoSampleNum++;
sl@0
   984
sl@0
   985
  if (updateVideoMetaData(handle, framesize, duration, keyframe) < 0)
sl@0
   986
    return MP4_ERROR;
sl@0
   987
sl@0
   988
  if (handle->flags & MP4_FLAG_METADATALAST)
sl@0
   989
  {
sl@0
   990
    if (writeFile(handle, buffer, framesize) < 0)
sl@0
   991
      return MP4_ERROR;
sl@0
   992
sl@0
   993
    handle->mediaDataBytes += framesize;
sl@0
   994
  }
sl@0
   995
  else
sl@0
   996
  {
sl@0
   997
    if (writeTmpFile(handle, buffer, framesize) < 0)
sl@0
   998
      return MP4_ERROR;
sl@0
   999
  }
sl@0
  1000
sl@0
  1001
  PRINT((_L("3GPMP4Lib::MP4ComposeWriteVideoFrame out")));
sl@0
  1002
  return MP4_OK;
sl@0
  1003
}
sl@0
  1004
sl@0
  1005
extern EXPORT_C MP4Err MP4ComposeWriteAudioFrames(MP4Handle apihandle,
sl@0
  1006
                                                               mp4_u8 *buffer,
sl@0
  1007
                                                               mp4_u32 bytestowrite,
sl@0
  1008
                                                               mp4_u32 numberofframes,
sl@0
  1009
                                                               mp4_u32 duration)
sl@0
  1010
{
sl@0
  1011
  MP4HandleImp handle = (MP4HandleImp)apihandle;
sl@0
  1012
  PRINT((_L("3GPMP4Lib::MP4ComposeWriteAudioFrames in")));
sl@0
  1013
sl@0
  1014
  if ( handle->audioTimeScale == 0)	
sl@0
  1015
  	  {
sl@0
  1016
  	  PRINT((_L("3GPMP4Lib::MP4ComposeWriteAudioFrames Error 14 - AudioTimeScale is 0")));
sl@0
  1017
      return MP4_TIMESCALE_NOT_SET;
sl@0
  1018
	  }
sl@0
  1019
	  
sl@0
  1020
  PRINT((_L("3GPMP4Lib::MP4ComposeWriteAudioFrames Audio Timescale ok")));	  
sl@0
  1021
sl@0
  1022
  if (bytestowrite == 0)
sl@0
  1023
    return MP4_ERROR;
sl@0
  1024
sl@0
  1025
  handle->audioDuration += duration;
sl@0
  1026
  handle->audioFrameCount += numberofframes;
sl@0
  1027
  handle->audioMediaDataSize += bytestowrite;
sl@0
  1028
sl@0
  1029
  PRINT((_L("3GPMP4Lib::MP4ComposeWriteAudioFrames updating audio metadata")));	  
sl@0
  1030
  
sl@0
  1031
  if (updateAudioMetaData(handle, bytestowrite, duration) < 0)
sl@0
  1032
    return MP4_ERROR;
sl@0
  1033
sl@0
  1034
  if (handle->flags & MP4_FLAG_METADATALAST)
sl@0
  1035
  {
sl@0
  1036
	PRINT((_L("3GPMP4Lib::MP4ComposeWriteAudioFrames writing to file")));	    
sl@0
  1037
    if (writeFile(handle, buffer, bytestowrite) < 0)
sl@0
  1038
      return MP4_ERROR;
sl@0
  1039
sl@0
  1040
    handle->mediaDataBytes += bytestowrite;
sl@0
  1041
  }
sl@0
  1042
  else
sl@0
  1043
  {
sl@0
  1044
	PRINT((_L("3GPMP4Lib::MP4ComposeWriteAudioFrames writing to temp file")));	      
sl@0
  1045
    if (writeTmpFile(handle, buffer, bytestowrite) < 0)
sl@0
  1046
      return MP4_ERROR;
sl@0
  1047
  }
sl@0
  1048
  
sl@0
  1049
  PRINT((_L("3GPMP4Lib::MP4ComposeWriteAudioFrames out")));
sl@0
  1050
  return MP4_OK;
sl@0
  1051
}
sl@0
  1052
sl@0
  1053
extern EXPORT_C MP4Err MP4ComposeWriteVideoDecoderSpecificInfo(MP4Handle apihandle,
sl@0
  1054
                                                                            mp4_u8 *info,
sl@0
  1055
                                                                            mp4_u32 infosize)
sl@0
  1056
{
sl@0
  1057
  MP4HandleImp handle = (MP4HandleImp)apihandle;
sl@0
  1058
sl@0
  1059
  if ( (handle->type & MP4_TYPE_MPEG4_VIDEO) || containsAvcVideo( handle->type ) )
sl@0
  1060
      {
sl@0
  1061
      if ((handle->videoDecSpecificInfo = (mp4_u8 *)mp4malloc(infosize)) == NULL)
sl@0
  1062
        return MP4_ERROR;
sl@0
  1063
sl@0
  1064
      mp4memcpy(handle->videoDecSpecificInfo, info, infosize);
sl@0
  1065
      handle->videoDecSpecificInfoSize = infosize;
sl@0
  1066
      }
sl@0
  1067
  else
sl@0
  1068
      {
sl@0
  1069
      // H.263, save level only
sl@0
  1070
      if ( *info >= 10 && *info < 100 )
sl@0
  1071
          {
sl@0
  1072
          handle->videoLevel = *info;
sl@0
  1073
          }
sl@0
  1074
      }
sl@0
  1075
  return MP4_OK;
sl@0
  1076
}
sl@0
  1077
sl@0
  1078
extern EXPORT_C MP4Err MP4ComposeWriteAudioDecoderSpecificInfo(MP4Handle apihandle,
sl@0
  1079
                                                                            mp4_u8 *info,
sl@0
  1080
                                                                            mp4_u32 infosize)
sl@0
  1081
{
sl@0
  1082
  MP4HandleImp handle = (MP4HandleImp)apihandle;
sl@0
  1083
sl@0
  1084
  if ((handle->audioDecSpecificInfo = (mp4_u8 *)mp4malloc(infosize)) == NULL)
sl@0
  1085
    return MP4_ERROR;
sl@0
  1086
sl@0
  1087
  mp4memcpy(handle->audioDecSpecificInfo, info, infosize);
sl@0
  1088
  handle->audioDecSpecificInfoSize = infosize;
sl@0
  1089
sl@0
  1090
  return MP4_OK;
sl@0
  1091
}
sl@0
  1092
sl@0
  1093
extern EXPORT_C MP4Err MP4ComposeSetFlags(MP4Handle apihandle,
sl@0
  1094
                                                       mp4_u32 flags)
sl@0
  1095
{
sl@0
  1096
  MP4HandleImp handle = (MP4HandleImp)apihandle;
sl@0
  1097
  handle->flags |= flags;
sl@0
  1098
sl@0
  1099
  if (handle->flags & MP4_FLAG_METADATALAST)
sl@0
  1100
  {
sl@0
  1101
    if (handle->tmpfile)
sl@0
  1102
    {
sl@0
  1103
      closeTmpFile(handle);
sl@0
  1104
      deleteTmpFile(handle);
sl@0
  1105
    }
sl@0
  1106
  }
sl@0
  1107
sl@0
  1108
  if (handle->flags & MP4_FLAG_LONGCLIP)
sl@0
  1109
  {
sl@0
  1110
    // Open temporary files
sl@0
  1111
    MP4Err error = MP4_OK;
sl@0
  1112
    error = initMetaDataFiles(handle);
sl@0
  1113
    if ( error == MP4_OUT_OF_MEMORY )
sl@0
  1114
	    {
sl@0
  1115
	    return MP4_OUT_OF_MEMORY;
sl@0
  1116
	    }
sl@0
  1117
 	else if ( error != MP4_OK )
sl@0
  1118
	 	{
sl@0
  1119
		return MP4_ERROR;
sl@0
  1120
	 	}
sl@0
  1121
  }
sl@0
  1122
sl@0
  1123
  handle->generate3G2 = MP4FALSE;
sl@0
  1124
  handle->generateMP4 = MP4FALSE;   
sl@0
  1125
sl@0
  1126
  if (handle->flags & MP4_FLAG_GENERATE_3G2) // 3G2
sl@0
  1127
  {
sl@0
  1128
    // Generate 3G2 file.
sl@0
  1129
    handle->generate3G2 = MP4TRUE;
sl@0
  1130
    handle->generateMP4 = MP4FALSE;      
sl@0
  1131
  }
sl@0
  1132
  else if ( handle->flags & MP4_FLAG_GENERATE_MP4 ) // MP4
sl@0
  1133
	  {
sl@0
  1134
	  // if at least ONE audio/video codec is specified
sl@0
  1135
	  if (handle->type != MP4_TYPE_NONE)
sl@0
  1136
		  {
sl@0
  1137
	      /* Check if a 3GPP2 codec is being used */
sl@0
  1138
	      if ( handle->type & MP4_TYPE_QCELP_13K )
sl@0
  1139
	    	  {
sl@0
  1140
	    	  handle->generate3G2 = MP4TRUE;
sl@0
  1141
	    	  handle->generateMP4 = MP4FALSE;   
sl@0
  1142
	    	  }
sl@0
  1143
	      else 
sl@0
  1144
	    	  {
sl@0
  1145
			  // types other than MPEG-4 AUDIO & VIDEO  
sl@0
  1146
			  mp4_u32 type = handle->type >> 2;	
sl@0
  1147
		  
sl@0
  1148
			  // Check if a MPEG4 codec is being used
sl@0
  1149
			  if (type == MP4_TYPE_NONE)
sl@0
  1150
				  {
sl@0
  1151
				  // if ONLY MPEG4 Video and/or Audio codec is used, generate MP4 file.
sl@0
  1152
				  handle->generateMP4 = MP4TRUE;      
sl@0
  1153
				  handle->generate3G2 = MP4FALSE;
sl@0
  1154
				  }	  
sl@0
  1155
			  else
sl@0
  1156
				  {
sl@0
  1157
				  // ignoring both MPEG-4 audio and video, check again if only AVC codecs are 
sl@0
  1158
				  // used
sl@0
  1159
				  type <<= 2;			  
sl@0
  1160
				  if ( isAvcVideo(type) )
sl@0
  1161
					  {
sl@0
  1162
					  // generate MP4 file
sl@0
  1163
					  handle->generateMP4 = MP4TRUE;      
sl@0
  1164
					  handle->generate3G2 = MP4FALSE;
sl@0
  1165
					  }
sl@0
  1166
				  }
sl@0
  1167
	    	  }
sl@0
  1168
		  }
sl@0
  1169
	  }
sl@0
  1170
  else // 3GP
sl@0
  1171
  {
sl@0
  1172
      /* Check if a 3GPP2 codec is being used */
sl@0
  1173
      if ( handle->type & MP4_TYPE_QCELP_13K )
sl@0
  1174
      {
sl@0
  1175
        handle->generate3G2 = MP4TRUE;
sl@0
  1176
        handle->generateMP4 = MP4FALSE;   
sl@0
  1177
      }
sl@0
  1178
      // use defaults -> 3GP
sl@0
  1179
  }
sl@0
  1180
sl@0
  1181
  if ( (handle->flags & MP4_FLAG_LARGEFILEBUFFER) && !(handle->bufferWrite) )
sl@0
  1182
      {
sl@0
  1183
      TInt bufferSizeError = KErrNone;
sl@0
  1184
      bufferSizeError = handle->filewriter->SetOutputBufferSize( CFileWriter::EBufferSizeLarge, apihandle );
sl@0
  1185
      if ( bufferSizeError == KErrNoMemory )
sl@0
  1186
      	{
sl@0
  1187
      	return MP4_OUT_OF_MEMORY;
sl@0
  1188
      	}
sl@0
  1189
	  else if ( bufferSizeError != KErrNone )
sl@0
  1190
        {
sl@0
  1191
        return MP4_ERROR;
sl@0
  1192
        }
sl@0
  1193
      }
sl@0
  1194
  return MP4_OK;
sl@0
  1195
}
sl@0
  1196
sl@0
  1197
extern EXPORT_C MP4Err MP4ComposeSetQCELPStorageMode(MP4Handle apihandle, mp4_u8 qcelpStorageMode)
sl@0
  1198
{
sl@0
  1199
    MP4HandleImp handle = (MP4HandleImp)apihandle;
sl@0
  1200
sl@0
  1201
    if (qcelpStorageMode)
sl@0
  1202
      handle->qcelpStoredAsMPEGAudio = MP4TRUE;
sl@0
  1203
    else
sl@0
  1204
      handle->qcelpStoredAsMPEGAudio = MP4FALSE;
sl@0
  1205
sl@0
  1206
    return MP4_OK;
sl@0
  1207
sl@0
  1208
}
sl@0
  1209
sl@0
  1210
extern EXPORT_C MP4Err MP4ComposeSetVideoClipProperties(MP4Handle apihandle, const TVideoClipProperties& aVideoClipProperties)
sl@0
  1211
{
sl@0
  1212
    MP4HandleImp handle = (MP4HandleImp)apihandle;
sl@0
  1213
sl@0
  1214
    if ( !handle )
sl@0
  1215
    {
sl@0
  1216
        return MP4_ERROR;
sl@0
  1217
    }
sl@0
  1218
    else
sl@0
  1219
    {
sl@0
  1220
        if ( aVideoClipProperties.iH263Level )
sl@0
  1221
        {
sl@0
  1222
            handle->videoLevel = aVideoClipProperties.iH263Level;
sl@0
  1223
        }
sl@0
  1224
        return MP4_OK;
sl@0
  1225
    }
sl@0
  1226
}
sl@0
  1227
sl@0
  1228
extern EXPORT_C MP4Err MP4ComposeSetUserDataAtom(MP4Handle apihandle, 
sl@0
  1229
                                                            mp4_u8& udtaLocation,
sl@0
  1230
                                                            mp4_u8* buffer,
sl@0
  1231
                                                            mp4_u32& bufferSize )
sl@0
  1232
    {
sl@0
  1233
    userDataAtom* udta = NULL;
sl@0
  1234
    MP4HandleImp handle = (MP4HandleImp)apihandle;
sl@0
  1235
sl@0
  1236
    if (!handle)
sl@0
  1237
        return MP4_ERROR;
sl@0
  1238
sl@0
  1239
    if ( buffer == NULL )
sl@0
  1240
        {
sl@0
  1241
        return MP4_ERROR;
sl@0
  1242
        }
sl@0
  1243
    if ( !bufferSize )
sl@0
  1244
        {
sl@0
  1245
        return MP4_ERROR;
sl@0
  1246
        }
sl@0
  1247
sl@0
  1248
    // Check which UDTA atom to use
sl@0
  1249
    switch ( udtaLocation )
sl@0
  1250
        {
sl@0
  1251
        case MP4_UDTA_MOOV:
sl@0
  1252
            {
sl@0
  1253
            if ( handle->moovUDTA == NULL )
sl@0
  1254
                {
sl@0
  1255
                handle->moovUDTA = (userDataAtom *)mp4malloc(sizeof(userDataAtom));
sl@0
  1256
                }
sl@0
  1257
            udta = handle->moovUDTA;
sl@0
  1258
            break;
sl@0
  1259
            }
sl@0
  1260
        case MP4_UDTA_VIDEOTRAK:
sl@0
  1261
            {
sl@0
  1262
            if ( handle->videoUDTA == NULL )
sl@0
  1263
                {
sl@0
  1264
                handle->videoUDTA = (userDataAtom *)mp4malloc(sizeof(userDataAtom));
sl@0
  1265
                }
sl@0
  1266
            udta = handle->videoUDTA;
sl@0
  1267
            break;
sl@0
  1268
            }
sl@0
  1269
        case MP4_UDTA_AUDIOTRAK:
sl@0
  1270
            {
sl@0
  1271
            if ( handle->audioUDTA == NULL )
sl@0
  1272
                {
sl@0
  1273
                handle->audioUDTA = (userDataAtom *)mp4malloc(sizeof(userDataAtom));
sl@0
  1274
                }
sl@0
  1275
            udta = handle->audioUDTA;
sl@0
  1276
            break;
sl@0
  1277
            }
sl@0
  1278
       default:
sl@0
  1279
            {
sl@0
  1280
            return MP4_INVALID_TYPE;
sl@0
  1281
            }
sl@0
  1282
        }
sl@0
  1283
        
sl@0
  1284
    if ( udta == NULL )
sl@0
  1285
        {
sl@0
  1286
        return MP4_OUT_OF_MEMORY;
sl@0
  1287
        }
sl@0
  1288
sl@0
  1289
    // CHECK if there is old data in UDTA
sl@0
  1290
    if ( udta->contentdata && udta->atomcontentsize )
sl@0
  1291
        {
sl@0
  1292
        mp4_u8* temp;
sl@0
  1293
        if ((temp = (mp4_u8 *)mp4malloc(bufferSize + udta->atomcontentsize)) == NULL)
sl@0
  1294
            {
sl@0
  1295
            return MP4_OUT_OF_MEMORY;
sl@0
  1296
            }
sl@0
  1297
        mp4memcpy(temp, udta->contentdata, udta->atomcontentsize);
sl@0
  1298
        mp4memcpy(temp+udta->atomcontentsize, buffer, bufferSize);
sl@0
  1299
        mp4free(udta->contentdata);
sl@0
  1300
        udta->contentdata = temp;
sl@0
  1301
        udta->atomcontentsize += bufferSize;
sl@0
  1302
        }
sl@0
  1303
    else
sl@0
  1304
        {
sl@0
  1305
        if ((udta->contentdata = (mp4_u8 *)mp4malloc(bufferSize)) == NULL)
sl@0
  1306
            return MP4_OUT_OF_MEMORY;        
sl@0
  1307
        // Copy data from buffer to atom contentdata        
sl@0
  1308
        mp4memcpy(udta->contentdata, buffer, bufferSize);                
sl@0
  1309
        udta->atomcontentsize = bufferSize;
sl@0
  1310
        }
sl@0
  1311
sl@0
  1312
    return MP4_OK;
sl@0
  1313
    }
sl@0
  1314
	
sl@0
  1315
	
sl@0
  1316
extern EXPORT_C MP4Err MP4SetCustomFileBufferSizes( MP4Handle apihandle, 
sl@0
  1317
                                                               mp4_u32 mediaWriteBufferSize,
sl@0
  1318
                                                               mp4_u32 writeBufferMaxCount,
sl@0
  1319
                                                               mp4_u32 readBufferSize )
sl@0
  1320
    {
sl@0
  1321
    MP4HandleImp handle = (MP4HandleImp)apihandle;
sl@0
  1322
sl@0
  1323
    if (!handle)
sl@0
  1324
        return MP4_ERROR;
sl@0
  1325
    
sl@0
  1326
    // If no specific file size is given we try to use an 'optimal' buffer size.
sl@0
  1327
    if (readBufferSize == 0)
sl@0
  1328
    	{
sl@0
  1329
    	readBufferSize = RecommendedBufferSize(handle);
sl@0
  1330
		}
sl@0
  1331
sl@0
  1332
	if (readBufferSize > handle->readBufferSize)
sl@0
  1333
        {
sl@0
  1334
        handle->readBufferSize = readBufferSize;
sl@0
  1335
        if (handle->diskReadBuf)
sl@0
  1336
            {
sl@0
  1337
            mp4free(handle->diskReadBuf);
sl@0
  1338
            handle->diskReadBuf = NULL;
sl@0
  1339
            if ((handle->diskReadBuf = (mp4_u8 *)mp4malloc(handle->readBufferSize)) == NULL)
sl@0
  1340
                {
sl@0
  1341
                return MP4_OUT_OF_MEMORY;
sl@0
  1342
                }
sl@0
  1343
            }
sl@0
  1344
        }
sl@0
  1345
        
sl@0
  1346
    // Media Write buffer size
sl@0
  1347
    if ( (mediaWriteBufferSize) &&  
sl@0
  1348
         (mediaWriteBufferSize != handle->mediaWriteBufferSize) &&
sl@0
  1349
         (!(handle->bufferWrite)) )
sl@0
  1350
        {
sl@0
  1351
        handle->mediaWriteBufferSize = mediaWriteBufferSize;
sl@0
  1352
        if ( (handle->filewriter) )
sl@0
  1353
          {
sl@0
  1354
          if ( handle->filewriter->SetOutputBufferSize( CFileWriter::EBufferSizeCustom, apihandle ) < 0 )
sl@0
  1355
              {
sl@0
  1356
              return MP4_ERROR;
sl@0
  1357
              }
sl@0
  1358
          }
sl@0
  1359
        }
sl@0
  1360
        
sl@0
  1361
    // Write Buffer Max Count change
sl@0
  1362
    if ( (writeBufferMaxCount) &&  
sl@0
  1363
         (writeBufferMaxCount != handle->writeBufferMaxCount) &&
sl@0
  1364
         !(handle->bufferWrite) )
sl@0
  1365
        {
sl@0
  1366
        if ( writeBufferMaxCount >= 6 ) // min number of buffers is 4, +1 for soft limit, +1 for hardlimit = 6
sl@0
  1367
            {
sl@0
  1368
            handle->writeBufferMaxCount = writeBufferMaxCount;
sl@0
  1369
            if ( (handle->filewriter) )
sl@0
  1370
              {
sl@0
  1371
              handle->filewriter->SetOutputBufferCount( apihandle );
sl@0
  1372
              }
sl@0
  1373
            }
sl@0
  1374
        else
sl@0
  1375
            {
sl@0
  1376
            return MP4_ERROR;
sl@0
  1377
            }
sl@0
  1378
        }
sl@0
  1379
    return MP4_OK;
sl@0
  1380
    }
sl@0
  1381
sl@0
  1382
extern EXPORT_C MP4Err MP4ComposeWriteNextVideoFrameDependencies(MP4Handle apihandle, mp4_u8 aDependsOn, mp4_u8 aIsDependentOn, mp4_u8 aHasRedundancy)
sl@0
  1383
{
sl@0
  1384
	MP4HandleImp handle = (MP4HandleImp)apihandle;
sl@0
  1385
	
sl@0
  1386
	if( (aDependsOn > 2) || (aIsDependentOn > 2) || (aHasRedundancy > 2) )
sl@0
  1387
	{
sl@0
  1388
		return MP4_ERROR;
sl@0
  1389
	}
sl@0
  1390
	
sl@0
  1391
	if (updateVideoDependencyMetaData(handle, aDependsOn, aIsDependentOn, aHasRedundancy) < 0)
sl@0
  1392
	{
sl@0
  1393
		return MP4_ERROR;
sl@0
  1394
	}
sl@0
  1395
	
sl@0
  1396
	return MP4_OK;
sl@0
  1397
}
sl@0
  1398
sl@0
  1399
extern EXPORT_C MP4Err MP4ComposeSetTempFileRemoverObserver(
sl@0
  1400
                                        MP4Handle *apihandle,
sl@0
  1401
                                        M3GPMP4LibAsyncTempFileRemoverObserver *aObserver)
sl@0
  1402
{
sl@0
  1403
  PRINT((_L("3GPMP4Lib::MP4ComposeSetTempFileRemoverObserver in")));
sl@0
  1404
sl@0
  1405
  MP4Err error = MP4_OK;
sl@0
  1406
  MP4HandleImp* handle = (MP4HandleStruct **)apihandle;
sl@0
  1407
sl@0
  1408
  if ( handle != NULL && *handle != NULL )
sl@0
  1409
      {
sl@0
  1410
      (*handle)->tempFileRemoverObserver = aObserver;
sl@0
  1411
      }
sl@0
  1412
  else
sl@0
  1413
      {
sl@0
  1414
      error = MP4_ERROR;
sl@0
  1415
      }
sl@0
  1416
sl@0
  1417
sl@0
  1418
  PRINT((_L("3GPMP4Lib::MP4ComposeSetTempFileRemoverObserver out error=%d"), error));
sl@0
  1419
  return error;
sl@0
  1420
}
sl@0
  1421
// End of File