From c92538dfaa5eb7e9b2773f158cbb310545116abe Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 1 Aug 2012 17:07:35 +0200 Subject: Remove dead code This was done with the help of callcatcher [1]. Only functions which are statically known to be unused are removed. Some unused functions are not removed yet, because they might be needed in the near future (such as open_output_stream for the encode branch). There is one user visible change: the --subcc option did nothing, and is removed with this commit. [1] http://www.skynet.ie/~caolan/Packages/callcatcher.html --- sub/spudec.c | 19 --- sub/spudec.h | 2 - sub/sub.c | 70 ------------ sub/sub.h | 7 -- sub/sub_cc.c | 349 -------------------------------------------------------- sub/sub_cc.h | 29 ----- sub/subreader.c | 259 ----------------------------------------- sub/subreader.h | 6 - sub/vobsub.c | 241 -------------------------------------- sub/vobsub.h | 4 - 10 files changed, 986 deletions(-) delete mode 100644 sub/sub_cc.c delete mode 100644 sub/sub_cc.h (limited to 'sub') diff --git a/sub/spudec.c b/sub/spudec.c index a871aa3cd9..6eabaf5723 100644 --- a/sub/spudec.c +++ b/sub/spudec.c @@ -1209,16 +1209,6 @@ nothing_to_do: } } -void spudec_update_palette(void * this, unsigned int *palette) -{ - spudec_handle_t *spu = this; - if (spu && palette) { - memcpy(spu->global_palette, palette, sizeof(spu->global_palette)); - if(spu->hw_spu) - vo_control(spu->hw_spu, VOCTRL_SET_SPU_PALETTE, spu->global_palette); - } -} - void spudec_set_font_factor(void * this, double factor) { spudec_handle_t *spu = this; @@ -1334,15 +1324,6 @@ void spudec_free(void *this) } } -void spudec_set_hw_spu(void *this, struct vo *hw_spu) -{ - spudec_handle_t *spu = this; - if (!spu) - return; - spu->hw_spu = hw_spu; - vo_control(hw_spu, VOCTRL_SET_SPU_PALETTE, spu->global_palette); -} - /** * palette must contain at least 256 32-bit entries, otherwise crashes * are possible diff --git a/sub/spudec.h b/sub/spudec.h index 2b3828c34c..ad7ece4f7a 100644 --- a/sub/spudec.h +++ b/sub/spudec.h @@ -26,14 +26,12 @@ void spudec_assemble(void *this, unsigned char *packet, unsigned int len, int pt void spudec_draw(void *this, void (*draw_alpha)(void *ctx, int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride), void *ctx); void spudec_draw_scaled(void *this, unsigned int dxs, unsigned int dys, void (*draw_alpha)(void *ctx, int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride), void *ctx); int spudec_apply_palette_crop(void *this, uint32_t palette, int sx, int ex, int sy, int ey); -void spudec_update_palette(void *this, unsigned int *palette); void *spudec_new_scaled(unsigned int *palette, unsigned int frame_width, unsigned int frame_height, uint8_t *extradata, int extradata_len); void *spudec_new(unsigned int *palette); void spudec_free(void *this); void spudec_reset(void *this); // called after seek int spudec_visible(void *this); // check if spu is visible void spudec_set_font_factor(void * this, double factor); // sets the equivalent to ffactor -void spudec_set_hw_spu(void *this, struct vo *hw_spu); int spudec_changed(void *this); void spudec_calc_bbox(void *me, unsigned int dxs, unsigned int dys, unsigned int* bbox); void spudec_set_forced_subs_only(void * const this, const unsigned int flag); diff --git a/sub/sub.c b/sub/sub.c index 43fef147d2..933a53e37d 100644 --- a/sub/sub.c +++ b/sub/sub.c @@ -94,39 +94,6 @@ float font_factor = 0.75; float sub_delay = 0; float sub_fps = 0; -// renders char to a big per-object buffer where alpha and bitmap are separated -void draw_alpha_buf(mp_osd_obj_t* obj, int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride) -{ - int dststride = obj->stride; - int dstskip = obj->stride-w; - int srcskip = stride-w; - int i, j; - unsigned char *b = obj->bitmap_buffer + (y0-obj->bbox.y1)*dststride + (x0-obj->bbox.x1); - unsigned char *a = obj->alpha_buffer + (y0-obj->bbox.y1)*dststride + (x0-obj->bbox.x1); - unsigned char *bs = src; - unsigned char *as = srca; - - if (x0 < obj->bbox.x1 || x0+w > obj->bbox.x2 || y0 < obj->bbox.y1 || y0+h > obj->bbox.y2) { - fprintf(stderr, "osd text out of range: bbox [%d %d %d %d], txt [%d %d %d %d]\n", - obj->bbox.x1, obj->bbox.x2, obj->bbox.y1, obj->bbox.y2, - x0, x0+w, y0, y0+h); - return; - } - - for (i = 0; i < h; i++) { - for (j = 0; j < w; j++, b++, a++, bs++, as++) { - if (*b < *bs) *b = *bs; - if (*as) { - if (*a == 0 || *a > *as) *a = *as; - } - } - b+= dstskip; - a+= dstskip; - bs+= srcskip; - as+= srcskip; - } -} - // allocates/enlarges the alpha/bitmap buffer void osd_alloc_buf(mp_osd_obj_t* obj) { @@ -160,20 +127,6 @@ void vo_draw_text_from_buffer(mp_osd_obj_t* obj,void (*draw_alpha)(void *ctx, in } } -unsigned utf8_get_char(const char **str) { - const uint8_t *strp = (const uint8_t *)*str; - unsigned c; - GET_UTF8(c, *strp++, goto no_utf8;); - *str = (const char *)strp; - return c; - -no_utf8: - strp = (const uint8_t *)*str; - c = *strp++; - *str = (const char *)strp; - return c; -} - #ifdef CONFIG_DVDNAV void osd_set_nav_box (uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey) { nav_hl.sx = sx; @@ -392,28 +345,6 @@ void osd_set_text(struct osd_state *osd, const char *text) { osd->osd_text = talloc_strdup(osd, text); } -int vo_osd_changed_flag=0; - -void osd_remove_text(struct osd_state *osd, int dxs, int dys, - void (*remove)(int x0, int y0, int w, int h)) -{ - mp_osd_obj_t* obj=vo_osd_list; - osd_update(osd, dxs, dys); - while(obj){ - if(((obj->flags&OSDFLAG_CHANGED) || (obj->flags&OSDFLAG_VISIBLE)) && - (obj->flags&OSDFLAG_OLD_BBOX)){ - int w=obj->old_bbox.x2-obj->old_bbox.x1; - int h=obj->old_bbox.y2-obj->old_bbox.y1; - if(w>0 && h>0){ - vo_osd_changed_flag=obj->flags&OSDFLAG_CHANGED; // temp hack - remove(obj->old_bbox.x1,obj->old_bbox.y1,w,h); - } -// obj->flags&=~OSDFLAG_OLD_BBOX; - } - obj=obj->next; - } -} - void osd_draw_text_ext(struct osd_state *osd, int dxs, int dys, int left_border, int top_border, int right_border, int bottom_border, int orig_w, int orig_h, @@ -428,7 +359,6 @@ void osd_draw_text_ext(struct osd_state *osd, int dxs, int dys, bottom_border, orig_w, orig_h); while(obj){ if(obj->flags&OSDFLAG_VISIBLE){ - vo_osd_changed_flag=obj->flags&OSDFLAG_CHANGED; // temp hack switch(obj->type){ case OSDTYPE_SPU: vo_draw_spudec_sub(obj, draw_alpha, ctx); // FIXME diff --git a/sub/sub.h b/sub/sub.h index 5c2b6184c5..41b3b0ccff 100644 --- a/sub/sub.h +++ b/sub/sub.h @@ -166,8 +166,6 @@ void osd_draw_text_ext(struct osd_state *osd, int dxs, int dys, unsigned char *srca, int stride), void *ctx); -void osd_remove_text(struct osd_state *osd, int dxs, int dys, - void (*remove)(int x0, int y0, int w, int h)); struct osd_state *osd_create(struct MPOpts *opts, struct ass_library *asslib); void osd_set_text(struct osd_state *osd, const char *text); @@ -177,10 +175,6 @@ void vo_osd_resized(void); int vo_osd_check_range_update(int,int,int,int); void osd_free(struct osd_state *osd); -extern int vo_osd_changed_flag; - -unsigned utf8_get_char(const char **str); - #ifdef CONFIG_DVDNAV #include void osd_set_nav_box (uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey); @@ -193,7 +187,6 @@ void osd_set_nav_box (uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey); // used only by osd_ft.c or osd_libass.c void osd_alloc_buf(mp_osd_obj_t* obj); -void draw_alpha_buf(mp_osd_obj_t* obj, int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride); void vo_draw_text_from_buffer(mp_osd_obj_t* obj,void (*draw_alpha)(void *ctx, int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride), void *ctx); // defined in osd_ft.c or osd_libass.c diff --git a/sub/sub_cc.c b/sub/sub_cc.c deleted file mode 100644 index 8919ce84f4..0000000000 --- a/sub/sub_cc.c +++ /dev/null @@ -1,349 +0,0 @@ -/* - * decoder for Closed Captions - * - * This decoder relies on MPlayer's OSD to display subtitles. - * Be warned that decoding is somewhat preliminary, though it basically works. - * - * Most notably, only the text information is decoded as of now, discarding - * color, background and position info (see source below). - * - * uses source from the xine closed captions decoder - * - * Copyright (C) 2002 Matteo Giani - * - * This file is part of MPlayer. - * - * MPlayer is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * MPlayer is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include -#include -#include - -#include "config.h" -#include "sub_cc.h" - -#include "subreader.h" - -#include "libvo/video_out.h" -#include "sub.h" - - -#define CC_MAX_LINE_LENGTH 64 - -static char chartbl[128]; - -static subtitle buf1,buf2; -static subtitle *fb,*bb; - -static unsigned int cursor_pos=0; - -static int initialized=0; - -#define CC_ROLLON 1 -#define CC_ROLLUP 2 - -static int cc_mode=CC_ROLLON; -static int cc_lines=4; ///< number of visible rows in CC roll-up mode, not used in CC roll-on mode - -int subcc_enabled = 0; - -static void build_char_table(void) -{ - int i; - /* first the normal ASCII codes */ - for (i = 0; i < 128; i++) - chartbl[i] = (char) i; - /* now the special codes */ - chartbl[0x2a] = 'á'; - chartbl[0x5c] = 'é'; - chartbl[0x5e] = 'í'; - chartbl[0x5f] = 'ó'; - chartbl[0x60] = 'ú'; - chartbl[0x7b] = 'ç'; - chartbl[0x7c] = '÷'; - chartbl[0x7d] = 'Ñ'; - chartbl[0x7e] = 'ñ'; - chartbl[0x7f] = '¤'; /* FIXME: this should be a solid block */ -} - -static void clear_buffer(subtitle *buf) -{ - int i; - buf->lines=0; - for (i = 0; i < SUB_MAX_TEXT; i++) { - free(buf->text[i]); - buf->text[i] = NULL; - } -} - - -/** - \brief scroll buffer one line up - \param buf buffer to scroll -*/ -static void scroll_buffer(subtitle* buf) -{ - int i; - - while(buf->lines > cc_lines) - { - free(buf->text[0]); - - for(i = 0; i < buf->lines - 1; i++) buf->text[i] = buf->text[i+1]; - - buf->text[buf->lines-1] = NULL; - buf->lines--; - } -} - -static int channel; - -void subcc_init(void) -{ - int i; - //printf("subcc_init(): initing...\n"); - build_char_table(); - for(i=0;ilines) {bb->lines++; cursor_pos=0;} - if(bb->text[bb->lines - 1]==NULL) - { - bb->text[bb->lines - 1] = calloc(1, CC_MAX_LINE_LENGTH); - cursor_pos=0; - } - - if(c=='\n') - { - if(cursor_pos>0 && bb->lines < SUB_MAX_TEXT) - { - bb->lines++;cursor_pos=0; - if(cc_mode==CC_ROLLUP){ //Carriage return - scroll buffer one line up - bb->text[bb->lines - 1]=calloc(1, CC_MAX_LINE_LENGTH); - scroll_buffer(bb); - } - } - } - else - { - if(cursor_pos==CC_MAX_LINE_LENGTH-1) - { - fprintf(stderr,"CC: append_char() reached CC_MAX_LINE_LENGTH!\n"); - return; - } - bb->text[bb->lines - 1][cursor_pos++]=c; - } - //In CC roll-up mode data should be shown immediately - if(cc_mode==CC_ROLLUP) display_buffer(bb); -} - - -static void swap_buffers(void) -{ - subtitle *foo; - foo=fb; - fb=bb; - bb=foo; -} - -static int selected_channel(void) -{ - return subcc_enabled - 1; -} - -static void cc_decode_EIA608(unsigned short int data) -{ - - static unsigned short int lastcode=0x0000; - uint8_t c1 = data & 0x7f; - uint8_t c2 = (data >> 8) & 0x7f; - - if (c1 & 0x60) { /* normal character, 0x20 <= c1 <= 0x7f */ - if (channel != (selected_channel() & 1)) - return; - append_char(chartbl[c1]); - if(c2 & 0x60) /*c2 might not be a normal char even if c1 is*/ - append_char(chartbl[c2]); - } - else if (c1 & 0x10) // control code / special char - { - channel = (c1 & 0x08) >> 3; - if (channel != (selected_channel() & 1)) - return; - c1&=~0x08; - if(data!=lastcode) - { - if(c2 & 0x40) { /*PAC, Preamble Address Code */ - append_char('\n'); /*FIXME properly interpret PACs*/ - } - else - switch(c1) - { - case 0x10: break; // ext attribute - case 0x11: - if((c2 & 0x30)==0x30) - { - //printf("[debug]:Special char (ignored)\n"); - /*cc_decode_special_char()*/; - } - else if (c2 & 0x20) - { - //printf("[debug]: midrow_attr (ignored)\n"); - /*cc_decode_midrow_attr()*/; - } - break; - case 0x14: - switch(c2) - { - case 0x00: //CC roll-on mode - cc_mode=CC_ROLLON; - break; - case 0x25: //CC roll-up, 2 rows - case 0x26: //CC roll-up, 3 rows - case 0x27: //CC roll-up, 4 rows - cc_lines=c2-0x23; - cc_mode=CC_ROLLUP; - break; - case 0x2C: display_buffer(NULL); //EDM - clear_buffer(fb); break; - case 0x2d: append_char('\n'); //carriage return - break; - case 0x2e: clear_buffer(bb); //ENM - break; - case 0x2f: swap_buffers(); //Swap buffers - display_buffer(fb); - clear_buffer(bb); - break; - } - break; - case 0x17: - if( c2>=0x21 && c2<=0x23) //TAB - { - break; - } - } - } - } - lastcode=data; -} - -static void subcc_decode(const uint8_t *inputbuffer, unsigned int inputlength) -{ - /* The first number may denote a channel number. I don't have the - * EIA-708 standard, so it is hard to say. - * From what I could figure out so far, the general format seems to be: - * - * repeat - * - * 0xfe starts 2 byte sequence of unknown purpose. It might denote - * field #2 in line 21 of the VBI. - * Treating it identical of 0xff fixes - * http://samples.mplayerhq.hu/MPEG-VOB/ClosedCaptions/Starship_Troopers.vob - * - * 0xff starts 2 byte EIA-608 sequence, field #1 in line 21 of the VBI. - * Followed by a 3-code triplet that starts either with 0xff or - * 0xfe. In either case, the following triplet needs to be ignored - * for line 21, field 1. - * - * 0x00 is padding, followed by 2 more 0x00. - * - * 0x01 always seems to appear at the beginning, always seems to - * be followed by 0xf8, 8-bit number. - * The lower 7 bits of this 8-bit number seem to denote the - * number of code triplets that follow. - * The most significant bit denotes whether the Line 21 field 1 - * captioning information is at odd or even triplet offsets from this - * beginning triplet. 1 denotes odd offsets, 0 denotes even offsets. - * - * Most captions are encoded with odd offsets, so this is what we - * will assume. - * - * until end of packet - */ - const uint8_t *current = inputbuffer; - unsigned int curbytes = 0; - uint8_t data1, data2; - uint8_t cc_code; - int odd_offset = 1; - - while (curbytes < inputlength) { - cc_code = current[0]; - - if (inputlength - curbytes < 2) { -#ifdef LOG_DEBUG - fprintf(stderr, "Not enough data for 2-byte CC encoding\n"); -#endif - break; - } - - data1 = current[1]; - data2 = current[2]; - current += 3; curbytes += 3; - - switch (cc_code) { - case 0xfe: - case 0xff: - odd_offset ^= 1; - if (odd_offset != selected_channel() >> 1) - break; - /* expect EIA-608 CC1/CC2 encoding */ - // FIXME check parity! - // Parity check omitted assuming we are reading from a DVD and therefore - // we should encounter no "transmission errors". - cc_decode_EIA608(data1 | (data2 << 8)); - break; - - case 0x00: - /* This seems to be just padding */ - break; - - case 0x01: - odd_offset = data2 >> 7; - break; - - default: -//#ifdef LOG_DEBUG - fprintf(stderr, "Unknown CC encoding: %x\n", cc_code); -//#endif - break; - } - } -} - - -void subcc_process_data(const uint8_t *inputdata, unsigned int len) -{ - if(!subcc_enabled) return; - if(!initialized) subcc_init(); - - subcc_decode(inputdata, len); -} diff --git a/sub/sub_cc.h b/sub/sub_cc.h deleted file mode 100644 index f5f6924057..0000000000 --- a/sub/sub_cc.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * This file is part of MPlayer. - * - * MPlayer is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * MPlayer is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef MPLAYER_SUB_CC_H -#define MPLAYER_SUB_CC_H - -#include - -extern int subcc_enabled; - -void subcc_init(void); -void subcc_process_data(const uint8_t *inputdata, unsigned int len); - -#endif /* MPLAYER_SUB_CC_H */ diff --git a/sub/subreader.c b/sub/subreader.c index 6c12ba08a4..ae6f009bc4 100644 --- a/sub/subreader.c +++ b/sub/subreader.c @@ -1790,265 +1790,6 @@ if ((suboverlap_enabled == 2) || return subt_data; } -void list_sub_file(sub_data* subd){ - int i,j; - subtitle *subs = subd->subtitles; - - for(j=0; j < subd->sub_num; j++){ - subtitle* egysub=&subs[j]; - mp_msg(MSGT_SUBREADER,MSGL_INFO,"%i line%c (%li-%li)\n", - egysub->lines, - (1==egysub->lines)?' ':'s', - egysub->start, - egysub->end); - for (i=0; ilines; i++) { - mp_msg(MSGT_SUBREADER,MSGL_INFO,"\t\t%d: %s%s", i,egysub->text[i], i==egysub->lines-1?"":" \n "); - } - mp_msg(MSGT_SUBREADER,MSGL_INFO,"\n"); - } - - mp_msg(MSGT_SUBREADER,MSGL_INFO,"Subtitle format %s time.\n", - subd->sub_uses_time ? "uses":"doesn't use"); - mp_msg(MSGT_SUBREADER,MSGL_INFO,"Read %i subtitles, %i errors.\n", subd->sub_num, subd->sub_errs); -} - -void dump_srt(sub_data* subd, float fps){ - int i,j; - int h,m,s,ms; - FILE * fd; - subtitle * onesub; - unsigned long temp; - subtitle *subs = subd->subtitles; - - if (!subd->sub_uses_time && sub_fps == 0) - sub_fps = fps; - fd=fopen("dumpsub.srt","w"); - if(!fd) - { - perror("dump_srt: fopen"); - return; - } - for(i=0; i < subd->sub_num; i++) - { - onesub=subs+i; //=&subs[i]; - fprintf(fd,"%d\n",i+1);//line number - - temp=onesub->start; - if (!subd->sub_uses_time) - temp = temp * 100 / sub_fps; - temp -= sub_delay * 100; - h=temp/360000;temp%=360000; //h =1*100*60*60 - m=temp/6000; temp%=6000; //m =1*100*60 - s=temp/100; temp%=100; //s =1*100 - ms=temp*10; //ms=1*10 - fprintf(fd,"%02d:%02d:%02d,%03d --> ",h,m,s,ms); - - temp=onesub->end; - if (!subd->sub_uses_time) - temp = temp * 100 / sub_fps; - temp -= sub_delay * 100; - h=temp/360000;temp%=360000; - m=temp/6000; temp%=6000; - s=temp/100; temp%=100; - ms=temp*10; - fprintf(fd,"%02d:%02d:%02d,%03d\n",h,m,s,ms); - - for(j=0;jlines;j++) - fprintf(fd,"%s\n",onesub->text[j]); - - fprintf(fd,"\n"); - } - fclose(fd); - mp_msg(MSGT_SUBREADER,MSGL_INFO,"SUB: Subtitles dumped in \'dumpsub.srt\'.\n"); -} - -void dump_mpsub(sub_data* subd, float fps){ - int i,j; - FILE *fd; - float a,b; - subtitle *subs = subd->subtitles; - - mpsub_position = subd->sub_uses_time? (sub_delay*100) : (sub_delay*fps); - if (sub_fps==0) sub_fps=fps; - - fd=fopen ("dump.mpsub", "w"); - if (!fd) { - perror ("dump_mpsub: fopen"); - return; - } - - - if (subd->sub_uses_time) fprintf (fd,"FORMAT=TIME\n\n"); - else fprintf (fd, "FORMAT=%5.2f\n\n", fps); - - for(j=0; j < subd->sub_num; j++){ - subtitle* egysub=&subs[j]; - if (subd->sub_uses_time) { - a=((egysub->start-mpsub_position)/100.0); - b=((egysub->end-egysub->start)/100.0); - if ( (float)((int)a) == a) - fprintf (fd, "%.0f",a); - else - fprintf (fd, "%.2f",a); - - if ( (float)((int)b) == b) - fprintf (fd, " %.0f\n",b); - else - fprintf (fd, " %.2f\n",b); - } else { - fprintf (fd, "%ld %ld\n", (long)((egysub->start*(fps/sub_fps))-((mpsub_position*(fps/sub_fps)))), - (long)(((egysub->end)-(egysub->start))*(fps/sub_fps))); - } - - mpsub_position = egysub->end; - for (i=0; ilines; i++) { - fprintf (fd, "%s\n",egysub->text[i]); - } - fprintf (fd, "\n"); - } - fclose (fd); - mp_msg(MSGT_SUBREADER,MSGL_INFO,"SUB: Subtitles dumped in \'dump.mpsub\'.\n"); -} - -void dump_microdvd(sub_data* subd, float fps) { - int i, delay; - FILE *fd; - subtitle *subs = subd->subtitles; - if (sub_fps == 0) - sub_fps = fps; - fd = fopen("dumpsub.sub", "w"); - if (!fd) { - perror("dumpsub.sub: fopen"); - return; - } - delay = sub_delay * sub_fps; - for (i = 0; i < subd->sub_num; ++i) { - int j, start, end; - start = subs[i].start; - end = subs[i].end; - if (subd->sub_uses_time) { - start = start * sub_fps / 100 ; - end = end * sub_fps / 100; - } - else { - start = start * sub_fps / fps; - end = end * sub_fps / fps; - } - start -= delay; - end -= delay; - fprintf(fd, "{%d}{%d}", start, end); - for (j = 0; j < subs[i].lines; ++j) - fprintf(fd, "%s%s", j ? "|" : "", subs[i].text[j]); - fprintf(fd, "\n"); - } - fclose(fd); - mp_msg(MSGT_SUBREADER,MSGL_INFO,"SUB: Subtitles dumped in \'dumpsub.sub\'.\n"); -} - -void dump_jacosub(sub_data* subd, float fps) { - int i,j; - int h,m,s,cs; - FILE * fd; - subtitle * onesub; - unsigned long temp; - subtitle *subs = subd->subtitles; - - if (!subd->sub_uses_time && sub_fps == 0) - sub_fps = fps; - fd=fopen("dumpsub.jss","w"); - if(!fd) - { - perror("dump_jacosub: fopen"); - return; - } - fprintf(fd, "#TIMERES %d\n", (subd->sub_uses_time) ? 100 : (int)sub_fps); - for(i=0; i < subd->sub_num; i++) - { - onesub=subs+i; //=&subs[i]; - - temp=onesub->start; - if (!subd->sub_uses_time) - temp = temp * 100 / sub_fps; - temp -= sub_delay * 100; - h=temp/360000;temp%=360000; //h =1*100*60*60 - m=temp/6000; temp%=6000; //m =1*100*60 - s=temp/100; temp%=100; //s =1*100 - cs=temp; //cs=1*10 - fprintf(fd,"%02d:%02d:%02d.%02d ",h,m,s,cs); - - temp=onesub->end; - if (!subd->sub_uses_time) - temp = temp * 100 / sub_fps; - temp -= sub_delay * 100; - h=temp/360000;temp%=360000; - m=temp/6000; temp%=6000; - s=temp/100; temp%=100; - cs=temp; - fprintf(fd,"%02d:%02d:%02d.%02d {~} ",h,m,s,cs); - - for(j=0;jlines;j++) - fprintf(fd,"%s%s",j ? "\\n" : "", onesub->text[j]); - - fprintf(fd,"\n"); - } - fclose(fd); - mp_msg(MSGT_SUBREADER,MSGL_INFO,"SUB: Subtitles dumped in \'dumpsub.js\'.\n"); -} - -void dump_sami(sub_data* subd, float fps) { - int i,j; - FILE * fd; - subtitle * onesub; - unsigned long temp; - subtitle *subs = subd->subtitles; - - if (!subd->sub_uses_time && sub_fps == 0) - sub_fps = fps; - fd=fopen("dumpsub.smi","w"); - if(!fd) - { - perror("dump_jacosub: fopen"); - return; - } - fprintf(fd, "\n" - "\n" - " \n" - "\n" - "\n"); - for(i=0; i < subd->sub_num; i++) - { - onesub=subs+i; //=&subs[i]; - - temp=onesub->start; - if (!subd->sub_uses_time) - temp = temp * 100 / sub_fps; - temp -= sub_delay * 100; - fprintf(fd,"\t\n" - "\t

