shithub: opusfile

Download patch

ref: 5e3c66ce81e8bb667374dab8141c6c3351b82c69
parent: efc0d57af6862fb77b3a0fad21d32c6fd42106d8
author: Timothy B. Terriberry <[email protected]>
date: Sun May 12 14:53:27 EDT 2013

Move last few URL functions into http.c

This makes it easier to split http.c and friends into their own
 library.
This allows distributions to ship a libopusfile with generic Opus
 parsing support, and a libopusurl with http/https support.
Keeping the latter in a separate library means that GPL
 applications don't have to link against the GPL-incompatible
 openssl, and distributions don't have to disable http support to
 allow GPL applications to use libopusfile.

--- a/src/http.c
+++ b/src/http.c
@@ -3220,3 +3220,51 @@
   va_end(ap);
   return ret;
 }
+
+/*Convenience routines to open/test URLs in a single step.*/
+
+OggOpusFile *op_vopen_url(const char *_url,int *_error,va_list _ap){
+  OpusFileCallbacks  cb;
+  OggOpusFile       *of;
+  void              *source;
+  source=op_url_stream_vcreate(&cb,_url,_ap);
+  if(OP_UNLIKELY(source==NULL)){
+    if(_error!=NULL)*_error=OP_EFAULT;
+    return NULL;
+  }
+  of=op_open_callbacks(source,&cb,NULL,0,_error);
+  if(OP_UNLIKELY(of==NULL))(*cb.close)(source);
+  return of;
+}
+
+OggOpusFile *op_open_url(const char *_url,int *_error,...){
+  OggOpusFile *ret;
+  va_list      ap;
+  va_start(ap,_error);
+  ret=op_vopen_url(_url,_error,ap);
+  va_end(ap);
+  return ret;
+}
+
+OggOpusFile *op_vtest_url(const char *_url,int *_error,va_list _ap){
+  OpusFileCallbacks  cb;
+  OggOpusFile       *of;
+  void              *source;
+  source=op_url_stream_vcreate(&cb,_url,_ap);
+  if(OP_UNLIKELY(source==NULL)){
+    if(_error!=NULL)*_error=OP_EFAULT;
+    return NULL;
+  }
+  of=op_test_callbacks(source,&cb,NULL,0,_error);
+  if(OP_UNLIKELY(of==NULL))(*cb.close)(source);
+  return of;
+}
+
+OggOpusFile *op_test_url(const char *_url,int *_error,...){
+  OggOpusFile *ret;
+  va_list      ap;
+  va_start(ap,_error);
+  ret=op_vtest_url(_url,_error,ap);
+  va_end(ap);
+  return ret;
+}
--- a/src/opusfile.c
+++ b/src/opusfile.c
@@ -1611,21 +1611,6 @@
    _error);
 }
 
-OggOpusFile *op_vopen_url(const char *_url,int *_error,va_list _ap){
-  OpusFileCallbacks cb;
-  return op_open_close_on_failure(op_url_stream_vcreate(&cb,_url,_ap),&cb,
-   _error);
-}
-
-OggOpusFile *op_open_url(const char *_url,int *_error,...){
-  OggOpusFile *ret;
-  va_list      ap;
-  va_start(ap,_error);
-  ret=op_vopen_url(_url,_error,ap);
-  va_end(ap);
-  return ret;
-}
-
 /*Convenience routine to clean up from failure for the open functions that
    create their own streams.*/
 static OggOpusFile *op_test_close_on_failure(void *_source,
@@ -1650,21 +1635,6 @@
   OpusFileCallbacks cb;
   return op_test_close_on_failure(op_mem_stream_create(&cb,_data,_size),&cb,
    _error);
-}
-
-OggOpusFile *op_vtest_url(const char *_url,int *_error,va_list _ap){
-  OpusFileCallbacks cb;
-  return op_test_close_on_failure(op_url_stream_vcreate(&cb,_url,_ap),&cb,
-   _error);
-}
-
-OggOpusFile *op_test_url(const char *_url,int *_error,...){
-  OggOpusFile *ret;
-  va_list      ap;
-  va_start(ap,_error);
-  ret=op_vtest_url(_url,_error,ap);
-  va_end(ap);
-  return ret;
 }
 
 int op_test_open(OggOpusFile *_of){
--- a/unix/Makefile
+++ b/unix/Makefile
@@ -5,6 +5,7 @@
 TARGETLIBDIR = .
 # Name of the targets
 LIBOPUSFILE_TARGET = libopusfile.a
+LIBOPUSURL_TARGET = libopusurl.a
 OPUSFILE_EXAMPLE_TARGET = opusfile_example
 SEEKING_EXAMPLE_TARGET = seeking_example
 # Test targets
@@ -70,11 +71,17 @@
 opusfile.c \
 stream.c \
 
+LIBOPUSFILE_CHEADERS = \
+internal.h \
+
+LIBOPUSURL_CSOURCES = \
+http.c \
+
 ifneq ($(findstring mingw,${CC}),)
-LIBOPUSFILE_CSOURCES += wincerts.c
+LIBOPUSURL_CSOURCES += wincerts.c
 endif
 
-LIBOPUSFILE_CHEADERS = \
+LIBOPUSURL_CHEADERS = \
 internal.h \
 
 OPUSFILE_EXAMPLE_CSOURCES = opusfile_example.c
@@ -87,6 +94,9 @@
 LIBOPUSFILE_OBJS:= ${LIBOPUSFILE_CSOURCES:%.c=${WORKDIR}/%.o}
 LIBOPUSFILE_ASMS:= ${LIBOPUSFILE_OBJS:%.o=%.s}
 LIBOPUSFILE_DEPS:= ${LIBOPUSFILE_OBJS:%.o=%.d}
+LIBOPUSURL_OBJS:= ${LIBOPUSURL_CSOURCES:%.c=${WORKDIR}/%.o}
+LIBOPUSURL_ASMS:= ${LIBOPUSURL_OBJS:%.o=%.s}
+LIBOPUSURL_DEPS:= ${LIBOPUSURL_OBJS:%.o=%.d}
 OPUSFILE_EXAMPLE_OBJS:= ${OPUSFILE_EXAMPLE_CSOURCES:%.c=${WORKDIR}/%.o}
 SEEKING_EXAMPLE_OBJS:= ${SEEKING_EXAMPLE_CSOURCES:%.c=${WORKDIR}/%.o}
 #TODO: tests
@@ -93,6 +103,7 @@
 FOO_OBJS:= ${FOO_CSOURCES:%.c=${WORKDIR}/%.o}
 ALL_OBJS:= \
  ${LIBOPUSFILE_OBJS} \
+ ${LIBOPUSURL_OBJS} \
  ${OPUSFILE_EXAMPLE_OBJS} \
  ${SEEKING_EXAMPLE_OBJS} \
 
@@ -104,6 +115,8 @@
 # Prepend source path to file names.
 LIBOPUSFILE_CSOURCES:= ${LIBOPUSFILE_CSOURCES:%=${LIBSRCDIR}/%}
 LIBOPUSFILE_CHEADERS:= ${LIBOPUSFILE_CHEADERS:%=${LIBSRCDIR}/%}
+LIBOPUSURL_CSOURCES:= ${LIBOPUSURL_CSOURCES:%=${LIBSRCDIR}/%}
+LIBOPUSURL_CHEADERS:= ${LIBOPUSURL_CHEADERS:%=${LIBSRCDIR}/%}
 OPUSFILE_EXAMPLE_CSOURCES:= ${OPUSFILE_EXAMPLE_CSOURCES:%=${BINSRCDIR}/%}
 SEEKING_EXAMPLE_CSOURCES:= ${SEEKING_EXAMPLE_CSOURCES:%=${BINSRCDIR}/%}
 #TODO: tests
@@ -110,6 +123,7 @@
 FOO_CSOURCES:= ${FOO_CSOURCES:%=${TESTSRCDIR}/%}
 ALL_CSOURCES:= \
  ${LIBOPUSFILE_CSOURCES} \
+ ${LIBOPUSURL_CSOURCES} \
  ${OPUSFILE_EXAMPLE_CSOURCES} \
  ${SEEKING_EXAMPLE_CSOURCES} \
 
@@ -117,6 +131,7 @@
 # ${FOO_CSOURCES} \
 # Prepand target path to file names.
 LIBOPUSFILE_TARGET:= ${TARGETLIBDIR}/${LIBOPUSFILE_TARGET}
+LIBOPUSURL_TARGET:= ${TARGETLIBDIR}/${LIBOPUSURL_TARGET}
 OPUSFILE_EXAMPLE_TARGET:= ${TARGETBINDIR}/${OPUSFILE_EXAMPLE_TARGET}${EXEEXT}
 SEEKING_EXAMPLE_TARGET:= ${TARGETBINDIR}/${SEEKING_EXAMPLE_TARGET}${EXEEXT}
 # Prepend test path to file names.
@@ -125,6 +140,7 @@
 # Complete set of targets
 ALL_TARGETS:= \
  ${LIBOPUSFILE_TARGET} \
+ ${LIBOPUSURL_TARGET} \
  ${OPUSFILE_EXAMPLE_TARGET} \
  ${SEEKING_EXAMPLE_TARGET} \
 
@@ -141,17 +157,25 @@
 	$(AR) cqs $@ ${LIBOPUSFILE_OBJS}
 	-$(RANLIB) $@
 
+# libopusurl
+${LIBOPUSURL_TARGET}: ${LIBOPUSURL_OBJS}
+	mkdir -p ${TARGETLIBDIR}
+	$(AR) cqs $@ ${LIBOPUSURL_OBJS}
+	-$(RANLIB) $@
+
 # opusfile_example
-${OPUSFILE_EXAMPLE_TARGET}: ${OPUSFILE_EXAMPLE_OBJS} ${LIBOPUSFILE_TARGET}
+${OPUSFILE_EXAMPLE_TARGET}: ${OPUSFILE_EXAMPLE_OBJS} ${LIBOPUSFILE_TARGET} \
+ ${LIBOPUSURL_TARGET}
 	mkdir -p ${TARGETBINDIR}
-	${CC} ${CFLAGS} ${OPUSFILE_EXAMPLE_OBJS} ${LIBOPUSFILE_TARGET} ${LIBS} \
-         -o $@
+	${CC} ${CFLAGS} ${OPUSFILE_EXAMPLE_OBJS} ${LIBOPUSFILE_TARGET} \
+         ${LIBOPUSURL_TARGET} ${LIBS} -o $@
 
 # seeking_example
-${SEEKING_EXAMPLE_TARGET}: ${SEEKING_EXAMPLE_OBJS} ${LIBOPUSFILE_TARGET}
+${SEEKING_EXAMPLE_TARGET}: ${SEEKING_EXAMPLE_OBJS} ${LIBOPUSFILE_TARGET} \
+ ${LIBOPUSURL_TARGET}
 	mkdir -p ${TARGETBINDIR}
-	${CC} ${CFLAGS} ${SEEKING_EXAMPLE_OBJS} ${LIBOPUSFILE_TARGET} ${LIBS} \
-         -o $@
+	${CC} ${CFLAGS} ${SEEKING_EXAMPLE_OBJS} ${LIBOPUSFILE_TARGET} \
+         ${LIBOPUSURL_TARGET} ${LIBS} -o $@
 
 #TODO:
 #tests: foo