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 --- Makefile | 3 - asxparser.c | 17 - cfg-mplayer.h | 2 - input/input.c | 24 -- input/input.h | 6 - libaf/af_format.h | 1 - libaf/filter.c | 90 ----- libaf/filter.h | 13 - libaf/format.c | 45 --- libmpcodecs/dec_video.c | 13 - libmpcodecs/dec_video.h | 1 - libmpcodecs/pullup.c | 15 - libmpcodecs/pullup.h | 1 - libmpcodecs/vfcap.h | 2 - libmpdemux/demuxer.c | 48 --- libmpdemux/demuxer.h | 2 - libmpdemux/mpeg_packetizer.c | 23 -- libmpdemux/mpeg_packetizer.h | 9 - libmpdemux/stheader.h | 2 - libmpdemux/video.c | 3 - libmpdemux/yuv4mpeg.c | 767 ------------------------------------------- libmpdemux/yuv4mpeg.h | 452 ------------------------- libmpdemux/yuv4mpeg_intern.h | 78 ----- libmpdemux/yuv4mpeg_ratio.c | 112 ------- libvo/aspect.c | 5 - libvo/aspect.h | 1 - libvo/osd.c | 14 - libvo/osd.h | 1 - libvo/osd_template.c | 24 -- libvo/video_out.h | 1 - m_struct.c | 36 -- m_struct.h | 16 - mplayer.c | 3 - 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 - subopt-helper.c | 8 - subopt-helper.h | 1 - 45 files changed, 2825 deletions(-) delete mode 100644 libmpdemux/yuv4mpeg.c delete mode 100644 libmpdemux/yuv4mpeg.h delete mode 100644 libmpdemux/yuv4mpeg_intern.h delete mode 100644 libmpdemux/yuv4mpeg_ratio.c delete mode 100644 sub/sub_cc.c delete mode 100644 sub/sub_cc.h diff --git a/Makefile b/Makefile index f3209ff528..af3fd72135 100644 --- a/Makefile +++ b/Makefile @@ -370,8 +370,6 @@ SRCS_COMMON = asxparser.c \ libmpdemux/mp_taglists.c \ libmpdemux/mpeg_packetizer.c \ libmpdemux/video.c \ - libmpdemux/yuv4mpeg.c \ - libmpdemux/yuv4mpeg_ratio.c \ libvo/osd.c \ libvo/eosd_packer.c \ osdep/numcores.c \ @@ -392,7 +390,6 @@ SRCS_COMMON = asxparser.c \ sub/find_subfiles.c \ sub/spudec.c \ sub/sub.c \ - sub/sub_cc.c \ sub/subassconvert.c \ sub/subreader.c \ sub/vobsub.c \ diff --git a/asxparser.c b/asxparser.c index 89cf7bd1a1..44236b8c18 100644 --- a/asxparser.c +++ b/asxparser.c @@ -68,9 +68,6 @@ asx_parse_attribs(ASX_Parser_t* parser,char* buffer,char*** _attribs); char* asx_get_attrib(const char* attrib,char** attribs); -int -asx_attrib_to_enum(const char* val,char** valid_vals); - #define asx_free_attribs(a) asx_list_free(&a,free) ////// List utils @@ -109,20 +106,6 @@ asx_get_attrib(const char* attrib,char** attribs) { return NULL; } -int -asx_attrib_to_enum(const char* val,char** valid_vals) { - char** ptr; - int r = 0; - - if(valid_vals == NULL || val == NULL) return -2; - for(ptr = valid_vals ; ptr[0] != NULL ; ptr++) { - if(strcasecmp(val,ptr[0]) == 0) return r; - r++; - } - - return -1; -} - #define asx_warning_attrib_required(p,e,a) mp_msg(MSGT_PLAYTREE,MSGL_WARN,"At line %d : element %s don't have the required attribute %s",p->line,e,a) #define asx_warning_body_parse_error(p,e) mp_msg(MSGT_PLAYTREE,MSGL_WARN,"At line %d : error while parsing %s body",p->line,e) diff --git a/cfg-mplayer.h b/cfg-mplayer.h index 06a93d6bdb..6deea83634 100644 --- a/cfg-mplayer.h +++ b/cfg-mplayer.h @@ -581,8 +581,6 @@ const m_option_t common_opts[] = { // specify IFO file for VOBSUB subtitle {"ifo", &spudec_ifo, CONF_TYPE_STRING, 0, 0, 0, NULL}, // enable Closed Captioning display - {"subcc", &subcc_enabled, CONF_TYPE_INT, CONF_RANGE, 0, 4, NULL}, - {"no-subcc", &subcc_enabled, CONF_TYPE_FLAG, 0, 1, 0, NULL}, {"overlapsub", &suboverlap_enabled, CONF_TYPE_FLAG, 0, 0, 2, NULL}, {"sub-bg-color", &sub_bg_color, CONF_TYPE_INT, CONF_RANGE, 0, 255, NULL}, {"sub-bg-alpha", &sub_bg_alpha, CONF_TYPE_INT, CONF_RANGE, 0, 255, NULL}, diff --git a/input/input.c b/input/input.c index 73e48436dd..e162572bed 100644 --- a/input/input.c +++ b/input/input.c @@ -859,30 +859,6 @@ int mp_input_add_key_fd(struct input_ctx *ictx, int fd, int select, return 1; } -int mp_input_parse_and_queue_cmds(struct input_ctx *ictx, const char *str) -{ - int cmd_num = 0; - - while (*str == '\n' || *str == '\r' || *str == ' ') - ++str; - while (*str) { - mp_cmd_t *cmd; - size_t len = strcspn(str, "\r\n"); - char *cmdbuf = talloc_size(NULL, len + 1); - av_strlcpy(cmdbuf, str, len + 1); - cmd = mp_input_parse_cmd(cmdbuf); - if (cmd) { - mp_input_queue_cmd(ictx, cmd); - ++cmd_num; - } - str += len; - while (*str == '\n' || *str == '\r' || *str == ' ') - ++str; - talloc_free(cmdbuf); - } - return cmd_num; -} - mp_cmd_t *mp_input_parse_cmd(char *str) { int i, l; diff --git a/input/input.h b/input/input.h index a4d9b8dab6..9092e2226d 100644 --- a/input/input.h +++ b/input/input.h @@ -252,12 +252,6 @@ struct mp_cmd *mp_input_get_cmd(struct input_ctx *ictx, int time, /* Parse text and return corresponding struct mp_cmd. */ struct mp_cmd *mp_input_parse_cmd(char *str); -/** - * Parse and queue commands separated by '\n'. - * Return number of commands queued. - */ -int mp_input_parse_and_queue_cmds(struct input_ctx *ictx, const char *str); - // After getting a command from mp_input_get_cmd you need to free it using this // function void mp_cmd_free(struct mp_cmd *cmd); diff --git a/libaf/af_format.h b/libaf/af_format.h index 751e97ef3a..e5e5e15b58 100644 --- a/libaf/af_format.h +++ b/libaf/af_format.h @@ -111,7 +111,6 @@ #define AF_FORMAT_IS_AC3(fmt) (((fmt) & AF_FORMAT_SPECIAL_MASK) == AF_FORMAT_AC3) -int af_str2fmt(const char *str); int af_str2fmt_short(const char *str); int af_fmt2bits(int format); int af_bits2fmt(int bits); diff --git a/libaf/filter.c b/libaf/filter.c index c5ab039130..b272125fd8 100644 --- a/libaf/filter.c +++ b/libaf/filter.c @@ -46,51 +46,6 @@ inline FLOAT_TYPE af_filter_fir(register unsigned int n, const FLOAT_TYPE* w, return y; } -/* C implementation of parallel FIR filter y(k)=w(k) * x(k) (where * denotes convolution) - - n number of filter taps, where mod(n,4)==0 - d number of filters - xi current index in xq - w filter taps k by n big - x input signal must be a circular buffers which are indexed backwards - y output buffer - s output buffer stride -*/ -FLOAT_TYPE* af_filter_pfir(unsigned int n, unsigned int d, unsigned int xi, - const FLOAT_TYPE** w, const FLOAT_TYPE** x, FLOAT_TYPE* y, - unsigned int s) -{ - register const FLOAT_TYPE* xt = *x + xi; - register const FLOAT_TYPE* wt = *w; - register int nt = 2*n; - while(d-- > 0){ - *y = af_filter_fir(n,wt,xt); - wt+=n; - xt+=nt; - y+=s; - } - return y; -} - -/* Add new data to circular queue designed to be used with a parallel - FIR filter, with d filters. xq is the circular queue, in pointing - at the new samples, xi current index in xq and n the length of the - filter. xq must be n*2 by k big, s is the index for in. -*/ -int af_filter_updatepq(unsigned int n, unsigned int d, unsigned int xi, - FLOAT_TYPE** xq, const FLOAT_TYPE* in, unsigned int s) -{ - register FLOAT_TYPE* txq = *xq + xi; - register int nt = n*2; - - while(d-- >0){ - *txq= *(txq+n) = *in; - txq+=nt; - in+=s; - } - return (++xi)&(n-1); -} - /****************************************************************************** * FIR filter design ******************************************************************************/ @@ -234,51 +189,6 @@ int af_filter_design_fir(unsigned int n, FLOAT_TYPE* w, const FLOAT_TYPE* fc, return 0; } -/* Design polyphase FIR filter from prototype filter - - n length of prototype filter - k number of polyphase components - w prototype filter taps - pw Parallel FIR filter - g Filter gain - flags FWD forward indexing - REW reverse indexing - ODD multiply every 2nd filter tap by -1 => HP filter - - returns 0 if OK, -1 if fail -*/ -int af_filter_design_pfir(unsigned int n, unsigned int k, const FLOAT_TYPE* w, - FLOAT_TYPE** pw, FLOAT_TYPE g, unsigned int flags) -{ - int l = (int)n/k; // Length of individual FIR filters - int i; // Counters - int j; - FLOAT_TYPE t; // g * w[i] - - // Sanity check - if(l<1 || k<1 || !w || !pw) - return -1; - - // Do the stuff - if(flags&REW){ - for(j=l-1;j>-1;j--){//Columns - for(i=0;i<(int)k;i++){//Rows - t=g * *w++; - pw[i][j]=t * ((flags & ODD) ? ((j & 1) ? -1 : 1) : 1); - } - } - } - else{ - for(j=0;jvfilter; - if (vf) { - int ret = vf->control(vf, VFCTRL_SET_PP_LEVEL, (void *) (&quality)); - if (ret == CONTROL_TRUE) - return; // success - } - const struct vd_functions *vd = sh_video->vd_driver; - if (vd) - vd->control(sh_video, VDCTRL_SET_PP_LEVEL, (void *) (&quality)); -} - int set_video_colors(sh_video_t *sh_video, const char *item, int value) { vf_instance_t *vf = sh_video->vfilter; diff --git a/libmpcodecs/dec_video.h b/libmpcodecs/dec_video.h index ab4b55bef7..878744396c 100644 --- a/libmpcodecs/dec_video.h +++ b/libmpcodecs/dec_video.h @@ -36,7 +36,6 @@ void *decode_video(sh_video_t *sh_video, struct demux_packet *packet, int filter_video(sh_video_t *sh_video, void *frame, double pts); int get_video_quality_max(sh_video_t *sh_video); -void set_video_quality(sh_video_t *sh_video, int quality); int get_video_colors(sh_video_t *sh_video, const char *item, int *value); int set_video_colors(sh_video_t *sh_video, const char *item, int value); diff --git a/libmpcodecs/pullup.c b/libmpcodecs/pullup.c index b70aa9b56f..bd25c187d6 100644 --- a/libmpcodecs/pullup.c +++ b/libmpcodecs/pullup.c @@ -442,21 +442,6 @@ void pullup_submit_field(struct pullup_context *c, struct pullup_buffer *b, c->head = c->head->next; } -void pullup_flush_fields(struct pullup_context *c) -{ - struct pullup_field *f; - - for (f = c->first; f && f != c->head; f = f->next) { - pullup_release_buffer(f->buffer, f->parity); - f->buffer = 0; - } - c->first = c->last = 0; -} - - - - - diff --git a/libmpcodecs/pullup.h b/libmpcodecs/pullup.h index 99aaa45dc2..0948737919 100644 --- a/libmpcodecs/pullup.h +++ b/libmpcodecs/pullup.h @@ -89,7 +89,6 @@ struct pullup_buffer *pullup_get_buffer(struct pullup_context *c, int parity); void pullup_submit_field(struct pullup_context *c, struct pullup_buffer *b, int parity, double pts); -void pullup_flush_fields(struct pullup_context *c); struct pullup_frame *pullup_get_frame(struct pullup_context *c); void pullup_pack_frame(struct pullup_context *c, struct pullup_frame *fr); diff --git a/libmpcodecs/vfcap.h b/libmpcodecs/vfcap.h index c9b943177d..eca9b5ef7f 100644 --- a/libmpcodecs/vfcap.h +++ b/libmpcodecs/vfcap.h @@ -26,8 +26,6 @@ #define VFCAP_CSP_SUPPORTED_BY_HW 0x2 // set if the driver/filter can draw OSD #define VFCAP_OSD 0x4 -// set if the driver/filter can handle compressed SPU stream -#define VFCAP_SPU 0x8 // scaling up/down by hardware, or software: #define VFCAP_HWSCALE_UP 0x10 #define VFCAP_HWSCALE_DOWN 0x20 diff --git a/libmpdemux/demuxer.c b/libmpdemux/demuxer.c index e77e32b942..d6e7584915 100644 --- a/libmpdemux/demuxer.c +++ b/libmpdemux/demuxer.c @@ -309,17 +309,6 @@ sh_sub_t *new_sh_sub_sid(demuxer_t *demuxer, int id, int sid) return demuxer->s_streams[id]; } -struct sh_sub *new_sh_sub_sid_lang(struct demuxer *demuxer, int id, int sid, - const char *lang) -{ - struct sh_sub *sh = new_sh_sub_sid(demuxer, id, sid); - if (lang && lang[0] && strcmp(lang, "und")) { - sh->lang = talloc_strdup(sh, lang); - mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SID_%d_LANG=%s\n", sid, lang); - } - return sh; -} - static void free_sh_sub(sh_sub_t *sh) { mp_msg(MSGT_DEMUXER, MSGL_DBG2, "DEMUXER: freeing sh_sub at %p\n", sh); @@ -681,43 +670,6 @@ int demux_read_data(demux_stream_t *ds, unsigned char *mem, int len) return bytes; } -/** - * \brief read data until the given 3-byte pattern is encountered, up to maxlen - * \param mem memory to read data into, may be NULL to discard data - * \param maxlen maximum number of bytes to read - * \param read number of bytes actually read - * \param pattern pattern to search for (lowest 8 bits are ignored) - * \return whether pattern was found - */ -int demux_pattern_3(demux_stream_t *ds, unsigned char *mem, int maxlen, - int *read, uint32_t pattern) -{ - register uint32_t head = 0xffffff00; - register uint32_t pat = pattern & 0xffffff00; - int total_len = 0; - do { - register unsigned char *ds_buf = &ds->buffer[ds->buffer_size]; - int len = ds->buffer_size - ds->buffer_pos; - register long pos = -len; - if (unlikely(pos >= 0)) { // buffer is empty - ds_fill_buffer(ds); - continue; - } - do { - head |= ds_buf[pos]; - head <<= 8; - } while (++pos && head != pat); - len += pos; - if (total_len + len > maxlen) - len = maxlen - total_len; - len = demux_read_data(ds, mem ? &mem[total_len] : NULL, len); - total_len += len; - } while ((head != pat || total_len < 3) && total_len < maxlen && !ds->eof); - if (read) - *read = total_len; - return total_len >= 3 && head == pat; -} - void ds_free_packs(demux_stream_t *ds) { demux_packet_t *dp = ds->first; diff --git a/libmpdemux/demuxer.h b/libmpdemux/demuxer.h index 0e208d666e..295c148ec0 100644 --- a/libmpdemux/demuxer.h +++ b/libmpdemux/demuxer.h @@ -317,8 +317,6 @@ static inline int ds_tell_pts(struct demux_stream *ds) } int demux_read_data(struct demux_stream *ds, unsigned char *mem, int len); -int demux_pattern_3(struct demux_stream *ds, unsigned char *mem, int maxlen, - int *read, uint32_t pattern); #define demux_peekc(ds) ( \ (likely(ds->buffer_posbuffer_size)) ? ds->buffer[ds->buffer_pos] \ diff --git a/libmpdemux/mpeg_packetizer.c b/libmpdemux/mpeg_packetizer.c index 0b4b1fa8d5..82e688df12 100644 --- a/libmpdemux/mpeg_packetizer.c +++ b/libmpdemux/mpeg_packetizer.c @@ -145,26 +145,3 @@ send_mpeg_pes_packet (unsigned char *data, int len, int id, uint64_t pts, { return send_mpeg_pes_packet_ll(data, len, id, pts, type, NULL, 0, 0, my_write); } - - -/* Send MPEG PS packet */ -int -send_mpeg_ps_packet(unsigned char *data, int len, int id, uint64_t pts, int type, - int my_write (const unsigned char *data, int len)) -{ - if(type == 2) - my_write (ps2_header, sizeof (ps2_header)); - else - my_write (ps1_header, sizeof (ps1_header)); - return send_mpeg_pes_packet (data, len, id, pts, type, my_write); -} - -/* Send MPEG 2 LPCM packet */ -int -send_mpeg_lpcm_packet(unsigned char* data, int len, - int id, uint64_t pts, int freq_id, - int my_write (const unsigned char *data, int len)) -{ - unsigned char header[7] = {0xA0, 0x07, 0x00, 0x04, 0x0C, 1 | (freq_id << 4), 0x80}; - return send_mpeg_pes_packet_ll(data, len, 0xBD, pts, 2, header, sizeof(header), 1, my_write); -} diff --git a/libmpdemux/mpeg_packetizer.h b/libmpdemux/mpeg_packetizer.h index 380b0b463b..ec9325bfad 100644 --- a/libmpdemux/mpeg_packetizer.h +++ b/libmpdemux/mpeg_packetizer.h @@ -34,13 +34,4 @@ int send_mpeg_pes_packet (unsigned char *data, int len, int id, uint64_t pts, int type, int my_write (const unsigned char *data, int len)); -/* Send MPEG PS packet */ -int send_mpeg_ps_packet (unsigned char *data, int len, int id, uint64_t pts, - int type,int my_write (const unsigned char *data, int len)); - -/* Send MPEG 2 LPCM packet */ -int send_mpeg_lpcm_packet (unsigned char *data, int len, - int id, uint64_t pts, int freq_id, - int my_write (const unsigned char *data, int len)); - #endif /* MPLAYER_MPEG_PACKETIZER_H */ diff --git a/libmpdemux/stheader.h b/libmpdemux/stheader.h index 6feefa9ef0..c93bcf8185 100644 --- a/libmpdemux/stheader.h +++ b/libmpdemux/stheader.h @@ -159,8 +159,6 @@ struct sh_audio *new_sh_audio_aid(struct demuxer *demuxer, int id, int aid); struct sh_video *new_sh_video_vid(struct demuxer *demuxer, int id, int vid); #define new_sh_sub(d, i) new_sh_sub_sid(d, i, i) struct sh_sub *new_sh_sub_sid(struct demuxer *demuxer, int id, int sid); -struct sh_sub *new_sh_sub_sid_lang(struct demuxer *demuxer, int id, int sid, - const char *lang); void free_sh_audio(struct demuxer *demuxer, int id); void free_sh_video(struct sh_video *sh); diff --git a/libmpdemux/video.c b/libmpdemux/video.c index 7daef29360..27e924f883 100644 --- a/libmpdemux/video.c +++ b/libmpdemux/video.c @@ -34,9 +34,6 @@ #endif #include "stheader.h" -/* sub_cc (closed captions)*/ -#include "sub/sub_cc.h" - /* biCompression constant */ #define BI_RGB 0L diff --git a/libmpdemux/yuv4mpeg.c b/libmpdemux/yuv4mpeg.c deleted file mode 100644 index 1606faa41b..0000000000 --- a/libmpdemux/yuv4mpeg.c +++ /dev/null @@ -1,767 +0,0 @@ -/* - * yuv4mpeg.c: Functions for reading and writing "new" YUV4MPEG streams - * - * Copyright (C) 2001 Matthew J. Marjanovic - * - * This file is part of the MJPEG Tools package (mjpeg.sourceforge.net). - * Ported to mplayer by Rik Snel - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#include "config.h" - -#include -#include -#include -#include -#include "yuv4mpeg.h" -#include "yuv4mpeg_intern.h" -#include "mp_msg.h" -#include "libavutil/attributes.h" - -static int _y4mparam_allow_unknown_tags = 1; /* default is forgiveness */ - -static void *(*_y4m_alloc)(size_t bytes) = malloc; -static void (*_y4m_free)(void *ptr) = free; - -int y4m_allow_unknown_tags(int yn) { - int old = _y4mparam_allow_unknown_tags; - if (yn >= 0) _y4mparam_allow_unknown_tags = (yn) ? 1 : 0; - return old; -} - - - -/************************************************************************* - * - * Convenience functions for fd read/write - * - * - guaranteed to transfer entire payload (or fail) - * - returns: - * 0 on complete success - * +(# of remaining bytes) on eof (for y4m_read) - * -(# of rem. bytes) on error (and ERRNO should be set) - * - *************************************************************************/ - - -ssize_t y4m_read(stream_t *s, char *buf, size_t len) -{ - ssize_t n; - - while (len > 0) { - n = stream_read(s, buf, len); - if (n <= 0) { - /* return amount left to read */ - if (n == 0) - return len; /* n == 0 --> eof */ - else - return -len; /* n < 0 --> error */ - } - buf += n; - len -= n; - } - return 0; -} - - -#if 0 /* not needed */ -ssize_t y4m_write(int fd, char *buf, size_t len) -{ - ssize_t n; - - while (len > 0) { - n = write(fd, buf, len); - if (n < 0) return -len; /* return amount left to write */ - buf += n; - len -= n; - } - return 0; -} -#endif - - -/************************************************************************* - * - * "Extra tags" handling - * - *************************************************************************/ - - -static char *y4m_new_xtag(void) -{ - return _y4m_alloc(Y4M_MAX_XTAG_SIZE); -} - - -void y4m_init_xtag_list(y4m_xtag_list_t *xtags) -{ - int i; - xtags->count = 0; - for (i = 0; i < Y4M_MAX_XTAGS; i++) { - xtags->tags[i] = NULL; - } -} - - -void y4m_fini_xtag_list(y4m_xtag_list_t *xtags) -{ - int i; - for (i = 0; i < Y4M_MAX_XTAGS; i++) { - if (xtags->tags[i] != NULL) { - _y4m_free(xtags->tags[i]); - xtags->tags[i] = NULL; - } - } - xtags->count = 0; -} - - -void y4m_copy_xtag_list(y4m_xtag_list_t *dest, const y4m_xtag_list_t *src) -{ - int i; - for (i = 0; i < src->count; i++) { - if (dest->tags[i] == NULL) - dest->tags[i] = y4m_new_xtag(); - strncpy(dest->tags[i], src->tags[i], Y4M_MAX_XTAG_SIZE); - } - dest->count = src->count; -} - - - -#if 0 -static int y4m_snprint_xtags(char *s, int maxn, y4m_xtag_list_t *xtags) -{ - int i, room; - - for (i = 0, room = maxn - 1; i < xtags->count; i++) { - int n = snprintf(s, room + 1, " %s", xtags->tags[i]); - if ((n < 0) || (n > room)) return Y4M_ERR_HEADER; - s += n; - room -= n; - } - s[0] = '\n'; /* finish off header with newline */ - s[1] = '\0'; /* ...and end-of-string */ - return Y4M_OK; -} -#endif - - -int y4m_xtag_count(const y4m_xtag_list_t *xtags) -{ - return xtags->count; -} - - -const char *y4m_xtag_get(const y4m_xtag_list_t *xtags, int n) -{ - if (n >= xtags->count) - return NULL; - else - return xtags->tags[n]; -} - - -int y4m_xtag_add(y4m_xtag_list_t *xtags, const char *tag) -{ - if (xtags->count >= Y4M_MAX_XTAGS) return Y4M_ERR_XXTAGS; - if (xtags->tags[xtags->count] == NULL) { - xtags->tags[xtags->count] = y4m_new_xtag(); - } - strncpy(xtags->tags[xtags->count], tag, Y4M_MAX_XTAG_SIZE); - (xtags->count)++; - return Y4M_OK; -} - - -int y4m_xtag_remove(y4m_xtag_list_t *xtags, int n) -{ - int i; - char *q; - - if ((n < 0) || (n >= xtags->count)) return Y4M_ERR_RANGE; - q = xtags->tags[n]; - for (i = n; i < (xtags->count - 1); i++) - xtags->tags[i] = xtags->tags[i+1]; - xtags->tags[i] = q; - (xtags->count)--; - return Y4M_OK; -} - - -int y4m_xtag_clearlist(y4m_xtag_list_t *xtags) -{ - xtags->count = 0; - return Y4M_OK; -} - - -int y4m_xtag_addlist(y4m_xtag_list_t *dest, const y4m_xtag_list_t *src) -{ - int i, j; - - if ((dest->count + src->count) > Y4M_MAX_XTAGS) return Y4M_ERR_XXTAGS; - for (i = dest->count, j = 0; - j < src->count; - i++, j++) { - if (dest->tags[i] == NULL) - dest->tags[i] = y4m_new_xtag(); - strncpy(dest->tags[i], src->tags[i], Y4M_MAX_XTAG_SIZE); - } - dest->count += src->count; - return Y4M_OK; -} - - -/************************************************************************* - * - * Creators/destructors for y4m_*_info_t structures - * - *************************************************************************/ - - -void y4m_init_stream_info(y4m_stream_info_t *info) -{ - if (info == NULL) return; - /* initialize info */ - info->width = Y4M_UNKNOWN; - info->height = Y4M_UNKNOWN; - info->interlace = Y4M_UNKNOWN; - info->framerate = y4m_fps_UNKNOWN; - info->sampleaspect = y4m_sar_UNKNOWN; - y4m_init_xtag_list(&(info->x_tags)); -} - - -void y4m_copy_stream_info(y4m_stream_info_t *dest, y4m_stream_info_t *src) -{ - if ((dest == NULL) || (src == NULL)) return; - /* copy info */ - dest->width = src->width; - dest->height = src->height; - dest->interlace = src->interlace; - dest->framerate = src->framerate; - dest->sampleaspect = src->sampleaspect; - y4m_copy_xtag_list(&(dest->x_tags), &(src->x_tags)); -} - - -void y4m_fini_stream_info(y4m_stream_info_t *info) -{ - if (info == NULL) return; - y4m_fini_xtag_list(&(info->x_tags)); -} - - -void y4m_si_set_width(y4m_stream_info_t *si, int width) -{ - si->width = width; - si->framelength = (si->height * si->width) * 3 / 2; -} - -int y4m_si_get_width(y4m_stream_info_t *si) -{ return si->width; } - -void y4m_si_set_height(y4m_stream_info_t *si, int height) -{ - si->height = height; - si->framelength = (si->height * si->width) * 3 / 2; -} - -int y4m_si_get_height(y4m_stream_info_t *si) -{ return si->height; } - -void y4m_si_set_interlace(y4m_stream_info_t *si, int interlace) -{ si->interlace = interlace; } - -int y4m_si_get_interlace(y4m_stream_info_t *si) -{ return si->interlace; } - -void y4m_si_set_framerate(y4m_stream_info_t *si, y4m_ratio_t framerate) -{ si->framerate = framerate; } - -y4m_ratio_t y4m_si_get_framerate(y4m_stream_info_t *si) -{ return si->framerate; } - -void y4m_si_set_sampleaspect(y4m_stream_info_t *si, y4m_ratio_t sar) -{ si->sampleaspect = sar; } - -y4m_ratio_t y4m_si_get_sampleaspect(y4m_stream_info_t *si) -{ return si->sampleaspect; } - -int y4m_si_get_framelength(y4m_stream_info_t *si) -{ return si->framelength; } - -y4m_xtag_list_t *y4m_si_xtags(y4m_stream_info_t *si) -{ return &(si->x_tags); } - - - -void y4m_init_frame_info(y4m_frame_info_t *info) -{ - if (info == NULL) return; - /* initialize info */ - y4m_init_xtag_list(&(info->x_tags)); -} - - -void y4m_copy_frame_info(y4m_frame_info_t *dest, y4m_frame_info_t *src) -{ - if ((dest == NULL) || (src == NULL)) return; - /* copy info */ - y4m_copy_xtag_list(&(dest->x_tags), &(src->x_tags)); -} - - -void y4m_fini_frame_info(y4m_frame_info_t *info) -{ - if (info == NULL) return; - y4m_fini_xtag_list(&(info->x_tags)); -} - - - -/************************************************************************* - * - * Tag parsing - * - *************************************************************************/ - -int y4m_parse_stream_tags(char *s, y4m_stream_info_t *i) -{ - char *token, *value; - char tag; - int err; - - /* parse fields */ - for (token = strtok(s, Y4M_DELIM); - token != NULL; - token = strtok(NULL, Y4M_DELIM)) { - if (token[0] == '\0') continue; /* skip empty strings */ - tag = token[0]; - value = token + 1; - switch (tag) { - case 'W': /* width */ - i->width = atoi(value); - if (i->width <= 0) return Y4M_ERR_RANGE; - break; - case 'H': /* height */ - i->height = atoi(value); - if (i->height <= 0) return Y4M_ERR_RANGE; - break; - case 'F': /* frame rate (fps) */ - if ((err = y4m_parse_ratio(&(i->framerate), value)) != Y4M_OK) - return err; - if (i->framerate.n < 0) return Y4M_ERR_RANGE; - break; - case 'I': /* interlacing */ - switch (value[0]) { - case 'p': i->interlace = Y4M_ILACE_NONE; break; - case 't': i->interlace = Y4M_ILACE_TOP_FIRST; break; - case 'b': i->interlace = Y4M_ILACE_BOTTOM_FIRST; break; - case '?': - default: - i->interlace = Y4M_UNKNOWN; break; - } - break; - case 'A': /* sample (pixel) aspect ratio */ - if ((err = y4m_parse_ratio(&(i->sampleaspect), value)) != Y4M_OK) - return err; - if (i->sampleaspect.n < 0) return Y4M_ERR_RANGE; - break; - case 'X': /* 'X' meta-tag */ - if ((err = y4m_xtag_add(&(i->x_tags), token)) != Y4M_OK) return err; - break; - default: - /* possible error on unknown options */ - if (_y4mparam_allow_unknown_tags) { - /* unknown tags ok: store in xtag list and warn... */ - if ((err = y4m_xtag_add(&(i->x_tags), token)) != Y4M_OK) return err; - mp_msg(MSGT_DEMUX, MSGL_WARN, "Unknown stream tag encountered: '%s'\n", token); - } else { - /* unknown tags are *not* ok */ - return Y4M_ERR_BADTAG; - } - break; - } - } - /* Error checking... width and height must be known since we can't - * parse without them - */ - if( i->width == Y4M_UNKNOWN || i->height == Y4M_UNKNOWN ) - return Y4M_ERR_HEADER; - /* ta da! done. */ - return Y4M_OK; -} - - - -static int y4m_parse_frame_tags(char *s, y4m_frame_info_t *i) -{ - char *token, *value av_unused; - char tag; - int err; - - /* parse fields */ - for (token = strtok(s, Y4M_DELIM); - token != NULL; - token = strtok(NULL, Y4M_DELIM)) { - if (token[0] == '\0') continue; /* skip empty strings */ - tag = token[0]; - value = token + 1; - switch (tag) { - case 'X': /* 'X' meta-tag */ - if ((err = y4m_xtag_add(&(i->x_tags), token)) != Y4M_OK) return err; - break; - default: - /* possible error on unknown options */ - if (_y4mparam_allow_unknown_tags) { - /* unknown tags ok: store in xtag list and warn... */ - if ((err = y4m_xtag_add(&(i->x_tags), token)) != Y4M_OK) return err; - mp_msg(MSGT_DEMUX, MSGL_WARN, "Unknown frame tag encountered: '%s'\n", token); - } else { - /* unknown tags are *not* ok */ - return Y4M_ERR_BADTAG; - } - break; - } - } - /* ta da! done. */ - return Y4M_OK; -} - - - - - -/************************************************************************* - * - * Read/Write stream header - * - *************************************************************************/ - - -int y4m_read_stream_header(stream_t *s, y4m_stream_info_t *i) -{ - char line[Y4M_LINE_MAX]; - char *p; - int n; - int err; - - /* read the header line */ - for (n = 0, p = line; n < Y4M_LINE_MAX; n++, p++) { - if (y4m_read(s, p, 1)) - return Y4M_ERR_SYSTEM; - if (*p == '\n') { - *p = '\0'; /* Replace linefeed by end of string */ - break; - } - } - if (n >= Y4M_LINE_MAX) - return Y4M_ERR_HEADER; - /* look for keyword in header */ - if (strncmp(line, Y4M_MAGIC, strlen(Y4M_MAGIC))) - return Y4M_ERR_MAGIC; - if ((err = y4m_parse_stream_tags(line + strlen(Y4M_MAGIC), i)) != Y4M_OK) - return err; - - i->framelength = (i->height * i->width) * 3 / 2; - return Y4M_OK; -} - - -#if 0 -int y4m_write_stream_header(int fd, y4m_stream_info_t *i) -{ - char s[Y4M_LINE_MAX+1]; - int n; - int err; - - y4m_ratio_reduce(&(i->framerate)); - y4m_ratio_reduce(&(i->sampleaspect)); - n = snprintf(s, sizeof(s), "%s W%d H%d F%d:%d I%s A%d:%d", - Y4M_MAGIC, - i->width, - i->height, - i->framerate.n, i->framerate.d, - (i->interlace == Y4M_ILACE_NONE) ? "p" : - (i->interlace == Y4M_ILACE_TOP_FIRST) ? "t" : - (i->interlace == Y4M_ILACE_BOTTOM_FIRST) ? "b" : "?", - i->sampleaspect.n, i->sampleaspect.d); - if ((n < 0) || (n > Y4M_LINE_MAX)) return Y4M_ERR_HEADER; - if ((err = y4m_snprint_xtags(s + n, sizeof(s) - n - 1, &(i->x_tags))) - != Y4M_OK) - return err; - /* non-zero on error */ - return (y4m_write(fd, s, strlen(s)) ? Y4M_ERR_SYSTEM : Y4M_OK); -} -#endif - - - - -/************************************************************************* - * - * Read/Write frame header - * - *************************************************************************/ - -int y4m_read_frame_header(stream_t *s, y4m_frame_info_t *i) -{ - char line[Y4M_LINE_MAX]; - char *p; - int n; - ssize_t remain; - - /* This is more clever than read_stream_header... - Try to read "FRAME\n" all at once, and don't try to parse - if nothing else is there... - */ - remain = y4m_read(s, line, sizeof(Y4M_FRAME_MAGIC)); - if (remain != 0) - { - /* A clean EOF should end exactly at a frame-boundary */ - if( remain == sizeof(Y4M_FRAME_MAGIC) ) - return Y4M_ERR_EOF; - else - return Y4M_ERR_SYSTEM; - } - if (strncmp(line, Y4M_FRAME_MAGIC, sizeof(Y4M_FRAME_MAGIC)-1)) - return Y4M_ERR_MAGIC; - if (line[sizeof(Y4M_FRAME_MAGIC)-1] == '\n') - return Y4M_OK; /* done -- no tags: that was the end-of-line. */ - - if (line[sizeof(Y4M_FRAME_MAGIC)-1] != Y4M_DELIM[0]) { - return Y4M_ERR_MAGIC; /* wasn't a space -- what was it? */ - } - - /* proceed to get the tags... (overwrite the magic) */ - for (n = 0, p = line; n < Y4M_LINE_MAX; n++, p++) { - if (y4m_read(s, p, 1)) - return Y4M_ERR_SYSTEM; - if (*p == '\n') { - *p = '\0'; /* Replace linefeed by end of string */ - break; - } - } - if (n >= Y4M_LINE_MAX) return Y4M_ERR_HEADER; - /* non-zero on error */ - return y4m_parse_frame_tags(line, i); -} - - -#if 0 -int y4m_write_frame_header(int fd, y4m_frame_info_t *i) -{ - char s[Y4M_LINE_MAX+1]; - int n; - int err; - - n = snprintf(s, sizeof(s), "%s", Y4M_FRAME_MAGIC); - if ((n < 0) || (n > Y4M_LINE_MAX)) return Y4M_ERR_HEADER; - if ((err = y4m_snprint_xtags(s + n, sizeof(s) - n - 1, &(i->x_tags))) - != Y4M_OK) - return err; - /* non-zero on error */ - return (y4m_write(fd, s, strlen(s)) ? Y4M_ERR_SYSTEM : Y4M_OK); -} -#endif - - - -/************************************************************************* - * - * Read/Write entire frame - * - *************************************************************************/ - -int y4m_read_frame(stream_t *s, y4m_stream_info_t *si, - y4m_frame_info_t *fi, unsigned char *yuv[3]) -{ - int err; - int w = si->width; - int h = si->height; - - /* Read frame header */ - if ((err = y4m_read_frame_header(s, fi)) != Y4M_OK) return err; - /* Read luminance scanlines */ - if (y4m_read(s, yuv[0], w*h)) return Y4M_ERR_SYSTEM; - /* Read chrominance scanlines */ - if (y4m_read(s, yuv[1], w*h/4)) return Y4M_ERR_SYSTEM; - if (y4m_read(s, yuv[2], w*h/4)) return Y4M_ERR_SYSTEM; - - return Y4M_OK; -} - - - -#if 0 -int y4m_write_frame(int fd, y4m_stream_info_t *si, - y4m_frame_info_t *fi, unsigned char *yuv[3]) -{ - int err; - int w = si->width; - int h = si->height; - - /* Write frame header */ - if ((err = y4m_write_frame_header(fd, fi)) != Y4M_OK) return err; - /* Write luminance,chrominance scanlines */ - if (y4m_write(fd, yuv[0], w*h) || - y4m_write(fd, yuv[1], w*h/4) || - y4m_write(fd, yuv[2], w*h/4)) - return Y4M_ERR_SYSTEM; - return Y4M_OK; -} -#endif - - -/************************************************************************* - * - * Read/Write entire frame, (de)interleaved (to)from two separate fields - * - *************************************************************************/ - -#if 0 -int y4m_read_fields(int fd, y4m_stream_info_t *si, y4m_frame_info_t *fi, - unsigned char *upper_field[3], - unsigned char *lower_field[3]) -{ - int i, y, err; - int width = si->width; - int height = si->height; - - /* Read frame header */ - if ((err = y4m_read_frame_header(fd, fi)) != Y4M_OK) return err; - /* Read Y', Cb, and Cr planes */ - for (i = 0; i < 3; i++) { - unsigned char *srctop = upper_field[i]; - unsigned char *srcbot = lower_field[i]; - /* alternately write one line from each */ - for (y = 0; y < height; y += 2) { - if (y4m_read(fd, srctop, width)) return Y4M_ERR_SYSTEM; - srctop += width; - if (y4m_read(fd, srcbot, width)) return Y4M_ERR_SYSTEM; - srcbot += width; - } - /* for chroma, width/height are half as big */ - if (i == 0) { - width /= 2; - height /= 2; - } - } - return Y4M_OK; -} - - - -int y4m_write_fields(int fd, y4m_stream_info_t *si, y4m_frame_info_t *fi, - unsigned char *upper_field[3], - unsigned char *lower_field[3]) -{ - int i, y, err; - int width = si->width; - int height = si->height; - - /* Write frame header */ - if ((err = y4m_write_frame_header(fd, fi)) != Y4M_OK) return err; - /* Write Y', Cb, and Cr planes */ - for (i = 0; i < 3; i++) { - unsigned char *srctop = upper_field[i]; - unsigned char *srcbot = lower_field[i]; - /* alternately write one line from each */ - for (y = 0; y < height; y += 2) { - if (y4m_write(fd, srctop, width)) return Y4M_ERR_SYSTEM; - srctop += width; - if (y4m_write(fd, srcbot, width)) return Y4M_ERR_SYSTEM; - srcbot += width; - } - /* for chroma, width/height are half as big */ - if (i == 0) { - width /= 2; - height /= 2; - } - } - return Y4M_OK; -} -#endif - - -/************************************************************************* - * - * Handy logging of stream info - * - *************************************************************************/ - -void y4m_log_stream_info(const char *prefix, y4m_stream_info_t *i) -{ - char s[256]; - - snprintf(s, sizeof(s), " frame size: "); - if (i->width == Y4M_UNKNOWN) - snprintf(s+strlen(s), sizeof(s)-strlen(s), "(?)x"); - else - snprintf(s+strlen(s), sizeof(s)-strlen(s), "%dx", i->width); - if (i->height == Y4M_UNKNOWN) - snprintf(s+strlen(s), sizeof(s)-strlen(s), "(?) pixels "); - else - snprintf(s+strlen(s), sizeof(s)-strlen(s), "%d pixels ", i->height); - if (i->framelength == Y4M_UNKNOWN) - snprintf(s+strlen(s), sizeof(s)-strlen(s), "(? bytes)"); - else - snprintf(s+strlen(s), sizeof(s)-strlen(s), "(%d bytes)", i->framelength); - mp_msg(MSGT_DEMUX, MSGL_V, "%s%s\n", prefix, s); - if ((i->framerate.n == 0) && (i->framerate.d == 0)) - mp_msg(MSGT_DEMUX, MSGL_V, "%s frame rate: ??? fps\n", prefix); - else - mp_msg(MSGT_DEMUX, MSGL_V, "%s frame rate: %d/%d fps (~%f)\n", prefix, - i->framerate.n, i->framerate.d, - (double) i->framerate.n / (double) i->framerate.d); - mp_msg(MSGT_DEMUX, MSGL_V, "%s interlace: %s\n", prefix, - (i->interlace == Y4M_ILACE_NONE) ? "none/progressive" : - (i->interlace == Y4M_ILACE_TOP_FIRST) ? "top-field-first" : - (i->interlace == Y4M_ILACE_BOTTOM_FIRST) ? "bottom-field-first" : - "anyone's guess"); - if ((i->sampleaspect.n == 0) && (i->sampleaspect.d == 0)) - mp_msg(MSGT_DEMUX, MSGL_V, "%ssample aspect ratio: ?:?\n", prefix); - else - mp_msg(MSGT_DEMUX, MSGL_V, "%ssample aspect ratio: %d:%d\n", prefix, - i->sampleaspect.n, i->sampleaspect.d); -} - - -/************************************************************************* - * - * Convert error code to string - * - *************************************************************************/ - -const char *y4m_strerr(int err) -{ - switch (err) { - case Y4M_OK: return "no error"; - case Y4M_ERR_RANGE: return "parameter out of range"; - case Y4M_ERR_SYSTEM: return "stream ended unexpectedly (failed read/write)"; - case Y4M_ERR_HEADER: return "bad stream or frame header"; - case Y4M_ERR_BADTAG: return "unknown header tag"; - case Y4M_ERR_MAGIC: return "bad header magic"; - case Y4M_ERR_XXTAGS: return "too many xtags"; - case Y4M_ERR_EOF: return "end-of-file"; - default: - return "unknown error code"; - } -} diff --git a/libmpdemux/yuv4mpeg.h b/libmpdemux/yuv4mpeg.h deleted file mode 100644 index 6e97662111..0000000000 --- a/libmpdemux/yuv4mpeg.h +++ /dev/null @@ -1,452 +0,0 @@ -/* - * yuv4mpeg.h: Functions for reading and writing "new" YUV4MPEG2 streams. - * - * Stream format is described at the end of this file. - * - * - * Copyright (C) 2001 Matthew J. Marjanovic - * - * This file is part of the MJPEG Tools package (mjpeg.sourceforge.net). - * Ported to mplayer by Rik Snel - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef MPLAYER_YUV4MPEG_H -#define MPLAYER_YUV4MPEG_H - -#include -//#include "mp_msg.h" -#include "stream/stream.h" - - - -/************************************************************************ - * error codes returned by y4m_* functions - ************************************************************************/ -#define Y4M_OK 0 -#define Y4M_ERR_RANGE 1 -#define Y4M_ERR_SYSTEM 2 -#define Y4M_ERR_HEADER 3 -#define Y4M_ERR_BADTAG 4 -#define Y4M_ERR_MAGIC 5 -#define Y4M_ERR_EOF 6 -#define Y4M_ERR_XXTAGS 7 - - -/* generic 'unknown' value for integer parameters (e.g. interlace, height) */ -#define Y4M_UNKNOWN -1 - - - -/************************************************************************ - * 'ratio' datatype, for rational numbers - * (see 'ratio' functions down below) - ************************************************************************/ -typedef struct y4m_ratio { - int n; /* numerator */ - int d; /* denominator */ -} y4m_ratio_t; - - -/************************************************************************ - * useful standard framerates (as ratios) - ************************************************************************/ -extern const y4m_ratio_t y4m_fps_UNKNOWN; -extern const y4m_ratio_t y4m_fps_NTSC_FILM; /* 24000/1001 film (in NTSC) */ -extern const y4m_ratio_t y4m_fps_FILM; /* 24fps film */ -extern const y4m_ratio_t y4m_fps_PAL; /* 25fps PAL */ -extern const y4m_ratio_t y4m_fps_NTSC; /* 30000/1001 NTSC */ -extern const y4m_ratio_t y4m_fps_30; /* 30fps */ -extern const y4m_ratio_t y4m_fps_PAL_FIELD; /* 50fps PAL field rate */ -extern const y4m_ratio_t y4m_fps_NTSC_FIELD; /* 60000/1001 NTSC field rate */ -extern const y4m_ratio_t y4m_fps_60; /* 60fps */ - -/************************************************************************ - * useful standard sample (pixel) aspect ratios - ************************************************************************/ -extern const y4m_ratio_t y4m_sar_UNKNOWN; -extern const y4m_ratio_t y4m_sar_SQUARE; /* square pixels */ -extern const y4m_ratio_t y4m_sar_NTSC_CCIR601; /* 525-line (NTSC) Rec.601 */ -extern const y4m_ratio_t y4m_sar_NTSC_16_9; /* 16:9 NTSC/Rec.601 */ -extern const y4m_ratio_t y4m_sar_NTSC_SVCD_4_3; /* NTSC SVCD 4:3 */ -extern const y4m_ratio_t y4m_sar_NTSC_SVCD_16_9;/* NTSC SVCD 16:9 */ -extern const y4m_ratio_t y4m_sar_PAL_CCIR601; /* 625-line (PAL) Rec.601 */ -extern const y4m_ratio_t y4m_sar_PAL_16_9; /* 16:9 PAL/Rec.601 */ -extern const y4m_ratio_t y4m_sar_PAL_SVCD_4_3; /* PAL SVCD 4:3 */ -extern const y4m_ratio_t y4m_sar_PAL_SVCD_16_9; /* PAL SVCD 16:9 */ - - -/************************************************************************ - * 'xtag_list' --- list of unparsed and/or meta/X header tags - * - * Do not touch this structure directly! - * - * Use the y4m_xtag_*() functions (see below). - * You must initialize/finalize this structure before/after use. - ************************************************************************/ -#define Y4M_MAX_XTAGS 32 /* maximum number of xtags in list */ -#define Y4M_MAX_XTAG_SIZE 32 /* max length of an xtag (including 'X') */ -typedef struct y4m_xtag_list { - int count; - char *tags[Y4M_MAX_XTAGS]; -} y4m_xtag_list_t; - - - -/************************************************************************ - * 'stream_info' --- stream header information - * - * Do not touch this structure directly! - * - * Use the y4m_si_*() functions (see below). - * You must initialize/finalize this structure before/after use. - ************************************************************************/ -typedef struct y4m_stream_info { - /* values from header */ - int width; - int height; - int interlace; /* see Y4M_ILACE_* definitions below */ - y4m_ratio_t framerate; /* frames-per-second; 0:0 == unknown */ - y4m_ratio_t sampleaspect; /* pixel width/height; 0:0 == unknown */ - /* computed/derivative values */ - int framelength; /* bytes of data per frame (not including header) */ - /* mystical X tags */ - y4m_xtag_list_t x_tags; -} y4m_stream_info_t; - -/* possible options for the interlace parameter */ -#define Y4M_ILACE_NONE 0 /* non-interlaced, progressive frame */ -#define Y4M_ILACE_TOP_FIRST 1 /* interlaced, top-field first */ -#define Y4M_ILACE_BOTTOM_FIRST 2 /* interlaced, bottom-field first */ - - -/************************************************************************ - * 'frame_info' --- frame header information - * - * Do not touch this structure directly! - * - * Use the y4m_fi_*() functions (see below). - * You must initialize/finalize this structure before/after use. - ************************************************************************/ -typedef struct y4m_frame_info { - /* mystical X tags */ - y4m_xtag_list_t x_tags; -} y4m_frame_info_t; - - - -#ifdef __cplusplus -extern "C" { -#else -#endif - - -/************************************************************************ - * 'ratio' functions - ************************************************************************/ - -/* 'normalize' a ratio (remove common factors) */ -void y4m_ratio_reduce(y4m_ratio_t *r); - -/* parse "nnn:ddd" into a ratio (returns Y4M_OK or Y4M_ERR_RANGE) */ -int y4m_parse_ratio(y4m_ratio_t *r, const char *s); - -/* quick test of two ratios for equality (i.e. identical components) */ -#define Y4M_RATIO_EQL(a,b) ( ((a).n == (b).n) && ((a).d == (b).d) ) - -/* quick conversion of a ratio to a double (no divide-by-zero check!) */ -#define Y4M_RATIO_DBL(r) ((double)(r).n / (double)(r).d) - - - -/************************************************************************ - * 'xtag' functions - * - * o Before using an xtag_list (but after the structure/memory has been - * allocated), you must initialize it via y4m_init_xtag_list(). - * o After using an xtag_list (but before the structure is released), - * call y4m_fini_xtag_list() to free internal memory. - * - ************************************************************************/ - -/* initialize an xtag_list structure */ -void y4m_init_xtag_list(y4m_xtag_list_t *xtags); - -/* finalize an xtag_list structure */ -void y4m_fini_xtag_list(y4m_xtag_list_t *xtags); - -/* make one xtag_list into a copy of another */ -void y4m_copy_xtag_list(y4m_xtag_list_t *dest, const y4m_xtag_list_t *src); - -/* return number of tags in an xtag_list */ -int y4m_xtag_count(const y4m_xtag_list_t *xtags); - -/* access n'th tag in an xtag_list */ -const char *y4m_xtag_get(const y4m_xtag_list_t *xtags, int n); - -/* append a new tag to an xtag_list - returns: Y4M_OK - success - Y4M_ERR_XXTAGS - list is already full */ -int y4m_xtag_add(y4m_xtag_list_t *xtags, const char *tag); - -/* remove a tag from an xtag_list - returns: Y4M_OK - success - Y4M_ERR_RANGE - n is out of range */ -int y4m_xtag_remove(y4m_xtag_list_t *xtags, int n); - -/* remove all tags from an xtag_list - returns: Y4M_OK - success */ -int y4m_xtag_clearlist(y4m_xtag_list_t *xtags); - -/* append copies of tags from src list to dest list - returns: Y4M_OK - success - Y4M_ERR_XXTAGS - operation would overfill dest list */ -int y4m_xtag_addlist(y4m_xtag_list_t *dest, const y4m_xtag_list_t *src); - - - -/************************************************************************ - * '*_info' functions - * - * o Before using a *_info structure (but after the structure/memory has - * been allocated), you must initialize it via y4m_init_*_info(). - * o After using a *_info structure (but before the structure is released), - * call y4m_fini_*_info() to free internal memory. - * o Use the 'set' and 'get' accessors to modify or access the fields in - * the structures; don't touch the structure directly. (Ok, so there - * is no really convenient C syntax to prevent you from doing this, - * but we are all responsible programmers here, so just don't do it!) - * - ************************************************************************/ - -/* initialize a stream_info structure */ -void y4m_init_stream_info(y4m_stream_info_t *i); - -/* finalize a stream_info structure */ -void y4m_fini_stream_info(y4m_stream_info_t *i); - -/* make one stream_info into a copy of another */ -void y4m_copy_stream_info(y4m_stream_info_t *dest, y4m_stream_info_t *src); - -/* access or set stream_info fields */ -void y4m_si_set_width(y4m_stream_info_t *si, int width); -int y4m_si_get_width(y4m_stream_info_t *si); -void y4m_si_set_height(y4m_stream_info_t *si, int height); -int y4m_si_get_height(y4m_stream_info_t *si); -void y4m_si_set_interlace(y4m_stream_info_t *si, int interlace); -int y4m_si_get_interlace(y4m_stream_info_t *si); -void y4m_si_set_framerate(y4m_stream_info_t *si, y4m_ratio_t framerate); -y4m_ratio_t y4m_si_get_framerate(y4m_stream_info_t *si); -void y4m_si_set_sampleaspect(y4m_stream_info_t *si, y4m_ratio_t sar); -y4m_ratio_t y4m_si_get_sampleaspect(y4m_stream_info_t *si); -int y4m_si_get_framelength(y4m_stream_info_t *si); - -/* access stream_info xtag_list */ -y4m_xtag_list_t *y4m_si_xtags(y4m_stream_info_t *si); - - -/* initialize a frame_info structure */ -void y4m_init_frame_info(y4m_frame_info_t *i); - -/* finalize a frame_info structure */ -void y4m_fini_frame_info(y4m_frame_info_t *i); - -/* make one frame_info into a copy of another */ -void y4m_copy_frame_info(y4m_frame_info_t *dest, y4m_frame_info_t *src); - -/* access frame_info xtag_list */ -y4m_xtag_list_t *y4m_fi_xtags(y4m_frame_info_t *fi); - - - -/************************************************************************ - * blocking read and write functions - * - * o guaranteed to transfer entire payload (or fail) - * o return values: - * 0 (zero) complete success - * -(# of remaining bytes) error (and errno left set) - * +(# of remaining bytes) EOF (for y4m_read only) - * - ************************************************************************/ - -/* read len bytes from fd into buf */ -ssize_t y4m_read(stream_t *s, char *buf, size_t len); - -#if 0 -/* write len bytes from fd into buf */ -ssize_t y4m_write(int fd, char *buf, size_t len); -#endif - - -/************************************************************************ - * stream header processing functions - * - * o return values: - * Y4M_OK - success - * Y4M_ERR_* - error (see y4m_strerr() for descriptions) - * - ************************************************************************/ - -/* parse a string of stream header tags */ -int y4m_parse_stream_tags(char *s, y4m_stream_info_t *i); - -/* read a stream header from file descriptor fd */ -int y4m_read_stream_header(stream_t *s, y4m_stream_info_t *i); - -#if 0 -/* write a stream header to file descriptor fd */ -int y4m_write_stream_header(int fd, y4m_stream_info_t *i); -#endif - - -/************************************************************************ - * frame processing functions - * - * o return values: - * Y4M_OK - success - * Y4M_ERR_* - error (see y4m_strerr() for descriptions) - * - ************************************************************************/ - -/* read a frame header from file descriptor fd */ -int y4m_read_frame_header(stream_t *s, y4m_frame_info_t *i); - -#if 0 -/* write a frame header to file descriptor fd */ -int y4m_write_frame_header(int fd, y4m_frame_info_t *i); -#endif - -/* read a complete frame (header + data) - o yuv[3] points to three buffers, one each for Y, U, V planes */ -int y4m_read_frame(stream_t *s, y4m_stream_info_t *si, - y4m_frame_info_t *fi, unsigned char *yuv[3]); - -#if 0 -/* write a complete frame (header + data) - o yuv[3] points to three buffers, one each for Y, U, V planes */ -int y4m_write_frame(int fd, y4m_stream_info_t *si, - y4m_frame_info_t *fi, unsigned char *yuv[3]); -#endif - -#if 0 -/* read a complete frame (header + data), but de-interleave fields - into two separate buffers - o upper_field[3] same as yuv[3] above, but for upper field - o lower_field[3] same as yuv[3] above, but for lower field -*/ -int y4m_read_fields(int fd, y4m_stream_info_t *si, y4m_frame_info_t *fi, - unsigned char *upper_field[3], - unsigned char *lower_field[3]); - -/* write a complete frame (header + data), but interleave fields - from two separate buffers - o upper_field[3] same as yuv[3] above, but for upper field - o lower_field[3] same as yuv[3] above, but for lower field -*/ -int y4m_write_fields(int fd, y4m_stream_info_t *si, y4m_frame_info_t *fi, - unsigned char *upper_field[3], - unsigned char *lower_field[3]); - -#endif - -/************************************************************************ - * miscellaneous functions - ************************************************************************/ - -/* convenient dump of stream header info via mjpeg_log facility - * - each logged/printed line is prefixed by 'prefix' - */ -void y4m_log_stream_info(const char *prefix, y4m_stream_info_t *i); - -/* convert a Y4M_ERR_* error code into mildly explanatory string */ -const char *y4m_strerr(int err); - -/* set 'allow_unknown_tag' flag for library... - o yn = 0 : unknown header tags will produce a parsing error - o yn = 1 : unknown header tags/values will produce a warning, but - are otherwise passed along via the xtags list - o yn = -1: don't change, just return current setting - - return value: previous setting of flag -*/ -int y4m_allow_unknown_tags(int yn); - - -#ifdef __cplusplus -} -#endif - -/************************************************************************ - ************************************************************************ - - Description of the (new!, forever?) YUV4MPEG2 stream format: - - STREAM consists of - o one '\n' terminated STREAM-HEADER - o unlimited number of FRAMEs - - FRAME consists of - o one '\n' terminated FRAME-HEADER - o "length" octets of planar YCrCb 4:2:0 image data - (if frame is interlaced, then the two fields are interleaved) - - - STREAM-HEADER consists of - o string "YUV4MPEG2 " (note the space after the '2') - o unlimited number of ' ' separated TAGGED-FIELDs - o '\n' line terminator - - FRAME-HEADER consists of - o string "FRAME " (note the space after the 'E') - o unlimited number of ' ' separated TAGGED-FIELDs - o '\n' line terminator - - - TAGGED-FIELD consists of - o single ascii character tag - o VALUE (which does not contain whitespace) - - VALUE consists of - o integer (base 10 ascii representation) - or o RATIO - or o single ascii character - or o generic ascii string - - RATIO consists of - o numerator (integer) - o ':' (a colon) - o denominator (integer) - - - The currently supported tags for the STREAM-HEADER: - W - [integer] frame width, pixels, should be > 0 - H - [integer] frame height, pixels, should be > 0 - I - [char] interlacing: p - progressive (none) - t - top-field-first - b - bottom-field-first - ? - unknown - F - [ratio] frame-rate, 0:0 == unknown - A - [ratio] sample (pixel) aspect ratio, 0:0 == unknown - X - [character string] 'metadata' (unparsed, but passed around) - - The currently supported tags for the FRAME-HEADER: - X - character string 'metadata' (unparsed, but passed around) - - ************************************************************************ - ************************************************************************/ - -#endif /* MPLAYER_YUV4MPEG_H */ diff --git a/libmpdemux/yuv4mpeg_intern.h b/libmpdemux/yuv4mpeg_intern.h deleted file mode 100644 index 963f2e3240..0000000000 --- a/libmpdemux/yuv4mpeg_intern.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * yuv4mpeg_intern.h: Internal constants for "new" YUV4MPEG streams - * - * Copyright (C) 2001 Andrew Stevens - * - * This file is part of the MJPEG Tools package (mjpeg.sourceforge.net). - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public License - * as published by the Free Software Foundation. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef MPLAYER_YUV4MPEG_INTERN_H -#define MPLAYER_YUV4MPEG_INTERN_H - - -#define Y4M_MAGIC "YUV4MPEG2" -#define Y4M_FRAME_MAGIC "FRAME" - -#define Y4M_DELIM " " /* single-character(space) separating tagged fields */ - -#define Y4M_LINE_MAX 256 /* max number of characters in a header line - (including the '\n', but not the '\0') */ - - -/* standard framerate ratios */ -#define Y4M_FPS_UNKNOWN { 0, 0 } -#define Y4M_FPS_NTSC_FILM { 24000, 1001 } -#define Y4M_FPS_FILM { 24, 1 } -#define Y4M_FPS_PAL { 25, 1 } -#define Y4M_FPS_NTSC { 30000, 1001 } -#define Y4M_FPS_30 { 30, 1 } -#define Y4M_FPS_PAL_FIELD { 50, 1 } -#define Y4M_FPS_NTSC_FIELD { 60000, 1001 } -#define Y4M_FPS_60 { 60, 1 } - -/* standard sample/pixel aspect ratios */ -#define Y4M_SAR_UNKNOWN { 0, 0 } -#define Y4M_SAR_SQUARE { 1, 1 } -#define Y4M_SAR_NTSC_CCIR601 { 10, 11 } -#define Y4M_SAR_NTSC_16_9 { 40, 33 } -#define Y4M_SAR_NTSC_SVCD_4_3 { 15, 11 } -#define Y4M_SAR_NTSC_SVCD_16_9 { 20, 11 } -#define Y4M_SAR_PAL_CCIR601 { 59, 54 } -#define Y4M_SAR_PAL_16_9 { 118, 81 } -#define Y4M_SAR_PAL_SVCD_4_3 { 59, 36 } -#define Y4M_SAR_PAL_SVCD_16_9 { 59, 27 } - -#define Y4M_SAR_MPEG1_1 Y4M_SAR_SQUARE -#define Y4M_SAR_MPEG1_2 { 10000, 6735 } -#define Y4M_SAR_MPEG1_3 { 10000, 7031 } /* Anamorphic 16:9 PAL */ -#define Y4M_SAR_MPEG1_4 { 10000, 7615 } -#define Y4M_SAR_MPEG1_5 { 10000, 8055 } -#define Y4M_SAR_MPEG1_6 { 10000, 8437 } /* Anamorphic 16:9 NTSC */ -#define Y4M_SAR_MPEG1_7 { 10000, 8935 } -#define Y4M_SAR_MPEG1_8 { 10000, 9375 } /* PAL/SECAM 4:3 */ -#define Y4M_SAR_MPEG1_9 { 10000, 9815 } -#define Y4M_SAR_MPEG1_10 { 10000, 10255 } -#define Y4M_SAR_MPEG1_11 { 10000, 10695 } -#define Y4M_SAR_MPEG1_12 { 10000, 11250 } /* NTSC 4:3 */ -#define Y4M_SAR_MPEG1_13 { 10000, 11575 } -#define Y4M_SAR_MPEG1_14 { 10000, 12015 } - -#define Y4M_DAR_MPEG2_1 { 1, 1} -#define Y4M_DAR_MPEG2_2 { 4, 3 } -#define Y4M_DAR_MPEG2_3 { 16, 9 } -#define Y4M_DAR_MPEG2_4 { 221, 100 } - -#endif /* MPLAYER_YUV4MPEG_INTERN_H */ diff --git a/libmpdemux/yuv4mpeg_ratio.c b/libmpdemux/yuv4mpeg_ratio.c deleted file mode 100644 index be5475c1b1..0000000000 --- a/libmpdemux/yuv4mpeg_ratio.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * yuv4mpeg_ratio.c: Functions for dealing with y4m_ratio_t datatype. - * - * Copyright (C) 2001 Matthew J. Marjanovic - * - * This file is part of the MJPEG Tools package (mjpeg.sourceforge.net). - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#include "config.h" - -#include -#include "yuv4mpeg.h" -#include "yuv4mpeg_intern.h" - - -/* useful list of standard framerates */ -const y4m_ratio_t y4m_fps_UNKNOWN = Y4M_FPS_UNKNOWN; -const y4m_ratio_t y4m_fps_NTSC_FILM = Y4M_FPS_NTSC_FILM; -const y4m_ratio_t y4m_fps_FILM = Y4M_FPS_FILM