Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
agfline committed Jun 17, 2023
1 parent a4957b4 commit 6216311
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 27 deletions.
2 changes: 1 addition & 1 deletion include/libaaf/CFBDump.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void cfb_dump_nodeStream( CFB_Data *cfbd, cfbNode *node );

void cfb_dump_nodePathStream( CFB_Data *cfbd, const wchar_t *path );

void cfb_dump_nodePaths( CFB_Data *cfbd, uint32_t prevPath, char strArray[][CFB_PATH_NAME_SZ], uint32_t *str_i, cfbNode *node );
void cfb_dump_nodePaths( CFB_Data *cfbd, uint32_t prevPath, char *strArray[], uint32_t *str_i, cfbNode *node );


void cfb_dump_header( CFB_Data *cfbd );
Expand Down
13 changes: 10 additions & 3 deletions src/AAFIface/AAFIAudioFiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,7 @@ int aafi_extract_audio_essence( AAF_Iface *aafi, aafiAudioEssence *audioEssence,
/* Retrieve stream from CFB */

unsigned char *data = NULL;
size_t datasz = 0;
uint64_t datasz = 0;

cfb_getStream( aafi->aafd->cfbd, audioEssence->node, &data, &datasz );

Expand Down Expand Up @@ -1438,15 +1438,22 @@ int aafi_extract_audio_essence( AAF_Iface *aafi, aafiAudioEssence *audioEssence,
wavBext.time_reference = eu2sample( audioEssence->samplerate, audioEssence->mobSlotEditRate, audioEssence->timeReference );
}

if ( riff_writeWavFileHeader( fp, &wavFmt, &wavBext, datasz ) < 0 ) {
if ( datasz >= (2^32) ) {
// TODO RF64 support ?
_error( aafi->ctx.options.verb, "Audio essence is bigger than maximum wav size (2^32 bytes) : %lu bytes\n", datasz );
free(data);
return -1;
}

if ( riff_writeWavFileHeader( fp, &wavFmt, &wavBext, (uint32_t)datasz ) < 0 ) {
_error( aafi->ctx.options.verb, "Could not write wav audio essence header : %s\n", filePath );
}
}


// printf("Writting to file : %c %c %c %c\n", data[0], data[1], data[2], data[3] );

size_t writtenBytes = fwrite( data, sizeof(unsigned char), datasz, fp );
uint64_t writtenBytes = fwrite( data, sizeof(unsigned char), datasz, fp );

if ( writtenBytes < datasz ) {
_error( aafi->ctx.options.verb, "Could not write audio essence file (%"PRIu64" bytes written out of %"PRIu64" bytes) : %s\n", writtenBytes, datasz, filePath );
Expand Down
12 changes: 9 additions & 3 deletions src/AAFIface/AAFIParser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1221,20 +1221,26 @@ static int parse_PCMDescriptor( AAF_Iface *aafi, aafObject *PCMDescriptor, td *_



uint32_t *samplesize = (uint32_t*)aaf_get_propertyValue( PCMDescriptor, PID_SoundDescriptor_QuantizationBits );
uint32_t *samplesize = (uint32_t*)aaf_get_propertyValue( PCMDescriptor, PID_SoundDescriptor_QuantizationBits ); // uint32_t in AAF std

if ( samplesize == NULL ) /* req */
{
DUMP_OBJ_ERROR( aafi, PCMDescriptor, &__td, "Missing PID_SoundDescriptor_QuantizationBits" );
return -1;
}

audioEssence->samplesize = *samplesize;
if ( *samplesize >= (2^15) )
{
DUMP_OBJ_ERROR( aafi, PCMDescriptor, &__td, "PID_SoundDescriptor_QuantizationBits value error : %u", *samplesize );
return -1;
}

audioEssence->samplesize = (int16_t)*samplesize;

if ( aafi->Audio->samplesize >= 0 )
{
/* Set global AAF SampleSize, if it equals preceding. Otherwise set to -1 */
aafi->Audio->samplesize = ( aafi->Audio->samplesize == 0 || (uint16_t)aafi->Audio->samplesize == *samplesize ) ? *samplesize : (unsigned)-1;
aafi->Audio->samplesize = ( aafi->Audio->samplesize == 0 || (uint16_t)aafi->Audio->samplesize == audioEssence->samplesize ) ? audioEssence->samplesize : -1;
}


Expand Down
53 changes: 33 additions & 20 deletions src/LibCFB/CFBDump.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,22 +149,23 @@ void cfb_dump_nodePathStream( CFB_Data *cfbd, const wchar_t *path )



static int compareStrings( const void *a, const void *b )
{
return strcmp( (const char *)a, (const char *)b );
}
// static int compareStrings( const void *a, const void *b )
// {
// return strcmp( (const char *)a, (const char *)b );
// }

void cfb_dump_nodePaths( CFB_Data *cfbd, uint32_t prevPath, char strArray[][CFB_PATH_NAME_SZ], uint32_t *str_i, cfbNode *node )
// void cfb_dump_nodePaths( CFB_Data *cfbd, uint32_t prevPath, char strArray[][CFB_PATH_NAME_SZ], uint32_t *str_i, cfbNode *node )
void cfb_dump_nodePaths( CFB_Data *cfbd, uint32_t prevPath, char *strArray[], uint32_t *str_i, cfbNode *node )
{

/*
* the begining of the first function call.
*/

if ( node == NULL )
{
/*
* the begining of the first function call.
*/

node = cfbd->nodes[0];
strArray = calloc( cfbd->nodes_cnt * CFB_PATH_NAME_SZ, sizeof(char) );
strArray = calloc( cfbd->nodes_cnt, sizeof(char*) );
}


Expand All @@ -173,19 +174,30 @@ void cfb_dump_nodePaths( CFB_Data *cfbd, uint32_t prevPath, char strArray[][CFB_

char *name = cfb_utf16toa( node->_ab, node->_cb );

snprintf( strArray[thisPath], CFB_PATH_NAME_SZ, "%s/%s", strArray[prevPath], name );
int pathlen = snprintf( NULL, 0, "%s/%s", strArray[prevPath], name );

(*str_i)++;
if ( pathlen < 0 ) {
// TODO error
return;
}

pathlen++;

strArray[thisPath] = malloc( pathlen );

snprintf( strArray[thisPath], pathlen, "%s/%s", strArray[prevPath], name );

free( name );

(*str_i)++;



if ( (int32_t)node->_sidChild > 0 )
cfb_dump_nodePaths( cfbd, thisPath, strArray, str_i, cfbd->nodes[node->_sidChild] );
cfb_dump_nodePaths( cfbd, thisPath, strArray, str_i, cfbd->nodes[node->_sidChild] );

if ( (int32_t)node->_sidLeftSib > 0 )
cfb_dump_nodePaths( cfbd, prevPath, strArray, str_i, cfbd->nodes[node->_sidLeftSib] );
cfb_dump_nodePaths( cfbd, prevPath, strArray, str_i, cfbd->nodes[node->_sidLeftSib] );

if ( (int32_t)node->_sidRightSib > 0 )
cfb_dump_nodePaths( cfbd, prevPath, strArray, str_i, cfbd->nodes[node->_sidRightSib] );
Expand All @@ -199,16 +211,17 @@ void cfb_dump_nodePaths( CFB_Data *cfbd, uint32_t prevPath, char strArray[][CFB_

if ( node == cfbd->nodes[0] )
{
uint32_t i = 0;
/* commented out because output is proper this way... why did we call qsort() in the first place ?! */
// qsort( strArray, *str_i, sizeof(char*), compareStrings );

qsort( strArray, *str_i, CFB_PATH_NAME_SZ, compareStrings );

for ( i = 0; i < cfbd->nodes_cnt && strArray[i][0] != 0x00; i++ )
printf( "%s\n", strArray[i] );
for ( uint32_t i = 0; i < cfbd->nodes_cnt && strArray[i] != NULL; i++ ) {
printf( "%05i : %s\n", i, strArray[i] );
free( strArray[i] );
}

free( strArray );

printf( "\n\n" );
printf( "\n\n" );
}

}
Expand Down

0 comments on commit 6216311

Please sign in to comment.