diff options
Diffstat (limited to 'sub/vobsub.c')
-rw-r--r-- | sub/vobsub.c | 241 |
1 files changed, 0 insertions, 241 deletions
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 <URL:http://www.mplayerhq.hu/> for more information about MPlayer\n" - "# See <URL:http://wiki.multimedia.cx/index.php?title=VOBsub> 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); - } -} |