fix timecode problem in linking library, bugfixes

git-svn-id: svn://code.dyne.org/veejay/trunk@1315 eb8d1916-c9e9-0310-b8de-cf0c9472ead5
This commit is contained in:
Niels Elburg
2009-03-14 16:30:44 +00:00
parent 3b03e61116
commit 7cd82efc88
20 changed files with 10 additions and 3778 deletions

View File

@@ -1,8 +1,5 @@
# Process with automake to produce Makefile.in # Process with automake to produce Makefile.in
SUBDIRS = mjpeg SUBDIRS = src
if USE_GVEEJAYRELOADED
SUBDIRS += src
endif
EXTRA_DIST = \ EXTRA_DIST = \
autogen.sh\ autogen.sh\

View File

@@ -666,7 +666,6 @@ dnl Output a Makefile or two and the lib/header descriptor script
dnl dnl
AC_CONFIG_FILES([ AC_CONFIG_FILES([
Makefile Makefile
mjpeg/Makefile
src/Makefile src/Makefile
gveejay-paths.sh gveejay-paths.sh
]) ])

View File

@@ -1,6 +0,0 @@
MAINTAINERCLEANFILES = Makefile.in
AM_CFLAGS=$(OP_CFLAGS) -freg-struct-return
INCLUDES = -I$(top_srcdir) -I$(includedir) -I$(top_srcdir)/mjpegtools
MJPEGUTILS_LIB_FILE = libmjpegutils.la
noinst_LTLIBRARIES = $(MJPEGUTILS_LIB_FILE)
libmjpegutils_la_SOURCES = mjpeg_logging.c mpegconsts.c mpegtimecode.c yuv4mpeg.c yuv4mpeg_ratio.c

View File

@@ -1,18 +0,0 @@
/* fast int primitives. min,max,rnddiv2
*
* WARNING: Assumes 2's complement arithmetic.
*/
static inline int intmax( register int x, register int y )
{
return x < y ? y : x;
}
static inline int intmin( register int x, register int y )
{
return x < y ? x : y;
}
static inline int rnddiv2( int x )
{
return (x+(x>0))>>1;
}

View File

@@ -1,46 +0,0 @@
/*
$Id: format_codes.h,v 1.10 2005/12/09 23:07:56 wackston2 Exp $
Copyright (C) 2001 Andrew Stevens <andrew.stevens@planet-interkom.de>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __FORMAT_CODES_H__
#define __FORMAT_CODES_H__
#define MPEG_FORMAT_MPEG1 0
#define MPEG_FORMAT_VCD 1
#define MPEG_FORMAT_VCD_NSR 2
#define MPEG_FORMAT_MPEG2 3
#define MPEG_FORMAT_SVCD 4
#define MPEG_FORMAT_SVCD_NSR 5
#define MPEG_FORMAT_VCD_STILL 6
#define MPEG_FORMAT_SVCD_STILL 7
#define MPEG_FORMAT_DVD_NAV 8
#define MPEG_FORMAT_DVD 9
#define MPEG_FORMAT_ATSC480i 10
#define MPEG_FORMAT_ATSC480p 11
#define MPEG_FORMAT_ATSC720p 12
#define MPEG_FORMAT_ATSC1080i 13
#define MPEG_FORMAT_FIRST 0
#define MPEG_FORMAT_LAST MPEG_FORMAT_ATSC1080i
#define MPEG_STILLS_FORMAT(x) ((x)==MPEG_FORMAT_VCD_STILL||(x)==MPEG_FORMAT_SVCD_STILL)
#define MPEG_ATSC_FORMAT(x) ((x)>=MPEG_FORMAT_ATSC480i && (x)<=MPEG_FORMAT_ATSC1080i)
#define MPEG_HDTV_FORMAT(x) MPEG_ATSC_FORMAT(x)
#define MPEG_SDTV_FORMAT(x) (!MPEG_HDTV_FORMAT(x))
#endif /* __FORMAT_CODES_H__ */

View File

@@ -1,230 +0,0 @@
/*
$Id: mjpeg_logging.c,v 1.16 2007/04/01 18:06:06 sms00 Exp $
Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include "mjpeg_logging.h"
#ifdef HAVE___PROGNAME
extern const char *__progname;
#endif
/*
* Put these here and NOT in the exported header file mjpeg_logging.h
*
* since ALL program use of these should use the API below (mjpeg_warn,
* mjpeg_error,etc) these symbols do not need to be exported and possibly
* conflict with syslog.h
*/
#define LOG_DEBUG 1
#define LOG_INFO 2
#define LOG_WARN 3
#define LOG_ERROR 4
static log_level_t mjpeg_log_verbosity = 0;
static char *default_handler_id = NULL;
static int default_mjpeg_log_filter( log_level_t level )
{
int verb_from_env;
if( mjpeg_log_verbosity == 0 )
{
char *mjpeg_verb_env = getenv("MJPEG_VERBOSITY");
if( mjpeg_verb_env != NULL )
{
verb_from_env = LOG_WARN-atoi(mjpeg_verb_env);
if( verb_from_env >= LOG_DEBUG && verb_from_env <= LOG_ERROR )
mjpeg_log_verbosity = (log_level_t)verb_from_env;
}
}
return (level < LOG_WARN && level < mjpeg_log_verbosity);
}
static mjpeg_log_filter_t _filter = default_mjpeg_log_filter;
static void
default_mjpeg_log_handler(log_level_t level, const char message[])
{
const char *ids;
if( (*_filter)( level ) )
return;
if (default_handler_id != NULL) {
ids = default_handler_id;
} else {
#ifdef HAVE___PROGNAME
ids = __progname;
#else
ids = "???";
#endif
}
switch(level) {
case LOG_ERROR:
fprintf(stderr, "**ERROR: [%s] %s\n", ids, message);
break;
case LOG_DEBUG:
fprintf(stderr, "--DEBUG: [%s] %s\n", ids, message);
break;
case LOG_WARN:
fprintf(stderr, "++ WARN: [%s] %s\n", ids, message);
break;
case LOG_INFO:
fprintf(stderr, " INFO: [%s] %s\n", ids, message);
break;
default:
assert(0);
}
}
static mjpeg_log_handler_t _handler = default_mjpeg_log_handler;
mjpeg_log_handler_t
mjpeg_log_set_handler(mjpeg_log_handler_t new_handler)
{
mjpeg_log_handler_t old_handler = _handler;
_handler = new_handler;
return old_handler;
}
/***************
* Set default log handlers degree of verboseity.
* 0 = quiet, 1 = info, 2 = debug
*************/
int
mjpeg_default_handler_verbosity(int verbosity)
{
int prev_verb = mjpeg_log_verbosity;
mjpeg_log_verbosity = (log_level_t)(LOG_WARN - verbosity);
return prev_verb;
}
/*
* Set identifier string used by default handler
*/
int
mjpeg_default_handler_identifier(const char *new_id)
{
const char *s;
if (new_id == NULL) {
if (default_handler_id != NULL)
free(default_handler_id);
default_handler_id = NULL;
return 0;
}
/* find basename of new_id (remove any directory prefix) */
if ((s = strrchr(new_id, '/')) == NULL)
s = new_id;
else
s = s + 1;
default_handler_id = strdup(s);
return 0;
}
static void
mjpeg_logv(log_level_t level, const char format[], va_list args)
{
char buf[1024] = { 0, };
/* TODO: Original had a re-entrancy error trap to assist bug
finding. To make this work with multi-threaded applications a
lock is needed hence delete.
*/
vsnprintf(buf, sizeof(buf)-1, format, args);
_handler(level, buf);
}
void
mjpeg_log(log_level_t level, const char format[], ...)
{
va_list args;
va_start (args, format);
mjpeg_logv(level, format, args);
va_end (args);
}
void
mjpeg_debug(const char format[], ...)
{
va_list args;
va_start (args, format);
mjpeg_logv(LOG_DEBUG, format, args);
va_end (args);
}
void
mjpeg_info(const char format[], ...)
{
va_list args;
va_start (args, format);
mjpeg_logv(LOG_INFO, format, args);
va_end (args);
}
void
mjpeg_warn(const char format[], ...)
{
va_list args;
va_start (args, format);
mjpeg_logv(LOG_WARN, format, args);
va_end (args);
}
void
mjpeg_error(const char format[], ...)
{
va_list args;
va_start (args, format);
mjpeg_logv(LOG_ERROR, format, args);
va_end (args);
}
void
mjpeg_error_exit1(const char format[], ...)
{
va_list args;
va_start( args, format );
mjpeg_logv( LOG_ERROR, format, args);
va_end(args);
exit(EXIT_FAILURE);
}
log_level_t
mjpeg_loglev_t(const char *level)
{
if (strcasecmp("debug", level) == 0) return(LOG_DEBUG);
else if (strcasecmp("info", level) == 0) return(LOG_INFO);
else if (strcasecmp("warn", level) == 0) return(LOG_WARN);
else if (strcasecmp("error", level) == 0) return(LOG_ERROR);
return(0);
}

