📄 open.c
字号:
d->packs_left=-1; // for Navi stuff d->angle_seek=0; /* XXX dvd_last_chapter is in the range 1..nr_of_ptts */ if ( dvd_last_chapter > 0 && dvd_last_chapter < tt_srpt->title[dvd_title].nr_of_ptts ) { pgn=vts_file->vts_ptt_srpt->title[ttn-1].ptt[dvd_last_chapter].pgn; d->last_cell=d->cur_pgc->program_map[pgn-1] - 1; } else d->last_cell=d->cur_pgc->nr_of_cells; if( d->cur_pgc->cell_playback[d->cur_cell].block_type == BLOCK_TYPE_ANGLE_BLOCK ) d->cur_cell+=dvd_angle; d->cur_pack = d->cur_pgc->cell_playback[ d->cur_cell ].first_sector; d->cell_last_pack=d->cur_pgc->cell_playback[ d->cur_cell ].last_sector; mp_msg(MSGT_DVD,MSGL_V, "DVD start cell: %d pack: 0x%X-0x%X \n",d->cur_cell,d->cur_pack,d->cell_last_pack); // ... (unimplemented)// return NULL; stream=new_stream(-1,STREAMTYPE_DVD); stream->start_pos=(off_t)d->cur_pack*2048; stream->end_pos=(off_t)(d->cur_pgc->cell_playback[d->last_cell-1].last_sector)*2048; mp_msg(MSGT_DVD,MSGL_V,"DVD start=%d end=%d \n",d->cur_pack,d->cur_pgc->cell_playback[d->last_cell-1].last_sector); stream->priv=(void*)d; return stream;}#endif#ifdef MPLAYER_NETWORK#ifdef STREAMING_LIVE_DOT_COM // Check for a SDP file: if (strncmp("sdp://",filename,6) == 0) { filename += 6;#if defined(__CYGWIN__) || defined(__MINGW32__) f=open(filename,O_RDONLY|O_BINARY);#else f=open(filename,O_RDONLY);#endif if(f<0){ mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_FileNotFound,filename);return NULL; } len=lseek(f,0,SEEK_END); lseek(f,0,SEEK_SET); if (len == -1) return NULL;#ifdef _LARGEFILE_SOURCE mp_msg(MSGT_OPEN,MSGL_V,"File size is %lld bytes\n", (long long)len);#else mp_msg(MSGT_OPEN,MSGL_V,"File size is %u bytes\n", (unsigned int)len);#endif return stream_open_sdp(f, len, file_format); }#endif // FIXME: to avoid nonsense error messages... if (strncmp("tv://", filename, 5) && strncmp("mf://", filename, 5) && strncmp("vcd://", filename, 6) && strncmp("dvb://", filename, 6) && strncmp("cdda://", filename, 7) && strncmp("cddb://", filename, 7) && strncmp("mpst://", filename, 7) && strncmp("tivo://", filename, 7) && strstr(filename, "://")) { url = url_new(filename); } if(url) { if (strcmp(url->protocol, "smb")==0){#ifdef LIBSMBCLIENT // we need init of libsmbclient int err; // FIXME: HACK: make the username/password global varaibles // so the auth_fn function should grab it ... // i cannot thing other way... err = smbc_init(smb_auth_fn, 10); /* Initialize things */ // libsmbclient using if (err < 0) { mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_SMBInitError,err); return NULL; } f=smbc_open(filename, O_RDONLY, 0666); // cannot open the file, outputs that // MSGTR_FileNotFound -> MSGTR_SMBFileNotFound if(f<0){ mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_SMBFileNotFound,filename); return NULL; } len=smbc_lseek(f,0,SEEK_END); smbc_lseek(f,0,SEEK_SET); // FIXME: I really wonder is such situation -> but who cares ;)// if (len == -1) // return new_stream(f,STREAMTYPE_STREAM); // open as stream url_free(url); url = NULL; stream=new_stream(f,STREAMTYPE_SMB); stream->end_pos=len; return stream;#else mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_SMBNotCompiled); return NULL;#endif } stream=new_stream(f,STREAMTYPE_STREAM); if (strcmp(url->protocol, "ftp")) { // ftp is handled somewhere else if( streaming_start( stream, file_format, url )<0){ mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_UnableOpenURL, filename); url_free(url); url = NULL; return NULL; } else { mp_msg(MSGT_OPEN,MSGL_INFO,MSGTR_ConnToServer, url->hostname ); url_free(url); url = NULL; return stream; } } }#endif//============ Open STDIN or plain FILE ============ return open_stream_full(filename,STREAM_READ,options,file_format);}int dvd_parse_chapter_range(m_option_t *conf, const char *range){ const char *s; char *t; if (!range) return M_OPT_MISSING_PARAM; s = range; dvd_chapter = 1; dvd_last_chapter = 0; if (*range && isdigit(*range)) { dvd_chapter = strtol(range, &s, 10); if (range == s) { mp_msg(MSGT_OPEN, MSGL_ERR, "Invalid chapter range specification %s\n", range); return M_OPT_INVALID; } } if (*s == 0) return 0; else if (*s != '-') { mp_msg(MSGT_OPEN, MSGL_ERR, "Invalid chapter range specification %s\n", range); return M_OPT_INVALID; } ++s; if (*s == 0) return 0; if (! isdigit(*s)) { mp_msg(MSGT_OPEN, MSGL_ERR, "Invalid chapter range specification %s\n", range); return M_OPT_INVALID; } dvd_last_chapter = strtol(s, &t, 10); if (s == t || *t) { mp_msg(MSGT_OPEN, MSGL_ERR, "Invalid chapter range specification %s\n", range); return M_OPT_INVALID; } return 0;}#ifdef USE_DVDREADint dvd_chapter_from_cell(dvd_priv_t* dvd,int title,int cell){ pgc_t * cur_pgc; ptt_info_t* ptt; int chapter = cell; int pgc_id,pgn; if(title < 0 || cell < 0){ return 0; } /* for most DVD's chapter == cell */ /* but there are more complecated cases... */ if(chapter >= dvd->vmg_file->tt_srpt->title[title].nr_of_ptts){ chapter = dvd->vmg_file->tt_srpt->title[title].nr_of_ptts-1; } title = dvd->tt_srpt->title[title].vts_ttn-1; ptt = dvd->vts_file->vts_ptt_srpt->title[title].ptt; while(chapter >= 0){ pgc_id = ptt[chapter].pgcn; pgn = ptt[chapter].pgn; cur_pgc = dvd->vts_file->vts_pgcit->pgci_srp[pgc_id-1].pgc; if(cell >= cur_pgc->program_map[pgn-1]-1){ return chapter; } --chapter; } /* didn't find a chapter ??? */ return chapter;}int dvd_aid_from_lang(stream_t *stream, unsigned char* lang){dvd_priv_t *d=stream->priv;int code,i;if(lang){ while(strlen(lang)>=2){ code=lang[1]|(lang[0]<<8); for(i=0;i<d->nr_of_channels;i++){ if(d->audio_streams[i].language==code){ mp_msg(MSGT_OPEN,MSGL_INFO,"Selected DVD audio channel: %d language: %c%c\n", d->audio_streams[i].id, lang[0],lang[1]); return d->audio_streams[i].id; }// printf("%X != %X (%c%c)\n",code,d->audio_streams[i].language,lang[0],lang[1]); } lang+=2; while (lang[0]==',' || lang[0]==' ') ++lang; } mp_msg(MSGT_OPEN,MSGL_WARN,"No matching DVD audio language found!\n");}return -1;}int dvd_number_of_subs(stream_t *stream){ dvd_priv_t *d; if (!stream) return -1; d = stream->priv; if (!d) return -1; return d->nr_of_subtitles;}int dvd_lang_from_sid(stream_t *stream, int id){ dvd_priv_t *d; if (!stream) return 0; d = stream->priv; if (!d) return 0; if (id >= d->nr_of_subtitles) return 0; return d->subtitles[id].language;}int dvd_sid_from_lang(stream_t *stream, unsigned char* lang){dvd_priv_t *d=stream->priv;int code,i; while(lang && strlen(lang)>=2){ code=lang[1]|(lang[0]<<8); for(i=0;i<d->nr_of_subtitles;i++){ if(d->subtitles[i].language==code){ mp_msg(MSGT_OPEN,MSGL_INFO,"Selected DVD subtitle channel: %d language: %c%c\n", d->subtitles[i].id, lang[0],lang[1]); return d->subtitles[i].id; } } lang+=2; while (lang[0]==',' || lang[0]==' ') ++lang; } mp_msg(MSGT_OPEN,MSGL_WARN,"No matching DVD subtitle language found!\n"); return -1;}static int dvd_next_cell(dvd_priv_t *d){ int next_cell=d->cur_cell; mp_msg(MSGT_DVD,MSGL_V, "dvd_next_cell: next1=0x%X \n",next_cell); if( d->cur_pgc->cell_playback[ next_cell ].block_type == BLOCK_TYPE_ANGLE_BLOCK ) { while(next_cell<d->last_cell){ if( d->cur_pgc->cell_playback[next_cell].block_mode == BLOCK_MODE_LAST_CELL ) break; ++next_cell; } } mp_msg(MSGT_DVD,MSGL_V, "dvd_next_cell: next2=0x%X \n",next_cell); ++next_cell; if(next_cell>=d->last_cell) return -1; // EOF if( d->cur_pgc->cell_playback[next_cell].block_type == BLOCK_TYPE_ANGLE_BLOCK ){ next_cell+=dvd_angle; if(next_cell>=d->last_cell) return -1; // EOF } mp_msg(MSGT_DVD,MSGL_V, "dvd_next_cell: next3=0x%X \n",next_cell); return next_cell;}int dvd_read_sector(dvd_priv_t *d,unsigned char* data){ int len; if(d->packs_left==0){ /** * If we're not at the end of this cell, we can determine the next * VOBU to display using the VOBU_SRI information section of the * DSI. Using this value correctly follows the current angle, * avoiding the doubled scenes in The Matrix, and makes our life * really happy. * * Otherwise, we set our next address past the end of this cell to * force the code above to go to the next cell in the program. */ if( d->dsi_pack.vobu_sri.next_vobu != SRI_END_OF_CELL ) { d->cur_pack= d->dsi_pack.dsi_gi.nv_pck_lbn + ( d->dsi_pack.vobu_sri.next_vobu & 0x7fffffff ); mp_msg(MSGT_DVD,MSGL_DBG2, "Navi new pos=0x%X \n",d->cur_pack); } else { // end of cell! find next cell! mp_msg(MSGT_DVD,MSGL_V, "--- END OF CELL !!! ---\n"); d->cur_pack=d->cell_last_pack+1; } }read_next: if(d->cur_pack>d->cell_last_pack){ // end of cell! int next=dvd_next_cell(d); if(next>=0){ d->cur_cell=next;// if( d->cur_pgc->cell_playback[d->cur_cell].block_type // == BLOCK_TYPE_ANGLE_BLOCK ) d->cur_cell+=dvd_angle; d->cur_pack = d->cur_pgc->cell_playback[ d->cur_cell ].first_sector; d->cell_last_pack=d->cur_pgc->cell_playback[ d->cur_cell ].last_sector; mp_msg(MSGT_DVD,MSGL_V, "DVD next cell: %d pack: 0x%X-0x%X \n",d->cur_cell,d->cur_pack,d->cell_last_pack); } else return -1; // EOF } len = DVDReadBlocks( d->title, d->cur_pack, 1, data ); if(!len) return -1; //error if(data[38]==0 && data[39]==0 && data[40]==1 && data[41]==0xBF && data[1024]==0 && data[1025]==0 && data[1026]==1 && data[1027]==0xBF){ // found a Navi packet!!!#if LIBDVDREAD_VERSION >= DVDREAD_VERSION(0,9,0) navRead_DSI( &d->dsi_pack, &(data[ DSI_START_BYTE ]) );#else navRead_DSI( &d->dsi_pack, &(data[ DSI_START_BYTE ]), sizeof(dsi_t) );#endif if(d->cur_pack != d->dsi_pack.dsi_gi.nv_pck_lbn ){ mp_msg(MSGT_DVD,MSGL_V, "Invalid NAVI packet! lba=0x%X navi=0x%X \n", d->cur_pack,d->dsi_pack.dsi_gi.nv_pck_lbn); } else { // process! d->packs_left = d->dsi_pack.dsi_gi.vobu_ea; mp_msg(MSGT_DVD,MSGL_DBG2, "Found NAVI packet! lba=0x%X len=%d \n",d->cur_pack,d->packs_left); //navPrint_DSI(&d->dsi_pack); mp_msg(MSGT_DVD,MSGL_DBG3,"\r### CELL %d: Navi: %d/%d IFO: %d/%d \n",d->cur_cell, d->dsi_pack.dsi_gi.vobu_c_idn,d->dsi_pack.dsi_gi.vobu_vob_idn, d->cur_pgc->cell_position[d->cur_cell].cell_nr, d->cur_pgc->cell_position[d->cur_cell].vob_id_nr); if(d->angle_seek){ int i,skip=0;#if defined(__GNUC__) && ( defined(__sparc__) || defined(hpux) ) // workaround for a bug in the sparc/hpux version of gcc 2.95.X ... 3.2, // it generates incorrect code for unaligned access to a packed // structure member, resulting in an mplayer crash with a SIGBUS // signal. // // See also gcc problem report PR c/7847: // http://gcc.gnu.org/cgi-bin/gnatsweb.pl?database=gcc&cmd=view+audit-trail&pr=7847 for(i=0;i<9;i++){ // check if all values zero: typeof(d->dsi_pack.sml_agli.data[i].address) tmp_addr; memcpy(&tmp_addr,&d->dsi_pack.sml_agli.data[i].address,sizeof(tmp_addr)); if((skip=tmp_addr)!=0) break; }#else for(i=0;i<9;i++) // check if all values zero: if((skip=d->dsi_pack.sml_agli.data[i].address)!=0) break;#endif if(skip){ // sml_agli table has valid data (at least one non-zero): d->cur_pack=d->dsi_pack.dsi_gi.nv_pck_lbn+ d->dsi_pack.sml_agli.data[dvd_angle].address; d->angle_seek=0; mp_msg(MSGT_DVD,MSGL_V, "Angle-seek synced using sml_agli map! new_lba=0x%X \n",d->cur_pack); } else { // check if we're in the right cell, jump otherwise: if( (d->dsi_pack.dsi_gi.vobu_c_idn==d->cur_pgc->cell_position[d->cur_cell].cell_nr) && (d->dsi_pack.dsi_gi.vobu_vob_idn==d->cur_pgc->cell_position[d->cur_cell].vob_id_nr) ){ d->angle_seek=0; mp_msg(MSGT_DVD,MSGL_V, "Angle-seek synced by cell/vob IDN search! \n"); } else { // wrong angle, skip this vobu: d->cur_pack=d->dsi_pack.dsi_gi.nv_pck_lbn+ d->dsi_pack.dsi_gi.vobu_ea; d->angle_seek=2; // DEBUG } } } } ++d->cur_pack; goto read_next; } ++d->cur_pack; if(d->packs_left>=0) --d->packs_left; if(d->angle_seek){ if(d->angle_seek==2) mp_msg(MSGT_DVD,MSGL_V, "!!! warning! reading packet while angle_seek !!!\n"); goto read_next; // searching for Navi packet } return d->cur_pack-1;}void dvd_seek(dvd_priv_t *d,int pos){ d->packs_left=-1; d->cur_pack=pos; // check if we stay in current cell (speedup things, and avoid angle skip)if(d->cur_pack>d->cell_last_pack || d->cur_pack<d->cur_pgc->cell_playback[ d->cur_cell ].first_sector){ // ok, cell change, find the right cell! d->cur_cell=0; if( d->cur_pgc->cell_playback[d->cur_cell].block_type == BLOCK_TYPE_ANGLE_BLOCK ) d->cur_cell+=dvd_angle; while(1){ int next; d->cell_last_pack=d->cur_pgc->cell_playback[ d->cur_cell ].last_sector; if(d->cur_pack<d->cur_pgc->cell_playback[ d->cur_cell ].first_sector){ d->cur_pack=d->cur_pgc->cell_playback[ d->cur_cell ].first_sector; break; } if(d->cur_pack<=d->cell_last_pack) break; // ok, we find it! :) next=dvd_next_cell(d); if(next<0){// d->cur_pack=d->cell_last_pack+1; break; // we're after the last cell } d->cur_cell=next; }}mp_msg(MSGT_DVD,MSGL_V, "DVD Seek! lba=0x%X cell=%d packs: 0x%X-0x%X \n", d->cur_pack,d->cur_cell,d->cur_pgc->cell_playback[ d->cur_cell ].first_sector,d->cell_last_pack);// if we're in interleaved multi-angle cell, find the right angle chain!// (read Navi block, and use the seamless angle jump table)d->angle_seek=1;}void dvd_close(dvd_priv_t *d) { ifoClose(d->vts_file); ifoClose(d->vmg_file); DVDCloseFile(d->title); DVDClose(d->dvd); dvd_chapter = 1; dvd_last_chapter = 0;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -