On 2014-05-17, Sergey Bronnikov <este...@gmail.com> wrote:

> $ cat audio/opusfile/pkg/DESCR
> Opusfile provides application developers with a high-level API for
> decoding and seeking in .opus files.
>
> Tested on amd64, -current.

I had looked at porting opusfile earlier, but had hoped the ftime()
problem would go away.  Apparently not.  Sigh.

-static opus_int32 op_time_diff_ms(const struct timeb *_end,
- const struct timeb *_start){
+static opus_int32 op_time_diff_ms(const struct timeval *_end,
+ const struct timeval *_start){
   opus_int64 dtime;
-  dtime=_end->time-(opus_int64)_start->time;
-  OP_ASSERT(_end->millitm<1000);
-  OP_ASSERT(_start->millitm<1000);
-  if(OP_UNLIKELY(dtime>(OP_INT32_MAX-1000)/1000))return OP_INT32_MAX;
-  if(OP_UNLIKELY(dtime<(OP_INT32_MIN+1000)/1000))return OP_INT32_MIN;
-  return (opus_int32)dtime*1000+_end->millitm-_start->millitm;
+  dtime=(opus_int64)(_end->tv_usec-_start->tv_usec)/1000;
+  if(OP_UNLIKELY(dtime>OP_INT32_MAX))return OP_INT32_MAX;
+  if(OP_UNLIKELY(dtime<OP_INT32_MIN))return OP_INT32_MIN;
+  return (opus_int32)dtime;
 }

That's wrong.  You are losing the full seconds of the time difference.
How about this instead?

-static opus_int32 op_time_diff_ms(const struct timeb *_end,
- const struct timeb *_start){
+static opus_int32 op_time_diff_ms(const struct timeval *_end,
+ const struct timeval *_start){
   opus_int64 dtime;
-  dtime=_end->time-(opus_int64)_start->time;
-  OP_ASSERT(_end->millitm<1000);
-  OP_ASSERT(_start->millitm<1000);
-  if(OP_UNLIKELY(dtime>(OP_INT32_MAX-1000)/1000))return OP_INT32_MAX;
-  if(OP_UNLIKELY(dtime<(OP_INT32_MIN+1000)/1000))return OP_INT32_MIN;
-  return (opus_int32)dtime*1000+_end->millitm-_start->millitm;
+  dtime=_end->tv_sec-_start->tv_sec;
+  dtime=dtime*1000+(_end->tv_usec-_start->tv_usec)/1000;
+  if(OP_UNLIKELY(dtime>OP_INT32_MAX))return OP_INT32_MAX;
+  if(OP_UNLIKELY(dtime<OP_INT32_MIN))return OP_INT32_MIN;
+  return (opus_int32)dtime;
 }

I found an old WIP port of mine and sort of merged the two.  Diff
below.  Notable changes:
* Remove spurious SHARED_ONLY.
* Doesn't need gmake, and with --disable-maintainer-mode the autotools
  cascade doesn't trigger.
* Remove debug FLAVOR.
* Remove NO_TEST.  We only set this if there is no test target, not
  if there is an empty one.
* Add --enable-fixed-point on arm to be in sync with audio/opus.
  (That's just a guess.  I need the arm people to speak up about
  special casing fixed/floating point code on that platform.)

diff -uNr opusfile.orig/Makefile opusfile/Makefile
--- opusfile.orig/Makefile      Wed May 14 18:09:50 2014
+++ opusfile/Makefile   Thu May 22 20:00:41 2014
@@ -1,11 +1,9 @@
 # $OpenBSD $
 
-COMMENT =              encode, inspect, and decode Opus files
+COMMENT =              high-level decoding and seeking API for Opus files
 DISTNAME =             opusfile-0.5
 CATEGORIES =           audio
 
-SHARED_ONLY =          Yes
-
 SHARED_LIBS +=         opusfile                  0.0 # 3.0
 SHARED_LIBS +=         opusurl                   0.0 # 3.0
 
@@ -15,7 +13,7 @@
 # BSD
 PERMIT_PACKAGE_CDROM = Yes
 
-WANTLIB += crypto m ogg opus ssl
+WANTLIB =              crypto m ogg opus ssl
 
 MASTER_SITES =         http://downloads.xiph.org/releases/opus/ \
                        https://ftp.mozilla.org/pub/mozilla.org/opus/
@@ -24,17 +22,13 @@
                        audio/opus
 
 SEPARATE_BUILD =       Yes
-USE_GMAKE =            Yes
 CONFIGURE_STYLE =      gnu
-CONFIGURE_ARGS =       --disable-doc
+CONFIGURE_ARGS =       ${CONFIGURE_SHARED} \
+                       --disable-maintainer-mode
+CONFIGURE_ARGS +=      --disable-doc   # requires doxygen
 
-FLAVORS =              debug
-FLAVOR ?=
-
-.if ${FLAVOR:Mdebug}
-ALL_TARGET =           debug
+.if ${MACHINE_ARCH} == "arm"
+CONFIGURE_ARGS +=      --enable-fixed-point
 .endif
-
-NO_TEST =              Yes
 
 .include <bsd.port.mk>
diff -uNr opusfile.orig/patches/patch-src_http_c 
opusfile/patches/patch-src_http_c
--- opusfile.orig/patches/patch-src_http_c      Wed May  7 17:25:21 2014
+++ opusfile/patches/patch-src_http_c   Thu May 22 19:55:48 2014
@@ -1,10 +1,10 @@
 $OpenBSD$
 
-no struct timeb / ftime(3) support. libcompat is gone.
-replace with struct timeval / gettimeofday(2).
+No struct timeb / ftime(3) support; libcompat is gone.
+Replace with struct timeval / gettimeofday(2).
 
 --- src/http.c.orig    Thu Dec  5 17:49:13 2013
-+++ src/http.c Tue May  6 19:15:21 2014
++++ src/http.c Thu May 22 19:55:42 2014
 @@ -347,7 +347,7 @@ typedef int op_sock;
  #  define op_reset_errno() (errno=0)
  
@@ -32,7 +32,7 @@
    /*A buffer used to build HTTP requests.*/
    OpusStringBuf    request;
    /*A buffer used to build proxy CONNECT requests.*/
-@@ -992,26 +992,24 @@ static int op_http_conn_estimate_available(OpusHTTPCon
+@@ -992,26 +992,25 @@ static int op_http_conn_estimate_available(OpusHTTPCon
    return available;
  }
  
@@ -47,7 +47,8 @@
 -  if(OP_UNLIKELY(dtime>(OP_INT32_MAX-1000)/1000))return OP_INT32_MAX;
 -  if(OP_UNLIKELY(dtime<(OP_INT32_MIN+1000)/1000))return OP_INT32_MIN;
 -  return (opus_int32)dtime*1000+_end->millitm-_start->millitm;
-+  dtime=(opus_int64)(_end->tv_usec-_start->tv_usec)/1000;
++  dtime=_end->tv_sec-_start->tv_sec;
++  dtime=dtime*1000+(_end->tv_usec-_start->tv_usec)/1000;
 +  if(OP_UNLIKELY(dtime>OP_INT32_MAX))return OP_INT32_MAX;
 +  if(OP_UNLIKELY(dtime<OP_INT32_MIN))return OP_INT32_MIN;
 +  return (opus_int32)dtime;
@@ -67,7 +68,7 @@
    read_delta_ms=op_time_diff_ms(&read_time,&_conn->read_time);
    read_rate=_conn->read_rate;
    read_delta_ms=OP_MAX(read_delta_ms,1);
-@@ -1902,7 +1900,7 @@ static int op_sock_connect_next(op_sock _fd,
+@@ -1902,7 +1901,7 @@ static int op_sock_connect_next(op_sock _fd,
  # define OP_NPROTOS (2)
  
  static int op_http_connect_impl(OpusHTTPStream *_stream,OpusHTTPConn *_conn,
@@ -76,7 +77,7 @@
    const struct addrinfo *addr;
    const struct addrinfo *addrs[OP_NPROTOS];
    struct pollfd          fds[OP_NPROTOS];
-@@ -1932,7 +1930,7 @@ static int op_http_connect_impl(OpusHTTPStream *_strea
+@@ -1932,7 +1931,7 @@ static int op_http_connect_impl(OpusHTTPStream *_strea
    _stream->free_head=_conn->next;
    _conn->next=_stream->lru_head;
    _stream->lru_head=_conn;
@@ -85,7 +86,7 @@
    *&_conn->read_time=*_start_time;
    _conn->read_bytes=0;
    _conn->read_rate=0;
-@@ -2034,14 +2032,14 @@ static int op_http_connect_impl(OpusHTTPStream *_strea
+@@ -2034,14 +2033,14 @@ static int op_http_connect_impl(OpusHTTPStream *_strea
  }
  
  static int op_http_connect(OpusHTTPStream *_stream,OpusHTTPConn *_conn,
@@ -103,7 +104,7 @@
    if(_addrs!=&_stream->addr_info||op_time_diff_ms(&resolve_time,
     &_stream->resolve_time)>=OP_RESOLVE_CACHE_TIMEOUT_MS){
      new_addrs=op_resolve(_stream->connect_host,_stream->connect_port);
-@@ -2191,8 +2189,8 @@ static int op_http_stream_open(OpusHTTPStream *_stream
+@@ -2191,8 +2190,8 @@ static int op_http_stream_open(OpusHTTPStream *_stream
    addrs=NULL;
    for(nredirs=0;nredirs<OP_REDIRECT_LIMIT;nredirs++){
      OpusParsedURL  next_url;
@@ -114,7 +115,7 @@
      char          *next;
      char          *status_code;
      int            minor_version_pos;
-@@ -2321,7 +2319,7 @@ static int op_http_stream_open(OpusHTTPStream *_stream
+@@ -2321,7 +2320,7 @@ static int op_http_stream_open(OpusHTTPStream *_stream
      if(OP_UNLIKELY(ret<0))return ret;
      ret=op_http_conn_read_response(_stream->conns+0,&_stream->response);
      if(OP_UNLIKELY(ret<0))return ret;
@@ -123,7 +124,7 @@
      next=op_http_parse_status_line(&v1_1_compat,&status_code,
       _stream->response.buf);
      if(OP_UNLIKELY(next==NULL))return OP_FALSE;
-@@ -2733,18 +2731,18 @@ static int op_http_conn_handle_response(OpusHTTPStream
+@@ -2733,18 +2732,18 @@ static int op_http_conn_handle_response(OpusHTTPStream
                  converted into a request for the rest.*/
  static int op_http_conn_open_pos(OpusHTTPStream *_stream,
   OpusHTTPConn *_conn,opus_int64 _pos,opus_int32 _chunk_size){
@@ -148,7 +149,7 @@
    _stream->cur_conni=_conn-_stream->conns;
    OP_ASSERT(_stream->cur_conni>=0&&_stream->cur_conni<OP_NCONNS_MAX);
    /*The connection has been successfully opened.
-@@ -2996,7 +2994,7 @@ static int op_http_conn_read_ahead(OpusHTTPStream *_st
+@@ -2996,7 +2995,7 @@ static int op_http_conn_read_ahead(OpusHTTPStream *_st
  }
  
  static int op_http_stream_seek(void *_stream,opus_int64 _offset,int _whence){
@@ -157,7 +158,7 @@
    OpusHTTPStream  *stream;
    OpusHTTPConn    *conn;
    OpusHTTPConn   **pnext;
-@@ -3037,7 +3035,7 @@ static int op_http_stream_seek(void *_stream,opus_int6
+@@ -3037,7 +3036,7 @@ static int op_http_stream_seek(void *_stream,opus_int6
      op_http_conn_read_rate_update(stream->conns+ci);
      *&seek_time=*&stream->conns[ci].read_time;
    }
diff -uNr opusfile.orig/pkg/PLIST opusfile/pkg/PLIST
--- opusfile.orig/pkg/PLIST     Wed May 14 18:09:50 2014
+++ opusfile/pkg/PLIST  Thu May 22 16:35:11 2014
@@ -1,4 +1,5 @@
 @comment $OpenBSD$
+include/opus/
 include/opus/opusfile.h
 lib/libopusfile.a
 lib/libopusfile.la
@@ -6,6 +7,7 @@
 lib/libopusurl.a
 lib/libopusurl.la
 @lib lib/libopusurl.so.${LIBopusurl_VERSION}
+lib/pkgconfig/
 lib/pkgconfig/opusfile.pc
 lib/pkgconfig/opusurl.pc
 share/doc/opusfile/
-- 
Christian "naddy" Weisgerber                          na...@mips.inka.de

Reply via email to