View File

@@ -1,77 +0,0 @@
/*
$Id: mjpeg_logging.h,v 1.11 2007/04/01 18:06:06 sms00 Exp $
Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __MJPEG_LOGGING_H__
#define __MJPEG_LOGGING_H__
#include <mjpeg_types.h>
/* to avoid changing all the places log_level_t is used */
typedef int log_level_t;
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
#define GNUC_PRINTF( format_idx, arg_idx ) \
__attribute__((format (printf, format_idx, arg_idx)))
#else /* !__GNUC__ */
#define GNUC_PRINTF( format_idx, arg_idx )
#endif /* !__GNUC__ */
#ifdef __cplusplus
extern "C" {
#endif
void
mjpeg_log(log_level_t level, const char format[], ...) GNUC_PRINTF(2, 3);
typedef int(*mjpeg_log_filter_t)(log_level_t level);
typedef void(*mjpeg_log_handler_t)(log_level_t level, const char message[]);
mjpeg_log_handler_t
mjpeg_log_set_handler(mjpeg_log_handler_t new_handler);
int
mjpeg_default_handler_identifier(const char *new_id);
int
mjpeg_default_handler_verbosity(int verbosity);
void
mjpeg_debug(const char format[], ...) GNUC_PRINTF(1,2);
void
mjpeg_info(const char format[], ...) GNUC_PRINTF(1,2);
void
mjpeg_warn(const char format[], ...) GNUC_PRINTF(1,2);
void
mjpeg_error(const char format[], ...) GNUC_PRINTF(1,2);
void
mjpeg_error_exit1(const char format[], ...) GNUC_PRINTF(1,2);
log_level_t
mjpeg_loglev_t(const char *str);
#ifdef __cplusplus
}
#endif
#endif /* __MJPEG_LOGGING_H__ */

View File

@@ -1,28 +0,0 @@
/*
$Id: mjpeg_types.h,v 1.16 2006/05/18 18:19:05 sms00 Exp $
Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __MJPEG_TYPES_H__
#define __MJPEG_TYPES_H__
#include <sys/types.h> /* FreeBSD, others - ssize_t */
#include <stdint.h>
#include <inttypes.h>
#endif /* __MJPEG_TYPES_H__ */

View File