", temp * 10); - - for(j=0;jlines;j++) - fprintf(fd,"%s%s",j ? "
" : "", onesub->text[j]); - - fprintf(fd,"\n"); - - temp=onesub->end; - if (!subd->sub_uses_time) - temp = temp * 100 / sub_fps; - temp -= sub_delay * 100; - fprintf(fd,"\t\n" - "\t

 \n", temp * 10); - } - fprintf(fd, "\n" - "\n"); - fclose(fd); - mp_msg(MSGT_SUBREADER,MSGL_INFO,"SUB: Subtitles dumped in \'dumpsub.smi\'.\n"); -} - void sub_free( sub_data * subd ) { int i, j; diff --git a/sub/subreader.h b/sub/subreader.h index a6d0831413..db84fdd9a8 100644 --- a/sub/subreader.h +++ b/sub/subreader.h @@ -91,12 +91,6 @@ void subcp_close (void); /* for demux_ogg.c */ const char* guess_buffer_cp(unsigned char* buffer, int buflen, const char *preferred_language, const char *fallback); const char* guess_cp(struct stream *st, const char *preferred_language, const char *fallback); #endif -void list_sub_file(sub_data* subd); -void dump_srt(sub_data* subd, float fps); -void dump_mpsub(sub_data* subd, float fps); -void dump_microdvd(sub_data* subd, float fps); -void dump_jacosub(sub_data* subd, float fps); -void dump_sami(sub_data* subd, float fps); void sub_free( sub_data * subd ); struct MPContext; void find_sub(struct MPContext *mpctx, sub_data* subd,int key); diff --git a/sub/vobsub.c b/sub/vobsub.c index c8480c89bd..ac2793062a 100644 --- a/sub/vobsub.c +++ b/sub/vobsub.c @@ -963,22 +963,6 @@ int vobsub_get_packet(void *vobhandle, float pts, void** data, int* timestamp) return -1; } -int vobsub_get_next_packet(void *vobhandle, void** data, int* timestamp) -{ - vobsub_t *vob = vobhandle; - if (vob->spu_streams && 0 <= vobsub_id && (unsigned) vobsub_id < vob->spu_streams_size) { - packet_queue_t *queue = vob->spu_streams + vobsub_id; - if (queue->current_index < queue->packets_size) { - packet_t *pkt = queue->packets + queue->current_index; - ++queue->current_index; - *data = pkt->data; - *timestamp = pkt->pts100; - return pkt->size; - } - } - return -1; -} - void vobsub_seek(void * vobhandle, float pts) { vobsub_t * vob = vobhandle; @@ -994,228 +978,3 @@ void vobsub_seek(void * vobhandle, float pts) vobsub_queue_reseek(queue, seek_pts100); } } - -void vobsub_reset(void *vobhandle) -{ - vobsub_t *vob = vobhandle; - if (vob->spu_streams) { - unsigned int n = vob->spu_streams_size; - while (n-- > 0) - vob->spu_streams[n].current_index = 0; - } -} - -/********************************************************************** - * Vobsub output - **********************************************************************/ - -typedef struct { - FILE *fsub; - FILE *fidx; - unsigned int aid; -} vobsub_out_t; - -static void create_idx(vobsub_out_t *me, const unsigned int *palette, - unsigned int orig_width, unsigned int orig_height) -{ - int i; - fprintf(me->fidx, - "# VobSub index file, v7 (do not modify this line!)\n" - "#\n" - "# Generated by %s\n" - "# See for more information about MPlayer\n" - "# See for more information about Vobsub\n" - "#\n" - "size: %ux%u\n", - mplayer_version, orig_width, orig_height); - if (palette) { - fputs("palette:", me->fidx); - for (i = 0; i < 16; ++i) { - const double y = palette[i] >> 16 & 0xff, - u = (palette[i] >> 8 & 0xff) - 128.0, - v = (palette[i] & 0xff) - 128.0; - if (i) - putc(',', me->fidx); - fprintf(me->fidx, " %02x%02x%02x", - av_clip_uint8(y + 1.4022 * u), - av_clip_uint8(y - 0.3456 * u - 0.7145 * v), - av_clip_uint8(y + 1.7710 * v)); - } - putc('\n', me->fidx); - } - - fprintf(me->fidx, "# ON: displays only forced subtitles, OFF: shows everything\n" - "forced subs: OFF\n"); -} - -void *vobsub_out_open(const char *basename, const unsigned int *palette, - unsigned int orig_width, unsigned int orig_height, - const char *id, unsigned int index) -{ - vobsub_out_t *result = NULL; - char *filename; - filename = malloc(strlen(basename) + 5); - if (filename) { - result = malloc(sizeof(vobsub_out_t)); - if (result) { - result->aid = index; - strcpy(filename, basename); - strcat(filename, ".sub"); - result->fsub = fopen(filename, "ab"); - if (result->fsub == NULL) - perror("Error: vobsub_out_open subtitle file open failed"); - strcpy(filename, basename); - strcat(filename, ".idx"); - result->fidx = fopen(filename, "ab"); - if (result->fidx) { - if (ftell(result->fidx) == 0) { - create_idx(result, palette, orig_width, orig_height); - /* Make the selected language the default language */ - fprintf(result->fidx, "\n# Language index in use\nlangidx: %u\n", index); - } - fprintf(result->fidx, "\nid: %s, index: %u\n", id ? id : "xx", index); - /* So that we can check the file now */ - fflush(result->fidx); - } else - perror("Error: vobsub_out_open index file open failed"); - free(filename); - } - } - return result; -} - -void vobsub_out_close(void *me) -{ - vobsub_out_t *vob = me; - if (vob->fidx) - fclose(vob->fidx); - if (vob->fsub) - fclose(vob->fsub); - free(vob); -} - -void vobsub_out_output(void *me, const unsigned char *packet, - int len, double pts) -{ - static double last_pts; - static int last_pts_set = 0; - vobsub_out_t *vob = me; - if (vob->fsub) { - /* Windows' Vobsub require that every packet is exactly 2kB long */ - unsigned char buffer[2048]; - unsigned char *p; - int remain = 2048; - /* Do not output twice a line with the same timestamp, this - breaks Windows' Vobsub */ - if (vob->fidx && (!last_pts_set || last_pts != pts)) { - static unsigned int last_h = 9999, last_m = 9999, last_s = 9999, last_ms = 9999; - unsigned int h, m, ms; - double s; - s = pts; - h = s / 3600; - s -= h * 3600; - m = s / 60; - s -= m * 60; - ms = (s - (unsigned int) s) * 1000; - if (ms >= 1000) /* prevent overflows or bad float stuff */ - ms = 0; - if (h != last_h || m != last_m || (unsigned int) s != last_s || ms != last_ms) { - fprintf(vob->fidx, "timestamp: %02u:%02u:%02u:%03u, filepos: %09lx\n", - h, m, (unsigned int) s, ms, ftell(vob->fsub)); - last_h = h; - last_m = m; - last_s = (unsigned int) s; - last_ms = ms; - } - } - last_pts = pts; - last_pts_set = 1; - - /* Packet start code: Windows' Vobsub needs this */ - p = buffer; - *p++ = 0; /* 0x00 */ - *p++ = 0; - *p++ = 1; - *p++ = 0xba; - *p++ = 0x40; - memset(p, 0, 9); - p += 9; - { /* Packet */ - static unsigned char last_pts[5] = { 0, 0, 0, 0, 0}; - unsigned char now_pts[5]; - int pts_len, pad_len, datalen = len; - pts *= 90000; - now_pts[0] = 0x21 | (((unsigned long)pts >> 29) & 0x0e); - now_pts[1] = ((unsigned long)pts >> 22) & 0xff; - now_pts[2] = 0x01 | (((unsigned long)pts >> 14) & 0xfe); - now_pts[3] = ((unsigned long)pts >> 7) & 0xff; - now_pts[4] = 0x01 | (((unsigned long)pts << 1) & 0xfe); - pts_len = memcmp(last_pts, now_pts, sizeof(now_pts)) ? sizeof(now_pts) : 0; - memcpy(last_pts, now_pts, sizeof(now_pts)); - - datalen += 3; /* Version, PTS_flags, pts_len */ - datalen += pts_len; - datalen += 1; /* AID */ - pad_len = 2048 - (p - buffer) - 4 /* MPEG ID */ - 2 /* payload len */ - datalen; - /* XXX - Go figure what should go here! In any case the - packet has to be completely filled. If I can fill it - with padding (0x000001be) latter I'll do that. But if - there is only room for 6 bytes then I can not write a - padding packet. So I add some padding in the PTS - field. This looks like a dirty kludge. Oh well... */ - if (pad_len < 0) { - /* Packet is too big. Let's try omitting the PTS field */ - datalen -= pts_len; - pts_len = 0; - pad_len = 0; - } else if (pad_len > 6) - pad_len = 0; - datalen += pad_len; - - *p++ = 0; /* 0x0e */ - *p++ = 0; - *p++ = 1; - *p++ = 0xbd; - - *p++ = (datalen >> 8) & 0xff; /* length of payload */ - *p++ = datalen & 0xff; - *p++ = 0x80; /* System-2 (.VOB) stream */ - *p++ = pts_len ? 0x80 : 0x00; /* pts_flags */ - *p++ = pts_len + pad_len; - memcpy(p, now_pts, pts_len); - p += pts_len; - memset(p, 0, pad_len); - p += pad_len; - } - *p++ = 0x20 | vob->aid; /* aid */ - if (fwrite(buffer, p - buffer, 1, vob->fsub) != 1 - || fwrite(packet, len, 1, vob->fsub) != 1) - perror("ERROR: vobsub write failed"); - else - remain -= p - buffer + len; - - /* Padding */ - if (remain >= 6) { - p = buffer; - *p++ = 0x00; - *p++ = 0x00; - *p++ = 0x01; - *p++ = 0xbe; - *p++ = (remain - 6) >> 8; - *p++ = (remain - 6) & 0xff; - /* for better compression, blank this */ - memset(buffer + 6, 0, remain - (p - buffer)); - if (fwrite(buffer, remain, 1, vob->fsub) != 1) - perror("ERROR: vobsub padding write failed"); - } else if (remain > 0) { - /* I don't know what to output. But anyway the block - needs to be 2KB big */ - memset(buffer, 0, remain); - if (fwrite(buffer, remain, 1, vob->fsub) != 1) - perror("ERROR: vobsub blank padding write failed"); - } else if (remain < 0) - fprintf(stderr, - "\nERROR: wrong thing happened...\n" - " I wrote a %i data bytes spu packet and that's too long\n", len); - } -} diff --git a/sub/vobsub.h b/sub/vobsub.h index 3cef1347e5..0851e90c14 100644 --- a/sub/vobsub.h +++ b/sub/vobsub.h @@ -23,7 +23,6 @@ void *vobsub_open(const char *subname, const char *const ifo, const int force, v void vobsub_reset(void *vob); int vobsub_parse_ifo(void* this, const char *const name, unsigned int *palette, unsigned int *width, unsigned int *height, int force, int sid, char *langid); int vobsub_get_packet(void *vobhandle, float pts,void** data, int* timestamp); -int vobsub_get_next_packet(void *vobhandle, void** data, int* timestamp); void vobsub_close(void *this); unsigned int vobsub_get_indexes_count(void * /* vobhandle */); char *vobsub_get_id(void * /* vobhandle */, unsigned int /* index */); @@ -38,9 +37,6 @@ unsigned int vobsub_palette_to_yuv(unsigned int pal); /// Convert rgb value to yuv. unsigned int vobsub_rgb_to_yuv(unsigned int rgb); -void *vobsub_out_open(const char *basename, const unsigned int *palette, unsigned int orig_width, unsigned int orig_height, const char *id, unsigned int index); -void vobsub_out_output(void *me, const unsigned char *packet, int len, double pts); -void vobsub_out_close(void *me); int vobsub_set_from_lang(void *vobhandle, char **lang); void vobsub_seek(void * vobhandle, float pts); -- cgit v1.2.3