@@ -85,8 +85,11 @@ int ch,n;
8585 return 0 ;
8686}
8787
88- static int parse_idx1 (FILE *in, int chunk_len)
88+ static int parse_idx1 (void *hdl, FILE *in, int chunk_len)
8989{
90+ videoobject *mp4 = (videoobject *)hdl;
91+ if (mp4 == NULL ) return 0 ;
92+
9093struct index_entry_t index_entry;
9194int t,framenum = 0 ;
9295
@@ -105,18 +108,18 @@ int t,framenum = 0;
105108
106109 if (0 == strcmp (index_entry.ckid , " 00dc" ) || 0 == strcmp (index_entry.ckid , " 00db" )) // video frame compressed or baseband
107110 {
108- if (metaoffsets)
111+ if (mp4-> metaoffsets )
109112 {
110- metaoffsets[framenum] = movi_offset + 4 + (uint64_t )index_entry.dwChunkOffset ;
111- metasizes[framenum] = (uint64_t )index_entry.dwChunkLength ;
113+ mp4-> metaoffsets [framenum] = movi_offset + 4 + (uint64_t )index_entry.dwChunkOffset ;
114+ mp4-> metasizes [framenum] = (uint64_t )index_entry.dwChunkLength ;
112115 framenum++;
113116 }
114117 }
115118
116119
117- indexcount = framenum;
118- trak_clockcount = meta_clockcount = clockcount = indexcount * basemetadataduration;
119- videolength = metadatalength = (float )clockcount / (float )clockdemon;
120+ mp4-> indexcount = framenum;
121+ mp4-> trak_clockcount = mp4-> meta_clockcount = mp4-> clockcount = mp4-> indexcount * mp4-> basemetadataduration ;
122+ mp4-> videolength = mp4-> metadatalength = (float )mp4-> clockcount / (float )mp4-> clockdemon ;
120123
121124
122125#if PRINT_AVI_STRUCTURE
@@ -133,8 +136,11 @@ int t,framenum = 0;
133136 return 0 ;
134137}
135138
136- static int read_avi_header (FILE *in,struct avi_header_t *avi_header)
139+ static int read_avi_header (void *hdl, FILE *in,struct avi_header_t *avi_header)
137140{
141+ videoobject *mp4 = (videoobject *)hdl;
142+ if (mp4 == NULL ) return 0 ;
143+
138144 avi_header->TimeBetweenFrames =read_long (in);
139145 avi_header->MaximumDataRate =read_long (in);
140146 avi_header->PaddingGranularity =read_long (in);
@@ -169,14 +175,16 @@ static int read_avi_header(FILE *in,struct avi_header_t *avi_header)
169175#endif
170176
171177
172- indexcount = avi_header->TotalNumberOfFrames ;
173- basemetadataduration = avi_header->TimeBetweenFrames ;
174- trak_clockdemon = meta_clockdemon = clockdemon = 1000000 ;
175- trak_clockcount = meta_clockcount = clockcount = indexcount * basemetadataduration;
176- videolength = metadatalength = (float )clockcount / (float )clockdemon;
177178
178- metasizes = (uint32_t *)malloc (indexcount * 4 );
179- metaoffsets = (uint64_t *)malloc (indexcount * 8 );
179+ mp4->indexcount = avi_header->TotalNumberOfFrames ;
180+ mp4->basemetadataduration = avi_header->TimeBetweenFrames ;
181+ mp4->trak_clockdemon = mp4->meta_clockdemon = mp4->clockdemon = 1000000 ;
182+ mp4->trak_clockcount = mp4->meta_clockcount = mp4->clockcount = mp4->indexcount * mp4->basemetadataduration ;
183+ mp4->videolength = mp4->metadatalength = (float )mp4->clockcount / (float )mp4->clockdemon ;
184+
185+ mp4->metasizes = (uint32_t *)malloc (mp4->indexcount * 4 );
186+ mp4->metasize_count = mp4->indexcount ;
187+ mp4->metaoffsets = (uint64_t *)malloc (mp4->indexcount * 8 );
180188
181189 return 0 ;
182190}
@@ -435,7 +443,7 @@ int stream_type=0; // 0=video 1=sound
435443 return 0 ;
436444}
437445
438- static int parse_hdrl (FILE *in,struct avi_header_t *avi_header, struct stream_header_t *stream_header, struct stream_format_t *stream_format, unsigned int size)
446+ static int parse_hdrl (void *hdl, FILE *in,struct avi_header_t *avi_header, struct stream_header_t *stream_header, struct stream_format_t *stream_format, unsigned int size)
439447{
440448char chunk_id[5 ];
441449int chunk_size;
@@ -456,7 +464,7 @@ long offset=ftell(in);
456464 end_of_chunk=end_of_chunk+(4 -(end_of_chunk%4 ));
457465 }
458466
459- read_avi_header (in,avi_header);
467+ read_avi_header (hdl, in,avi_header);
460468
461469#if PRINT_AVI_STRUCTURE
462470 printf (" }\n " );
@@ -471,16 +479,25 @@ long offset=ftell(in);
471479 return 0 ;
472480}
473481
474- static int parse_riff (FILE *in )
482+ static int parse_riff (void *hdl )
475483{
484+ FILE *in;
476485char chunk_id[5 ];
477486int chunk_size;
478487char chunk_type[5 ];
479488int end_of_chunk,end_of_subchunk;
480489struct avi_header_t avi_header;
481490struct stream_header_t stream_header;
482491struct stream_format_t stream_format={0 };
483- long offset=ftell (in);
492+ long offset;
493+
494+ videoobject *mp4 = (videoobject *)hdl;
495+ if (mp4 == NULL ) return 0 ;
496+
497+ in = mp4->mediafp ;
498+ offset= ftell (in);
499+
500+
484501
485502 read_chars (in,chunk_id,4 );
486503 chunk_size=read_long (in);
@@ -546,7 +563,7 @@ long offset=ftell(in);
546563 else
547564 if (STRINGCASECOMPARE (" hdrl" ,chunk_type)==0 )
548565 {
549- parse_hdrl (in,&avi_header,&stream_header,&stream_format, chunk_size);
566+ parse_hdrl (hdl, in,&avi_header,&stream_header,&stream_format, chunk_size);
550567 /* skip_chunk(in); */
551568 }
552569 else
@@ -567,7 +584,7 @@ long offset=ftell(in);
567584 if (STRINGCASECOMPARE (" idx1" ,chunk_id)==0 )
568585 {
569586 fseek (in,ftell (in)-4 ,SEEK_SET);
570- parse_idx1 (in,chunk_size);
587+ parse_idx1 (hdl, in,chunk_size);
571588 }
572589 else
573590 {
@@ -596,30 +613,28 @@ long offset=ftell(in);
596613 return 0 ;
597614}
598615
599- float OpenAVISource (char *filename, uint32_t traktype, uint32_t subtype)
616+ void * OpenAVISource (char *filename, uint32_t traktype, uint32_t subtype)
600617{
601- metasizes = NULL ;
602- metaoffsets = NULL ;
603- indexcount = 0 ;
604- videolength = 0.0 ;
605- metadatalength = 0.0 ;
606- basemetadataduration = 0 ;
607- basemetadataoffset = 0 ;
618+ videoobject *mp4 = (videoobject *)malloc (sizeof (videoobject));
619+ if (mp4 == NULL ) return NULL ;
620+
621+ memset (mp4, 0 , sizeof (videoobject));
622+
608623
609624#ifdef _WINDOWS
610- fopen_s (&mediafp, filename, " rb" );
625+ fopen_s (&mp4-> mediafp , filename, " rb" );
611626#else
612627 mediafp = fopen (filename, " rb" );
613628#endif
614629
615- if (mediafp == 0 )
630+ if (mp4-> mediafp == 0 )
616631 {
617632 printf (" Could not open %s for input\n " , filename);
618633 exit (1 );
619634 }
620635
621- parse_riff (mediafp );
636+ parse_riff (( void *)mp4 );
622637
623- return videolength ;
638+ return ( void *)mp4 ;
624639}
625640
0 commit comments