@@ -1,513 +0,0 @@
/*
* mpegconsts.c: Video format constants for MPEG and utilities for display
* and conversion to format used for yuv4mpeg
*
* Copyright (C) 2001 Andrew Stevens <andrew.stevens@philips.com>
* Copyright (C) 2001 Matthew Marjanovic <maddog@mir.com>
*
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <config.h>
#include "mpegconsts.h"
#include "yuv4mpeg.h"
#include "yuv4mpeg_intern.h"
#include "format_codes.h"
static y4m_ratio_t
mpeg_framerates[] = {
Y4M_FPS_UNKNOWN,
Y4M_FPS_NTSC_FILM,
Y4M_FPS_FILM,
Y4M_FPS_PAL,
Y4M_FPS_NTSC,
Y4M_FPS_30,
Y4M_FPS_PAL_FIELD,
Y4M_FPS_NTSC_FIELD,
Y4M_FPS_60
};
#define MPEG_NUM_RATES (sizeof(mpeg_framerates)/sizeof(mpeg_framerates[0]))
static const mpeg_framerate_code_t mpeg_num_framerates = MPEG_NUM_RATES;
static const char *
framerate_definitions[MPEG_NUM_RATES] =
{
"illegal",
"24000.0/1001.0 (NTSC 3:2 pulldown converted FILM)",
"24.0 (NATIVE FILM)",
"25.0 (PAL/SECAM VIDEO / converted FILM)",
"30000.0/1001.0 (NTSC VIDEO)",
"30.0",
"50.0 (PAL FIELD RATE)",
"60000.0/1001.0 (NTSC FIELD RATE)",
"60.0"
};
static const char *mpeg1_aspect_ratio_definitions[] =
{
"illegal",
"1:1 (square pixels)",
"1:0.6735",
"1:0.7031 (16:9 Anamorphic PAL/SECAM for 720x578/352x288 images)",
"1:0.7615",
"1:0.8055",
"1:0.8437 (16:9 Anamorphic NTSC for 720x480/352x240 images)",
"1:0.8935",
"1:0.9375 (4:3 PAL/SECAM for 720x578/352x288 images)",
"1:0.9815",
"1:1.0255",
"1:1:0695",
"1:1.1250 (4:3 NTSC for 720x480/352x240 images)",
"1:1.1575",
"1:1.2015"
};
static const y4m_ratio_t mpeg1_aspect_ratios[] =
{
Y4M_SAR_UNKNOWN,
Y4M_SAR_MPEG1_1,
Y4M_SAR_MPEG1_2,
Y4M_SAR_MPEG1_3, /* Anamorphic 16:9 PAL */
Y4M_SAR_MPEG1_4,
Y4M_SAR_MPEG1_5,
Y4M_SAR_MPEG1_6, /* Anamorphic 16:9 NTSC */
Y4M_SAR_MPEG1_7,
Y4M_SAR_MPEG1_8, /* PAL/SECAM 4:3 */
Y4M_SAR_MPEG1_9,
Y4M_SAR_MPEG1_10,
Y4M_SAR_MPEG1_11,
Y4M_SAR_MPEG1_12, /* NTSC 4:3 */
Y4M_SAR_MPEG1_13,
Y4M_SAR_MPEG1_14,
};
static const char *mpeg2_aspect_ratio_definitions[] =
{
"illegal",
"1:1 pixels",
"4:3 display",
"16:9 display",
"2.21:1 display"
};
static const y4m_ratio_t mpeg2_aspect_ratios[] =
{
Y4M_DAR_UNKNOWN,
Y4M_DAR_MPEG2_1,
Y4M_DAR_MPEG2_2,
Y4M_DAR_MPEG2_3,
Y4M_DAR_MPEG2_4
};
static const char **aspect_ratio_definitions[2] =
{
mpeg1_aspect_ratio_definitions,
mpeg2_aspect_ratio_definitions
};
static const y4m_ratio_t *mpeg_aspect_ratios[2] =
{
mpeg1_aspect_ratios,
mpeg2_aspect_ratios
};
static const mpeg_aspect_code_t mpeg_num_aspect_ratios[2] =
{
sizeof(mpeg1_aspect_ratios)/sizeof(mpeg1_aspect_ratios[0]),
sizeof(mpeg2_aspect_ratios)/sizeof(mpeg2_aspect_ratios[0])
};
static const char *mjpegtools_format_code_definitions[MPEG_FORMAT_LAST+1] =
{
"Generic MPEG1",
"Standard VCD",
"Stretched VCD",
"Generic MPEG2",
"Standard SVCD",
"Stretched SVCD",
"VCD Still",
"SVCD Still",
"DVD with dummy navigation packets",
"Standard DVD",
"ATSC 480i",
"ATSC 480p",
"ATSC 720p",
"ATSC 1080i"
};
/*
* Is code a valid MPEG framerate code?
*/
int
mpeg_valid_framerate_code( mpeg_framerate_code_t code )
{
return ((code > 0) && (code < mpeg_num_framerates)) ? 1 : 0;
}
/*
* Convert MPEG frame-rate code to corresponding frame-rate
*/
y4m_ratio_t
mpeg_framerate( mpeg_framerate_code_t code )
{
if ((code > 0) && (code < mpeg_num_framerates))
return mpeg_framerates[code];
else
return y4m_fps_UNKNOWN;
}
/*
* Look-up MPEG frame rate code for a (exact) frame rate.
*/
mpeg_framerate_code_t
mpeg_framerate_code( y4m_ratio_t framerate )
{
mpeg_framerate_code_t i;
y4m_ratio_reduce(&framerate);
/* start at '1', because 0 is unknown/illegal */
for (i = 1; i < mpeg_num_framerates; ++i) {
if (Y4M_RATIO_EQL(framerate, mpeg_framerates[i]))
return i;
}
return 0;
}
/* small enough to distinguish 1/1000 from 1/1001 */
#define MPEG_FPS_TOLERANCE 0.0001
y4m_ratio_t
mpeg_conform_framerate( double fps )
{
mpeg_framerate_code_t i;
y4m_ratio_t result;
/* try to match it to a standard frame rate */
/* (start at '1', because 0 is unknown/illegal) */
for (i = 1; i < mpeg_num_framerates; i++)
{
double deviation = 1.0 - (Y4M_RATIO_DBL(mpeg_framerates[i]) / fps);
if ( (deviation > -MPEG_FPS_TOLERANCE) &&
(deviation < +MPEG_FPS_TOLERANCE) )
return mpeg_framerates[i];
}
/* no luck? just turn it into a ratio (8 decimal place accuracy) */
result.n = (int)((fps * 100000000.0) + 0.5);
result.d = 100000000;
y4m_ratio_reduce(&result);
return result;
}
/*
* Is code a valid MPEG aspect-ratio code?
*/
int
mpeg_valid_aspect_code( int version, mpeg_framerate_code_t c )
{
if ((version == 1) || (version == 2))
return ((c > 0) && (c < mpeg_num_aspect_ratios[version-1])) ? 1 : 0;
else
return 0;
}
/*
* Convert MPEG aspect-ratio code to corresponding aspect-ratio
*/
y4m_ratio_t
mpeg_aspect_ratio( int mpeg_version, mpeg_aspect_code_t code )
{
y4m_ratio_t ratio;
if ((mpeg_version >= 1) && (mpeg_version <= 2) &&
(code > 0) && (code < mpeg_num_aspect_ratios[mpeg_version-1]))
{
ratio = mpeg_aspect_ratios[mpeg_version-1][code];
y4m_ratio_reduce(&ratio);
return ratio;
}
else
return y4m_sar_UNKNOWN;
}
/*
* Look-up corresponding MPEG aspect ratio code given an exact aspect ratio.
*
* WARNING: The semantics of aspect ratio coding *changed* between
* MPEG1 and MPEG2. In MPEG1 it is the *pixel* aspect ratio. In
* MPEG2 it is the (far more sensible) aspect ratio of the eventual
* display.
*
*/
mpeg_aspect_code_t
mpeg_frame_aspect_code( int mpeg_version, y4m_ratio_t aspect_ratio )
{
mpeg_aspect_code_t i;
y4m_ratio_t red_ratio = aspect_ratio;
y4m_ratio_reduce( &red_ratio );
if( mpeg_version < 1 || mpeg_version > 2 )
return 0;
/* (start at '1', because 0 is unknown/illegal) */
for( i = 1; i < mpeg_num_aspect_ratios[mpeg_version-1]; ++i )
{
y4m_ratio_t red_entry = mpeg_aspect_ratios[mpeg_version-1][i];
y4m_ratio_reduce( &red_entry );
if( Y4M_RATIO_EQL( red_entry, red_ratio) )
return i;
}
return 0;
}
/*
* Guess the correct MPEG aspect ratio code,
* given the true sample aspect ratio and frame size of a video stream
* (and the MPEG version, 1 or 2).
*
* Returns 0 if it has no good guess.
*
*/
/* this is big enough to accommodate the difference between 720 and 704 */
#define GUESS_ASPECT_TOLERANCE 0.03
mpeg_aspect_code_t
mpeg_guess_mpeg_aspect_code(int mpeg_version, y4m_ratio_t sampleaspect,
int frame_width, int frame_height)
{
if (Y4M_RATIO_EQL(sampleaspect, y4m_sar_UNKNOWN))
{
return 0;
}
switch (mpeg_version) {
case 1:
if (Y4M_RATIO_EQL(sampleaspect, y4m_sar_SQUARE))
{
return 1;
}
else if (Y4M_RATIO_EQL(sampleaspect, y4m_sar_NTSC_CCIR601))
{
return 12;
}
else if (Y4M_RATIO_EQL(sampleaspect, y4m_sar_NTSC_16_9))
{
return 6;
}
else if (Y4M_RATIO_EQL(sampleaspect, y4m_sar_PAL_CCIR601))
{
return 8;
}
else if (Y4M_RATIO_EQL(sampleaspect, y4m_sar_PAL_16_9))
{
return 3;
}
return 0;
break;
case 2:
if (Y4M_RATIO_EQL(sampleaspect, y4m_sar_SQUARE))
{
return 1; /* '1' means square *pixels* in MPEG-2; go figure. */
}
else
{
int i;
double true_far; /* true frame aspect ratio */
true_far =
(double)(sampleaspect.n * frame_width) /
(double)(sampleaspect.d * frame_height);
/* start at '2'... */
for (i = 2; i < (int)(mpeg_num_aspect_ratios[mpeg_version-1]); i++)
{
double ratio =
true_far / Y4M_RATIO_DBL(mpeg_aspect_ratios[mpeg_version-1][i]);
if ( (ratio > (1.0 - GUESS_ASPECT_TOLERANCE)) &&
(ratio < (1.0 + GUESS_ASPECT_TOLERANCE)) )
return i;
}
return 0;
}
break;
default:
return 0;
break;
}
}
/*
* Guess the true sample aspect ratio of a video stream,
* given the MPEG aspect ratio code and the actual frame size
* (and the MPEG version, 1 or 2).
*
* Returns y4m_sar_UNKNOWN if it has no good guess.
*
*/
y4m_ratio_t
mpeg_guess_sample_aspect_ratio(int mpeg_version,
mpeg_aspect_code_t code,
int frame_width, int frame_height)
{
switch (mpeg_version)
{
case 1:
/* MPEG-1 codes turn into SAR's, just not quite the right ones.
For the common/known values, we provide the ratio used in practice,
otherwise say we don't know.*/
switch (code)
{
case 1: return y4m_sar_SQUARE; break;
case 3: return y4m_sar_PAL_16_9; break;
case 6: return y4m_sar_NTSC_16_9; break;
case 8: return y4m_sar_PAL_CCIR601; break;
case 12: return y4m_sar_NTSC_CCIR601; break;
default:
return y4m_sar_UNKNOWN; break;
}
break;
case 2:
/* MPEG-2 codes turn into Display Aspect Ratios, though not exactly the
DAR's used in practice. For common/standard frame sizes, we provide
the original SAR; otherwise, we say we don't know. */
if (code == 1)
{
return y4m_sar_SQUARE; /* '1' means square *pixels* in MPEG-2 */
}
else if ((code >= 2) && (code <= 4))
{
return y4m_guess_sar(frame_width, frame_height,
mpeg2_aspect_ratios[code]);
}
else
{
return y4m_sar_UNKNOWN;
}
break;
default:
return y4m_sar_UNKNOWN;
break;
}
}
/*
* Look-up MPEG explanatory definition string for frame rate code
*
*/
const char *
mpeg_framerate_code_definition( mpeg_framerate_code_t code )
{
if( code == 0 || code >= mpeg_num_framerates )
return "UNDEFINED: illegal/reserved frame-rate ratio code";
return framerate_definitions[code];
}
/*
* Look-up MPEG explanatory definition string aspect ratio code for an
* aspect ratio code
*
*/
const char *
mpeg_aspect_code_definition( int mpeg_version, mpeg_aspect_code_t code )
{
if( mpeg_version < 1 || mpeg_version > 2 )
return "UNDEFINED: illegal MPEG version";
if( code < 1 || code >= mpeg_num_aspect_ratios[mpeg_version-1] )
return "UNDEFINED: illegal aspect ratio code";
return aspect_ratio_definitions[mpeg_version-1][code];
}
/*
* Look-up explanatory definition of interlace field order code
*
*/
const char *
mpeg_interlace_code_definition( int yuv4m_interlace_code )
{
const char *def;
switch( yuv4m_interlace_code )
{
case Y4M_UNKNOWN :
def = "unknown";
break;
case Y4M_ILACE_NONE :
def = "none/progressive";
break;
case Y4M_ILACE_TOP_FIRST :
def = "top-field-first";
break;
case Y4M_ILACE_BOTTOM_FIRST :
def = "bottom-field-first";
break;
default :
def = "UNDEFINED: illegal video interlacing type-code!";
break;
}
return def;
}
/*
* Look-up explanatory definition of mjepgtools preset format code
*
*/
const char *mpeg_format_code_defintion( int format_code )
{
if(format_code >= MPEG_FORMAT_FIRST && format_code <= MPEG_FORMAT_LAST )
return mjpegtools_format_code_definitions[format_code];
else
return "UNDEFINED: illegal format code!";
};
/*
* Local variables:
* c-file-style: "stroustrup"
* tab-width: 4
* indent-tabs-mode: nil
* End:
*/

View File

