shithub: opusfile

Download patch

ref: 6f482ef4154113291c7bc55a51fe20193676879e
parent: 933157f174ed5c7313b583bf9352c3fc28d57ba9
author: Timothy B. Terriberry <tterribe@xiph.org>
date: Wed Mar 26 12:44:28 EDT 2014

Minor cleanups.

Makes style slightly more consistent.
Also fixes the return code of op_fetch_headers() to make it
 consistently return OP_EBADHEADER if the stream runs out of pages
 after a valid OpusHead packet is found.
Previously, if a valid OpusHead was found, it would return
 OP_ENOTFORMAT if it ran out of pages before finding one without
 its BOS flag set, and OP_EBADHEADER if it ran out of pages after
 finding one without its BOS flag set.

--- a/src/opusfile.c
+++ b/src/opusfile.c
@@ -156,8 +156,8 @@
 /*Save a tiny smidge of verbosity to make the code more readable.*/
 static int op_seek_helper(OggOpusFile *_of,opus_int64 _offset){
   if(_offset==_of->offset)return 0;
-  if(_of->callbacks.seek==NULL||
-   (*_of->callbacks.seek)(_of->source,_offset,SEEK_SET)){
+  if(_of->callbacks.seek==NULL
+   ||(*_of->callbacks.seek)(_of->source,_offset,SEEK_SET)){
     return OP_EREAD;
   }
   _of->offset=_offset;
@@ -496,22 +496,20 @@
       ogg_stream_pagein(&_of->os,_og);
       if(OP_LIKELY(ogg_stream_packetout(&_of->os,&op)>0)){
         ret=opus_head_parse(_head,op.packet,op.bytes);
-        if(OP_UNLIKELY(ret<0)){
-          /*If it's just a stream type we don't recognize, ignore it.
-            Everything else is fatal.*/
-          if(ret!=OP_ENOTFORMAT)return ret;
-        }
         /*Found a valid Opus header.
           Continue setup.*/
-        else _of->ready_state=OP_STREAMSET;
+        if(OP_LIKELY(ret>=0))_of->ready_state=OP_STREAMSET;
+        /*If it's just a stream type we don't recognize, ignore it.
+          Everything else is fatal.*/
+        else if(ret!=OP_ENOTFORMAT)return ret;
       }
     }
     /*Get the next page.
       No need to clamp the boundary offset against _of->end, as all errors
-       become OP_ENOTFORMAT.*/
+       become OP_ENOTFORMAT or OP_EBADHEADER.*/
     if(OP_UNLIKELY(op_get_next_page(_of,_og,
      OP_ADV_OFFSET(_of->offset,OP_CHUNK_SIZE))<0)){
-      return OP_ENOTFORMAT;
+      return _of->ready_state<OP_STREAMSET?OP_ENOTFORMAT:OP_EBADHEADER;
     }
   }
   if(OP_UNLIKELY(_of->ready_state!=OP_STREAMSET))return OP_ENOTFORMAT;