ref: 21f7285015b06a6e4b10fd5fd09696f34995a352
parent: e2d7b266a0cbb09203d1d2fc547ebbd73e293fe6
author: Timothy B. Terriberry <[email protected]>
date: Sun Oct 21 14:09:59 EDT 2012
Fix a few minor nits. - The DIGIT character sets shouldn't need to list "0" twice. - Avoid a lookup for the port number in getaddrinfo(). - Resolve the OPUS_SET_GAIN TODO (by refusing to implement a fallback). - A few more minor things.
--- a/src/http.c
+++ b/src/http.c
@@ -70,8 +70,8 @@
/*URI character classes (from RFC 3986).*/
#define OP_URL_ALPHA \
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
-#define OP_URL_DIGIT "01234567890"
-#define OP_URL_HEXDIGIT "01234567890ABCDEFabcdef"
+#define OP_URL_DIGIT "0123456789"
+#define OP_URL_HEXDIGIT "0123456789ABCDEFabcdef"
/*Not a character class, but the characters allowed in <scheme>.*/
#define OP_URL_SCHEME OP_URL_ALPHA OP_URL_DIGIT "+-."
#define OP_URL_GEN_DELIMS "#/:?@[]"
@@ -573,6 +573,7 @@
char service[6];
memset(&hints,0,sizeof(hints));
hints.ai_socktype=SOCK_STREAM;
+ hints.ai_flags=AI_NUMERICSERV;
OP_ASSERT(_port<=65535U);
sprintf(service,"%u",_port);
if(OP_LIKELY(!getaddrinfo(_host,service,&hints,&addrs)))return addrs;
@@ -1042,7 +1043,7 @@
return OP_EIMPL;
}
-# define OP_HTTP_DIGIT "01234567890"
+# define OP_HTTP_DIGIT "0123456789"
/*The Reason-Phrase is not allowed to contain control characters, except
horizontal tab (HT: \011).*/
--- a/src/opusfile.c
+++ b/src/opusfile.c
@@ -54,16 +54,8 @@
area if we only want coarse navigation through the stream.
We implement and expose both strategies.*/
-/*Many, many internal helpers.
- The intention is not to be confusing.
- Rampant duplication and monolithic function implementation (though we do have
- some large, omnibus functions still) would be harder to understand anyway.
- The high level functions are last.
- Begin grokking near the end of the file if you prefer to read things
- top-down.*/
-
/*The maximum number of bytes in a page (including the page headers).*/
-#define OP_PAGE_SIZE (65307)
+#define OP_PAGE_SIZE_MAX (65307)
/*The default amount to seek backwards per step when trying to find the
previous page.
This must be at least as large as the maximum size of a page.*/
@@ -132,6 +124,14 @@
return err;
}
+/*Many, many internal helpers.
+ The intention is not to be confusing.
+ Rampant duplication and monolithic function implementation (though we do have
+ some large, omnibus functions still) would be harder to understand anyway.
+ The high level functions are last.
+ Begin grokking near the end of the file if you prefer to read things
+ top-down.*/
+
/*The read/seek functions track absolute position within the stream.*/
/*Read a little more data from the file/pipe into the ogg_sync framer.
@@ -301,7 +301,7 @@
do{
opus_int64 search_start;
int ret;
- OP_ASSERT(chunk_size>=OP_PAGE_SIZE);
+ OP_ASSERT(chunk_size>=OP_PAGE_SIZE_MAX);
begin=OP_MAX(begin-chunk_size,0);
ret=op_seek_helper(_of,begin);
if(OP_UNLIKELY(ret<0))return ret;
@@ -320,7 +320,7 @@
_sr->offset=_offset=llret;
_sr->serialno=serialno;
OP_ASSERT(_of->offset-_offset>=0);
- OP_ASSERT(_of->offset-_offset<=OP_PAGE_SIZE);
+ OP_ASSERT(_of->offset-_offset<=OP_PAGE_SIZE_MAX);
_sr->size=(opus_int32)(_of->offset-_offset);
_sr->gp=ogg_page_granulepos(&og);
/*If this page is from the stream we're looking for, remember it.*/
@@ -344,7 +344,7 @@
This is mildly helpful when seeks are very expensive (http).*/
chunk_size=OP_MIN(2*chunk_size,OP_CHUNK_SIZE_MAX);
/*Avoid quadratic complexity if we hit an invalid patch of the file.*/
- end=OP_MIN(begin+OP_PAGE_SIZE-1,original_end);
+ end=OP_MIN(begin+OP_PAGE_SIZE_MAX-1,original_end);
}
while(_offset<0);
if(_chunk_size!=NULL)*_chunk_size=chunk_size;
@@ -951,11 +951,11 @@
offset1=_sr[sri].offset;
serialno1=_sr[sri].serialno;
for(srj=sri;srj-->0;){
- ogg_int64_t gp2;
- opus_int64 offset2;
- opus_int64 num;
- ogg_int64_t den;
- ogg_int64_t ipart;
+ ogg_int64_t gp2;
+ opus_int64 offset2;
+ opus_int64 num;
+ ogg_int64_t den;
+ ogg_int64_t ipart;
gp2=_sr[srj].gp;
if(gp2<gp2_min)continue;
/*Oh, and also make sure these came from the same stream.*/
@@ -1088,7 +1088,7 @@
_sr[nsr].search_start=bisect;
_sr[nsr].offset=last;
OP_ASSERT(_of->offset-last>=0);
- OP_ASSERT(_of->offset-last<=OP_PAGE_SIZE);
+ OP_ASSERT(_of->offset-last<=OP_PAGE_SIZE_MAX);
_sr[nsr].size=(opus_int32)(_of->offset-last);
nsr++;
}
@@ -1197,10 +1197,13 @@
_of->od_channel_count=channel_count;
memcpy(_of->od_mapping,head->mapping,sizeof(*head->mapping)*channel_count);
}
- /*TODO: Implement this when not available, or require sufficiently new
- libopus?*/
#if defined(OPUS_SET_GAIN)
opus_multistream_decoder_ctl(_of->od,OPUS_SET_GAIN(head->output_gain));
+#else
+/*A fallback that works with both float and fixed-point is a bunch of work,
+ so just force people to use a sufficiently new version.
+ This is deployed well enough at this point that this shouldn't be a burden.*/
+# error "libopus 1.0.1 or later required"
#endif
_of->ready_state=OP_INITSET;
_of->bytes_tracked=0;