@@ -1,171 +0,0 @@
/*
* mpegconsts.c: Video format constants for MPEG and utilities for display
* and conversion to format used for yuv4mpeg
*
* Copyright (C) 2001 Andrew Stevens <andrew.stevens@philips.com>
*
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __MPEGCONSTS_H__
#define __MPEGCONSTS_H__
#include <yuv4mpeg.h>
typedef unsigned int mpeg_framerate_code_t;
typedef unsigned int mpeg_aspect_code_t;
#ifdef __cplusplus
#define START_CPP_WRAP extern "C" {
#define END_CPP_WRAP };
#else
#define START_CPP_WRAP
#define END_CPP_WRAP
#endif
START_CPP_WRAP
/*
* Convert MPEG frame-rate code to corresponding frame-rate
* y4m_fps_UNKNOWN = { 0, 0 } = Undefined/resrerved code.
*/
y4m_ratio_t
mpeg_framerate( mpeg_framerate_code_t code );
/*
* Is code a valid MPEG frame-rate code?
* Return 1 if true; 0 otherwise.
*/
int
mpeg_valid_framerate_code( mpeg_framerate_code_t code );
/*
* Look-up MPEG frame rate code for a (exact) frame rate.
* 0 = No MPEG code defined for frame-rate
*/
mpeg_framerate_code_t
mpeg_framerate_code( y4m_ratio_t framerate );
/*
* Convert floating-point framerate to an exact ratio.
* Uses a standard MPEG rate, if it finds one within MPEG_FPS_TOLERANCE
* (see mpegconsts.c), otherwise uses "fps:1000000" as the ratio.
*/
y4m_ratio_t
mpeg_conform_framerate( double fps );
/*
* Convert MPEG aspect ratio code to corresponding aspect ratio
*
* WARNING: The semantics of aspect ratio coding *changed* between
* MPEG1 and MPEG2. In MPEG1 it is the *pixel* aspect ratio. In
* MPEG2 it is the (far more sensible) aspect ratio of the eventual
* display.
*
*/
y4m_ratio_t
mpeg_aspect_ratio( int mpeg_version, mpeg_aspect_code_t code );
/*
* Is code a valid MPEG(1,2) aspect-ratio code?
* Return 1 if true; 0 otherwise.
*/
int
mpeg_valid_aspect_code( int mpeg_version, mpeg_aspect_code_t code );
/*
* Look-up MPEG aspect ratio code for an aspect ratio - tolerance
* is Y4M_ASPECT_MULT used by YUV4MPEG (see yuv4mpeg_intern.h)
*
* WARNING: The semantics of aspect ratio coding *changed* between
* MPEG1 and MPEG2. In MPEG1 it is the *pixel* aspect ratio. In
* MPEG2 it is the (far more sensible) aspect ratio of the eventual
* display.
*
*/
mpeg_aspect_code_t
mpeg_frame_aspect_code( int mpeg_version, y4m_ratio_t aspect_ratio );
/*
* Look-up MPEG explanatory definition string aspect ratio code for an
* aspect ratio code
*
*/
const char *
mpeg_aspect_code_definition( int mpeg_version, mpeg_aspect_code_t code );
/*
* Look-up MPEG explanatory definition string aspect ratio code for an
* frame rate code
*
*/
const char *
mpeg_framerate_code_definition( mpeg_framerate_code_t code );
const char *
mpeg_interlace_code_definition( int yuv4m_interlace_code );
/*
* Guess the correct MPEG aspect ratio code,
* given the true sample aspect ratio and frame size of a video stream
* (and the MPEG version, 1 or 2).
*
* Returns 0 if it has no good answer.
*
*/
mpeg_aspect_code_t
mpeg_guess_mpeg_aspect_code(int mpeg_version, y4m_ratio_t sampleaspect,
int frame_width, int frame_height);
/*
* Guess the true sample aspect ratio of a video stream,
* given the MPEG aspect ratio code and the actual frame size
* (and the MPEG version, 1 or 2).
*
* Returns y4m_sar_UNKNOWN if it has no good answer.
*
*/
y4m_ratio_t
mpeg_guess_sample_aspect_ratio(int mpeg_version,
mpeg_aspect_code_t code,
int frame_width, int frame_height);
/*
* Look-up MJPEGTOOLS MPEG preset format code explanatory definition string a
*
*/
const char *mpeg_format_code_defintion( int format_code );
END_CPP_WRAP
#endif /* __MPEGCONSTS_H__ */

View File

@@ -1,105 +0,0 @@
/*
* Copyright (C) 2001 Kawamata/Hitoshi <hitoshi.kawamata@nifty.ne.jp>
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <config.h>
#include <stdlib.h>
#include "mpegtimecode.h"
/**************************************************************
* // NTSC DROP FRAME TIMECODE / 29.97fps (SMTPE)
* // hh:mm:ss:ff
* // hh: 0..
* // mm: 0..59
* // ss: 0..59
* // ff: 0..29 # ss != 0 || mm % 10 == 0
* // 2..29 # ss == 0 && mm % 10 != 0
* //
* // 00:00:00:00 00:00:00:01 00:00:00:02 ... 00:00:00:29
* // 00:00:01:00 00:00:01:01 00:00:01:02 ... 00:00:01:29
* // :
* // 00:00:59:00 00:00:59:01 00:00:59:02 ... 00:00:59:29
* // 00:01:00:02 ... 00:01:00:29
* // 00:01:01:00 00:01:01:01 00:01:01:02 ... 00:01:00:29
* // :
* // 00:01:59:00 00:01:59:01 00:01:59:02 ... 00:01:59:29
* // 00:02:00:02 ... 00:02:00:29
* // 00:02:01:00 00:02:01:01 00:02:01:02 ... 00:02:00:29
* // :
* // :
* // 00:09:59:00 00:09:59:01 00:09:59:02 ... 00:09:59:29
* // 00:10:00:00 00:10:00:01 00:10:00:02 ... 00:10:00:29
* // 00:10:01:00 00:10:01:01 00:10:01:02 ... 00:10:01:29
* // :
* // 00:10:59:00 00:10:59:01 00:10:59:02 ... 00:10:59:29
* // 00:11:00:02 ... 00:11:00:29
* // 00:11:01:00 00:11:01:01 00:11:01:02 ... 00:11:00:29
* // :
* // :
* // DROP FRAME / 59.94fps (no any standard)
* // DROP FRAME / 23.976fps (no any standard)
***************************************************************/
int dropframetimecode = -1;
/* mpeg_timecode() return -tc->f on first frame in the minute, tc->f on other. */
int
mpeg_timecode(MPEG_timecode_t *tc, int f, int fpscode, double fps)
{
static const int ifpss[] = { 0, 24, 24, 25, 30, 30, 50, 60, 60, };
int h, m, s;
if (dropframetimecode < 0) {
char *env = getenv("MJPEG_DROP_FRAME_TIME_CODE");
dropframetimecode = (env && *env != '0' && *env != 'n' && *env != 'N');
}
if (dropframetimecode &&
0 < fpscode && fpscode + 1 < sizeof ifpss / sizeof ifpss[0] &&
ifpss[fpscode] == ifpss[fpscode + 1]) {
int topinmin = 0, k = (30*4) / ifpss[fpscode];
f *= k; /* frame# when 119.88fps */
h = (f / ((10*60*30-18)*4)); /* # of 10min. */
f %= ((10*60*30-18)*4); /* frame# in 10min. */
f -= (2*4); /* frame# in 10min. - (2*4) */
m = (f / ((60*30-2)*4)); /* min. in 10min. */
topinmin = ((f - k) / ((60*30-2)*4) < m);
m += (h % 6 * 10); /* min. */
h /= 6; /* hour */
f %= ((60*30-2)*4); /* frame# in min. - (2*4)*/
f += (2*4); /* frame# in min. */
s = f / (30*4); /* sec. */
f %= (30*4); /* frame# in sec. */
f /= k; /* frame# in sec. on original fps */
tc->f = f;
if (topinmin)
f = -f;
} else {
int ifps = ((0 < fpscode && fpscode < sizeof ifpss / sizeof ifpss[0])?
ifpss[fpscode]: (int)(fps + .5));
s = f / ifps;
f %= ifps;
m = s / 60;
s %= 60;
h = m / 60;
m %= 60;
tc->f = f;
}
tc->s = s;
tc->m = m;
tc->h = h;
return f;
}

View File

