diff --git a/linux/Makefile b/linux/Makefile
index 50def5170..ac2f31a29 100644
--- a/linux/Makefile
+++ b/linux/Makefile
@@ -1,100 +1,75 @@
-# Comment out the following line if you don't have libpng
+SHELL = /bin/sh
-CPPFLAGS += -DGPAC_CONFIG_LINUX -D_FILE_OFFSET_BITS=64 -I../src/gpacmp4 -I../src/libpng/ -I../src/zlib/
-CFLAGS += -g -Wno-write-strings
+CC = gcc
+CXX = g++
-CXXFLAGS = $(CFLAGS)
-CC = $(CXX)
+CFLAGS = -O3
+ALL_FLAGS = -Wno-write-strings -DGPAC_CONFIG_LINUX -D_FILE_OFFSET_BITS=64
+LDFLAGS = -I../src/gpacmp4/ -I../src/libpng -I../src/zlib -lm -zmuldefs
-bindir = $(HOME)/bin
-INSTALL = cp -f -p
-INSTALL_PROGRAM = cp -f -p
+TARGET = ccextractor
+OBJS_DIR = objs
VPATH = ../src:../src/gpacmp4:../src/libpng:../src/zlib
-src_OBJS = \
- 608_helpers.o 608.o 608_sami.o 608_smptett.o 608_srt.o 608_spupng.o \
- 708_encoding.o 708.o activity.o asf_functions.o avc_functions.o \
- cc_bitstream.o cc_decoders_common.o ccextractor.o constants.o \
- encoding.o es_functions.o es_userdata.o file_functions.o \
- general_loop.o mp4.o myth.o output.o params_dump.o params.o \
- sequencing.o stream_functions.o telxcc.o timing.o ts_functions.o \
- utility.o wtv_functions.o xds.o dvb_subtitle_decoder.o ts_tables.o
-
-gpacmp4_OBJS = \
- avc_ext.o avilib.o av_parsers.o base_encoding.o bitstream.o \
- box_code_3gpp.o box_code_apple.o box_code_base.o box_code_isma.o \
- box_code_meta.o box_funcs.o data_map.o desc_private.o descriptors.o \
- error.o gpac_ogg.o hinting.o ipmpx_code.o ipmpx_parse.o \
- isom_intern.o isom_read.o isom_store.o isom_write.o list.o \
- media.o media_odf.o meta.o movie_fragments.o \
- odf_code.o odf_codec.o odf_command.o os_divers.o qos.o sample_descs.o \
- slc.o stbl_read.o stbl_write.o track.o tx3g.o url.o utf.o
-
-src_SRC = \
- ../src/608.cpp ../src/608_helpers.cpp ../src/608_sami.cpp \
- ../src/608_smptett.cpp ../src/608_spupng.cpp ../src/608_srt.cpp \
- ../src/708.cpp ../src/708_encoding.cpp ../src/activity.cpp \
- ../src/asf_functions.cpp ../src/avc_functions.cpp ../src/cc_bitstream.cpp \
- ../src/cc_decoders_common.cpp ../src/ccextractor.cpp ../src/constants.cpp \
- ../src/encoding.cpp ../src/es_functions.cpp ../src/es_userdata.cpp \
- ../src/file_functions.cpp ../src/general_loop.cpp ../src/myth.cpp \
- ../src/output.cpp ../src/params.cpp ../src/params_dump.cpp \
- ../src/sequencing.cpp ../src/stream_functions.cpp ../src/telxcc.cpp \
- ../src/timing.cpp ../src/ts_functions.cpp ../src/utility.cpp \
- ../src/wtv_functions.cpp ../src/xds.cpp ../src/dvb_subtitle_decoder.cpp \
- ../src/ts_tables.cpp
-
-gpacmp4_SRC = \
- ../src/gpacmp4/avc_ext.c ../src/gpacmp4/avilib.c \
- ../src/gpacmp4/av_parsers.c ../src/gpacmp4/base_encoding.c \
- ../src/gpacmp4/bitstream.c ../src/gpacmp4/box_code_3gpp.c \
- ../src/gpacmp4/box_code_apple.c ../src/gpacmp4/box_code_base.c \
- ../src/gpacmp4/box_code_isma.c ../src/gpacmp4/box_code_meta.c \
- ../src/gpacmp4/box_funcs.c ../src/gpacmp4/data_map.c \
- ../src/gpacmp4/desc_private.c ../src/gpacmp4/descriptors.c \
- ../src/gpacmp4/error.c ../src/gpacmp4/gpac_ogg.c \
- ../src/gpacmp4/hinting.c ../src/gpacmp4/ipmpx_code.c \
- ../src/gpacmp4/ipmpx_parse.c ../src/gpacmp4/isom_intern.c \
- ../src/gpacmp4/isom_read.c ../src/gpacmp4/isom_store.c \
- ../src/gpacmp4/isom_write.c ../src/gpacmp4/list.c \
- ../src/gpacmp4/media.c ../src/gpacmp4/media_odf.c \
- ../src/gpacmp4/meta.c ../src/gpacmp4/movie_fragments.c \
- ../src/gpacmp4/mp4.cpp ../src/gpacmp4/odf_code.c \
- ../src/gpacmp4/odf_codec.c ../src/gpacmp4/odf_command.c \
- ../src/gpacmp4/os_divers.c ../src/gpacmp4/qos.c \
- ../src/gpacmp4/sample_descs.c ../src/gpacmp4/slc.c \
- ../src/gpacmp4/stbl_read.c ../src/gpacmp4/stbl_write.c \
- ../src/gpacmp4/track.c ../src/gpacmp4/tx3g.c \
- ../src/gpacmp4/url.c ../src/gpacmp4/utf.c
-
-libpng_SRC = $(wildcard ../src/libpng/*.c)
-
-libpng_OBJS = $(libpng_SRC:.c=.o)
-
-zlib_SRC = \
- ../src/zlib/adler32.c ../src/zlib/crc32.c ../src/zlib/deflate.c \
- ../src/zlib/inffast.c ../src/zlib/inflate.c ../src/zlib/inftrees.c \
- ../src/zlib/trees.c ../src/zlib/zutil.c
-
-zlib_OBJS = \
- adler32.o crc32.o deflate.o inffast.o inflate.o inftrees.o \
- trees.o zutil.o
+SRCS_DIR = ../src
+SRCS_C = $(wildcard $(SRCS_DIR)/*.c)
+SRCS_CPP = $(wildcard $(SRCS_DIR)/*.cpp)
+OBJS = $(SRCS_C:$(SRCS_DIR)/%.c=$(OBJS_DIR)/%.o) \
+ $(SRCS_CPP:$(SRCS_DIR)/%.cpp=$(OBJS_DIR)/%.o)
+
+SRCS_PNG_DIR = $(SRCS_DIR)/libpng
+SRCS_PNG = $(wildcard $(SRCS_PNG_DIR)/*.c)
+OBJS_PNG = $(SRCS_PNG:$(SRCS_PNG_DIR)/%.c=$(OBJS_DIR)/%.o)
+
+SRCS_GPACMP4_DIR = $(SRCS_DIR)/gpacmp4
+SRCS_GPACMP4_C = $(wildcard $(SRCS_GPACMP4_DIR)/*.c)
+SRCS_GPACMP4_CPP = $(wildcard $(SRCS_GPACMP4_DIR)/*.cpp)
+OBJS_GPACMP4 = $(SRCS_GPACMP4_C:$(SRCS_GPACMP4_DIR)/%.c=$(OBJS_DIR)/%.o) \
+ $(SRCS_GPACMP4_CPP:$(SRCS_GPACMP4_DIR)/%.cpp=$(OBJS_DIR)/%.o)
+
+SRCS_ZLIB_DIR = $(SRCS_DIR)/zlib
+SRCS_ZLIB = $(wildcard $(SRCS_ZLIB_DIR)/*.c)
+OBJS_ZLIB = $(SRCS_ZLIB:$(SRCS_ZLIB_DIR)/%.c=$(OBJS_DIR)/%.o)
+
+INSTLALL = cp -f -p
+INSTLALL_PROGRAM = $(INSTLALL)
+DESTDIR = /usr/bin
.PHONY: all
-all: ccextractor
+all: objs_dir $(TARGET)
+
+.PHONY: objs_dir
+objs_dir:
+ mkdir -p $(OBJS_DIR)
+
+$(TARGET): $(OBJS) $(OBJS_PNG) $(OBJS_GPACMP4) $(OBJS_ZLIB)
+ $(CXX) $(ALL_FLAGS) $(CFLAGS) $(OBJS) $(OBJS_PNG) $(OBJS_GPACMP4) $(OBJS_ZLIB) $(LDFLAGS) -o $@
+
+$(OBJS_DIR)/%.o: %.c
+ $(CC) -c $(ALL_FLAGS) $(CFLAGS) $< -o $@ -I../src/gpacmp4
+
+$(OBJS_DIR)/%.o: %.cpp
+ $(CC) -c $(ALL_FLAGS) $(CFLAGS) $< -o $@ -I../src/gpacmp4
.PHONY: clean
clean:
- rm -f *.o ccextractor depend
-
-ccextractor: $(src_OBJS) $(gpacmp4_OBJS) $(libpng_OBJS) $(zlib_OBJS)
+ rm $(TARGET) 2>/dev/null || true
+ rm $(OBJS_PNG) $(OBJS_ZLIB) $(OBJS_GPACMP4) $(OBJS) 2>/dev/null || true
+ rm -rd $(OBJS_DIR) 2>/dev/null || true
+ rm .depend 2>/dev/null || true
.PHONY: install
-install: ccextractor
- $(INSTALL_PROGRAM) ccextractor $(bindir)
+install: $(TARGET)
+ $(INSTLALL_PROGRAM) $(TARGET) $(DESTDIR)
+
+.PHONY: uninstall
+uninstall:
+ rm -iv $(DESTDIR)/$(TARGET)
-depend:
- $(CXX) $(CXXFLAGS) -E -MM $(src_SRC) $(gpacmp4_SRC) $(libpng_SRC) $(zlib_SRC) > depend
+.PHONY: depend dep
+depend dep:
+ $(CXX) $(CXXFLAGS) -E -MM $(SRCS_C) $(SRCS_CPP) $(SRCS_PNG) $(SRCS_ZLIB) \
+ $(SRCS_GPACMP4_C) $(SRCS_GPACMP4_CPP) > .depend
-include depend
+-include .depend
diff --git a/linux/build b/linux/build
index e91b6e68b..c17a1eee3 100644
--- a/linux/build
+++ b/linux/build
@@ -1,2 +1,2 @@
#!/bin/bash
-g++ -Wno-write-strings -DGPAC_CONFIG_LINUX -D_FILE_OFFSET_BITS=64 -I../src/gpacmp4/ -I../src/libpng/ -I../src/zlib/ -o ccextractor $(find ../src/ -name '*.cpp') $(find ../src/ -name '*.c')
+make
diff --git a/linux/builddebug b/linux/builddebug
index 4e199e990..53fbd4fad 100644
--- a/linux/builddebug
+++ b/linux/builddebug
@@ -1,2 +1,2 @@
#!/bin/bash
-g++ -Wno-write-strings -g -DGPAC_CONFIG_LINUX -D_FILE_OFFSET_BITS=64 -I../src/gpacmp4/ -I../src/libpng/ -I../src/zlib/ -o ccextractor $(find ../src/ -name '*.cpp') $(find ../src/ -name '*.c')
+make CFLAGS="-g -O0"
diff --git a/src/608_spupng.cpp b/src/608_spupng.cpp
index 250e05e85..4c49e5023 100644
--- a/src/608_spupng.cpp
+++ b/src/608_spupng.cpp
@@ -24,66 +24,83 @@ void
write_spumux_header(struct s_context_cc608 *context)
{
if (0 == context->spupng_data)
- context->spupng_data = new SpuPng(context);
- ((SpuPng*)context->spupng_data)->writeHeader();
+ context->spupng_data = spunpg_init(context);
+
+ spupng_write_header((struct spupng_t*)context->spupng_data);
}
void
write_spumux_footer(struct s_context_cc608 *context)
{
- if (0 != context->spupng_data)
+ if (0 != context->spupng_data)
{
- ((SpuPng*)context->spupng_data)->writeFooter();
- delete (SpuPng*)context->spupng_data;
- context->spupng_data = 0;
- context->out->fh = -1;
+ struct spupng_t *sp = (struct spupng_t *) context->spupng_data;
+
+ spupng_write_footer(sp);
+ spunpg_free(sp);
+
+ context->spupng_data = 0;
+ context->out->fh = -1;
}
}
int
write_cc_buffer_as_spupng(struct eia608_screen *data, struct s_context_cc608 *context)
{
- if (0 != context->spupng_data)
+ if (0 != context->spupng_data)
{
- return ((SpuPng*)context->spupng_data)->writeCCBuffer(data, context);
+ struct spupng_t *sp = (struct spupng_t *) context->spupng_data;
+ return spupng_write_ccbuffer(sp, data, context);
}
return 0;
}
static int initialized = 0;
-SpuPng::SpuPng(struct s_context_cc608 *context)
+struct spupng_t *spunpg_init(struct s_context_cc608 *context)
{
+ struct spupng_t *sp = (struct spupng_t *) malloc(sizeof(struct spupng_t));
+ if (NULL == sp)
+ fatal(EXIT_NOT_ENOUGH_MEMORY, "Memory allocation failed");
+
if (!initialized)
{
initialized = 1;
- initFont();
+ spupng_init_font();
}
- if ((fpxml = fdopen(context->out->fh, "w")) == NULL)
+ if ((sp->fpxml = fdopen(context->out->fh, "w")) == NULL)
{
- fatal(EXIT_FILE_CREATION_FAILED, "Cannot open %s: %s\n", context->out->filename, strerror(errno));
+ fatal(EXIT_FILE_CREATION_FAILED, "Cannot open %s: %s\n",
+ context->out->filename, strerror(errno));
}
- dirname = new char [strlen(context->out->filename) + 3];
- strcpy(dirname, context->out->filename);
- char* p = strrchr(dirname, '.');
- if (0 == p)
- p = dirname + strlen(dirname);
+ sp->dirname = (char *) malloc(
+ sizeof(char) * (strlen(context->out->filename) + 3));
+ if (NULL == sp)
+ fatal(EXIT_NOT_ENOUGH_MEMORY, "Memory allocation failed");
+
+ strcpy(sp->dirname, context->out->filename);
+ char* p = strrchr(sp->dirname, '.');
+ if (NULL == p)
+ p = sp->dirname + strlen(sp->dirname);
*p = '\0';
- strcat(dirname, ".d");
- if (mkdir(dirname, 0777) != 0)
+ strcat(sp->dirname, ".d");
+ if (0 != mkdir(sp->dirname, 0777))
{
if (errno != EEXIST)
{
- fatal(EXIT_FILE_CREATION_FAILED, "Cannot create %s: %s\n", dirname, strerror(errno));
+ fatal(EXIT_FILE_CREATION_FAILED, "Cannot create %s: %s\n",
+ sp->dirname, strerror(errno));
}
// If dirname isn't a directory or if we don't have write permission,
- // the first attempt to create a .png file will fail and we'll exit.
+ // the first attempt to create a .png file will fail and we'll XXxit.
}
// enough to append /subNNNN.png
- pngfile = new char [ strlen(dirname) + 13 ];
- fileIndex = 0;
+ sp->pngfile = (char *) malloc(sizeof(char) * (strlen(sp->dirname) + 13));
+ if (NULL == sp)
+ fatal(EXIT_NOT_ENOUGH_MEMORY, "Memory allocation failed");
+ sp->fileIndex = 0;
// For NTSC closed captions and 720x480 DVD subtitle resolution:
// Each character is 16x26.
@@ -92,35 +109,39 @@ SpuPng::SpuPng(struct s_context_cc608 *context)
// To center image in 720x480 DVD screen, offset image by 88 and 45
// Need to keep yOffset even to prevent flicker on interlaced displays
// Would need to do something different for PAL format and teletext.
- xOffset = 88;
- yOffset = 46;
+ sp->xOffset = 88;
+ sp->yOffset = 46;
+
+ return sp;
}
-SpuPng::~SpuPng()
+void
+spunpg_free(struct spupng_t *sp)
{
- delete [] dirname;
- delete [] pngfile;
+ free(sp->dirname);
+ free(sp->pngfile);
+ free(sp);
}
-
-void
-SpuPng::writeHeader()
+void
+spupng_write_header(struct spupng_t *sp)
{
- fprintf(fpxml, "\n\n");
+ fprintf(sp->fpxml, "\n\n");
if (num_input_files > 0)
- fprintf(fpxml, "\n", inputfile[0]);
+ fprintf(sp->fpxml, "\n", inputfile[0]);
}
-void
-SpuPng::writeFooter()
+void
+spupng_write_footer(struct spupng_t *sp)
{
- fprintf(fpxml, "\n\n");
- fflush(fpxml);
- fclose(fpxml);
+ fprintf(sp->fpxml, "\n\n");
+ fflush(sp->fpxml);
+ fclose(sp->fpxml);
}
int
-SpuPng::writeCCBuffer(struct eia608_screen* data, struct s_context_cc608 *context)
+spupng_write_ccbuffer(struct spupng_t *sp, struct eia608_screen* data,
+ struct s_context_cc608 *context)
{
LLONG ms_start = context->current_visible_start_ms + subs_delay;
if (ms_start < 0)
@@ -145,30 +166,32 @@ SpuPng::writeCCBuffer(struct eia608_screen* data, struct s_context_cc608 *contex
return 0;
}
- LLONG ms_end=get_visible_end()+subs_delay;
+ LLONG ms_end = get_visible_end() + subs_delay;
- sprintf(pngfile, "%s/sub%04d.png", dirname, fileIndex++);
- if ((fppng = fopen(pngfile, "wb")) == NULL)
+ sprintf(sp->pngfile, "%s/sub%04d.png", sp->dirname, sp->fileIndex++);
+ if ((sp->fppng = fopen(sp->pngfile, "wb")) == NULL)
{
- fatal(EXIT_FILE_CREATION_FAILED, "Cannot open %s: %s\n", pngfile, strerror(errno));
+ fatal(EXIT_FILE_CREATION_FAILED, "Cannot open %s: %s\n",
+ sp->pngfile, strerror(errno));
}
- if (!exportPNG(data))
+ if (!spupng_export_png(sp, data))
{
- fatal(EXIT_FILE_CREATION_FAILED, "Cannot write %s: %s\n", pngfile, strerror(errno));
+ fatal(EXIT_FILE_CREATION_FAILED, "Cannot write %s: %s\n",
+ sp->pngfile, strerror(errno));
}
- fclose(fppng);
+ fclose(sp->fppng);
- fprintf(fpxml, "fpxml, "fpxml, " end=\"%.3f\"", ((double)ms_end) / 1000);
dbg_print(CCX_DMT_608, " end=\"%.3f\"", ((double)ms_end) / 1000);
- fprintf(fpxml, " image=\"%s\"", pngfile);
- dbg_print(CCX_DMT_608, " image=\"%s\"", pngfile);
- fprintf(fpxml, " xoffset=\"%d\"", xOffset);
- dbg_print(CCX_DMT_608, " xoffset=\"%d\"", xOffset);
- fprintf(fpxml, " yoffset=\"%d\"", yOffset);
- dbg_print(CCX_DMT_608, " yoffset=\"%d\"", yOffset);
- fprintf(fpxml, ">\n\n");
+ fprintf(sp->fpxml, "-->\n");
dbg_print(CCX_DMT_608, "-->\n");
- fflush(fpxml);
+ fflush(sp->fpxml);
return 1;
}
@@ -210,8 +233,8 @@ SpuPng::writeCCBuffer(struct eia608_screen* data, struct s_context_cc608 *contex
// Begin copy from http://zapping.cvs.sourceforge.net/viewvc/zapping/vbi/src/exp-gfx.c?view=markup&pathrev=zvbi-0-2-33
//
-void
-SpuPng::initFont(void)
+void
+spupng_init_font()
{
uint8_t *t, *p;
int i, j;
@@ -230,7 +253,7 @@ SpuPng::initFont(void)
free (t);
#endif
if (!(t = (uint8_t*)malloc(ccfont2_width * ccfont2_height / 8)))
- exit(EXIT_FAILURE);
+ fatal(EXIT_NOT_ENOUGH_MEMORY, "Memory allocation failed");
for (p = t, i = 0; i < CCH; i++)
for (j = 0; j < ccfont2_height; p += ccfont2_width / 8, j += CCH)
@@ -480,20 +503,19 @@ static png_byte alpha[10] =
0
};
-int
-SpuPng::writePNG(struct eia608_screen* data,
- png_structp png_ptr, png_infop info_ptr,
- png_bytep image,
- png_bytep* row_pointer,
- unsigned int ww,
- unsigned int wh)
+int
+spupng_write_png(struct spupng_t *sp, struct eia608_screen* data,
+ png_structp png_ptr, png_infop info_ptr,
+ png_bytep image,
+ png_bytep* row_pointer,
+ unsigned int ww, unsigned int wh)
{
unsigned int i;
if (setjmp(png_jmpbuf(png_ptr)))
return 0;
- png_init_io (png_ptr, fppng);
+ png_init_io (png_ptr, sp->fppng);
png_set_IHDR (png_ptr,
info_ptr,
@@ -522,8 +544,8 @@ SpuPng::writePNG(struct eia608_screen* data,
return 1;
}
-int
-SpuPng::exportPNG(struct eia608_screen* data)
+int
+spupng_export_png(struct spupng_t *sp, struct eia608_screen* data)
{
png_structp png_ptr;
png_infop info_ptr;
@@ -575,7 +597,7 @@ SpuPng::exportPNG(struct eia608_screen* data)
goto unknown_error;
}
- if (!writePNG (data, png_ptr, info_ptr, image, row_pointer, ww, wh)) {
+ if (!spupng_write_png (sp, data, png_ptr, info_ptr, image, row_pointer, ww, wh)) {
png_destroy_write_struct (&png_ptr, &info_ptr);
goto write_error;
}
diff --git a/src/608_spupng.h b/src/608_spupng.h
index 92be8011c..5b79d1290 100644
--- a/src/608_spupng.h
+++ b/src/608_spupng.h
@@ -3,34 +3,35 @@
#include "png.h"
#include "ccextractor.h"
-class SpuPng
+struct spupng_t
{
- public:
- SpuPng(struct s_context_cc608 *context);
- ~SpuPng();
-
- void writeHeader();
- void writeFooter();
-
- int writeCCBuffer(struct eia608_screen* data, struct s_context_cc608 *context);
-
- private:
- static void initFont(void);
- int writePNG(struct eia608_screen* data,
- png_structp png_ptr, png_infop info_ptr,
- png_bytep image,
- png_bytep* row_pointer,
- unsigned int ww,
- unsigned int wh);
- int exportPNG(struct eia608_screen* data);
-
- FILE* fpxml;
- FILE* fppng;
- char* dirname;
- char* pngfile;
- int fileIndex;
- int xOffset;
- int yOffset;
+ FILE* fpxml;
+ FILE* fppng;
+ char* dirname;
+ char* pngfile;
+ int fileIndex;
+ int xOffset;
+ int yOffset;
};
+struct spupng_t *spunpg_init(struct s_context_cc608 *context);
+void spunpg_free(struct spupng_t *spupng);
+
+void spupng_write_header(struct spupng_t *spupng);
+void spupng_write_footer(struct spupng_t *spupng);
+
+int spupng_write_ccbuffer(struct spupng_t *spupng, struct eia608_screen* data,
+ struct s_context_cc608 *context);
+
+void spupng_init_font();
+
+int spupng_write_png(struct spupng_t *spupng,
+ struct eia608_screen* data,
+ png_structp png_ptr, png_infop info_ptr,
+ png_bytep image,
+ png_bytep* row_pointer,
+ unsigned int ww, unsigned int wh);
+
+int spupng_export_png(struct spupng_t *spupng, struct eia608_screen* data);
+
#endif /* __608_SPUPNG_H__ */