2001-02-24 20:28:24 +00:00
|
|
|
// .asf fileformat docs from http://divx.euro.ru
|
|
|
|
|
2001-04-23 03:42:17 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2001-08-01 09:14:02 +00:00
|
|
|
#include <unistd.h>
|
2001-04-23 03:42:17 +00:00
|
|
|
|
|
|
|
extern int verbose; // defined in mplayer.c
|
|
|
|
|
2001-08-17 00:40:25 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "mp_msg.h"
|
|
|
|
|
2001-04-23 03:42:17 +00:00
|
|
|
#include "stream.h"
|
|
|
|
#include "demuxer.h"
|
|
|
|
#include "stheader.h"
|
2001-10-21 15:47:31 +00:00
|
|
|
|
2001-07-19 15:15:21 +00:00
|
|
|
#include "asf.h"
|
2001-04-23 03:42:17 +00:00
|
|
|
|
2001-07-19 15:15:21 +00:00
|
|
|
#ifdef ARCH_X86
|
|
|
|
#define ASF_LOAD_GUID_PREFIX(guid) (*(uint32_t *)(guid))
|
2001-05-21 13:04:34 +00:00
|
|
|
#else
|
2001-07-19 15:15:21 +00:00
|
|
|
#define ASF_LOAD_GUID_PREFIX(guid) \
|
|
|
|
((guid)[3] << 24 | (guid)[2] << 16 | (guid)[1] << 8 | (guid)[0])
|
2001-05-18 16:14:06 +00:00
|
|
|
#endif
|
2001-07-19 15:15:21 +00:00
|
|
|
|
|
|
|
#define ASF_GUID_PREFIX_audio_stream 0xF8699E40
|
|
|
|
#define ASF_GUID_PREFIX_video_stream 0xBC19EFC0
|
|
|
|
#define ASF_GUID_PREFIX_audio_conceal_none 0x49f1a440
|
|
|
|
#define ASF_GUID_PREFIX_audio_conceal_interleave 0xbfc3cd50
|
|
|
|
#define ASF_GUID_PREFIX_header 0x75B22630
|
|
|
|
#define ASF_GUID_PREFIX_data_chunk 0x75b22636
|
|
|
|
#define ASF_GUID_PREFIX_index_chunk 0x33000890
|
|
|
|
#define ASF_GUID_PREFIX_stream_header 0xB7DC0791
|
|
|
|
#define ASF_GUID_PREFIX_header_2_0 0xD6E229D1
|
|
|
|
#define ASF_GUID_PREFIX_file_header 0x8CABDCA1
|
|
|
|
#define ASF_GUID_PREFIX_content_desc 0x75b22633
|
2002-01-24 05:30:41 +00:00
|
|
|
#define ASF_GUID_PREFIX_stream_group 0x7bf875ce
|
2001-07-19 15:15:21 +00:00
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-04-23 03:42:17 +00:00
|
|
|
static ASF_header_t asfh;
|
|
|
|
static ASF_obj_header_t objh;
|
|
|
|
static ASF_file_header_t fileh;
|
|
|
|
static ASF_stream_header_t streamh;
|
2001-05-16 23:40:55 +00:00
|
|
|
static ASF_content_description_t contenth;
|
2001-04-23 03:42:17 +00:00
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
unsigned char* asf_packet=NULL;
|
|
|
|
int asf_scrambling_h=1;
|
|
|
|
int asf_scrambling_w=1;
|
|
|
|
int asf_scrambling_b=1;
|
2001-04-23 03:42:17 +00:00
|
|
|
int asf_packetsize=0;
|
|
|
|
|
|
|
|
//int i;
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-05-18 16:14:06 +00:00
|
|
|
// the variable string is modify in this function
|
|
|
|
void pack_asf_string(char* string, int length) {
|
|
|
|
int i,j;
|
2001-05-20 13:24:41 +00:00
|
|
|
if( string==NULL ) return;
|
2001-05-18 16:14:06 +00:00
|
|
|
for( i=0, j=0; i<length && string[i]!='\0'; i+=2, j++) {
|
|
|
|
string[j]=string[i];
|
2001-05-16 23:40:55 +00:00
|
|
|
}
|
2001-05-18 16:14:06 +00:00
|
|
|
string[j]='\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
// the variable string is modify in this function
|
|
|
|
void print_asf_string(const char* name, char* string, int length) {
|
|
|
|
pack_asf_string(string, length);
|
2001-08-17 00:40:25 +00:00
|
|
|
mp_msg(MSGT_HEADER,MSGL_V,"%s%s\n", name, string);
|
2001-05-16 23:40:55 +00:00
|
|
|
}
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-07-19 15:15:21 +00:00
|
|
|
static char* asf_chunk_type(unsigned char* guid) {
|
|
|
|
static char tmp[60];
|
|
|
|
char *p;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
switch(ASF_LOAD_GUID_PREFIX(guid)){
|
|
|
|
case ASF_GUID_PREFIX_audio_stream:
|
|
|
|
return "guid_audio_stream";
|
|
|
|
case ASF_GUID_PREFIX_video_stream:
|
|
|
|
return "guid_video_stream";
|
|
|
|
case ASF_GUID_PREFIX_audio_conceal_none:
|
|
|
|
return "guid_audio_conceal_none";
|
|
|
|
case ASF_GUID_PREFIX_audio_conceal_interleave:
|
|
|
|
return "guid_audio_conceal_interleave";
|
|
|
|
case ASF_GUID_PREFIX_header:
|
|
|
|
return "guid_header";
|
|
|
|
case ASF_GUID_PREFIX_data_chunk:
|
|
|
|
return "guid_data_chunk";
|
|
|
|
case ASF_GUID_PREFIX_index_chunk:
|
|
|
|
return "guid_index_chunk";
|
|
|
|
case ASF_GUID_PREFIX_stream_header:
|
|
|
|
return "guid_stream_header";
|
|
|
|
case ASF_GUID_PREFIX_header_2_0:
|
|
|
|
return "guid_header_2_0";
|
|
|
|
case ASF_GUID_PREFIX_file_header:
|
|
|
|
return "guid_file_header";
|
|
|
|
case ASF_GUID_PREFIX_content_desc:
|
|
|
|
return "guid_content_desc";
|
|
|
|
default:
|
|
|
|
strcpy(tmp, "unknown guid ");
|
|
|
|
p = tmp + strlen(tmp);
|
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
if ((1 << i) & ((1<<4) | (1<<6) | (1<<8))) *p++ = '-';
|
|
|
|
sprintf(p, "%02x", guid[i]);
|
|
|
|
p += 2;
|
|
|
|
}
|
|
|
|
return tmp;
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-23 03:42:17 +00:00
|
|
|
int asf_check_header(demuxer_t *demuxer){
|
2001-02-24 20:28:24 +00:00
|
|
|
unsigned char asfhdrguid[16]={0x30,0x26,0xB2,0x75,0x8E,0x66,0xCF,0x11,0xA6,0xD9,0x00,0xAA,0x00,0x62,0xCE,0x6C};
|
|
|
|
stream_read(demuxer->stream,(char*) &asfh,sizeof(asfh)); // header obj
|
2001-07-19 15:15:21 +00:00
|
|
|
le2me_ASF_header_t(&asfh); // swap to machine endian
|
2001-02-24 20:28:24 +00:00
|
|
|
// for(i=0;i<16;i++) printf(" %02X",temp[i]);printf("\n");
|
|
|
|
// for(i=0;i<16;i++) printf(" %02X",asfhdrguid[i]);printf("\n");
|
|
|
|
if(memcmp(asfhdrguid,asfh.objh.guid,16)){
|
2001-08-17 00:40:25 +00:00
|
|
|
mp_msg(MSGT_HEADER,MSGL_V,"ASF_check: not ASF guid!\n");
|
2001-02-24 20:28:24 +00:00
|
|
|
return 0; // not ASF guid
|
|
|
|
}
|
|
|
|
if(asfh.cno>256){
|
2001-08-17 00:40:25 +00:00
|
|
|
mp_msg(MSGT_HEADER,MSGL_V,"ASF_check: invalid subchunks_no %d\n",(int) asfh.cno);
|
2001-02-24 20:28:24 +00:00
|
|
|
return 0; // invalid header???
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2001-04-23 22:51:13 +00:00
|
|
|
extern void print_wave_header(WAVEFORMATEX *h);
|
|
|
|
extern void print_video_header(BITMAPINFOHEADER *h);
|
|
|
|
|
2001-04-23 03:42:17 +00:00
|
|
|
int read_asf_header(demuxer_t *demuxer){
|
2001-05-16 23:40:55 +00:00
|
|
|
static unsigned char buffer[1024];
|
2002-02-05 16:50:10 +00:00
|
|
|
uint32_t* streams = NULL;
|
2002-01-26 01:21:41 +00:00
|
|
|
int audio_streams=0;
|
|
|
|
int video_streams=0;
|
2002-02-05 16:50:10 +00:00
|
|
|
uint16_t stream_count=0;
|
|
|
|
int best_video = -1;
|
|
|
|
int best_audio = -1;
|
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
#if 1
|
2001-04-11 01:38:57 +00:00
|
|
|
//printf("ASF file! (subchunks: %d)\n",asfh.cno);
|
2001-02-24 20:28:24 +00:00
|
|
|
while(!stream_eof(demuxer->stream)){
|
|
|
|
int pos,endpos;
|
|
|
|
pos=stream_tell(demuxer->stream);
|
|
|
|
stream_read(demuxer->stream,(char*) &objh,sizeof(objh));
|
2001-07-19 15:15:21 +00:00
|
|
|
le2me_ASF_obj_header_t(&objh);
|
2001-02-24 20:28:24 +00:00
|
|
|
if(stream_eof(demuxer->stream)) break; // EOF
|
|
|
|
endpos=pos+objh.size;
|
|
|
|
// for(i=0;i<16;i++) printf("%02X ",objh.guid[i]);
|
2001-04-11 01:38:57 +00:00
|
|
|
//printf("0x%08X [%s] %d\n",pos, asf_chunk_type(objh.guid),(int) objh.size);
|
2001-07-19 15:15:21 +00:00
|
|
|
switch(ASF_LOAD_GUID_PREFIX(objh.guid)){
|
|
|
|
case ASF_GUID_PREFIX_stream_header:
|
2001-02-24 20:28:24 +00:00
|
|
|
stream_read(demuxer->stream,(char*) &streamh,sizeof(streamh));
|
2001-07-19 15:15:21 +00:00
|
|
|
le2me_ASF_stream_header_t(&streamh);
|
|
|
|
if(verbose){
|
2001-08-17 00:40:25 +00:00
|
|
|
mp_msg(MSGT_HEADER,MSGL_V,"stream type: %s\n",asf_chunk_type(streamh.type));
|
|
|
|
mp_msg(MSGT_HEADER,MSGL_V,"stream concealment: %s\n",asf_chunk_type(streamh.concealment));
|
|
|
|
mp_msg(MSGT_HEADER,MSGL_V,"type: %d bytes, stream: %d bytes ID: %d\n",(int)streamh.type_size,(int)streamh.stream_size,(int)streamh.stream_no);
|
|
|
|
mp_msg(MSGT_HEADER,MSGL_V,"unk1: %lX unk2: %X\n",(unsigned long)streamh.unk1,(unsigned int)streamh.unk2);
|
|
|
|
mp_msg(MSGT_HEADER,MSGL_V,"FILEPOS=0x%X\n",stream_tell(demuxer->stream));
|
2001-07-19 15:15:21 +00:00
|
|
|
}
|
2001-05-16 23:40:55 +00:00
|
|
|
if(streamh.type_size>1024 || streamh.stream_size>1024){
|
2001-08-17 00:40:25 +00:00
|
|
|
mp_msg(MSGT_HEADER,MSGL_FATAL,"FATAL: header size bigger than 1024 bytes!\n"
|
|
|
|
"Please contact mplayer authors, and upload/send this file.\n");
|
2001-08-22 19:40:46 +00:00
|
|
|
return 0;
|
2001-05-16 23:40:55 +00:00
|
|
|
}
|
2001-02-24 20:28:24 +00:00
|
|
|
// type-specific data:
|
|
|
|
stream_read(demuxer->stream,(char*) buffer,streamh.type_size);
|
2001-07-19 15:15:21 +00:00
|
|
|
switch(ASF_LOAD_GUID_PREFIX(streamh.type)){
|
|
|
|
case ASF_GUID_PREFIX_audio_stream: {
|
2001-07-07 18:46:15 +00:00
|
|
|
sh_audio_t* sh_audio=new_sh_audio(demuxer,streamh.stream_no & 0x7F);
|
2002-01-26 01:21:41 +00:00
|
|
|
++audio_streams;
|
2001-04-15 14:33:49 +00:00
|
|
|
sh_audio->wf=calloc((streamh.type_size<sizeof(WAVEFORMATEX))?sizeof(WAVEFORMATEX):streamh.type_size,1);
|
|
|
|
memcpy(sh_audio->wf,buffer,streamh.type_size);
|
2001-07-19 15:15:21 +00:00
|
|
|
le2me_WAVEFORMATEX(sh_audio->wf);
|
2001-04-15 14:33:49 +00:00
|
|
|
if(verbose>=1) print_wave_header(sh_audio->wf);
|
2001-07-19 15:15:21 +00:00
|
|
|
if(ASF_LOAD_GUID_PREFIX(streamh.concealment)==ASF_GUID_PREFIX_audio_conceal_interleave){
|
2001-02-24 20:28:24 +00:00
|
|
|
stream_read(demuxer->stream,(char*) buffer,streamh.stream_size);
|
|
|
|
asf_scrambling_h=buffer[0];
|
|
|
|
asf_scrambling_w=(buffer[2]<<8)|buffer[1];
|
|
|
|
asf_scrambling_b=(buffer[4]<<8)|buffer[3];
|
|
|
|
asf_scrambling_w/=asf_scrambling_b;
|
|
|
|
} else {
|
|
|
|
asf_scrambling_b=asf_scrambling_h=asf_scrambling_w=1;
|
|
|
|
}
|
2001-08-17 00:40:25 +00:00
|
|
|
mp_msg(MSGT_HEADER,MSGL_V,"ASF: audio scrambling: %d x %d x %d\n",asf_scrambling_h,asf_scrambling_w,asf_scrambling_b);
|
2001-04-15 03:40:37 +00:00
|
|
|
//if(demuxer->audio->id==-1) demuxer->audio->id=streamh.stream_no & 0x7F;
|
2001-02-24 20:28:24 +00:00
|
|
|
break;
|
2001-04-06 01:18:59 +00:00
|
|
|
}
|
2001-07-19 15:15:21 +00:00
|
|
|
case ASF_GUID_PREFIX_video_stream: {
|
2001-07-07 18:46:15 +00:00
|
|
|
sh_video_t* sh_video=new_sh_video(demuxer,streamh.stream_no & 0x7F);
|
2002-02-05 16:50:10 +00:00
|
|
|
unsigned int len=streamh.type_size-(4+4+1+2);
|
2002-01-26 01:21:41 +00:00
|
|
|
++video_streams;
|
2001-04-15 14:33:49 +00:00
|
|
|
// sh_video->bih=malloc(chunksize); memset(sh_video->bih,0,chunksize);
|
|
|
|
sh_video->bih=calloc((len<sizeof(BITMAPINFOHEADER))?sizeof(BITMAPINFOHEADER):len,1);
|
|
|
|
memcpy(sh_video->bih,&buffer[4+4+1+2],len);
|
2001-07-19 15:15:21 +00:00
|
|
|
le2me_BITMAPINFOHEADER(sh_video->bih);
|
2001-04-15 03:40:37 +00:00
|
|
|
//sh_video->fps=(float)sh_video->video.dwRate/(float)sh_video->video.dwScale;
|
|
|
|
//sh_video->frametime=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
|
2001-04-15 14:33:49 +00:00
|
|
|
if(verbose>=1) print_video_header(sh_video->bih);
|
2001-02-24 20:28:24 +00:00
|
|
|
//asf_video_id=streamh.stream_no & 0x7F;
|
2001-04-15 03:40:37 +00:00
|
|
|
//if(demuxer->video->id==-1) demuxer->video->id=streamh.stream_no & 0x7F;
|
2001-02-24 20:28:24 +00:00
|
|
|
break;
|
2001-04-06 01:18:59 +00:00
|
|
|
}
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
|
|
|
// stream-specific data:
|
|
|
|
// stream_read(demuxer->stream,(char*) buffer,streamh.stream_size);
|
|
|
|
break;
|
2001-07-19 15:15:21 +00:00
|
|
|
// case ASF_GUID_PREFIX_header_2_0: return "guid_header_2_0";
|
|
|
|
case ASF_GUID_PREFIX_file_header: // guid_file_header
|
2001-02-24 20:28:24 +00:00
|
|
|
stream_read(demuxer->stream,(char*) &fileh,sizeof(fileh));
|
2001-07-19 15:15:21 +00:00
|
|
|
le2me_ASF_file_header_t(&fileh);
|
2002-01-20 21:38:11 +00:00
|
|
|
//mp_msg(MSGT_HEADER,MSGL_V,"ASF: packets: %d flags: %d pack_size: %d frame_size: %d\n",(int)fileh.packets,(int)fileh.flags,(int)fileh.packetsize,(int)fileh.frame_size);
|
|
|
|
mp_msg(MSGT_HEADER,MSGL_V,"ASF: packets: %d flags: %d max_packet_size: %d min_packet_size: %d max_bitrate: %d preroll: %d\n",(int)fileh.num_packets,(int)fileh.flags,(int)fileh.min_packet_size,(int)fileh.max_packet_size,(int)fileh.max_bitrate,(int)fileh.preroll);
|
|
|
|
asf_packetsize=fileh.max_packet_size;
|
2001-04-23 03:42:17 +00:00
|
|
|
asf_packet=malloc(asf_packetsize); // !!!
|
2001-02-24 20:28:24 +00:00
|
|
|
break;
|
2001-07-19 15:15:21 +00:00
|
|
|
case ASF_GUID_PREFIX_data_chunk: // guid_data_chunk
|
2001-04-23 03:42:17 +00:00
|
|
|
demuxer->movi_start=stream_tell(demuxer->stream)+26;
|
|
|
|
demuxer->movi_end=endpos;
|
2001-08-29 17:39:10 +00:00
|
|
|
mp_msg(MSGT_HEADER,MSGL_V,"Found movie at 0x%X - 0x%X\n",(int)demuxer->movi_start,(int)demuxer->movi_end);
|
2001-02-24 20:28:24 +00:00
|
|
|
break;
|
|
|
|
|
2001-07-19 15:15:21 +00:00
|
|
|
// case ASF_GUID_PREFIX_index_chunk: return "guid_index_chunk";
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-07-19 15:15:21 +00:00
|
|
|
case ASF_GUID_PREFIX_content_desc: // Content description
|
2001-11-22 15:30:54 +00:00
|
|
|
{
|
2001-06-04 18:01:05 +00:00
|
|
|
char *string=NULL;
|
2001-05-19 00:07:30 +00:00
|
|
|
stream_read(demuxer->stream,(char*) &contenth,sizeof(contenth));
|
2001-07-19 15:15:21 +00:00
|
|
|
le2me_ASF_content_description_t(&contenth);
|
2001-08-17 00:40:25 +00:00
|
|
|
mp_msg(MSGT_HEADER,MSGL_V,"\n");
|
2001-05-16 23:40:55 +00:00
|
|
|
// extract the title
|
2001-05-20 13:24:41 +00:00
|
|
|
if( contenth.title_size!=0 ) {
|
|
|
|
string=(char*)malloc(contenth.title_size);
|
|
|
|
stream_read(demuxer->stream, string, contenth.title_size);
|
2001-11-22 15:30:54 +00:00
|
|
|
if(verbose)
|
|
|
|
print_asf_string(" Title: ", string, contenth.title_size);
|
|
|
|
else
|
|
|
|
pack_asf_string(string, contenth.title_size);
|
|
|
|
demux_info_add(demuxer, "name", string);
|
2001-05-20 13:24:41 +00:00
|
|
|
}
|
2001-05-16 23:40:55 +00:00
|
|
|
// extract the author
|
2001-05-20 13:24:41 +00:00
|
|
|
if( contenth.author_size!=0 ) {
|
|
|
|
string=(char*)realloc((void*)string, contenth.author_size);
|
|
|
|
stream_read(demuxer->stream, string, contenth.author_size);
|
2001-11-22 15:30:54 +00:00
|
|
|
if(verbose)
|
|
|
|
print_asf_string(" Author: ", string, contenth.author_size);
|
|
|
|
else
|
|
|
|
pack_asf_string(string, contenth.author_size);
|
|
|
|
demux_info_add(demuxer, "author", string);
|
2001-05-20 13:24:41 +00:00
|
|
|
}
|
2001-05-16 23:40:55 +00:00
|
|
|
// extract the copyright
|
2001-05-20 13:24:41 +00:00
|
|
|
if( contenth.copyright_size!=0 ) {
|
|
|
|
string=(char*)realloc((void*)string, contenth.copyright_size);
|
|
|
|
stream_read(demuxer->stream, string, contenth.copyright_size);
|
2001-11-22 15:30:54 +00:00
|
|
|
if(verbose)
|
|
|
|
print_asf_string(" Copyright: ", string, contenth.copyright_size);
|
|
|
|
else
|
|
|
|
pack_asf_string(string, contenth.copyright_size);
|
|
|
|
demux_info_add(demuxer, "copyright", string);
|
2001-05-20 13:24:41 +00:00
|
|
|
}
|
2001-05-16 23:40:55 +00:00
|
|
|
// extract the comment
|
2001-05-20 13:24:41 +00:00
|
|
|
if( contenth.comment_size!=0 ) {
|
|
|
|
string=(char*)realloc((void*)string, contenth.comment_size);
|
|
|
|
stream_read(demuxer->stream, string, contenth.comment_size);
|
2001-11-22 15:30:54 +00:00
|
|
|
if(verbose)
|
|
|
|
print_asf_string(" Comment: ", string, contenth.comment_size);
|
|
|
|
else
|
|
|
|
pack_asf_string(string, contenth.comment_size);
|
|
|
|
demux_info_add(demuxer, "comments", string);
|
2001-05-20 13:24:41 +00:00
|
|
|
}
|
2001-05-16 23:40:55 +00:00
|
|
|
// extract the rating
|
2001-05-20 13:24:41 +00:00
|
|
|
if( contenth.rating_size!=0 ) {
|
|
|
|
string=(char*)realloc((void*)string, contenth.rating_size);
|
|
|
|
stream_read(demuxer->stream, string, contenth.rating_size);
|
2001-11-22 15:30:54 +00:00
|
|
|
if(verbose)
|
|
|
|
print_asf_string(" Rating: ", string, contenth.rating_size);
|
2001-05-20 13:24:41 +00:00
|
|
|
}
|
2001-08-17 00:40:25 +00:00
|
|
|
mp_msg(MSGT_HEADER,MSGL_V,"\n");
|
2001-05-16 23:40:55 +00:00
|
|
|
free(string);
|
|
|
|
break;
|
2001-11-22 15:30:54 +00:00
|
|
|
}
|
2002-01-24 05:30:41 +00:00
|
|
|
case ASF_GUID_PREFIX_stream_group: {
|
2002-02-05 16:50:10 +00:00
|
|
|
uint16_t stream_id, i;
|
2002-01-24 05:30:41 +00:00
|
|
|
uint32_t max_bitrate;
|
|
|
|
char *object=NULL, *ptr=NULL;
|
|
|
|
printf("============ ASF Stream group == START ===\n");
|
2002-02-05 16:50:10 +00:00
|
|
|
printf(" object size = %d\n", (int)objh.size);
|
2002-01-24 05:30:41 +00:00
|
|
|
object = (char*)malloc(objh.size);
|
|
|
|
if( object==NULL ) {
|
|
|
|
printf("Memory allocation failed\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
stream_read( demuxer->stream, object, objh.size );
|
|
|
|
// FIXME: We need some endian handling below...
|
|
|
|
ptr = object;
|
|
|
|
stream_count = *(uint16_t*)ptr;
|
|
|
|
ptr += sizeof(uint16_t);
|
2002-02-05 16:50:10 +00:00
|
|
|
if(stream_count > 0)
|
|
|
|
streams = (uint32_t*)malloc(2*stream_count*sizeof(uint32_t));
|
2002-01-24 05:30:41 +00:00
|
|
|
printf(" stream count=[0x%x][%u]\n", stream_count, stream_count );
|
|
|
|
for( i=0 ; i<stream_count && ptr<((char*)object+objh.size) ; i++ ) {
|
|
|
|
stream_id = *(uint16_t*)ptr;
|
|
|
|
ptr += sizeof(uint16_t);
|
|
|
|
printf(" stream id=[0x%x][%u]\n", stream_id, stream_id );
|
|
|
|
max_bitrate = *(uint32_t*)ptr;
|
|
|
|
ptr += sizeof(uint32_t);
|
|
|
|
printf(" max bitrate=[0x%x][%u]\n", max_bitrate, max_bitrate );
|
2002-02-05 16:50:10 +00:00
|
|
|
streams[2*i] = stream_id;
|
|
|
|
streams[2*i+1] = max_bitrate;
|
2002-01-24 05:30:41 +00:00
|
|
|
}
|
|
|
|
printf("============ ASF Stream group == END ===\n");
|
|
|
|
free( object );
|
|
|
|
break;
|
|
|
|
}
|
2001-02-24 20:28:24 +00:00
|
|
|
} // switch GUID
|
2001-05-03 23:32:56 +00:00
|
|
|
|
2001-07-19 15:15:21 +00:00
|
|
|
if(ASF_LOAD_GUID_PREFIX(objh.guid)==ASF_GUID_PREFIX_data_chunk) break; // movi chunk
|
2001-05-03 23:32:56 +00:00
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
if(!stream_seek(demuxer->stream,endpos)) break;
|
|
|
|
} // while EOF
|
|
|
|
|
2002-02-05 16:50:10 +00:00
|
|
|
if(streams) {
|
|
|
|
uint32_t vr = 0, ar = 0,i;
|
|
|
|
for(i = 0; i < stream_count; i++) {
|
|
|
|
uint32_t id = streams[2*i];
|
|
|
|
uint32_t rate = streams[2*i+1];
|
|
|
|
if(demuxer->v_streams[id] && rate > vr) {
|
|
|
|
vr = rate;
|
|
|
|
best_video = id;
|
|
|
|
} else if(demuxer->a_streams[id] && rate > ar) {
|
|
|
|
ar = rate;
|
|
|
|
best_audio = id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(streams);
|
|
|
|
}
|
|
|
|
|
2002-01-26 01:21:41 +00:00
|
|
|
mp_msg(MSGT_HEADER,MSGL_V,"ASF: %d audio and %d video streams found\n",audio_streams,video_streams);
|
|
|
|
if(!audio_streams) demuxer->audio->id=-2; // nosound
|
2002-02-05 16:50:10 +00:00
|
|
|
else if(best_audio > 0 && demuxer->audio->id == -1) demuxer->audio->id=best_audio;
|
2002-01-26 01:21:41 +00:00
|
|
|
if(!video_streams){
|
|
|
|
if(!audio_streams){
|
|
|
|
mp_msg(MSGT_HEADER,MSGL_ERR,"ASF: no audio or video headers found - broken file?\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
demuxer->video->id=-2; // audio-only
|
2002-02-05 16:50:10 +00:00
|
|
|
} else if (best_video > 0 && demuxer->video->id == -1) demuxer->video->id = best_video;
|
2002-01-26 01:21:41 +00:00
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
#if 0
|
|
|
|
if(verbose){
|
|
|
|
printf("ASF duration: %d\n",(int)fileh.duration);
|
|
|
|
printf("ASF start pts: %d\n",(int)fileh.start_timestamp);
|
|
|
|
printf("ASF end pts: %d\n",(int)fileh.end_timestamp);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
return 1;
|
|
|
|
}
|