@@ -1,39 +0,0 @@
/* -*- mode:C -*- */
/*
* Copyright (C) 2001 Kawamata/Hitoshi <hitoshi.kawamata@nifty.ne.jp>
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __MPEGTIMECODE_H__
#define __MPEGTIMECODE_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
char h, m, s, f;
} MPEG_timecode_t;
extern int dropframetimecode;
extern int mpeg_timecode(MPEG_timecode_t *tc, int f, int fpscode, double fps);
/* mpeg_timecode() return -tc->f on first frame in the minute, tc->f on other. */
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,118 +0,0 @@
/* These are the MJPEG API extensions for the Video4Linux API,
first introduced by the Iomega Buz driver by Rainer Johanni
<rainer@johanni.de>
*/
/* This is identical with the mgavideo internal params struct,
please tell me if you change this struct here ! <gz@lysator.liu.se) */
struct mjpeg_params
{
/* The following parameters can only be queried */
int major_version; /* Major version number of driver */
int minor_version; /* Minor version number of driver */
/* Main control parameters */
int input; /* Input channel: 0 = Composite, 1 = S-VHS */
int norm; /* Norm: VIDEO_MODE_PAL or VIDEO_MODE_NTSC */
int decimation; /* decimation of captured video,
enlargement of video played back.
Valid values are 1, 2, 4 or 0.
0 is a special value where the user
has full control over video scaling */
/* The following parameters only have to be set if decimation==0,
for other values of decimation they provide the data how the image is captured */
int HorDcm; /* Horizontal decimation: 1, 2 or 4 */
int VerDcm; /* Vertical decimation: 1 or 2 */
int TmpDcm; /* Temporal decimation: 1 or 2,
if TmpDcm==2 in capture every second frame is dropped,
in playback every frame is played twice */
int field_per_buff; /* Number of fields per buffer: 1 or 2 */
int img_x; /* start of image in x direction */
int img_y; /* start of image in y direction */
int img_width; /* image width BEFORE decimation,
must be a multiple of HorDcm*16 */
int img_height; /* image height BEFORE decimation,
must be a multiple of VerDcm*8 */
/* --- End of parameters for decimation==0 only --- */
/* JPEG control parameters */
int quality; /* Measure for quality of compressed images.
Scales linearly with the size of the compressed images.
Must be beetween 0 and 100, 100 is a compression
ratio of 1:4 */
int odd_even; /* Which field should come first ???
This is more aptly named "top_first",
i.e. (odd_even==1) --> top-field-first */
int APPn; /* Number of APP segment to be written, must be 0..15 */
int APP_len; /* Length of data in JPEG APPn segment */
char APP_data[60]; /* Data in the JPEG APPn segment. */
int COM_len; /* Length of data in JPEG COM segment */
char COM_data[60]; /* Data in JPEG COM segment */
unsigned long jpeg_markers; /* Which markers should go into the JPEG output.
Unless you exactly know what you do, leave them untouched.
Inluding less markers will make the resulting code
smaller, but there will be fewer aplications
which can read it.
The presence of the APP and COM marker is
influenced by APP0_len and COM_len ONLY! */
#define JPEG_MARKER_DHT (1<<3) /* Define Huffman Tables */
#define JPEG_MARKER_DQT (1<<4) /* Define Quantization Tables */
#define JPEG_MARKER_DRI (1<<5) /* Define Restart Interval */
#define JPEG_MARKER_COM (1<<6) /* Comment segment */
#define JPEG_MARKER_APP (1<<7) /* App segment, driver will allways use APP0 */
int VFIFO_FB; /* Flag for enabling Video Fifo Feedback.
If this flag is turned on and JPEG decompressing
is going to the screen, the decompress process
is stopped every time the Video Fifo is full.
This enables a smooth decompress to the screen
but the video output signal will get scrambled */
/* Misc */
char reserved[312]; /* Makes 512 bytes for this structure */
};
struct mjpeg_requestbuffers
{
unsigned long count; /* Number of buffers for MJPEG grabbing */
unsigned long size; /* Size PER BUFFER in bytes */
};
struct mjpeg_sync
{
unsigned long frame; /* Frame (0 - n) for double buffer */
unsigned long length; /* number of code bytes in buffer (capture only) */
unsigned long seq; /* frame sequence number */
struct timeval timestamp; /* timestamp */
};
struct mjpeg_status
{
int input; /* Input channel, has to be set prior to BUZIOC_G_STATUS */
int signal; /* Returned: 1 if valid video signal detected */
int norm; /* Returned: VIDEO_MODE_PAL or VIDEO_MODE_NTSC */
int color; /* Returned: 1 if color signal detected */
};
/*
Private IOCTL to set up for displaying MJPEG
*/
#define MJPIOC_G_PARAMS _IOR ('v', BASE_VIDIOCPRIVATE+0, struct mjpeg_params)
#define MJPIOC_S_PARAMS _IOWR('v', BASE_VIDIOCPRIVATE+1, struct mjpeg_params)
#define MJPIOC_REQBUFS _IOWR('v', BASE_VIDIOCPRIVATE+2, struct mjpeg_requestbuffers)
#define MJPIOC_QBUF_CAPT _IOW ('v', BASE_VIDIOCPRIVATE+3, int)
#define MJPIOC_QBUF_PLAY _IOW ('v', BASE_VIDIOCPRIVATE+4, int)
#define MJPIOC_SYNC _IOR ('v', BASE_VIDIOCPRIVATE+5, struct mjpeg_sync)
#define MJPIOC_G_STATUS _IOWR('v', BASE_VIDIOCPRIVATE+6, struct mjpeg_status)

File diff suppressed because it is too large Load Diff

View File

