Skip to content

Commit

Permalink
build, codec-cfg.c: simplify builtin codecs.conf handling
Browse files Browse the repository at this point in the history
The player can read codec mapping (codecs.conf) from an external file
or use embedded defaults. Before, the defaults were stored in the
player binary in the form of final already-parsed data structures.
Simplify things by storing the text of the codecs.conf file instead,
and parse that at runtime the same way an external file would be
parsed.

To create the previous parsed form, the build system first compiled a
separate binary named "codec-cfg", which parsed etc/codecs.conf and
then wrote the results as a C data structure that could be compiled
into the program. The new simple conversion of codecs.conf into a C
string is handled by the new script TOOLS/file2string.py.

After removing the codec-cfg binary, HOST_CC is no longer used for
anything. Remove the --host-cc configure option and associated logic.

Also remove the codec2html and codec-cfg-test functionality. Building
those was already broken and nobody cared.

There was a broken 3-character-long "fourcc" entry in etc/codecs.conf.
This happened to be accepted before but triggered a parse error after
the changes. Remove the broken entry and make the parsing functions
explicitly test for this error.
  • Loading branch information
Uoti Urpala committed Jul 16, 2012
1 parent 39a45c7 commit 2ba8b91
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 598 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
/version.h
/codecs.conf.h
/codec-cfg
/codec-cfg-test
/codecs2html
/cpuinfo
/tags
/TAGS
Expand Down
181 changes: 0 additions & 181 deletions DOCS/tech/codecs-in.html

This file was deleted.

17 changes: 4 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -592,11 +592,8 @@ mplayer$(EXESUF): EXTRALIBS += $(EXTRALIBS_MPLAYER)
mplayer$(EXESUF):
$(CC) -o $@ $^ $(EXTRALIBS)

codec-cfg$(EXESUF): codec-cfg.c codec-cfg.h
$(HOST_CC) -O -DCODECS2HTML -I. -o $@ $<

codecs.conf.h: codec-cfg$(EXESUF) etc/codecs.conf
./$^ > $@
codecs.conf.h: TOOLS/file2string.py etc/codecs.conf
./$^ >$@

libvo/vdpau_template.c: TOOLS/vdpau_functions.py
./$< > $@
Expand Down Expand Up @@ -716,7 +713,7 @@ distclean: clean testsclean toolsclean driversclean
-$(RM) config.log config.mak config.h codecs.conf.h version.h TAGS tags
-$(RM) libvo/vdpau_template.c
-$(RM) libmpdemux/ebml_types.h libmpdemux/ebml_defs.c
-$(RM) $(call ADD_ALL_EXESUFS,codec-cfg cpuinfo)
-$(RM) $(call ADD_ALL_EXESUFS,cpuinfo)

doxygen:
doxygen DOCS/tech/Doxyfile
Expand All @@ -731,18 +728,12 @@ tags:

TEST_OBJS = mp_msg.o mp_fifo.o osdep/$(GETCH) osdep/$(TIMER) -ltermcap -lm

codec-cfg-test$(EXESUF): codec-cfg.c codecs.conf.h $(TEST_OBJS)
$(CC) -I. -DTESTING -o $@ $^

codecs2html$(EXESUF): codec-cfg.c $(TEST_OBJS)
$(CC) -I. -DCODECS2HTML -o $@ $^

LOADER_TEST_OBJS = $(SRCS_WIN32_EMULATION:.c=.o) $(SRCS_QTX_EMULATION:.S=.o) libavutil/libavutil.a osdep/mmap_anon.o cpudetect.o path.o $(TEST_OBJS)

loader/qtx/list$(EXESUF) loader/qtx/qtxload$(EXESUF): CFLAGS += -g
loader/qtx/list$(EXESUF) loader/qtx/qtxload$(EXESUF): $(LOADER_TEST_OBJS)

TESTS = codecs2html codec-cfg-test
TESTS =

ifdef ARCH_X86
TESTS += loader/qtx/list loader/qtx/qtxload
Expand Down
23 changes: 23 additions & 0 deletions TOOLS/file2string.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python3

# Convert the contents of a file into a C string constant.
# Note that the compiler will implicitly add an extra 0 byte at the end
# of every string, so code using the string may need to remove that to get
# the exact contents of the original file.

import sys

def main(infile):
conv = ['\\' + oct(c)[2:] for c in range(256)]
safe_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" \
"0123456789!#%&'()*+,-./:;<=>?[]^_{|}~ "
for c in safe_chars:
conv[ord(c)] = c
for c, esc in ("\nn", "\tt", r"\\", '""'):
conv[ord(c)] = '\\' + esc
for line in infile:
sys.stdout.write('"' + ''.join(conv[c] for c in line) + '"\n')

with open(sys.argv[1], 'rb') as infile:
sys.stdout.write("// Generated from %s\n\n" % sys.argv[1])
main(infile)
10 changes: 10 additions & 0 deletions bstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ struct bstr *bstr_splitlines(void *talloc_ctx, struct bstr str)
return r;
}

struct bstr bstr_getline(struct bstr str, struct bstr *rest)
{
int pos = bstrchr(str, '\n');
if (pos < 0)
pos = str.len;
if (rest)
*rest = bstr_cut(str, pos + 1);
return bstr_splice(str, 0, pos + 1);
}

bool bstr_eatstart(struct bstr *s, struct bstr prefix)
{
if (!bstr_startswith(*s, prefix))
Expand Down
6 changes: 6 additions & 0 deletions bstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ int bstrcspn(struct bstr str, const char *reject);

int bstr_find(struct bstr haystack, struct bstr needle);
struct bstr *bstr_splitlines(void *talloc_ctx, struct bstr str);
struct bstr bstr_getline(struct bstr str, struct bstr *rest);
struct bstr bstr_lstrip(struct bstr str);
struct bstr bstr_strip(struct bstr str);
struct bstr bstr_split(struct bstr str, const char *sep, struct bstr *rest);
Expand Down Expand Up @@ -135,6 +136,11 @@ static inline int bstr_find0(struct bstr haystack, const char *needle)
return bstr_find(haystack, bstr(needle));
}

static inline int bstr_eatstart0(struct bstr *s, char *prefix)
{
return bstr_eatstart(s, bstr(prefix));
}

#endif

// create a pair (not single value!) for "%.*s" printf syntax
Expand Down
Loading

0 comments on commit 2ba8b91

Please sign in to comment.