@@ -1,757 +0,0 @@
/*
* yuv4mpeg.h: Functions for reading and writing "new" YUV4MPEG2 streams.
*
* Stream format is described at the end of this file.
*
*
* Copyright (C) 2004 Matthew J. Marjanovic <maddog@mir.com>
*
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __YUV4MPEG_H__
#define __YUV4MPEG_H__
#include <stdlib.h>
#include <mjpeg_types.h>
#ifndef _WIN32
#include <unistd.h>
#endif
#include <mjpeg_logging.h>
/************************************************************************
* error codes returned by y4m_* functions
************************************************************************/
#define Y4M_OK 0
#define Y4M_ERR_RANGE 1 /* argument or tag value out of range */
#define Y4M_ERR_SYSTEM 2 /* failed system call, check errno */
#define Y4M_ERR_HEADER 3 /* illegal/malformed header */
#define Y4M_ERR_BADTAG 4 /* illegal tag character */
#define Y4M_ERR_MAGIC 5 /* bad header magic */
#define Y4M_ERR_EOF 6 /* end-of-file (clean) */
#define Y4M_ERR_XXTAGS 7 /* too many xtags */
#define Y4M_ERR_BADEOF 8 /* unexpected end-of-file */
#define Y4M_ERR_FEATURE 9 /* stream requires features beyond allowed level */
/* generic 'unknown' value for integer parameters (e.g. interlace, height) */
#define Y4M_UNKNOWN -1
/************************************************************************
* values for the "interlace" parameter [y4m_*_interlace()]
************************************************************************/
#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 */
#define Y4M_ILACE_MIXED 3 /* mixed, "refer to frame header" */
/************************************************************************
* values for the "chroma" parameter [y4m_*_chroma()]
************************************************************************/
#define Y4M_CHROMA_420JPEG 0 /* 4:2:0, H/V centered, for JPEG/MPEG-1 */
#define Y4M_CHROMA_420MPEG2 1 /* 4:2:0, H cosited, for MPEG-2 */
#define Y4M_CHROMA_420PALDV 2 /* 4:2:0, alternating Cb/Cr, for PAL-DV */
#define Y4M_CHROMA_444 3 /* 4:4:4, no subsampling, phew. */
#define Y4M_CHROMA_422 4 /* 4:2:2, H cosited */
#define Y4M_CHROMA_411 5 /* 4:1:1, H cosited */
#define Y4M_CHROMA_MONO 6 /* luma plane only */
#define Y4M_CHROMA_444ALPHA 7 /* 4:4:4 with an alpha channel */
/************************************************************************
* values for sampling parameters [y4m_*_spatial(), y4m_*_temporal()]
************************************************************************/
#define Y4M_SAMPLING_PROGRESSIVE 0
#define Y4M_SAMPLING_INTERLACED 1
/************************************************************************
* values for "presentation" parameter [y4m_*_presentation()]
************************************************************************/
#define Y4M_PRESENT_TOP_FIRST 0 /* top-field-first */
#define Y4M_PRESENT_TOP_FIRST_RPT 1 /* top-first, repeat top */
#define Y4M_PRESENT_BOTTOM_FIRST 2 /* bottom-field-first */
#define Y4M_PRESENT_BOTTOM_FIRST_RPT 3 /* bottom-first, repeat bottom */
#define Y4M_PRESENT_PROG_SINGLE 4 /* single progressive frame */
#define Y4M_PRESENT_PROG_DOUBLE 5 /* progressive frame, repeat once */
#define Y4M_PRESENT_PROG_TRIPLE 6 /* progressive frame, repeat twice */
#define Y4M_MAX_NUM_PLANES 4
/************************************************************************
* '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 (W:H)
************************************************************************/
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 */
extern const y4m_ratio_t y4m_sar_SQR_ANA16_9; /* anamorphic 16:9 sampled */
/* from 4:3 with square pixels */
/************************************************************************
* useful standard display aspect ratios (W:H)
************************************************************************/
extern const y4m_ratio_t y4m_dar_UNKNOWN;
extern const y4m_ratio_t y4m_dar_4_3; /* standard TV */
extern const y4m_ratio_t y4m_dar_16_9; /* widescreen TV */
extern const y4m_ratio_t y4m_dar_221_100; /* word-to-your-mother TV */
#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 y4m_xtag_list_t;
typedef struct _y4m_stream_info y4m_stream_info_t;
typedef struct _y4m_frame_info y4m_frame_info_t;
#ifdef __cplusplus
#define BEGIN_CDECLS extern "C" {
#define END_CDECLS }
#else
#define BEGIN_CDECLS
#define END_CDECLS
#endif
BEGIN_CDECLS
/************************************************************************
* '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)
/*************************************************************************
*
* Guess the true SAR (sample aspect ratio) from a list of commonly
* encountered values, given the "suggested" display aspect ratio (DAR),
* and the true frame width and height.
*
* Returns y4m_sar_UNKNOWN if no match is found.
*
*************************************************************************/
y4m_ratio_t y4m_guess_sar(int width, int height, y4m_ratio_t dar);
/*************************************************************************
*
* Chroma Subsampling Mode information
*
* x_ratio, y_ratio - subsampling of chroma planes
* x_offset, y_offset - offset of chroma sample grid,
* relative to luma (0,0) sample
*
*************************************************************************/
y4m_ratio_t y4m_chroma_ss_x_ratio(int chroma_mode);
y4m_ratio_t y4m_chroma_ss_y_ratio(int chroma_mode);
#if 0
y4m_ratio_t y4m_chroma_ss_x_offset(int chroma_mode, int field, int plane);
y4m_ratio_t y4m_chroma_ss_y_offset(int chroma_mode, int field, int plane);
#endif
/* Given a string containing a (case-insensitive) chroma-tag keyword,
return appropriate chroma mode (or Y4M_UNKNOWN) */
int y4m_chroma_parse_keyword(const char *s);
/* Given a Y4M_CHROMA_* mode, return appropriate chroma-tag keyword,
or NULL if there is none. */
const char *y4m_chroma_keyword(int chroma_mode);
/* Given a Y4M_CHROMA_* mode, return appropriate chroma mode description,
or NULL if there is none. */
const char *y4m_chroma_description(int chroma_mode);
/************************************************************************
* '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);
/* reset stream_info back to default/unknown values */
void y4m_clear_stream_info(y4m_stream_info_t *info);
/* make one stream_info into a copy of another */
void y4m_copy_stream_info(y4m_stream_info_t *dest,
const y4m_stream_info_t *src);
/* access or set stream_info fields */
/* level 0 */
int y4m_si_get_width(const y4m_stream_info_t *si);
int y4m_si_get_height(const y4m_stream_info_t *si);
int y4m_si_get_interlace(const y4m_stream_info_t *si);
y4m_ratio_t y4m_si_get_framerate(const y4m_stream_info_t *si);
y4m_ratio_t y4m_si_get_sampleaspect(const y4m_stream_info_t *si);
void y4m_si_set_width(y4m_stream_info_t *si, int width);
void y4m_si_set_height(y4m_stream_info_t *si, int height);
void y4m_si_set_interlace(y4m_stream_info_t *si, int interlace);
void y4m_si_set_framerate(y4m_stream_info_t *si, y4m_ratio_t framerate);
void y4m_si_set_sampleaspect(y4m_stream_info_t *si, y4m_ratio_t sar);
/* level 1 */
void y4m_si_set_chroma(y4m_stream_info_t *si, int chroma_mode);
int y4m_si_get_chroma(const y4m_stream_info_t *si);
/* derived quantities (no setter) */
/* level 0 */
int y4m_si_get_framelength(const y4m_stream_info_t *si);
/* level 1 */
int y4m_si_get_plane_count(const y4m_stream_info_t *si);
int y4m_si_get_plane_width(const y4m_stream_info_t *si, int plane);
int y4m_si_get_plane_height(const y4m_stream_info_t *si, int plane);
int y4m_si_get_plane_length(const y4m_stream_info_t *si, int plane);
/* 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);
/* reset frame_info back to default/unknown values */
void y4m_clear_frame_info(y4m_frame_info_t *info);
/* make one frame_info into a copy of another */
void y4m_copy_frame_info(y4m_frame_info_t *dest,
const y4m_frame_info_t *src);
/* access or set frame_info fields (level 1) */
int y4m_fi_get_presentation(const y4m_frame_info_t *fi);
int y4m_fi_get_temporal(const y4m_frame_info_t *fi);
int y4m_fi_get_spatial(const y4m_frame_info_t *fi);
void y4m_fi_set_presentation(y4m_frame_info_t *fi, int pres);
void y4m_fi_set_temporal(y4m_frame_info_t *fi, int sampling);
void y4m_fi_set_spatial(y4m_frame_info_t *fi, int sampling);
/* 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(int fd, void *buf, size_t len);
/* write len bytes from fd into buf */
ssize_t y4m_write(int fd, const void *buf, size_t len);
/************************************************************************
* callback based read and write
*
* The structures y4m_cb_reader_t and y4m_cb_writer_t must be
* set up by the caller before and of the *_read_*_cb() or
* *_write_*_cb() functions are called. Te return values of
* the read() and write() members have the same meaning as for
* y4m_read() and y4m_write()
*
************************************************************************/
typedef struct y4m_cb_reader_s
{
void * data;
ssize_t (*read)(void * data, void *buf, size_t len);
} y4m_cb_reader_t;
typedef struct y4m_cb_writer_s
{
void * data;
ssize_t (*write)(void * data, const void *buf, size_t len);
} y4m_cb_writer_t;
/* read len bytes from fd into buf */
ssize_t y4m_read_cb(y4m_cb_reader_t * fd, void *buf, size_t len);
/* write len bytes from fd into buf */
ssize_t y4m_write_cb(y4m_cb_writer_t * fd, const void *buf, size_t len);
/************************************************************************
* 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
(the current contents of stream_info are erased first) */
int y4m_read_stream_header(int fd, y4m_stream_info_t *i);
/* read a stream header with a callback reader
(the current contents of stream_info are erased first) */
int y4m_read_stream_header_cb(y4m_cb_reader_t * fd, y4m_stream_info_t *i);
/* write a stream header to file descriptor fd */
int y4m_write_stream_header(int fd, const y4m_stream_info_t *i);
/* write a stream header with a callback writer */
int y4m_write_stream_header_cb(y4m_cb_writer_t * fd, const y4m_stream_info_t *i);
/************************************************************************
* frame processing functions
*
* o return values:
* Y4M_OK - success
* Y4M_ERR_* - error (see y4m_strerr() for descriptions)
*
************************************************************************/
/* write a frame header to file descriptor fd */
int y4m_write_frame_header(int fd,
const y4m_stream_info_t *si,
const y4m_frame_info_t *fi);
/* write a frame header with a callback writer fd */
int y4m_write_frame_header_cb(y4m_cb_writer_t * fd,
const y4m_stream_info_t *si,
const y4m_frame_info_t *fi);
/* write a complete frame (header + data) to file descriptor fd
o planes[] points to 1-4 buffers, one each for image plane */
int y4m_write_frame(int fd, const y4m_stream_info_t *si,
const y4m_frame_info_t *fi, uint8_t * const *planes);
/* write a complete frame (header + data) with a callback writer fd
o planes[] points to 1-4 buffers, one each for image plane */
int y4m_write_frame_cb(y4m_cb_writer_t * fd, const y4m_stream_info_t *si,
const y4m_frame_info_t *fi, uint8_t * const *planes);
/* write a complete frame (header + data), to file descriptor fd
but interleave fields from two separate buffers
o upper_field[] same as planes[] above, but for upper field only
o lower_field[] same as planes[] above, but for lower field only
*/
int y4m_write_fields(int fd, const y4m_stream_info_t *si,
const y4m_frame_info_t *fi,
uint8_t * const *upper_field,
uint8_t * const *lower_field);
/* write a complete frame (header + data), with a callback writer fd
but interleave fields from two separate buffers
o upper_field[] same as planes[] above, but for upper field only
o lower_field[] same as planes[] above, but for lower field only
*/
int y4m_write_fields_cb(y4m_cb_writer_t * fd, const y4m_stream_info_t *si,
const y4m_frame_info_t *fi,
uint8_t * const *upper_field,
uint8_t * const *lower_field);
/* read a frame header from file descriptor fd
(the current contents of frame_info are erased first) */
int y4m_read_frame_header(int fd,
const y4m_stream_info_t *si,
y4m_frame_info_t *fi);
/* read a frame header with callback reader fd
(the current contents of frame_info are erased first) */
int y4m_read_frame_header_cb(y4m_cb_reader_t * fd,
const y4m_stream_info_t *si,
y4m_frame_info_t *fi);
/* read frame data from file descriptor fd
[to be called after y4m_read_frame_header()]
o planes[] points to 1-4 buffers, one each for image plane */
int y4m_read_frame_data(int fd, const y4m_stream_info_t *si,
y4m_frame_info_t *fi, uint8_t * const *planes);
/* read frame data with callback reader fd
[to be called after y4m_read_frame_header_cb()]
o planes[] points to 1-4 buffers, one each for image plane */
int y4m_read_frame_data_cb(y4m_cb_reader_t * fd, const y4m_stream_info_t *si,
y4m_frame_info_t *fi, uint8_t * const *planes);
/* read frame data from file descriptor fd,
but de-interleave fields into two separate buffers
[to be called after y4m_read_frame_header()]
o upper_field[] same as planes[] above, but for upper field only
o lower_field[] same as planes[] above, but for lower field only
*/
int y4m_read_fields_data(int fd, const y4m_stream_info_t *si,
y4m_frame_info_t *fi,
uint8_t * const *upper_field,
uint8_t * const *lower_field);
/* read frame data with callback reader fd,
but de-interleave fields into two separate buffers
[to be called after y4m_read_frame_header_cb()]
o upper_field[] same as planes[] above, but for upper field only
o lower_field[] same as planes[] above, but for lower field only
*/
int y4m_read_fields_data_cb(y4m_cb_reader_t * fd,
const y4m_stream_info_t *si,
y4m_frame_info_t *fi,
uint8_t * const *upper_field,
uint8_t * const *lower_field);
/* read a complete frame (header + data) from file descriptor fd,
o planes[] points to 1-4 buffers, one each for image plane */
int y4m_read_frame(int fd, const y4m_stream_info_t *si,
y4m_frame_info_t *fi, uint8_t * const *planes);
/* read a complete frame (header + data) from callback reader fd,
o planes[] points to 1-4 buffers, one each for image plane */
int y4m_read_frame_cb(y4m_cb_reader_t * fd, const y4m_stream_info_t *si,
y4m_frame_info_t *fi, uint8_t * const *planes);
/* read a complete frame (header + data) from file descriptor fd,
but de-interleave fields into two separate buffers
o upper_field[] same as planes[] above, but for upper field only
o lower_field[] same as planes[] above, but for lower field only
*/
int y4m_read_fields(int fd, const y4m_stream_info_t *si,
y4m_frame_info_t *fi,
uint8_t * const *upper_field,
uint8_t * const *lower_field);
/* read a complete frame (header + data) from callback_reader fd,
but de-interleave fields into two separate buffers
o upper_field[] same as planes[] above, but for upper field only
o lower_field[] same as planes[] above, but for lower field only
*/
int y4m_read_fields_cb(y4m_cb_reader_t * fd, const y4m_stream_info_t *si,
y4m_frame_info_t *fi,
uint8_t * const *upper_field,
uint8_t * const *lower_field);
/************************************************************************
* 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(log_level_t level, const char *prefix,
const 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);
/* set level of "accepted extensions" for the library...
o level = 0: default - conform to original YUV4MPEG2 spec; yield errors
when reading or writing a stream which exceeds it.
o level = 1: allow reading/writing streams which contain non-420jpeg
chroma and/or mixed-mode interlacing
o level = -1: don't change, just return current setting
return value: previous setting of level
*/
int y4m_accept_extensions(int level);
END_CDECLS
/************************************************************************
************************************************************************
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"
o unlimited number TAGGED-FIELDs, each preceded by ' ' separator
o '\n' line terminator
FRAME-HEADER consists of
o string "FRAME"
o unlimited number of TAGGED-FIELDs, each preceded by ' ' separator
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 non-whitespace 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
C - [string] chroma-subsampling/data format
420jpeg (default)
420mpeg2
420paldv
411
422
444 - non-subsampled Y'CbCr
444alpha - Y'CbCr with alpha channel (with Y' black/white point)
mono - Y' plane only
I - [char] interlacing: p - progressive (none)
t - top-field-first
b - bottom-field-first
m - mixed -- see 'I' tag in frame header
? - 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:
Ixyz - framing/sampling (required if-and-only-if stream is "Im")
x: t - top-field-first
T - top-field-first and repeat
b - bottom-field-first
B - bottom-field-first and repeat
1 - single progressive frame
2 - double progressive frame (repeat)
3 - triple progressive frame (repeat twice)
y: p - progressive: fields sampled at same time
i - interlaced: fields sampled at different times
z: p - progressive: subsampling over whole frame
i - interlaced: each field subsampled independently
? - unknown (allowed only for non-4:2:0 subsampling)
X - character string 'metadata' (unparsed, but passed around)
************************************************************************
************************************************************************/
/*
THAT'S ALL FOLKS!
Thank you for reading the source code. We hope you have thoroughly
enjoyed the experience.
*/
#ifdef INTERNAL_Y4M_LIBCODE_STUFF_QPX
#define Y4MPRIVATIZE(identifier) identifier
#else
#define Y4MPRIVATIZE(identifier) PRIVATE##identifier
#endif
/*
* Actual structure definitions of structures which you shouldn't touch.
*
*/
/************************************************************************
* '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.
************************************************************************/
struct _y4m_xtag_list {
int Y4MPRIVATIZE(count);
char *Y4MPRIVATIZE(tags)[Y4M_MAX_XTAGS];
};
/************************************************************************
* '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.
************************************************************************/
struct _y4m_stream_info {
/* values from header/setters */
int Y4MPRIVATIZE(width);
int Y4MPRIVATIZE(height);
int Y4MPRIVATIZE(interlace); /* see Y4M_ILACE_* definitions */
y4m_ratio_t Y4MPRIVATIZE(framerate); /* see Y4M_FPS_* definitions */
y4m_ratio_t Y4MPRIVATIZE(sampleaspect); /* see Y4M_SAR_* definitions */
int Y4MPRIVATIZE(chroma); /* see Y4M_CHROMA_* definitions */
/* mystical X tags */
y4m_xtag_list_t Y4MPRIVATIZE(x_tags);
};
/************************************************************************
* '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.
************************************************************************/
struct _y4m_frame_info {
int Y4MPRIVATIZE(spatial); /* see Y4M_SAMPLING_* definitions */
int Y4MPRIVATIZE(temporal); /* see Y4M_SAMPLING_* definitions */
int Y4MPRIVATIZE(presentation); /* see Y4M_PRESENT_* definitions */
/* mystical X tags */
y4m_xtag_list_t Y4MPRIVATIZE(x_tags);
};
#undef Y4MPRIVATIZE
#endif /* __YUV4MPEG_H__ */

View File

@@ -1,85 +0,0 @@
/*
* yuv4mpeg_intern.h: Internal constants for "new" YUV4MPEG streams
*
* Copyright (C) 2001 Andrew Stevens <andrew.stevens@philips.com>
* Copyright (C) 2001 Matthew J. Marjanovic <maddog@mir.com>
*
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __YUV4MPEG_INTERN_H__
#define __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_SQR_ANA_16_9 { 4, 3 }
#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_UNKNOWN { 0, 0 }
#define Y4M_DAR_4_3 { 4, 3 }
#define Y4M_DAR_16_9 { 16, 9 }
#define Y4M_DAR_221_100 { 221, 100 }
#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 /* __YUV4MPEG_INTERN_H__ */

View File

@@ -1,157 +0,0 @@
/*
* yuv4mpeg_ratio.c: Functions for dealing with y4m_ratio_t datatype.
*
* Copyright (C) 2001 Matthew J. Marjanovic <maddog@mir.com>
*
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#include <config.h>
#include <string.h>
#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;
const y4m_ratio_t y4m_fps_PAL = Y4M_FPS_PAL;
const y4m_ratio_t y4m_fps_NTSC = Y4M_FPS_NTSC;
const y4m_ratio_t y4m_fps_30 = Y4M_FPS_30;
const y4m_ratio_t y4m_fps_PAL_FIELD = Y4M_FPS_PAL_FIELD;
const y4m_ratio_t y4m_fps_NTSC_FIELD = Y4M_FPS_NTSC_FIELD;
const y4m_ratio_t y4m_fps_60 = Y4M_FPS_60;
/* useful list of standard sample aspect ratios */
const y4m_ratio_t y4m_sar_UNKNOWN = Y4M_SAR_UNKNOWN;
const y4m_ratio_t y4m_sar_SQUARE = Y4M_SAR_SQUARE;
const y4m_ratio_t y4m_sar_SQR_ANA_16_9 = Y4M_SAR_SQR_ANA_16_9;
const y4m_ratio_t y4m_sar_NTSC_CCIR601 = Y4M_SAR_NTSC_CCIR601;
const y4m_ratio_t y4m_sar_NTSC_16_9 = Y4M_SAR_NTSC_16_9;
const y4m_ratio_t y4m_sar_NTSC_SVCD_4_3 = Y4M_SAR_NTSC_SVCD_4_3;
const y4m_ratio_t y4m_sar_NTSC_SVCD_16_9 = Y4M_SAR_NTSC_SVCD_16_9;
const y4m_ratio_t y4m_sar_PAL_CCIR601 = Y4M_SAR_PAL_CCIR601;
const y4m_ratio_t y4m_sar_PAL_16_9 = Y4M_SAR_PAL_16_9;
const y4m_ratio_t y4m_sar_PAL_SVCD_4_3 = Y4M_SAR_PAL_SVCD_4_3;
const y4m_ratio_t y4m_sar_PAL_SVCD_16_9 = Y4M_SAR_PAL_SVCD_16_9;
/* useful list of standard display aspect ratios */
const y4m_ratio_t y4m_dar_UNKNOWN = Y4M_DAR_UNKNOWN;
const y4m_ratio_t y4m_dar_4_3 = Y4M_DAR_4_3;
const y4m_ratio_t y4m_dar_16_9 = Y4M_DAR_16_9;
const y4m_ratio_t y4m_dar_221_100 = Y4M_DAR_221_100;
/*
* Euler's algorithm for greatest common divisor
*/
static int gcd(int a, int b)
{
a = (a >= 0) ? a : -a;
b = (b >= 0) ? b : -b;
while (b > 0) {
int x = b;
b = a % b;
a = x;
}
return a;
}
/*************************************************************************
*
* Remove common factors from a ratio
*
*************************************************************************/
void y4m_ratio_reduce(y4m_ratio_t *r)
{
int d;
if ((r->n == 0) && (r->d == 0)) return; /* "unknown" */
d = gcd(r->n, r->d);
r->n /= d;
r->d /= d;
}
/*************************************************************************
*
* Parse "nnn:ddd" into a ratio
*
* returns: Y4M_OK - success
* Y4M_ERR_RANGE - range error
*
*************************************************************************/
int y4m_parse_ratio(y4m_ratio_t *r, const char *s)
{
char *t = strchr(s, ':');
if (t == NULL) return Y4M_ERR_RANGE;
r->n = atoi(s);
r->d = atoi(t+1);
if (r->d < 0) return Y4M_ERR_RANGE;
/* 0:0 == unknown, so that is ok, otherwise zero denominator is bad */
if ((r->d == 0) && (r->n != 0)) return Y4M_ERR_RANGE;
y4m_ratio_reduce(r);
return Y4M_OK;
}
/*************************************************************************
*
* Guess the true SAR (sample aspect ratio) from a list of commonly
* encountered values, given the "suggested" display aspect ratio, and
* the true frame width and height.
*
* Returns y4m_sar_UNKNOWN if no match is found.
*
*************************************************************************/
/* this is big enough to accommodate the difference between 720 and 704 */
#define GUESS_ASPECT_TOLERANCE 0.03
y4m_ratio_t y4m_guess_sar(int width, int height, y4m_ratio_t dar)
{
int i;
double implicit_sar = (double)(dar.n * height) / (double)(dar.d * width);
const y4m_ratio_t *sarray[] =
{
&y4m_sar_SQUARE,
&y4m_sar_NTSC_CCIR601,
&y4m_sar_NTSC_16_9,
&y4m_sar_NTSC_SVCD_4_3,
&y4m_sar_NTSC_SVCD_16_9,
&y4m_sar_PAL_CCIR601,
&y4m_sar_PAL_16_9,
&y4m_sar_PAL_SVCD_4_3,
&y4m_sar_PAL_SVCD_16_9,
&y4m_sar_UNKNOWN
};
for (i = 0; !(Y4M_RATIO_EQL(*(sarray[i]),y4m_sar_UNKNOWN)); i++) {
double ratio = implicit_sar / Y4M_RATIO_DBL(*(sarray[i]));
if ( (ratio > (1.0 - GUESS_ASPECT_TOLERANCE)) &&
(ratio < (1.0 + GUESS_ASPECT_TOLERANCE)) )
return *(sarray[i]);
}
return y4m_sar_UNKNOWN;
}

View File

@@ -2,20 +2,15 @@
MAINTAINERCLEANFILES = Makefile.in MAINTAINERCLEANFILES = Makefile.in
AM_CFLAGS=$(OP_CFLAGS) AM_CFLAGS=$(OP_CFLAGS)
INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src -I$(top_srcdir)/mjpeg $(VEEJAY_CFLAGS ) $(GTK_CFLAGS) \ INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src $(VEEJAY_CFLAGS ) $(GTK_CFLAGS) \
$(GLIB_CFLAGS) $(GLADE_CFLAGS) -DGNOMELOCALEDIR=\""$(datadir)/locale"\" -DGVEEJAY_DATADIR=\""$(gveejay_datadir)"\" $(GLIB_CFLAGS) $(GLADE_CFLAGS) -DGNOMELOCALEDIR=\""$(datadir)/locale"\" -DGVEEJAY_DATADIR=\""$(gveejay_datadir)"\"
GVEEJAY_BIN=reloaded GVEEJAY_BIN=reloaded
reloaded_SOURCES = widgets/gtkcolorsel.c widgets/gtkknob.c widgets/cellrendererspin.c widgets/gtktimeselection.c vj-midi.c curve.c utils.c tracksources.c gveejay.c keyboard.c sequence.c multitrack.c vj-api.c ${gveejay_headers} reloaded_SOURCES = widgets/gtkcolorsel.c widgets/gtkknob.c widgets/cellrendererspin.c widgets/gtktimeselection.c vj-midi.c curve.c utils.c tracksources.c gveejay.c keyboard.c sequence.c multitrack.c vj-api.c mjpeg_logging.c mpegconsts.c mpegtimecode.c yuv4mpeg.c yuv4mpeg_ratio.c ${gveejay_headers}
LAUNCHER_BIN=gveejay
gveejay_SOURCES = launcher.c ${gveejay_headers}
bin_PROGRAMS = $(GVEEJAY_BIN) bin_PROGRAMS = $(GVEEJAY_BIN)
gveejay_LDFLAGS= $(VEEJAY_LIBS) $(GTK_LIBS) $(GLIB_LIBS) $(GLADE_LIBS) -lgthread-2.0 -export-dynamic reloaded_LDFLAGS = $(VEEJAY_LIBS) $(GTK_LIBS) $(GLIB_LIBS)\
reloaded_LDFLAGS = -L$(top_builddir)/mjpeg/ -lmjpegutils $(VEEJAY_LIBS) $(GTK_LIBS) $(GLIB_LIBS)\
$(GLADE_LIBS) $(FFMPEG_AVCODEC_LIBS) $(FFMPEG_SWSCALER_LIBS) $(ALSA_LIBS) -lgthread-2.0 -export-dynamic $(GLADE_LIBS) $(FFMPEG_AVCODEC_LIBS) $(FFMPEG_SWSCALER_LIBS) $(ALSA_LIBS) -lgthread-2.0 -export-dynamic

View File

@@ -60,9 +60,10 @@ char *format_time(int pos, double fps)
{ {
static char temp[256]; static char temp[256];
MPEG_timecode_t tc; MPEG_timecode_t tc;
y4m_ratio_t r = mpeg_conform_framerate(fps);
mpeg_timecode(&tc, mpeg_timecode(&tc,
pos, pos,
mpeg_framerate_code(mpeg_conform_framerate(fps)), mpeg_framerate_code(r),
fps ); fps );
sprintf(temp, "%d:%2.2d:%2.2d:%2.2d",tc.h, tc.m, tc.s, tc.f ); sprintf(temp, "%d:%2.2d:%2.2d:%2.2d",tc.h, tc.m, tc.s, tc.f );
return strdup(temp); return strdup(temp);

View File

@@ -4941,11 +4941,14 @@ static void reload_editlist_contents()
if(nl < 0 || nl >= num_files) if(nl < 0 || nl >= num_files)
{ {
free(tmp);
g_free(eltext);
return; return;
} }
int file_len = _el_get_nframes( nl ); int file_len = _el_get_nframes( nl );
if(file_len <= 0) if(file_len <= 0)
{ {
free(tmp);
row_num++; row_num++;
continue; continue;
} }
@@ -4956,6 +4959,7 @@ static void reload_editlist_contents()
if(n2 <= n1 ) if(n2 <= n1 )
{ {
free(tmp);
row_num++; row_num++;
continue; continue;
} }